Make wgpu_test::valid print errors it detects. (#6136)

* Make `wgpu_test::valid` print errors it detects.

When a block passed to `wgpu_test::valid` actually raises validation
errors, include the full error in the panic message.

---------

Co-authored-by: Erich Gubler <erichdongubler@gmail.com>
This commit is contained in:
Jim Blandy 2024-08-23 07:17:28 -07:00 committed by GitHub
parent 5b148f2db6
commit 15d64c362e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -54,10 +54,16 @@ pub fn fail<T>(
}
/// Run some code in an error scope and assert that validation succeeds.
#[track_caller]
pub fn valid<T>(device: &wgpu::Device, callback: impl FnOnce() -> T) -> T {
device.push_error_scope(wgpu::ErrorFilter::Validation);
let result = callback();
assert!(pollster::block_on(device.pop_error_scope()).is_none());
if let Some(error) = pollster::block_on(device.pop_error_scope()) {
panic!(
"`valid` block at {} encountered wgpu error:\n{error}",
std::panic::Location::caller()
);
}
result
}