Skip to content

Commit 3a5d0f2

Browse files
andyleisersonjimblandy
authored andcommitted
Deferred error reporting for other command encoder operations
* clear commands * query set functions * command_encoder_as_hal_mut * ray_tracing
1 parent e702d1c commit 3a5d0f2

File tree

10 files changed

+688
-690
lines changed

10 files changed

+688
-690
lines changed

tests/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ pub use run::{execute_test, TestingContext};
2727
pub use wgpu_macros::gpu_test;
2828

2929
/// Run some code in an error scope and assert that validation fails.
30+
///
31+
/// Note that errors related to commands for the GPU (i.e. raised by methods on
32+
/// GPUCommandEncoder, GPURenderPassEncoder, GPUComputePassEncoder,
33+
/// GPURenderBundleEncoder) are usually not raised immediately. They are raised
34+
/// only when `finish()` is called on the command encoder. Tests of such error
35+
/// cases should call `fail` with a closure that calls `finish()`, not with a
36+
/// closure that encodes the actual command.
3037
pub fn fail<T>(
3138
device: &wgpu::Device,
3239
callback: impl FnOnce() -> T,

tests/tests/wgpu-gpu/buffer.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -344,13 +344,12 @@ static CLEAR_OFFSET_OUTSIDE_RESOURCE_BOUNDS: GpuTestConfiguration = GpuTestConfi
344344

345345
let out_of_bounds = size.checked_add(wgpu::COPY_BUFFER_ALIGNMENT).unwrap();
346346

347+
let mut encoder = ctx.device.create_command_encoder(&Default::default());
348+
encoder.clear_buffer(&buffer, out_of_bounds, None);
349+
347350
wgpu_test::fail(
348351
&ctx.device,
349-
|| {
350-
ctx.device
351-
.create_command_encoder(&Default::default())
352-
.clear_buffer(&buffer, out_of_bounds, None)
353-
},
352+
|| encoder.finish(),
354353
Some("Clear of 20..20 would end up overrunning the bounds of the buffer of size 16"),
355354
);
356355
});
@@ -370,17 +369,16 @@ static CLEAR_OFFSET_PLUS_SIZE_OUTSIDE_U64_BOUNDS: GpuTestConfiguration =
370369
let max_valid_offset = u64::MAX - (u64::MAX % wgpu::COPY_BUFFER_ALIGNMENT);
371370
let smallest_aligned_invalid_size = wgpu::COPY_BUFFER_ALIGNMENT;
372371

372+
let mut encoder = ctx.device.create_command_encoder(&Default::default());
373+
encoder.clear_buffer(
374+
&buffer,
375+
max_valid_offset,
376+
Some(smallest_aligned_invalid_size),
377+
);
378+
373379
wgpu_test::fail(
374380
&ctx.device,
375-
|| {
376-
ctx.device
377-
.create_command_encoder(&Default::default())
378-
.clear_buffer(
379-
&buffer,
380-
max_valid_offset,
381-
Some(smallest_aligned_invalid_size),
382-
)
383-
},
381+
|| encoder.finish(),
384382
Some(concat!(
385383
"Clear starts at offset 18446744073709551612 with size of 4, ",
386384
"but these added together exceed `u64::MAX`"

tests/tests/wgpu-gpu/device.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -330,20 +330,19 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne
330330
);
331331

332332
// Texture clear should fail.
333+
encoder_for_clear.clear_texture(
334+
&texture_for_write,
335+
&wgpu::ImageSubresourceRange {
336+
aspect: wgpu::TextureAspect::All,
337+
base_mip_level: 0,
338+
mip_level_count: None,
339+
base_array_layer: 0,
340+
array_layer_count: None,
341+
},
342+
);
333343
fail(
334344
&ctx.device,
335-
|| {
336-
encoder_for_clear.clear_texture(
337-
&texture_for_write,
338-
&wgpu::ImageSubresourceRange {
339-
aspect: wgpu::TextureAspect::All,
340-
base_mip_level: 0,
341-
mip_level_count: None,
342-
base_array_layer: 0,
343-
array_layer_count: None,
344-
},
345-
);
346-
},
345+
|| encoder_for_clear.finish(),
347346
Some("device with '' label is invalid"),
348347
);
349348

tests/tests/wgpu-gpu/ray_tracing/as_build.rs

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,8 @@ fn blas_compaction(ctx: TestingContext) {
188188
let mut build_entry = as_ctx.blas_build_entry();
189189
build_entry.blas = &compacted;
190190

191-
fail(
192-
&ctx.device,
193-
|| fail_encoder.build_acceleration_structures([&build_entry], []),
194-
None,
195-
);
191+
fail_encoder.build_acceleration_structures([&build_entry], []);
192+
fail(&ctx.device, || fail_encoder.finish(), None);
196193
}
197194

198195
#[gpu_test]
@@ -733,13 +730,8 @@ fn only_tlas_vertex_return(ctx: TestingContext) {
733730
label: Some("TLAS 1"),
734731
});
735732

736-
fail(
737-
&ctx.device,
738-
|| {
739-
encoder_tlas.build_acceleration_structures([], [&as_ctx.tlas]);
740-
},
741-
None,
742-
);
733+
encoder_tlas.build_acceleration_structures([], [&as_ctx.tlas]);
734+
fail(&ctx.device, || encoder_tlas.finish(), None);
743735
}
744736

745737
#[gpu_test]
@@ -817,30 +809,29 @@ fn test_as_build_format_stride(
817809
.create_command_encoder(&CommandEncoderDescriptor {
818810
label: Some("BLAS_1"),
819811
});
820-
fail_if(
812+
command_encoder.build_acceleration_structures(
813+
&[BlasBuildEntry {
814+
blas: &blas,
815+
geometry: BlasGeometries::TriangleGeometries(vec![BlasTriangleGeometry {
816+
size: &blas_size,
817+
vertex_buffer: &vertices,
818+
first_vertex: 0,
819+
vertex_stride: stride,
820+
index_buffer: None,
821+
first_index: None,
822+
transform_buffer: None,
823+
transform_buffer_offset: None,
824+
}]),
825+
}],
826+
&[],
827+
);
828+
let command_buffer = fail_if(
821829
&ctx.device,
822830
invalid_combination,
823-
|| {
824-
command_encoder.build_acceleration_structures(
825-
&[BlasBuildEntry {
826-
blas: &blas,
827-
geometry: BlasGeometries::TriangleGeometries(vec![BlasTriangleGeometry {
828-
size: &blas_size,
829-
vertex_buffer: &vertices,
830-
first_vertex: 0,
831-
vertex_stride: stride,
832-
index_buffer: None,
833-
first_index: None,
834-
transform_buffer: None,
835-
transform_buffer_offset: None,
836-
}]),
837-
}],
838-
&[],
839-
)
840-
},
831+
|| command_encoder.finish(),
841832
None,
842833
);
843834
if !invalid_combination {
844-
ctx.queue.submit([command_encoder.finish()]);
835+
ctx.queue.submit([command_buffer]);
845836
}
846837
}

0 commit comments

Comments
 (0)