File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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!(
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ use alloc::sync::Arc;
99use alloc:: vec:: Vec ;
1010
1111impl 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.
Original file line number Diff line number Diff line change @@ -281,7 +281,7 @@ mod validation_canary;
281281#[ cfg( feature = "validation_canary" ) ]
282282pub use validation_canary:: { ValidationCanary , VALIDATION_CANARY } ;
283283
284- mod audit;
284+ pub mod audit;
285285
286286pub ( crate ) use dynamic:: impl_dyn_resource;
287287pub use dynamic:: {
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments