Skip to content

Commit 2721210

Browse files
Vecvecteoxoy
authored andcommitted
Unify debug groups and markers.
1 parent 6237dbf commit 2721210

3 files changed

Lines changed: 82 additions & 125 deletions

File tree

wgpu-core/src/command/compute.rs

Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ pub enum ComputePassErrorInner {
150150
ResourceUsageCompatibility(#[from] ResourceUsageCompatibilityError),
151151
#[error(transparent)]
152152
MissingBufferUsage(#[from] MissingBufferUsageError),
153-
#[error("Cannot pop debug group, because number of pushed debug groups is zero")]
154-
InvalidPopDebugGroup,
153+
#[error(transparent)]
154+
InvalidPopDebugGroup(#[from] pass::InvalidPopDebugGroup),
155155
#[error(transparent)]
156156
Dispatch(#[from] DispatchError),
157157
#[error(transparent)]
@@ -211,11 +211,9 @@ where
211211

212212
struct State<'scope, 'snatch_guard, 'cmd_buf, 'raw_encoder> {
213213
pipeline: Option<Arc<ComputePipeline>>,
214-
debug_scope_depth: u32,
215214

216215
general: pass::BaseState<'scope, 'snatch_guard, 'cmd_buf, 'raw_encoder>,
217216

218-
string_offset: usize,
219217
active_query: Option<(Arc<resource::QuerySet>, u32)>,
220218

221219
push_constants: Vec<u32>,
@@ -493,7 +491,6 @@ impl Global {
493491

494492
let mut state = State {
495493
pipeline: None,
496-
debug_scope_depth: 0,
497494

498495
general: pass::BaseState {
499496
device,
@@ -510,9 +507,10 @@ impl Global {
510507

511508
snatch_guard: &snatch_guard,
512509
scope: device.new_usage_scope(),
513-
},
514510

515-
string_offset: 0,
511+
debug_scope_depth: 0,
512+
string_offset: 0,
513+
},
516514
active_query: None,
517515

518516
push_constants: Vec::new(),
@@ -637,14 +635,15 @@ impl Global {
637635
.map_pass_err(scope)?;
638636
}
639637
ArcComputeCommand::PushDebugGroup { color: _, len } => {
640-
push_debug_group(&mut state, &base.string_data, len);
638+
pass::push_debug_group(&mut state.general, &base.string_data, len);
641639
}
642640
ArcComputeCommand::PopDebugGroup => {
643641
let scope = PassErrorScope::PopDebugGroup;
644-
pop_debug_group(&mut state).map_pass_err(scope)?;
642+
pass::pop_debug_group::<ComputePassErrorInner>(&mut state.general)
643+
.map_pass_err(scope)?;
645644
}
646645
ArcComputeCommand::InsertDebugMarker { color: _, len } => {
647-
insert_debug_marker(&mut state, &base.string_data, len);
646+
pass::insert_debug_marker(&mut state.general, &base.string_data, len);
648647
}
649648
ArcComputeCommand::WriteTimestamp {
650649
query_set,
@@ -1000,55 +999,6 @@ fn dispatch_indirect(
1000999
Ok(())
10011000
}
10021001

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

wgpu-core/src/command/pass.rs

Lines changed: 64 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

@@ -34,6 +35,10 @@ pub struct MissingPipeline;
3435
#[error("Setting `values_offset` to be `None` is only for internal use in render bundles")]
3536
pub struct InvalidValuesOffset;
3637

38+
#[derive(Clone, Debug, Error)]
39+
#[error("Cannot pop debug group, because number of pushed debug groups is zero")]
40+
pub struct InvalidPopDebugGroup;
41+
3742
pub(crate) struct BaseState<'scope, 'snatch_guard, 'cmd_buf, 'raw_encoder> {
3843
pub(crate) device: &'cmd_buf Arc<Device>,
3944

@@ -57,6 +62,9 @@ pub(crate) struct BaseState<'scope, 'snatch_guard, 'cmd_buf, 'raw_encoder> {
5762
pub(crate) dynamic_offset_count: usize,
5863

5964
pub(crate) snatch_guard: &'snatch_guard SnatchGuard<'snatch_guard>,
65+
66+
pub(crate) debug_scope_depth: u32,
67+
pub(crate) string_offset: usize,
6068
}
6169

6270
pub(crate) fn set_bind_group<E>(
@@ -290,3 +298,59 @@ where
290298
query_set.validate_and_write_timestamp(state.raw_encoder, query_index, pending_query_resets)?;
291299
Ok(())
292300
}
301+
302+
pub(crate) fn push_debug_group(state: &mut BaseState, string_data: &[u8], len: usize) {
303+
state.debug_scope_depth += 1;
304+
if !state
305+
.device
306+
.instance_flags
307+
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
308+
{
309+
let label =
310+
str::from_utf8(&string_data[state.string_offset..state.string_offset + len]).unwrap();
311+
312+
api_log!("Pass::push_debug_group {label:?}");
313+
unsafe {
314+
state.raw_encoder.begin_debug_marker(label);
315+
}
316+
}
317+
state.string_offset += len;
318+
}
319+
320+
pub(crate) fn pop_debug_group<E>(state: &mut BaseState) -> Result<(), E>
321+
where
322+
E: From<InvalidPopDebugGroup>,
323+
{
324+
api_log!("Pass::pop_debug_group");
325+
326+
if state.debug_scope_depth == 0 {
327+
return Err(InvalidPopDebugGroup.into());
328+
}
329+
state.debug_scope_depth -= 1;
330+
if !state
331+
.device
332+
.instance_flags
333+
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
334+
{
335+
unsafe {
336+
state.raw_encoder.end_debug_marker();
337+
}
338+
}
339+
Ok(())
340+
}
341+
342+
pub(crate) fn insert_debug_marker(state: &mut BaseState, string_data: &[u8], len: usize) {
343+
if !state
344+
.device
345+
.instance_flags
346+
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
347+
{
348+
let label =
349+
str::from_utf8(&string_data[state.string_offset..state.string_offset + len]).unwrap();
350+
api_log!("Pass::insert_debug_marker {label:?}");
351+
unsafe {
352+
state.raw_encoder.insert_debug_marker(label);
353+
}
354+
}
355+
state.string_offset += len;
356+
}

wgpu-core/src/command/render.rs

Lines changed: 9 additions & 66 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
}
@@ -721,8 +718,8 @@ pub enum RenderPassErrorInner {
721718
end_count_offset: u64,
722719
count_buffer_size: u64,
723720
},
724-
#[error("Cannot pop debug group, because number of pushed debug groups is zero")]
725-
InvalidPopDebugGroup,
721+
#[error(transparent)]
722+
InvalidPopDebugGroup(#[from] pass::InvalidPopDebugGroup),
726723
#[error(transparent)]
727724
ResourceUsageCompatibility(#[from] ResourceUsageCompatibilityError),
728725
#[error("Render bundle has incompatible targets, {0}")]
@@ -1829,7 +1826,6 @@ impl Global {
18291826
pipeline: None,
18301827
index: IndexState::default(),
18311828
vertex: VertexState::default(),
1832-
debug_scope_depth: 0,
18331829

18341830
info,
18351831

@@ -1848,8 +1844,10 @@ impl Global {
18481844

18491845
temp_offsets: Vec::new(),
18501846
dynamic_offset_count: 0,
1847+
1848+
debug_scope_depth: 0,
1849+
string_offset: 0,
18511850
},
1852-
string_offset: 0,
18531851

18541852
active_occlusion_query: None,
18551853
active_pipeline_statistics_query: None,
@@ -2036,14 +2034,15 @@ impl Global {
20362034
.map_pass_err(scope)?;
20372035
}
20382036
ArcRenderCommand::PushDebugGroup { color: _, len } => {
2039-
push_debug_group(&mut state, &base.string_data, len);
2037+
pass::push_debug_group(&mut state.general, &base.string_data, len);
20402038
}
20412039
ArcRenderCommand::PopDebugGroup => {
20422040
let scope = PassErrorScope::PopDebugGroup;
2043-
pop_debug_group(&mut state).map_pass_err(scope)?;
2041+
pass::pop_debug_group::<RenderPassErrorInner>(&mut state.general)
2042+
.map_pass_err(scope)?;
20442043
}
20452044
ArcRenderCommand::InsertDebugMarker { color: _, len } => {
2046-
insert_debug_marker(&mut state, &base.string_data, len);
2045+
pass::insert_debug_marker(&mut state.general, &base.string_data, len);
20472046
}
20482047
ArcRenderCommand::WriteTimestamp {
20492048
query_set,
@@ -2836,62 +2835,6 @@ fn multi_draw_indirect_count(
28362835
Ok(())
28372836
}
28382837

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

0 commit comments

Comments
 (0)