From 2afb2ded7e025afa7ba3963d07db92ece9f29941 Mon Sep 17 00:00:00 2001 From: Frank Yellin Date: Fri, 15 Nov 2024 11:54:07 -0800 Subject: [PATCH] Change so that there is only one --- tests/tests/push_constants.rs | 104 ++++++++++++++++------------------ 1 file changed, 48 insertions(+), 56 deletions(-) diff --git a/tests/tests/push_constants.rs b/tests/tests/push_constants.rs index da9e2ae8eb..819534e8ba 100644 --- a/tests/tests/push_constants.rs +++ b/tests/tests/push_constants.rs @@ -25,34 +25,6 @@ static PARTIAL_UPDATE: GpuTestConfiguration = GpuTestConfiguration::new() ) .run_async(partial_update_test); -#[gpu_test] -static RENDER_PASS_TEST: GpuTestConfiguration = GpuTestConfiguration::new() - .parameters( - TestParameters::default() - // On Vulkan, we get a strange internal error that makes no sense. - .skip(FailureCase::backend(wgpu::Backends::VULKAN )) - .features(wgpu::Features::PUSH_CONSTANTS) - .limits(wgpu::Limits { - max_push_constant_size: 64, - ..Default::default() - }), - ) - .run_async(|ctx| render_pass_test(ctx, false)); - -#[gpu_test] -static RENDER_BUNDLE_TEST: GpuTestConfiguration = GpuTestConfiguration::new() - .parameters( - TestParameters::default() - // On Vulkan, we get a strange internal error that makes no sense. - .skip(FailureCase::backend(wgpu::Backends::VULKAN )) - .features(Features::PUSH_CONSTANTS) - .limits(Limits { - max_push_constant_size: 64, - ..Default::default() - }), - ) - .run_async(|ctx| render_pass_test(ctx, true)); - const SHADER: &str = r#" struct Pc { offset: u32, @@ -185,8 +157,34 @@ async fn partial_update_test(ctx: TestingContext) { // second 4 floats the first update assert_eq!(floats, [1.0, 2.0, 3.0, 4.0, 1.0, 5.0, 3.0, 4.0]); } +#[gpu_test] +static RENDER_PASS_TEST: GpuTestConfiguration = GpuTestConfiguration::new() + .parameters( + TestParameters::default() + // On Vulkan, we get a strange internal error that makes no sense. + // .skip(FailureCase::backend(wgpu::Backends::VULKAN )) + .features(wgpu::Features::PUSH_CONSTANTS) + .limits(wgpu::Limits { + max_push_constant_size: 128, + ..Default::default() + }), + ) + .run_async(|ctx| render_pass_test(ctx, false)); + +#[gpu_test] +static RENDER_BUNDLE_TEST: GpuTestConfiguration = GpuTestConfiguration::new() + .parameters( + TestParameters::default() + // On Vulkan, we get a strange internal error that makes no sense. + // .skip(FailureCase::backend(wgpu::Backends::VULKAN )) + .features(Features::PUSH_CONSTANTS) + .limits(Limits { + max_push_constant_size: 128, + ..Default::default() + }), + ) + .run_async(|ctx| render_pass_test(ctx, true)); -// // This shader subtracts the values in the second half of the push_constants from the // values in the first half, and stores the result in the buffer. // We test push constants in both the vertex shader and the fragment shader. @@ -291,16 +289,10 @@ async fn render_pass_test(ctx: TestingContext, use_render_bundle: bool) { .device .create_pipeline_layout(&PipelineLayoutDescriptor { bind_group_layouts: &[&bind_group_layout], - push_constant_ranges: &[ - PushConstantRange { - stages: ShaderStages::VERTEX, - range: 0..(4 * count), - }, - PushConstantRange { - stages: ShaderStages::FRAGMENT, - range: (4 * count)..(8 * count), - }, - ], + push_constant_ranges: &[PushConstantRange { + stages: ShaderStages::VERTEX_FRAGMENT, + range: 0..(8 * count), + }], ..Default::default() }); @@ -353,23 +345,29 @@ async fn render_pass_test(ctx: TestingContext, use_render_bundle: bool) { }], }); - let data1: Vec = (0..count).map(|i| (i as i32) * (i as i32) + 100).collect(); - let data2: Vec = (0..count).map(|i| (i as i32) * 200 - 1).collect(); + let data1: Vec = (0..count).map(|i| (i * i) as i32).collect(); + let data2: Vec = (0..count) + .map(|i| { + let i = i as i32; + (i - 5) * (i - 5) + }) + .collect(); let expected_result: Vec = zip(&data1, &data2).map(|(a, b)| a - b).collect(); + let data = data1 + .into_iter() + .chain(data2.into_iter()) + .collect::>(); fn do_encoding<'a>( encoder: &mut dyn RenderEncoder<'a>, pipeline: &'a RenderPipeline, bind_group: &'a BindGroup, - data1: Vec, - data2: Vec, + data: Vec, ) { - let count = data1.len() as u32; - let data1_as_u8: &[u8] = bytemuck::cast_slice(data1.as_slice()); - let data2_as_u8: &[u8] = bytemuck::cast_slice(data2.as_slice()); + let count = (data.len() as u32) / 2; + let data_as_u8: &[u8] = bytemuck::cast_slice(data.as_slice()); encoder.set_pipeline(pipeline); - encoder.set_push_constants(ShaderStages::VERTEX, 0, data1_as_u8); - encoder.set_push_constants(ShaderStages::FRAGMENT, 4 * count, data2_as_u8); + encoder.set_push_constants(ShaderStages::VERTEX_FRAGMENT, 0, data_as_u8); encoder.set_bind_group(0, Some(bind_group), &[]); encoder.draw(0..count, 0..1); } @@ -388,18 +386,12 @@ async fn render_pass_test(ctx: TestingContext, use_render_bundle: bool) { sample_count: 1, ..RenderBundleEncoderDescriptor::default() }); - do_encoding( - &mut render_bundle_encoder, - &pipeline, - &bind_group, - data1, - data2, - ); + do_encoding(&mut render_bundle_encoder, &pipeline, &bind_group, data); let render_bundle = render_bundle_encoder.finish(&RenderBundleDescriptor::default()); render_pass.execute_bundles([&render_bundle]); } else { // Execute the commands directly. - do_encoding(&mut render_pass, &pipeline, &bind_group, data1, data2); + do_encoding(&mut render_pass, &pipeline, &bind_group, data); } } // Move the result to the cpu buffer, so that we can read them.