Skip to content

Commit e827166

Browse files
committed
Unify debug groups and markers.
1 parent 52a3b83 commit e827166

File tree

3 files changed

+73
-121
lines changed

3 files changed

+73
-121
lines changed

wgpu-core/src/command/compute.rs

Lines changed: 8 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,9 @@ where
202202

203203
struct State<'scope, 'snatch_guard, 'cmd_buf, 'raw_encoder> {
204204
pipeline: Option<Arc<ComputePipeline>>,
205-
debug_scope_depth: u32,
206205

207206
general: pass::BaseState<'scope, 'snatch_guard, 'cmd_buf, 'raw_encoder>,
208207

209-
string_offset: usize,
210208
active_query: Option<(Arc<resource::QuerySet>, u32)>,
211209

212210
push_constants: Vec<u32>,
@@ -484,7 +482,6 @@ impl Global {
484482

485483
let mut state = State {
486484
pipeline: None,
487-
debug_scope_depth: 0,
488485

489486
general: pass::BaseState {
490487
device,
@@ -501,9 +498,10 @@ impl Global {
501498

502499
snatch_guard: &snatch_guard,
503500
scope: device.new_usage_scope(),
504-
},
505501

506-
string_offset: 0,
502+
debug_scope_depth: 0,
503+
string_offset: 0,
504+
},
507505
active_query: None,
508506

509507
push_constants: Vec::new(),
@@ -631,14 +629,16 @@ impl Global {
631629
.map_pass_err(scope)?;
632630
}
633631
ArcComputeCommand::PushDebugGroup { color: _, len } => {
634-
push_debug_group(&mut state, &base.string_data, len);
632+
pass::push_debug_group(&mut state.general, &base.string_data, len);
635633
}
636634
ArcComputeCommand::PopDebugGroup => {
637635
let scope = PassErrorScope::PopDebugGroup;
638-
pop_debug_group(&mut state).map_pass_err(scope)?;
636+
pass::pop_debug_group(&mut state.general)
637+
.map_err(|_| ComputePassErrorInner::InvalidPopDebugGroup)
638+
.map_pass_err(scope)?;
639639
}
640640
ArcComputeCommand::InsertDebugMarker { color: _, len } => {
641-
insert_debug_marker(&mut state, &base.string_data, len);
641+
pass::insert_debug_marker(&mut state.general, &base.string_data, len);
642642
}
643643
ArcComputeCommand::WriteTimestamp {
644644
query_set,
@@ -994,55 +994,6 @@ fn dispatch_indirect(
994994
Ok(())
995995
}
996996

997-
fn push_debug_group(state: &mut State, string_data: &[u8], len: usize) {
998-
state.debug_scope_depth += 1;
999-
if !state
1000-
.general
1001-
.device
1002-
.instance_flags
1003-
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
1004-
{
1005-
let label =
1006-
str::from_utf8(&string_data[state.string_offset..state.string_offset + len]).unwrap();
1007-
unsafe {
1008-
state.general.raw_encoder.begin_debug_marker(label);
1009-
}
1010-
}
1011-
state.string_offset += len;
1012-
}
1013-
1014-
fn pop_debug_group(state: &mut State) -> Result<(), ComputePassErrorInner> {
1015-
if state.debug_scope_depth == 0 {
1016-
return Err(ComputePassErrorInner::InvalidPopDebugGroup);
1017-
}
1018-
state.debug_scope_depth -= 1;
1019-
if !state
1020-
.general
1021-
.device
1022-
.instance_flags
1023-
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
1024-
{
1025-
unsafe {
1026-
state.general.raw_encoder.end_debug_marker();
1027-
}
1028-
}
1029-
Ok(())
1030-
}
1031-
1032-
fn insert_debug_marker(state: &mut State, string_data: &[u8], len: usize) {
1033-
if !state
1034-
.general
1035-
.device
1036-
.instance_flags
1037-
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
1038-
{
1039-
let label =
1040-
str::from_utf8(&string_data[state.string_offset..state.string_offset + len]).unwrap();
1041-
unsafe { state.general.raw_encoder.insert_debug_marker(label) }
1042-
}
1043-
state.string_offset += len;
1044-
}
1045-
1046997
// Recording a compute pass.
1047998
//
1048999
// The only error that should be returned from these methods is

wgpu-core/src/command/pass.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::track::{ResourceUsageCompatibilityError, Tracker, UsageScope};
1414
use crate::{api_log, binding_model};
1515
use alloc::sync::Arc;
1616
use alloc::vec::Vec;
17+
use core::str;
1718
use thiserror::Error;
1819
use wgt::DynamicOffset;
1920

@@ -49,6 +50,9 @@ pub(crate) struct BaseState<'scope, 'snatch_guard, 'cmd_buf, 'raw_encoder> {
4950
pub(crate) dynamic_offset_count: usize,
5051

5152
pub(crate) snatch_guard: &'snatch_guard SnatchGuard<'snatch_guard>,
53+
54+
pub(crate) debug_scope_depth: u32,
55+
pub(crate) string_offset: usize,
5256
}
5357

5458
pub(crate) fn set_bind_group<E>(
@@ -278,3 +282,56 @@ where
278282
query_set.validate_and_write_timestamp(state.raw_encoder, query_index, pending_query_resets)?;
279283
Ok(())
280284
}
285+
286+
pub(crate) fn push_debug_group(state: &mut BaseState, string_data: &[u8], len: usize) {
287+
state.debug_scope_depth += 1;
288+
if !state
289+
.device
290+
.instance_flags
291+
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
292+
{
293+
let label =
294+
str::from_utf8(&string_data[state.string_offset..state.string_offset + len]).unwrap();
295+
296+
api_log!("Pass::push_debug_group {label:?}");
297+
unsafe {
298+
state.raw_encoder.begin_debug_marker(label);
299+
}
300+
}
301+
state.string_offset += len;
302+
}
303+
304+
pub(crate) fn pop_debug_group(state: &mut BaseState) -> Result<(), ()> {
305+
api_log!("Pass::pop_debug_group");
306+
307+
if state.debug_scope_depth == 0 {
308+
return Err(());
309+
}
310+
state.debug_scope_depth -= 1;
311+
if !state
312+
.device
313+
.instance_flags
314+
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
315+
{
316+
unsafe {
317+
state.raw_encoder.end_debug_marker();
318+
}
319+
}
320+
Ok(())
321+
}
322+
323+
pub(crate) fn insert_debug_marker(state: &mut BaseState, string_data: &[u8], len: usize) {
324+
if !state
325+
.device
326+
.instance_flags
327+
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
328+
{
329+
let label =
330+
str::from_utf8(&string_data[state.string_offset..state.string_offset + len]).unwrap();
331+
api_log!("Pass::insert_debug_marker {label:?}");
332+
unsafe {
333+
state.raw_encoder.insert_debug_marker(label);
334+
}
335+
}
336+
state.string_offset += len;
337+
}

wgpu-core/src/command/render.rs

Lines changed: 8 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -499,14 +499,11 @@ struct State<'scope, 'snatch_guard, 'cmd_buf, 'raw_encoder> {
499499
pipeline: Option<Arc<RenderPipeline>>,
500500
index: IndexState,
501501
vertex: VertexState,
502-
debug_scope_depth: u32,
503502

504503
info: RenderPassInfo,
505504

506505
general: pass::BaseState<'scope, 'snatch_guard, 'cmd_buf, 'raw_encoder>,
507506

508-
string_offset: usize,
509-
510507
active_occlusion_query: Option<(Arc<QuerySet>, u32)>,
511508
active_pipeline_statistics_query: Option<(Arc<QuerySet>, u32)>,
512509
}
@@ -1823,7 +1820,6 @@ impl Global {
18231820
pipeline: None,
18241821
index: IndexState::default(),
18251822
vertex: VertexState::default(),
1826-
debug_scope_depth: 0,
18271823

18281824
info,
18291825

@@ -1842,8 +1838,10 @@ impl Global {
18421838

18431839
temp_offsets: Vec::new(),
18441840
dynamic_offset_count: 0,
1841+
1842+
debug_scope_depth: 0,
1843+
string_offset: 0,
18451844
},
1846-
string_offset: 0,
18471845

18481846
active_occlusion_query: None,
18491847
active_pipeline_statistics_query: None,
@@ -2035,14 +2033,16 @@ impl Global {
20352033
.map_pass_err(scope)?;
20362034
}
20372035
ArcRenderCommand::PushDebugGroup { color: _, len } => {
2038-
push_debug_group(&mut state, &base.string_data, len);
2036+
pass::push_debug_group(&mut state.general, &base.string_data, len);
20392037
}
20402038
ArcRenderCommand::PopDebugGroup => {
20412039
let scope = PassErrorScope::PopDebugGroup;
2042-
pop_debug_group(&mut state).map_pass_err(scope)?;
2040+
pass::pop_debug_group(&mut state.general)
2041+
.map_err(|_| RenderPassErrorInner::InvalidPopDebugGroup)
2042+
.map_pass_err(scope)?;
20432043
}
20442044
ArcRenderCommand::InsertDebugMarker { color: _, len } => {
2045-
insert_debug_marker(&mut state, &base.string_data, len);
2045+
pass::insert_debug_marker(&mut state.general, &base.string_data, len);
20462046
}
20472047
ArcRenderCommand::WriteTimestamp {
20482048
query_set,
@@ -2835,62 +2835,6 @@ fn multi_draw_indirect_count(
28352835
Ok(())
28362836
}
28372837

2838-
fn push_debug_group(state: &mut State, string_data: &[u8], len: usize) {
2839-
state.debug_scope_depth += 1;
2840-
if !state
2841-
.general
2842-
.device
2843-
.instance_flags
2844-
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
2845-
{
2846-
let label =
2847-
str::from_utf8(&string_data[state.string_offset..state.string_offset + len]).unwrap();
2848-
2849-
api_log!("RenderPass::push_debug_group {label:?}");
2850-
unsafe {
2851-
state.general.raw_encoder.begin_debug_marker(label);
2852-
}
2853-
}
2854-
state.string_offset += len;
2855-
}
2856-
2857-
fn pop_debug_group(state: &mut State) -> Result<(), RenderPassErrorInner> {
2858-
api_log!("RenderPass::pop_debug_group");
2859-
2860-
if state.debug_scope_depth == 0 {
2861-
return Err(RenderPassErrorInner::InvalidPopDebugGroup);
2862-
}
2863-
state.debug_scope_depth -= 1;
2864-
if !state
2865-
.general
2866-
.device
2867-
.instance_flags
2868-
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
2869-
{
2870-
unsafe {
2871-
state.general.raw_encoder.end_debug_marker();
2872-
}
2873-
}
2874-
Ok(())
2875-
}
2876-
2877-
fn insert_debug_marker(state: &mut State, string_data: &[u8], len: usize) {
2878-
if !state
2879-
.general
2880-
.device
2881-
.instance_flags
2882-
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
2883-
{
2884-
let label =
2885-
str::from_utf8(&string_data[state.string_offset..state.string_offset + len]).unwrap();
2886-
api_log!("RenderPass::insert_debug_marker {label:?}");
2887-
unsafe {
2888-
state.general.raw_encoder.insert_debug_marker(label);
2889-
}
2890-
}
2891-
state.string_offset += len;
2892-
}
2893-
28942838
fn execute_bundle(
28952839
state: &mut State,
28962840
indirect_draw_validation_resources: &mut crate::indirect_validation::DrawResources,

0 commit comments

Comments
 (0)