Skip to content

Commit 14b0af2

Browse files
committed
Unify debug groups and markers.
1 parent 4a3a4e0 commit 14b0af2

File tree

3 files changed

+77
-125
lines changed

3 files changed

+77
-125
lines changed

wgpu-core/src/command/compute.rs

Lines changed: 6 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,6 @@ pub enum ComputePassErrorInner {
134134
},
135135
#[error(transparent)]
136136
MissingBufferUsage(#[from] MissingBufferUsageError),
137-
#[error("Cannot pop debug group, because number of pushed debug groups is zero")]
138-
InvalidPopDebugGroup,
139137
#[error(transparent)]
140138
Dispatch(#[from] DispatchError),
141139
#[error(transparent)]
@@ -183,11 +181,9 @@ where
183181

184182
struct State<'scope, 'snatch_guard, 'cmd_buf, 'raw_encoder> {
185183
pipeline: Option<Arc<ComputePipeline>>,
186-
debug_scope_depth: u32,
187184

188185
general: pass::BaseState<'scope, 'snatch_guard, 'cmd_buf, 'raw_encoder>,
189186

190-
string_offset: usize,
191187
active_query: Option<(Arc<resource::QuerySet>, u32)>,
192188

193189
push_constants: Vec<u32>,
@@ -400,7 +396,6 @@ impl Global {
400396

401397
let mut state = State {
402398
pipeline: None,
403-
debug_scope_depth: 0,
404399

405400
general: pass::BaseState {
406401
device,
@@ -417,9 +412,10 @@ impl Global {
417412

418413
snatch_guard: &snatch_guard,
419414
scope: device.new_usage_scope(),
420-
},
421415

422-
string_offset: 0,
416+
debug_scope_depth: 0,
417+
string_offset: 0,
418+
},
423419
active_query: None,
424420

425421
push_constants: Vec::new(),
@@ -544,14 +540,14 @@ impl Global {
544540
dispatch_indirect(&mut state, cmd_buf, buffer, offset).map_pass_err(scope)?;
545541
}
546542
ArcComputeCommand::PushDebugGroup { color: _, len } => {
547-
push_debug_group(&mut state, &base.string_data, len);
543+
pass::push_debug_group(&mut state.general, &base.string_data, len);
548544
}
549545
ArcComputeCommand::PopDebugGroup => {
550546
let scope = PassErrorScope::PopDebugGroup;
551-
pop_debug_group(&mut state).map_pass_err(scope)?;
547+
pass::pop_debug_group(&mut state.general).map_pass_err(scope)?;
552548
}
553549
ArcComputeCommand::InsertDebugMarker { color: _, len } => {
554-
insert_debug_marker(&mut state, &base.string_data, len);
550+
pass::insert_debug_marker(&mut state.general, &base.string_data, len);
555551
}
556552
ArcComputeCommand::WriteTimestamp {
557553
query_set,
@@ -930,55 +926,6 @@ fn dispatch_indirect(
930926
Ok(())
931927
}
932928

933-
fn push_debug_group(state: &mut State, string_data: &[u8], len: usize) {
934-
state.debug_scope_depth += 1;
935-
if !state
936-
.general
937-
.device
938-
.instance_flags
939-
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
940-
{
941-
let label =
942-
str::from_utf8(&string_data[state.string_offset..state.string_offset + len]).unwrap();
943-
unsafe {
944-
state.general.raw_encoder.begin_debug_marker(label);
945-
}
946-
}
947-
state.string_offset += len;
948-
}
949-
950-
fn pop_debug_group(state: &mut State) -> Result<(), ComputePassErrorInner> {
951-
if state.debug_scope_depth == 0 {
952-
return Err(ComputePassErrorInner::InvalidPopDebugGroup);
953-
}
954-
state.debug_scope_depth -= 1;
955-
if !state
956-
.general
957-
.device
958-
.instance_flags
959-
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
960-
{
961-
unsafe {
962-
state.general.raw_encoder.end_debug_marker();
963-
}
964-
}
965-
Ok(())
966-
}
967-
968-
fn insert_debug_marker(state: &mut State, string_data: &[u8], len: usize) {
969-
if !state
970-
.general
971-
.device
972-
.instance_flags
973-
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
974-
{
975-
let label =
976-
str::from_utf8(&string_data[state.string_offset..state.string_offset + len]).unwrap();
977-
unsafe { state.general.raw_encoder.insert_debug_marker(label) }
978-
}
979-
state.string_offset += len;
980-
}
981-
982929
// Recording a compute pass.
983930
impl Global {
984931
pub fn compute_pass_set_bind_group(

wgpu-core/src/command/pass.rs

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

@@ -40,6 +41,8 @@ pub enum PassError {
4041
InvalidValuesOffset,
4142
#[error("Render pipeline must be set")]
4243
MissingPipeline,
44+
#[error("Cannot pop debug group, because number of pushed debug groups is zero")]
45+
InvalidPopDebugGroup,
4346
}
4447

4548
pub(crate) struct BaseState<'scope, 'snatch_guard, 'cmd_buf, 'raw_encoder> {
@@ -65,6 +68,9 @@ pub(crate) struct BaseState<'scope, 'snatch_guard, 'cmd_buf, 'raw_encoder> {
6568
pub(crate) dynamic_offset_count: usize,
6669

6770
pub(crate) snatch_guard: &'snatch_guard SnatchGuard<'snatch_guard>,
71+
72+
pub(crate) debug_scope_depth: u32,
73+
pub(crate) string_offset: usize,
6874
}
6975

7076
pub(crate) fn set_bind_group(
@@ -285,3 +291,56 @@ pub(crate) fn write_timestamp(
285291
query_set.validate_and_write_timestamp(state.raw_encoder, query_index, pending_query_resets)?;
286292
Ok(())
287293
}
294+
295+
pub(crate) fn push_debug_group(state: &mut BaseState, string_data: &[u8], len: usize) {
296+
state.debug_scope_depth += 1;
297+
if !state
298+
.device
299+
.instance_flags
300+
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
301+
{
302+
let label =
303+
str::from_utf8(&string_data[state.string_offset..state.string_offset + len]).unwrap();
304+
305+
api_log!("Pass::push_debug_group {label:?}");
306+
unsafe {
307+
state.raw_encoder.begin_debug_marker(label);
308+
}
309+
}
310+
state.string_offset += len;
311+
}
312+
313+
pub(crate) fn pop_debug_group(state: &mut BaseState) -> Result<(), PassError> {
314+
api_log!("Pass::pop_debug_group");
315+
316+
if state.debug_scope_depth == 0 {
317+
return Err(PassError::InvalidPopDebugGroup);
318+
}
319+
state.debug_scope_depth -= 1;
320+
if !state
321+
.device
322+
.instance_flags
323+
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
324+
{
325+
unsafe {
326+
state.raw_encoder.end_debug_marker();
327+
}
328+
}
329+
Ok(())
330+
}
331+
332+
pub(crate) fn insert_debug_marker(state: &mut BaseState, string_data: &[u8], len: usize) {
333+
if !state
334+
.device
335+
.instance_flags
336+
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
337+
{
338+
let label =
339+
str::from_utf8(&string_data[state.string_offset..state.string_offset + len]).unwrap();
340+
api_log!("Pass::insert_debug_marker {label:?}");
341+
unsafe {
342+
state.raw_encoder.insert_debug_marker(label);
343+
}
344+
}
345+
state.string_offset += len;
346+
}

wgpu-core/src/command/render.rs

Lines changed: 12 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -498,14 +498,11 @@ struct State<'scope, 'snatch_guard, 'cmd_buf, 'raw_encoder> {
498498
pipeline: Option<Arc<RenderPipeline>>,
499499
index: IndexState,
500500
vertex: VertexState,
501-
debug_scope_depth: u32,
502501

503502
info: RenderPassInfo,
504503

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

507-
string_offset: usize,
508-
509506
active_occlusion_query: Option<(Arc<QuerySet>, u32)>,
510507
active_pipeline_statistics_query: Option<(Arc<QuerySet>, u32)>,
511508
}
@@ -714,8 +711,6 @@ pub enum RenderPassErrorInner {
714711
end_count_offset: u64,
715712
count_buffer_size: u64,
716713
},
717-
#[error("Cannot pop debug group, because number of pushed debug groups is zero")]
718-
InvalidPopDebugGroup,
719714
#[error(transparent)]
720715
ResourceUsageCompatibility(#[from] ResourceUsageCompatibilityError),
721716
#[error("Render bundle has incompatible targets, {0}")]
@@ -1745,7 +1740,6 @@ impl Global {
17451740
pipeline: None,
17461741
index: IndexState::default(),
17471742
vertex: VertexState::default(),
1748-
debug_scope_depth: 0,
17491743

17501744
info,
17511745

@@ -1764,8 +1758,10 @@ impl Global {
17641758

17651759
temp_offsets: Vec::new(),
17661760
dynamic_offset_count: 0,
1761+
1762+
debug_scope_depth: 0,
1763+
string_offset: 0,
17671764
},
1768-
string_offset: 0,
17691765

17701766
active_occlusion_query: None,
17711767
active_pipeline_statistics_query: None,
@@ -1950,14 +1946,20 @@ impl Global {
19501946
.map_pass_err(scope)?;
19511947
}
19521948
ArcRenderCommand::PushDebugGroup { color: _, len } => {
1953-
push_debug_group(&mut state, &base.string_data, len);
1949+
pass::push_debug_group(&mut state.general, &base.string_data, len);
19541950
}
19551951
ArcRenderCommand::PopDebugGroup => {
19561952
let scope = PassErrorScope::PopDebugGroup;
1957-
pop_debug_group(&mut state).map_pass_err(scope)?;
1953+
pass::pop_debug_group(&mut state.general)
1954+
.map_err(|e| {
1955+
RenderPassErrorInner::RenderCommand(
1956+
RenderCommandError::GeneralPass(e),
1957+
)
1958+
})
1959+
.map_pass_err(scope)?;
19581960
}
19591961
ArcRenderCommand::InsertDebugMarker { color: _, len } => {
1960-
insert_debug_marker(&mut state, &base.string_data, len);
1962+
pass::insert_debug_marker(&mut state.general, &base.string_data, len);
19611963
}
19621964
ArcRenderCommand::WriteTimestamp {
19631965
query_set,
@@ -2754,62 +2756,6 @@ fn multi_draw_indirect_count(
27542756
Ok(())
27552757
}
27562758

2757-
fn push_debug_group(state: &mut State, string_data: &[u8], len: usize) {
2758-
state.debug_scope_depth += 1;
2759-
if !state
2760-
.general
2761-
.device
2762-
.instance_flags
2763-
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
2764-
{
2765-
let label =
2766-
str::from_utf8(&string_data[state.string_offset..state.string_offset + len]).unwrap();
2767-
2768-
api_log!("RenderPass::push_debug_group {label:?}");
2769-
unsafe {
2770-
state.general.raw_encoder.begin_debug_marker(label);
2771-
}
2772-
}
2773-
state.string_offset += len;
2774-
}
2775-
2776-
fn pop_debug_group(state: &mut State) -> Result<(), RenderPassErrorInner> {
2777-
api_log!("RenderPass::pop_debug_group");
2778-
2779-
if state.debug_scope_depth == 0 {
2780-
return Err(RenderPassErrorInner::InvalidPopDebugGroup);
2781-
}
2782-
state.debug_scope_depth -= 1;
2783-
if !state
2784-
.general
2785-
.device
2786-
.instance_flags
2787-
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
2788-
{
2789-
unsafe {
2790-
state.general.raw_encoder.end_debug_marker();
2791-
}
2792-
}
2793-
Ok(())
2794-
}
2795-
2796-
fn insert_debug_marker(state: &mut State, string_data: &[u8], len: usize) {
2797-
if !state
2798-
.general
2799-
.device
2800-
.instance_flags
2801-
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
2802-
{
2803-
let label =
2804-
str::from_utf8(&string_data[state.string_offset..state.string_offset + len]).unwrap();
2805-
api_log!("RenderPass::insert_debug_marker {label:?}");
2806-
unsafe {
2807-
state.general.raw_encoder.insert_debug_marker(label);
2808-
}
2809-
}
2810-
state.string_offset += len;
2811-
}
2812-
28132759
fn execute_bundle(
28142760
state: &mut State,
28152761
indirect_draw_validation_resources: &mut crate::indirect_validation::DrawResources,

0 commit comments

Comments
 (0)