Skip to content

Commit 87c1081

Browse files
committed
Actually make it possible to run tests with hal auditing enabled.
1 parent 9a2090f commit 87c1081

4 files changed

Lines changed: 21 additions & 3 deletions

File tree

wgpu-core/src/instance.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,16 @@ impl Instance {
138138
match unsafe { A::Instance::init(&hal_desc) } {
139139
Ok(instance) => {
140140
log::debug!("Instance::new: created {:?} backend", A::VARIANT);
141+
142+
let mut instance: Box<dyn hal::DynInstance> = Box::new(instance);
143+
144+
// If requested, wrap the new instance in the hal auditing layer.
145+
if instance_desc.flags.contains(wgt::InstanceFlags::AUDIT_HAL_USAGE) {
146+
instance = Box::new(hal::audit::Instance::new(instance, A::VARIANT));
147+
}
148+
141149
self.instance_per_backend
142-
.push((A::VARIANT, Box::new(instance)));
150+
.push((A::VARIANT, instance));
143151
}
144152
Err(err) => {
145153
log::debug!(

wgpu-hal/src/audit/instance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use alloc::sync::Arc;
99
use alloc::vec::Vec;
1010

1111
impl audit::Instance {
12-
fn new(backend: wgpu_types::Backend, inner: Box<dyn DynInstance>) -> Self {
12+
pub fn new(inner: Box<dyn DynInstance>, backend: wgpu_types::Backend) -> Self {
1313
let state = state::State::new(backend);
1414
let id = state.new_id();
1515
// Instances are their own parents.

wgpu-hal/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ mod validation_canary;
281281
#[cfg(feature = "validation_canary")]
282282
pub use validation_canary::{ValidationCanary, VALIDATION_CANARY};
283283

284-
mod audit;
284+
pub mod audit;
285285

286286
pub(crate) use dynamic::impl_dyn_resource;
287287
pub use dynamic::{

wgpu-types/src/instance.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ bitflags::bitflags! {
139139
///
140140
/// [rqs]: ../wgpu/struct.CommandEncoder.html#method.resolve_query_set
141141
const AUTOMATIC_TIMESTAMP_NORMALIZATION = 1 << 6;
142+
143+
/// Enable `wgpu_hal` safety invariant auditing layer.
144+
///
145+
/// When `Self::from_env()` is used, this flag is set if the
146+
/// `WGPU_AUDIT_HAL_USAGE` environment variable is set to a value other
147+
/// than `0`.
148+
const AUDIT_HAL_USAGE = 1 << 7;
142149
}
143150
}
144151

@@ -224,6 +231,9 @@ impl InstanceFlags {
224231
if let Some(bit) = env("WGPU_VALIDATION_INDIRECT_CALL") {
225232
self.set(Self::VALIDATION_INDIRECT_CALL, bit);
226233
}
234+
if let Some(bit) = env("WGPU_AUDIT_HAL_USAGE") {
235+
self.set(Self::AUDIT_HAL_USAGE, bit);
236+
}
227237

228238
self
229239
}

0 commit comments

Comments
 (0)