mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-26 09:21:04 +01:00
Implement validation canary
This commit is contained in:
1 parent
0b66ea66b8
commit
efa4f29248
4 files changed
+43
-3
No files matched your search
@@ -63,8 +63,8 @@ unsafe extern "system" fn output_debug_string_handler(
|
||||
});
|
||||
|
||||
if cfg!(debug_assertions) && level == log::Level::Error {
|
||||
// Panicking behind FFI is UB, so we just exit.
|
||||
std::process::exit(1);
|
||||
// Set canary and continue
|
||||
crate::VALIDATION_CANARY.set();
|
||||
}
|
||||
|
||||
excpt::EXCEPTION_CONTINUE_EXECUTION
|
||||
|
||||
@@ -259,7 +259,8 @@ fn gl_debug_message_callback(source: u32, gltype: u32, id: u32, severity: u32, m
|
||||
});
|
||||
|
||||
if cfg!(debug_assertions) && log_severity == log::Level::Error {
|
||||
std::process::exit(1);
|
||||
// Set canary and continue
|
||||
crate::VALIDATION_CANARY.set();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,6 +84,7 @@ use std::{
|
||||
num::{NonZeroU32, NonZeroU8},
|
||||
ops::{Range, RangeInclusive},
|
||||
ptr::NonNull,
|
||||
sync::atomic::AtomicBool,
|
||||
};
|
||||
|
||||
use bitflags::bitflags;
|
||||
@@ -1143,6 +1144,39 @@ pub struct ComputePassDescriptor<'a> {
|
||||
pub label: Label<'a>,
|
||||
}
|
||||
|
||||
/// Stores if any API validation error has occurred in this process
|
||||
/// since it was last reset.
|
||||
///
|
||||
/// This is used for internal wgpu testing only and _must not_ be used
|
||||
/// as a way to check for errors.
|
||||
///
|
||||
/// This works as a static because `cargo nextest` runs all of our
|
||||
/// tests in separate processes, so each test gets its own canary.
|
||||
///
|
||||
/// This prevents the issue of one validation error terminating the
|
||||
/// entire process.
|
||||
pub static VALIDATION_CANARY: ValidationCanary = ValidationCanary {
|
||||
inner: AtomicBool::new(false),
|
||||
};
|
||||
|
||||
/// Flag for internal testing.
|
||||
pub struct ValidationCanary {
|
||||
inner: AtomicBool,
|
||||
}
|
||||
|
||||
impl ValidationCanary {
|
||||
#[allow(dead_code)] // in some configurations this function is dead
|
||||
fn set(&self) {
|
||||
self.inner.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||
}
|
||||
|
||||
/// Returns true if any API validation error has occurred in this process
|
||||
/// since the last call to this function.
|
||||
pub fn get_and_reset(&self) -> bool {
|
||||
self.inner.swap(false, std::sync::atomic::Ordering::SeqCst)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_default_limits() {
|
||||
let limits = wgt::Limits::default();
|
||||
|
||||
@@ -112,6 +112,11 @@ unsafe extern "system" fn debug_utils_messenger_callback(
|
||||
});
|
||||
}
|
||||
|
||||
if cfg!(debug_assertions) && level == log::Level::Error {
|
||||
// Set canary and continue
|
||||
crate::VALIDATION_CANARY.set();
|
||||
}
|
||||
|
||||
vk::FALSE
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user