From 9972d2c18a4b1bf71f70f1a29a002598f806d8ee Mon Sep 17 00:00:00 2001 From: Deep Vora Date: Mon, 22 Jul 2024 17:33:55 -0500 Subject: [PATCH] chore: [wgpu-tests] use concrete error messages for failures resolves #5727 --- tests/tests/bind_group_layout_dedup.rs | 4 +- tests/tests/buffer.rs | 4 +- tests/tests/buffer_copy.rs | 57 ++++++++++++++++++++------ tests/tests/device.rs | 40 +++++++++--------- tests/tests/encoder.rs | 2 +- tests/tests/float32_filterable.rs | 2 +- tests/tests/life_cycle.rs | 4 +- tests/tests/nv12_texture/mod.rs | 8 ++-- tests/tests/queue_transfer.rs | 2 +- tests/tests/resource_error.rs | 28 ++++++++++--- tests/tests/transfer.rs | 2 +- 11 files changed, 101 insertions(+), 52 deletions(-) diff --git a/tests/tests/bind_group_layout_dedup.rs b/tests/tests/bind_group_layout_dedup.rs index 591f4f905..32f71b89d 100644 --- a/tests/tests/bind_group_layout_dedup.rs +++ b/tests/tests/bind_group_layout_dedup.rs @@ -373,7 +373,7 @@ fn separate_pipelines_have_incompatible_derived_bgls(ctx: TestingContext) { || { drop(pass); }, - None, + Some("label at index 0 is not compatible with the corresponding bindgrouplayout"), ); } @@ -445,7 +445,7 @@ fn derived_bgls_incompatible_with_regular_bgls(ctx: TestingContext) { || { drop(pass); }, - None, + Some("label at index 0 is not compatible with the corresponding bindgrouplayout"), ) } diff --git a/tests/tests/buffer.rs b/tests/tests/buffer.rs index 77bc9e064..80bb4b0c5 100644 --- a/tests/tests/buffer.rs +++ b/tests/tests/buffer.rs @@ -230,7 +230,7 @@ static MINIMUM_BUFFER_BINDING_SIZE_LAYOUT: GpuTestConfiguration = GpuTestConfigu cache: None, }); }, - None, + Some("shader global resourcebinding { group: 0, binding: 0 } is not available in the pipeline layout"), ); }); @@ -335,7 +335,7 @@ static MINIMUM_BUFFER_BINDING_SIZE_DISPATCH: GpuTestConfiguration = GpuTestConfi drop(pass); let _ = encoder.finish(); }, - None, + Some("buffer is bound with size 16 where the shader expects 32 in group[0] compact index 0"), ); }); diff --git a/tests/tests/buffer_copy.rs b/tests/tests/buffer_copy.rs index 698097f1b..a7e9eff8c 100644 --- a/tests/tests/buffer_copy.rs +++ b/tests/tests/buffer_copy.rs @@ -8,31 +8,62 @@ fn try_copy( ctx: &wgpu_test::TestingContext, offset: BufferAddress, size: BufferAddress, - should_fail: bool, + error_message: Option<&'static str>, ) { let buffer = ctx.device.create_buffer(&BUFFER_DESCRIPTOR); let data = vec![255; size as usize]; + fail_if( &ctx.device, - should_fail, + error_message.is_some(), || ctx.queue.write_buffer(&buffer, offset, &data), - None, + error_message, ); } #[gpu_test] static COPY_ALIGNMENT: GpuTestConfiguration = GpuTestConfiguration::new().run_sync(|ctx| { - try_copy(&ctx, 0, 0, false); - try_copy(&ctx, 4, 16 + 1, true); - try_copy(&ctx, 64, 20 + 2, true); - try_copy(&ctx, 256, 44 + 3, true); - try_copy(&ctx, 1024, 8 + 4, false); + try_copy(&ctx, 0, 0, None); + try_copy( + &ctx, + 4, + 16 + 1, + Some("copy size 17 does not respect `copy_buffer_alignment`"), + ); + try_copy( + &ctx, + 64, + 20 + 2, + Some("copy size 22 does not respect `copy_buffer_alignment`"), + ); + try_copy( + &ctx, + 256, + 44 + 3, + Some("copy size 47 does not respect `copy_buffer_alignment`"), + ); + try_copy(&ctx, 1024, 8 + 4, None); - try_copy(&ctx, 0, 4, false); - try_copy(&ctx, 4 + 1, 8, true); - try_copy(&ctx, 64 + 2, 12, true); - try_copy(&ctx, 256 + 3, 16, true); - try_copy(&ctx, 1024 + 4, 4, false); + try_copy(&ctx, 0, 4, None); + try_copy( + &ctx, + 4 + 1, + 8, + Some("buffer offset 5 is not aligned to block size or `copy_buffer_alignment`"), + ); + try_copy( + &ctx, + 64 + 2, + 12, + Some("buffer offset 66 is not aligned to block size or `copy_buffer_alignment`"), + ); + try_copy( + &ctx, + 256 + 3, + 16, + Some("buffer offset 259 is not aligned to block size or `copy_buffer_alignment`"), + ); + try_copy(&ctx, 1024 + 4, 4, None); }); const BUFFER_SIZE: BufferAddress = 1234; diff --git a/tests/tests/device.rs b/tests/tests/device.rs index d629f1b8e..4a636289b 100644 --- a/tests/tests/device.rs +++ b/tests/tests/device.rs @@ -298,7 +298,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne ctx.device .create_command_encoder(&wgpu::CommandEncoderDescriptor::default()); }, - None, + Some("device with '' label is invalid"), ); // Creating a buffer should fail. @@ -312,7 +312,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne mapped_at_creation: false, }); }, - None, + Some("device with '' label is invalid"), ); // Creating a texture should fail. @@ -334,7 +334,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne view_formats: &[], }); }, - None, + Some("device with '' label is invalid"), ); // Texture clear should fail. @@ -352,7 +352,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne }, ); }, - None, + Some("device with '' label is invalid"), ); // Creating a compute pass should fail. @@ -364,7 +364,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne timestamp_writes: None, }); }, - None, + Some("device with '' label is invalid"), ); // Creating a render pass should fail. @@ -383,7 +383,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne occlusion_query_set: None, }); }, - None, + Some("device with '' label is invalid"), ); // Copying a buffer to a buffer should fail. @@ -398,7 +398,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne 256, ); }, - None, + Some("device with '' label is invalid"), ); // Copying a buffer to a texture should fail. @@ -418,7 +418,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne texture_extent, ); }, - None, + Some("device with '' label is invalid"), ); // Copying a texture to a buffer should fail. @@ -438,7 +438,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne texture_extent, ); }, - None, + Some("device with '' label is invalid"), ); // Copying a texture to a texture should fail. @@ -451,7 +451,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne texture_extent, ); }, - None, + Some("device with '' label is invalid"), ); // Creating a bind group layout should fail. @@ -464,7 +464,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne entries: &[], }); }, - None, + Some("device with '' label is invalid"), ); // Creating a bind group should fail. @@ -482,7 +482,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne }], }); }, - None, + Some("device with '' label is invalid"), ); // Creating a pipeline layout should fail. @@ -496,7 +496,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne push_constant_ranges: &[], }); }, - None, + Some("device with '' label is invalid"), ); // Creating a shader module should fail. @@ -509,7 +509,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed("")), }); }, - None, + Some("device with '' label is invalid"), ); // Creating a shader module spirv should fail. @@ -522,7 +522,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne source: std::borrow::Cow::Borrowed(&[]), }); }, - None, + Some("device with '' label is invalid"), ); // Creating a render pipeline should fail. @@ -547,7 +547,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne cache: None, }); }, - None, + Some("device with '' label is invalid"), ); // Creating a compute pipeline should fail. @@ -564,7 +564,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne cache: None, }); }, - None, + Some("device with '' label is invalid"), ); // Creating a compute pipeline should fail. @@ -581,7 +581,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne cache: None, }); }, - None, + Some("device with '' label is invalid"), ); // Buffer map should fail. @@ -592,7 +592,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne .slice(..) .map_async(wgpu::MapMode::Write, |_| ()); }, - None, + Some("device with '' label is invalid"), ); // Buffer unmap should fail. @@ -601,7 +601,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne || { buffer_for_unmap.unmap(); }, - None, + Some("device with '' label is invalid"), ); }); diff --git a/tests/tests/encoder.rs b/tests/tests/encoder.rs index e4755dcd7..0be5efb90 100644 --- a/tests/tests/encoder.rs +++ b/tests/tests/encoder.rs @@ -68,7 +68,7 @@ static DROP_ENCODER_AFTER_ERROR: GpuTestConfiguration = GpuTestConfiguration::ne renderpass.set_viewport(0.0, 0.0, -1.0, -1.0, 0.0, 1.0); drop(renderpass); }, - None, + Some("viewport has invalid rect"), ); // This is the actual interesting error condition. We've created diff --git a/tests/tests/float32_filterable.rs b/tests/tests/float32_filterable.rs index ee288ac79..cc1ccd5a2 100644 --- a/tests/tests/float32_filterable.rs +++ b/tests/tests/float32_filterable.rs @@ -63,7 +63,7 @@ static FLOAT32_FILTERABLE_WITHOUT_FEATURE: GpuTestConfiguration = GpuTestConfigu || { create_texture_binding(device, wgpu::TextureFormat::R32Float, true); }, - None, + Some("texture binding 0 expects sample type = float { filterable: true }, but given a view with format = r32float"), ); }); diff --git a/tests/tests/life_cycle.rs b/tests/tests/life_cycle.rs index e959743a5..d8d21940c 100644 --- a/tests/tests/life_cycle.rs +++ b/tests/tests/life_cycle.rs @@ -4,7 +4,7 @@ use wgpu_test::{fail, gpu_test, GpuTestConfiguration}; static BUFFER_DESTROY: GpuTestConfiguration = GpuTestConfiguration::new().run_async(|ctx| async move { let buffer = ctx.device.create_buffer(&wgpu::BufferDescriptor { - label: None, + label: Some("buffer"), size: 256, usage: wgpu::BufferUsages::MAP_WRITE | wgpu::BufferUsages::COPY_SRC, mapped_at_creation: false, @@ -25,7 +25,7 @@ static BUFFER_DESTROY: GpuTestConfiguration = .slice(..) .map_async(wgpu::MapMode::Write, move |_| {}); }, - None, + Some("buffer with 'buffer' label has been destroyed"), ); buffer.destroy(); diff --git a/tests/tests/nv12_texture/mod.rs b/tests/tests/nv12_texture/mod.rs index 2f149d014..6ded163a3 100644 --- a/tests/tests/nv12_texture/mod.rs +++ b/tests/tests/nv12_texture/mod.rs @@ -149,7 +149,7 @@ static NV12_TEXTURE_VIEW_PLANE_ON_NON_PLANAR_FORMAT: GpuTestConfiguration = ..Default::default() }); }, - None, + Some("aspect plane0 is not in the source texture format r8unorm"), ); }); @@ -181,7 +181,7 @@ static NV12_TEXTURE_VIEW_PLANE_OUT_OF_BOUNDS: GpuTestConfiguration = GpuTestConf ..Default::default() }); }, - None, + Some("aspect plane2 is not in the source texture format nv12"), ); }); @@ -213,7 +213,7 @@ static NV12_TEXTURE_BAD_FORMAT_VIEW_PLANE: GpuTestConfiguration = GpuTestConfigu ..Default::default() }); }, - None, + Some("unable to view texture nv12 as rg8unorm"), ); }); @@ -241,6 +241,6 @@ static NV12_TEXTURE_BAD_SIZE: GpuTestConfiguration = GpuTestConfiguration::new() view_formats: &[], }); }, - None, + Some("width 255 is not a multiple of nv12's width multiple requirement"), ); }); diff --git a/tests/tests/queue_transfer.rs b/tests/tests/queue_transfer.rs index 79a79e0ec..6f816374c 100644 --- a/tests/tests/queue_transfer.rs +++ b/tests/tests/queue_transfer.rs @@ -46,6 +46,6 @@ static QUEUE_WRITE_TEXTURE_OVERFLOW: GpuTestConfiguration = }, ); }, - None, + Some("end up overrunning the bounds of the destination texture"), ); }); diff --git a/tests/tests/resource_error.rs b/tests/tests/resource_error.rs index 98b55044a..fc7e062f4 100644 --- a/tests/tests/resource_error.rs +++ b/tests/tests/resource_error.rs @@ -14,15 +14,24 @@ static BAD_BUFFER: GpuTestConfiguration = GpuTestConfiguration::new().run_sync(| mapped_at_creation: false, }) }, - None, + Some("`map` usage can only be combined with the opposite `copy`"), ); + let error = match ctx.adapter_info.backend.to_str() { + "vulkan" | "vk" => "bufferid id(0,1,vk) is invalid", + "dx12" | "d3d12" => "bufferid id(0,1,d3d12) is invalid", + "metal" | "mtl" => "bufferid id(0,1,mtl) is invalid", + "opengl" | "gles" | "gl" => "bufferid id(0,1,gl) is invalid", + "webgpu" => "bufferid id(0,1,webgpu) is invalid", + b => b, + }; + fail( &ctx.device, || buffer.slice(..).map_async(wgpu::MapMode::Write, |_| {}), - None, + Some(error), ); - fail(&ctx.device, || buffer.unmap(), None); + fail(&ctx.device, || buffer.unmap(), Some(error)); valid(&ctx.device, || buffer.destroy()); valid(&ctx.device, || buffer.destroy()); }); @@ -47,15 +56,24 @@ static BAD_TEXTURE: GpuTestConfiguration = GpuTestConfiguration::new().run_sync( view_formats: &[], }) }, - None, + Some("dimension x is zero"), ); + let error = match ctx.adapter_info.backend.to_str() { + "vulkan" | "vk" => "textureid id(0,1,vk) is invalid", + "dx12" | "d3d12" => "textureid id(0,1,d3d12) is invalid", + "metal" | "mtl" => "textureid id(0,1,mtl) is invalid", + "opengl" | "gles" | "gl" => "textureid id(0,1,gl) is invalid", + "webgpu" => "textureid id(0,1,webgpu) is invalid", + b => b, + }; + fail( &ctx.device, || { let _ = texture.create_view(&wgpu::TextureViewDescriptor::default()); }, - None, + Some(error), ); valid(&ctx.device, || texture.destroy()); valid(&ctx.device, || texture.destroy()); diff --git a/tests/tests/transfer.rs b/tests/tests/transfer.rs index e69f97559..3408fe2e8 100644 --- a/tests/tests/transfer.rs +++ b/tests/tests/transfer.rs @@ -64,6 +64,6 @@ static COPY_OVERFLOW_Z: GpuTestConfiguration = GpuTestConfiguration::new().run_s ); ctx.queue.submit(Some(encoder.finish())); }, - None, + Some("unable to select texture mip level"), ); });