chore: [wgpu-tests] use concrete error messages for failures

resolves #5727
This commit is contained in:
Deep Vora 2024-07-22 17:33:55 -05:00 committed by Erich Gubler
parent abc56417bb
commit 9972d2c18a
11 changed files with 101 additions and 52 deletions

View File

@ -373,7 +373,7 @@ fn separate_pipelines_have_incompatible_derived_bgls(ctx: TestingContext) {
|| { || {
drop(pass); 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); drop(pass);
}, },
None, Some("label at index 0 is not compatible with the corresponding bindgrouplayout"),
) )
} }

View File

@ -230,7 +230,7 @@ static MINIMUM_BUFFER_BINDING_SIZE_LAYOUT: GpuTestConfiguration = GpuTestConfigu
cache: None, 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); drop(pass);
let _ = encoder.finish(); let _ = encoder.finish();
}, },
None, Some("buffer is bound with size 16 where the shader expects 32 in group[0] compact index 0"),
); );
}); });

View File

@ -8,31 +8,62 @@ fn try_copy(
ctx: &wgpu_test::TestingContext, ctx: &wgpu_test::TestingContext,
offset: BufferAddress, offset: BufferAddress,
size: BufferAddress, size: BufferAddress,
should_fail: bool, error_message: Option<&'static str>,
) { ) {
let buffer = ctx.device.create_buffer(&BUFFER_DESCRIPTOR); let buffer = ctx.device.create_buffer(&BUFFER_DESCRIPTOR);
let data = vec![255; size as usize]; let data = vec![255; size as usize];
fail_if( fail_if(
&ctx.device, &ctx.device,
should_fail, error_message.is_some(),
|| ctx.queue.write_buffer(&buffer, offset, &data), || ctx.queue.write_buffer(&buffer, offset, &data),
None, error_message,
); );
} }
#[gpu_test] #[gpu_test]
static COPY_ALIGNMENT: GpuTestConfiguration = GpuTestConfiguration::new().run_sync(|ctx| { static COPY_ALIGNMENT: GpuTestConfiguration = GpuTestConfiguration::new().run_sync(|ctx| {
try_copy(&ctx, 0, 0, false); try_copy(&ctx, 0, 0, None);
try_copy(&ctx, 4, 16 + 1, true); try_copy(
try_copy(&ctx, 64, 20 + 2, true); &ctx,
try_copy(&ctx, 256, 44 + 3, true); 4,
try_copy(&ctx, 1024, 8 + 4, false); 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, 0, 4, None);
try_copy(&ctx, 4 + 1, 8, true); try_copy(
try_copy(&ctx, 64 + 2, 12, true); &ctx,
try_copy(&ctx, 256 + 3, 16, true); 4 + 1,
try_copy(&ctx, 1024 + 4, 4, false); 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; const BUFFER_SIZE: BufferAddress = 1234;

View File

@ -298,7 +298,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
ctx.device ctx.device
.create_command_encoder(&wgpu::CommandEncoderDescriptor::default()); .create_command_encoder(&wgpu::CommandEncoderDescriptor::default());
}, },
None, Some("device with '' label is invalid"),
); );
// Creating a buffer should fail. // Creating a buffer should fail.
@ -312,7 +312,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
mapped_at_creation: false, mapped_at_creation: false,
}); });
}, },
None, Some("device with '' label is invalid"),
); );
// Creating a texture should fail. // Creating a texture should fail.
@ -334,7 +334,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
view_formats: &[], view_formats: &[],
}); });
}, },
None, Some("device with '' label is invalid"),
); );
// Texture clear should fail. // 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. // Creating a compute pass should fail.
@ -364,7 +364,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
timestamp_writes: None, timestamp_writes: None,
}); });
}, },
None, Some("device with '' label is invalid"),
); );
// Creating a render pass should fail. // Creating a render pass should fail.
@ -383,7 +383,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
occlusion_query_set: None, occlusion_query_set: None,
}); });
}, },
None, Some("device with '' label is invalid"),
); );
// Copying a buffer to a buffer should fail. // Copying a buffer to a buffer should fail.
@ -398,7 +398,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
256, 256,
); );
}, },
None, Some("device with '' label is invalid"),
); );
// Copying a buffer to a texture should fail. // Copying a buffer to a texture should fail.
@ -418,7 +418,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
texture_extent, texture_extent,
); );
}, },
None, Some("device with '' label is invalid"),
); );
// Copying a texture to a buffer should fail. // Copying a texture to a buffer should fail.
@ -438,7 +438,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
texture_extent, texture_extent,
); );
}, },
None, Some("device with '' label is invalid"),
); );
// Copying a texture to a texture should fail. // Copying a texture to a texture should fail.
@ -451,7 +451,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
texture_extent, texture_extent,
); );
}, },
None, Some("device with '' label is invalid"),
); );
// Creating a bind group layout should fail. // Creating a bind group layout should fail.
@ -464,7 +464,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
entries: &[], entries: &[],
}); });
}, },
None, Some("device with '' label is invalid"),
); );
// Creating a bind group should fail. // 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. // Creating a pipeline layout should fail.
@ -496,7 +496,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
push_constant_ranges: &[], push_constant_ranges: &[],
}); });
}, },
None, Some("device with '' label is invalid"),
); );
// Creating a shader module should fail. // 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("")), source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed("")),
}); });
}, },
None, Some("device with '' label is invalid"),
); );
// Creating a shader module spirv should fail. // Creating a shader module spirv should fail.
@ -522,7 +522,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
source: std::borrow::Cow::Borrowed(&[]), source: std::borrow::Cow::Borrowed(&[]),
}); });
}, },
None, Some("device with '' label is invalid"),
); );
// Creating a render pipeline should fail. // Creating a render pipeline should fail.
@ -547,7 +547,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
cache: None, cache: None,
}); });
}, },
None, Some("device with '' label is invalid"),
); );
// Creating a compute pipeline should fail. // Creating a compute pipeline should fail.
@ -564,7 +564,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
cache: None, cache: None,
}); });
}, },
None, Some("device with '' label is invalid"),
); );
// Creating a compute pipeline should fail. // Creating a compute pipeline should fail.
@ -581,7 +581,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
cache: None, cache: None,
}); });
}, },
None, Some("device with '' label is invalid"),
); );
// Buffer map should fail. // Buffer map should fail.
@ -592,7 +592,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
.slice(..) .slice(..)
.map_async(wgpu::MapMode::Write, |_| ()); .map_async(wgpu::MapMode::Write, |_| ());
}, },
None, Some("device with '' label is invalid"),
); );
// Buffer unmap should fail. // Buffer unmap should fail.
@ -601,7 +601,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
|| { || {
buffer_for_unmap.unmap(); buffer_for_unmap.unmap();
}, },
None, Some("device with '' label is invalid"),
); );
}); });

View File

@ -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); renderpass.set_viewport(0.0, 0.0, -1.0, -1.0, 0.0, 1.0);
drop(renderpass); drop(renderpass);
}, },
None, Some("viewport has invalid rect"),
); );
// This is the actual interesting error condition. We've created // This is the actual interesting error condition. We've created

View File

@ -63,7 +63,7 @@ static FLOAT32_FILTERABLE_WITHOUT_FEATURE: GpuTestConfiguration = GpuTestConfigu
|| { || {
create_texture_binding(device, wgpu::TextureFormat::R32Float, true); 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"),
); );
}); });

View File

@ -4,7 +4,7 @@ use wgpu_test::{fail, gpu_test, GpuTestConfiguration};
static BUFFER_DESTROY: GpuTestConfiguration = static BUFFER_DESTROY: GpuTestConfiguration =
GpuTestConfiguration::new().run_async(|ctx| async move { GpuTestConfiguration::new().run_async(|ctx| async move {
let buffer = ctx.device.create_buffer(&wgpu::BufferDescriptor { let buffer = ctx.device.create_buffer(&wgpu::BufferDescriptor {
label: None, label: Some("buffer"),
size: 256, size: 256,
usage: wgpu::BufferUsages::MAP_WRITE | wgpu::BufferUsages::COPY_SRC, usage: wgpu::BufferUsages::MAP_WRITE | wgpu::BufferUsages::COPY_SRC,
mapped_at_creation: false, mapped_at_creation: false,
@ -25,7 +25,7 @@ static BUFFER_DESTROY: GpuTestConfiguration =
.slice(..) .slice(..)
.map_async(wgpu::MapMode::Write, move |_| {}); .map_async(wgpu::MapMode::Write, move |_| {});
}, },
None, Some("buffer with 'buffer' label has been destroyed"),
); );
buffer.destroy(); buffer.destroy();

View File

@ -149,7 +149,7 @@ static NV12_TEXTURE_VIEW_PLANE_ON_NON_PLANAR_FORMAT: GpuTestConfiguration =
..Default::default() ..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() ..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() ..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: &[], view_formats: &[],
}); });
}, },
None, Some("width 255 is not a multiple of nv12's width multiple requirement"),
); );
}); });

View File

@ -46,6 +46,6 @@ static QUEUE_WRITE_TEXTURE_OVERFLOW: GpuTestConfiguration =
}, },
); );
}, },
None, Some("end up overrunning the bounds of the destination texture"),
); );
}); });

View File

@ -14,15 +14,24 @@ static BAD_BUFFER: GpuTestConfiguration = GpuTestConfiguration::new().run_sync(|
mapped_at_creation: false, 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( fail(
&ctx.device, &ctx.device,
|| buffer.slice(..).map_async(wgpu::MapMode::Write, |_| {}), || 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());
valid(&ctx.device, || buffer.destroy()); valid(&ctx.device, || buffer.destroy());
}); });
@ -47,15 +56,24 @@ static BAD_TEXTURE: GpuTestConfiguration = GpuTestConfiguration::new().run_sync(
view_formats: &[], 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( fail(
&ctx.device, &ctx.device,
|| { || {
let _ = texture.create_view(&wgpu::TextureViewDescriptor::default()); let _ = texture.create_view(&wgpu::TextureViewDescriptor::default());
}, },
None, Some(error),
); );
valid(&ctx.device, || texture.destroy()); valid(&ctx.device, || texture.destroy());
valid(&ctx.device, || texture.destroy()); valid(&ctx.device, || texture.destroy());

View File

@ -64,6 +64,6 @@ static COPY_OVERFLOW_Z: GpuTestConfiguration = GpuTestConfiguration::new().run_s
); );
ctx.queue.submit(Some(encoder.finish())); ctx.queue.submit(Some(encoder.finish()));
}, },
None, Some("unable to select texture mip level"),
); );
}); });