From 4f4ba312b36f2c9190fea902a575dd6717f3e028 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Tue, 17 Oct 2023 21:29:05 -0700 Subject: [PATCH] fixup! Make it possible to filter labels out. --- wgpu-core/src/command/bundle.rs | 16 ++++++++++++---- wgpu-core/src/command/compute.rs | 16 ++++++++-------- wgpu-core/src/command/mod.rs | 32 +++++++++++++++++++++++++------- wgpu-core/src/command/render.rs | 24 +++++++++++------------- 4 files changed, 56 insertions(+), 32 deletions(-) diff --git a/wgpu-core/src/command/bundle.rs b/wgpu-core/src/command/bundle.rs index 0a4660a7988..54416da95ec 100644 --- a/wgpu-core/src/command/bundle.rs +++ b/wgpu-core/src/command/bundle.rs @@ -668,6 +668,9 @@ impl RenderBundleEncoder { texture_memory_init_actions, context: self.context, life_guard: LifeGuard::new(desc.label.borrow_or_default()), + discard_hal_labels: device + .instance_flags + .contains(wgt::InstanceFlags::DISCARD_HAL_LABELS), }) } @@ -746,6 +749,7 @@ pub struct RenderBundle { pub(super) texture_memory_init_actions: Vec, pub(super) context: RenderPassContext, pub(crate) life_guard: LifeGuard, + discard_hal_labels: bool, } #[cfg(any( @@ -788,8 +792,10 @@ impl RenderBundle { ) -> Result<(), ExecutionError> { let mut offsets = self.base.dynamic_offsets.as_slice(); let mut pipeline_layout_id = None::>; - if let Some(ref label) = self.base.label { - unsafe { raw.begin_debug_marker(label) }; + if !self.discard_hal_labels { + if let Some(ref label) = self.base.label { + unsafe { raw.begin_debug_marker(label) }; + } } for command in self.base.commands.iter() { @@ -966,8 +972,10 @@ impl RenderBundle { } } - if let Some(_) = self.base.label { - unsafe { raw.end_debug_marker() }; + if !self.discard_hal_labels { + if let Some(_) = self.base.label { + unsafe { raw.end_debug_marker() }; + } } Ok(()) diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 63e93ae7772..a5faf55572f 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -776,11 +776,11 @@ impl Global { } ComputeCommand::PushDebugGroup { color: _, len } => { state.debug_scope_depth += 1; + let label = + str::from_utf8(&base.string_data[string_offset..string_offset + len]) + .unwrap(); + string_offset += len; if !discard_hal_labels { - let label = - str::from_utf8(&base.string_data[string_offset..string_offset + len]) - .unwrap(); - string_offset += len; unsafe { raw.begin_debug_marker(label); } @@ -801,11 +801,11 @@ impl Global { } } ComputeCommand::InsertDebugMarker { color: _, len } => { + let label = + str::from_utf8(&base.string_data[string_offset..string_offset + len]) + .unwrap(); + string_offset += len; if !discard_hal_labels { - let label = - str::from_utf8(&base.string_data[string_offset..string_offset + len]) - .unwrap(); - string_offset += len; unsafe { raw.insert_debug_marker(label) } } } diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index 8f0abdc775e..843803a0f63 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -405,8 +405,14 @@ impl Global { } let cmd_buf_raw = cmd_buf.encoder.open(); - unsafe { - cmd_buf_raw.begin_debug_marker(label); + if !self + .instance + .flags + .contains(wgt::InstanceFlags::DISCARD_HAL_LABELS) + { + unsafe { + cmd_buf_raw.begin_debug_marker(label); + } } Ok(()) } @@ -430,9 +436,15 @@ impl Global { list.push(TraceCommand::InsertDebugMarker(label.to_string())); } - let cmd_buf_raw = cmd_buf.encoder.open(); - unsafe { - cmd_buf_raw.insert_debug_marker(label); + if !self + .instance + .flags + .contains(wgt::InstanceFlags::DISCARD_HAL_LABELS) + { + let cmd_buf_raw = cmd_buf.encoder.open(); + unsafe { + cmd_buf_raw.insert_debug_marker(label); + } } Ok(()) } @@ -456,8 +468,14 @@ impl Global { } let cmd_buf_raw = cmd_buf.encoder.open(); - unsafe { - cmd_buf_raw.end_debug_marker(); + if !self + .instance + .flags + .contains(wgt::InstanceFlags::DISCARD_HAL_LABELS) + { + unsafe { + cmd_buf_raw.end_debug_marker(); + } } Ok(()) } diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 8a3b7aad2c9..dd115750042 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -2163,14 +2163,13 @@ impl Global { } RenderCommand::PushDebugGroup { color: _, len } => { state.debug_scope_depth += 1; - if !discard_hal_labels { - let label = str::from_utf8( - &base.string_data[string_offset..string_offset + len], - ) - .unwrap(); + let label = + str::from_utf8(&base.string_data[string_offset..string_offset + len]) + .unwrap(); - log::trace!("RenderPass::push_debug_group {label:?}"); - string_offset += len; + log::trace!("RenderPass::push_debug_group {label:?}"); + string_offset += len; + if !discard_hal_labels { unsafe { raw.begin_debug_marker(label); } @@ -2192,13 +2191,12 @@ impl Global { } } RenderCommand::InsertDebugMarker { color: _, len } => { + let label = + str::from_utf8(&base.string_data[string_offset..string_offset + len]) + .unwrap(); + log::trace!("RenderPass::insert_debug_marker {label:?}"); + string_offset += len; if !discard_hal_labels { - let label = str::from_utf8( - &base.string_data[string_offset..string_offset + len], - ) - .unwrap(); - log::trace!("RenderPass::insert_debug_marker {label:?}"); - string_offset += len; unsafe { raw.insert_debug_marker(label); }