mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
Unify debug groups and markers.
This commit is contained in:
parent
6237dbf0b9
commit
27212104f8
@ -150,8 +150,8 @@ pub enum ComputePassErrorInner {
|
||||
ResourceUsageCompatibility(#[from] ResourceUsageCompatibilityError),
|
||||
#[error(transparent)]
|
||||
MissingBufferUsage(#[from] MissingBufferUsageError),
|
||||
#[error("Cannot pop debug group, because number of pushed debug groups is zero")]
|
||||
InvalidPopDebugGroup,
|
||||
#[error(transparent)]
|
||||
InvalidPopDebugGroup(#[from] pass::InvalidPopDebugGroup),
|
||||
#[error(transparent)]
|
||||
Dispatch(#[from] DispatchError),
|
||||
#[error(transparent)]
|
||||
@ -211,11 +211,9 @@ where
|
||||
|
||||
struct State<'scope, 'snatch_guard, 'cmd_buf, 'raw_encoder> {
|
||||
pipeline: Option<Arc<ComputePipeline>>,
|
||||
debug_scope_depth: u32,
|
||||
|
||||
general: pass::BaseState<'scope, 'snatch_guard, 'cmd_buf, 'raw_encoder>,
|
||||
|
||||
string_offset: usize,
|
||||
active_query: Option<(Arc<resource::QuerySet>, u32)>,
|
||||
|
||||
push_constants: Vec<u32>,
|
||||
@ -493,7 +491,6 @@ impl Global {
|
||||
|
||||
let mut state = State {
|
||||
pipeline: None,
|
||||
debug_scope_depth: 0,
|
||||
|
||||
general: pass::BaseState {
|
||||
device,
|
||||
@ -510,9 +507,10 @@ impl Global {
|
||||
|
||||
snatch_guard: &snatch_guard,
|
||||
scope: device.new_usage_scope(),
|
||||
},
|
||||
|
||||
string_offset: 0,
|
||||
debug_scope_depth: 0,
|
||||
string_offset: 0,
|
||||
},
|
||||
active_query: None,
|
||||
|
||||
push_constants: Vec::new(),
|
||||
@ -637,14 +635,15 @@ impl Global {
|
||||
.map_pass_err(scope)?;
|
||||
}
|
||||
ArcComputeCommand::PushDebugGroup { color: _, len } => {
|
||||
push_debug_group(&mut state, &base.string_data, len);
|
||||
pass::push_debug_group(&mut state.general, &base.string_data, len);
|
||||
}
|
||||
ArcComputeCommand::PopDebugGroup => {
|
||||
let scope = PassErrorScope::PopDebugGroup;
|
||||
pop_debug_group(&mut state).map_pass_err(scope)?;
|
||||
pass::pop_debug_group::<ComputePassErrorInner>(&mut state.general)
|
||||
.map_pass_err(scope)?;
|
||||
}
|
||||
ArcComputeCommand::InsertDebugMarker { color: _, len } => {
|
||||
insert_debug_marker(&mut state, &base.string_data, len);
|
||||
pass::insert_debug_marker(&mut state.general, &base.string_data, len);
|
||||
}
|
||||
ArcComputeCommand::WriteTimestamp {
|
||||
query_set,
|
||||
@ -1000,55 +999,6 @@ fn dispatch_indirect(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn push_debug_group(state: &mut State, string_data: &[u8], len: usize) {
|
||||
state.debug_scope_depth += 1;
|
||||
if !state
|
||||
.general
|
||||
.device
|
||||
.instance_flags
|
||||
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
|
||||
{
|
||||
let label =
|
||||
str::from_utf8(&string_data[state.string_offset..state.string_offset + len]).unwrap();
|
||||
unsafe {
|
||||
state.general.raw_encoder.begin_debug_marker(label);
|
||||
}
|
||||
}
|
||||
state.string_offset += len;
|
||||
}
|
||||
|
||||
fn pop_debug_group(state: &mut State) -> Result<(), ComputePassErrorInner> {
|
||||
if state.debug_scope_depth == 0 {
|
||||
return Err(ComputePassErrorInner::InvalidPopDebugGroup);
|
||||
}
|
||||
state.debug_scope_depth -= 1;
|
||||
if !state
|
||||
.general
|
||||
.device
|
||||
.instance_flags
|
||||
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
|
||||
{
|
||||
unsafe {
|
||||
state.general.raw_encoder.end_debug_marker();
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn insert_debug_marker(state: &mut State, string_data: &[u8], len: usize) {
|
||||
if !state
|
||||
.general
|
||||
.device
|
||||
.instance_flags
|
||||
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
|
||||
{
|
||||
let label =
|
||||
str::from_utf8(&string_data[state.string_offset..state.string_offset + len]).unwrap();
|
||||
unsafe { state.general.raw_encoder.insert_debug_marker(label) }
|
||||
}
|
||||
state.string_offset += len;
|
||||
}
|
||||
|
||||
// Recording a compute pass.
|
||||
//
|
||||
// The only error that should be returned from these methods is
|
||||
|
||||
@ -14,6 +14,7 @@ use crate::track::{ResourceUsageCompatibilityError, Tracker, UsageScope};
|
||||
use crate::{api_log, binding_model};
|
||||
use alloc::sync::Arc;
|
||||
use alloc::vec::Vec;
|
||||
use core::str;
|
||||
use thiserror::Error;
|
||||
use wgt::DynamicOffset;
|
||||
|
||||
@ -34,6 +35,10 @@ pub struct MissingPipeline;
|
||||
#[error("Setting `values_offset` to be `None` is only for internal use in render bundles")]
|
||||
pub struct InvalidValuesOffset;
|
||||
|
||||
#[derive(Clone, Debug, Error)]
|
||||
#[error("Cannot pop debug group, because number of pushed debug groups is zero")]
|
||||
pub struct InvalidPopDebugGroup;
|
||||
|
||||
pub(crate) struct BaseState<'scope, 'snatch_guard, 'cmd_buf, 'raw_encoder> {
|
||||
pub(crate) device: &'cmd_buf Arc<Device>,
|
||||
|
||||
@ -57,6 +62,9 @@ pub(crate) struct BaseState<'scope, 'snatch_guard, 'cmd_buf, 'raw_encoder> {
|
||||
pub(crate) dynamic_offset_count: usize,
|
||||
|
||||
pub(crate) snatch_guard: &'snatch_guard SnatchGuard<'snatch_guard>,
|
||||
|
||||
pub(crate) debug_scope_depth: u32,
|
||||
pub(crate) string_offset: usize,
|
||||
}
|
||||
|
||||
pub(crate) fn set_bind_group<E>(
|
||||
@ -290,3 +298,59 @@ where
|
||||
query_set.validate_and_write_timestamp(state.raw_encoder, query_index, pending_query_resets)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn push_debug_group(state: &mut BaseState, string_data: &[u8], len: usize) {
|
||||
state.debug_scope_depth += 1;
|
||||
if !state
|
||||
.device
|
||||
.instance_flags
|
||||
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
|
||||
{
|
||||
let label =
|
||||
str::from_utf8(&string_data[state.string_offset..state.string_offset + len]).unwrap();
|
||||
|
||||
api_log!("Pass::push_debug_group {label:?}");
|
||||
unsafe {
|
||||
state.raw_encoder.begin_debug_marker(label);
|
||||
}
|
||||
}
|
||||
state.string_offset += len;
|
||||
}
|
||||
|
||||
pub(crate) fn pop_debug_group<E>(state: &mut BaseState) -> Result<(), E>
|
||||
where
|
||||
E: From<InvalidPopDebugGroup>,
|
||||
{
|
||||
api_log!("Pass::pop_debug_group");
|
||||
|
||||
if state.debug_scope_depth == 0 {
|
||||
return Err(InvalidPopDebugGroup.into());
|
||||
}
|
||||
state.debug_scope_depth -= 1;
|
||||
if !state
|
||||
.device
|
||||
.instance_flags
|
||||
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
|
||||
{
|
||||
unsafe {
|
||||
state.raw_encoder.end_debug_marker();
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn insert_debug_marker(state: &mut BaseState, string_data: &[u8], len: usize) {
|
||||
if !state
|
||||
.device
|
||||
.instance_flags
|
||||
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
|
||||
{
|
||||
let label =
|
||||
str::from_utf8(&string_data[state.string_offset..state.string_offset + len]).unwrap();
|
||||
api_log!("Pass::insert_debug_marker {label:?}");
|
||||
unsafe {
|
||||
state.raw_encoder.insert_debug_marker(label);
|
||||
}
|
||||
}
|
||||
state.string_offset += len;
|
||||
}
|
||||
|
||||
@ -499,14 +499,11 @@ struct State<'scope, 'snatch_guard, 'cmd_buf, 'raw_encoder> {
|
||||
pipeline: Option<Arc<RenderPipeline>>,
|
||||
index: IndexState,
|
||||
vertex: VertexState,
|
||||
debug_scope_depth: u32,
|
||||
|
||||
info: RenderPassInfo,
|
||||
|
||||
general: pass::BaseState<'scope, 'snatch_guard, 'cmd_buf, 'raw_encoder>,
|
||||
|
||||
string_offset: usize,
|
||||
|
||||
active_occlusion_query: Option<(Arc<QuerySet>, u32)>,
|
||||
active_pipeline_statistics_query: Option<(Arc<QuerySet>, u32)>,
|
||||
}
|
||||
@ -721,8 +718,8 @@ pub enum RenderPassErrorInner {
|
||||
end_count_offset: u64,
|
||||
count_buffer_size: u64,
|
||||
},
|
||||
#[error("Cannot pop debug group, because number of pushed debug groups is zero")]
|
||||
InvalidPopDebugGroup,
|
||||
#[error(transparent)]
|
||||
InvalidPopDebugGroup(#[from] pass::InvalidPopDebugGroup),
|
||||
#[error(transparent)]
|
||||
ResourceUsageCompatibility(#[from] ResourceUsageCompatibilityError),
|
||||
#[error("Render bundle has incompatible targets, {0}")]
|
||||
@ -1829,7 +1826,6 @@ impl Global {
|
||||
pipeline: None,
|
||||
index: IndexState::default(),
|
||||
vertex: VertexState::default(),
|
||||
debug_scope_depth: 0,
|
||||
|
||||
info,
|
||||
|
||||
@ -1848,8 +1844,10 @@ impl Global {
|
||||
|
||||
temp_offsets: Vec::new(),
|
||||
dynamic_offset_count: 0,
|
||||
|
||||
debug_scope_depth: 0,
|
||||
string_offset: 0,
|
||||
},
|
||||
string_offset: 0,
|
||||
|
||||
active_occlusion_query: None,
|
||||
active_pipeline_statistics_query: None,
|
||||
@ -2036,14 +2034,15 @@ impl Global {
|
||||
.map_pass_err(scope)?;
|
||||
}
|
||||
ArcRenderCommand::PushDebugGroup { color: _, len } => {
|
||||
push_debug_group(&mut state, &base.string_data, len);
|
||||
pass::push_debug_group(&mut state.general, &base.string_data, len);
|
||||
}
|
||||
ArcRenderCommand::PopDebugGroup => {
|
||||
let scope = PassErrorScope::PopDebugGroup;
|
||||
pop_debug_group(&mut state).map_pass_err(scope)?;
|
||||
pass::pop_debug_group::<RenderPassErrorInner>(&mut state.general)
|
||||
.map_pass_err(scope)?;
|
||||
}
|
||||
ArcRenderCommand::InsertDebugMarker { color: _, len } => {
|
||||
insert_debug_marker(&mut state, &base.string_data, len);
|
||||
pass::insert_debug_marker(&mut state.general, &base.string_data, len);
|
||||
}
|
||||
ArcRenderCommand::WriteTimestamp {
|
||||
query_set,
|
||||
@ -2836,62 +2835,6 @@ fn multi_draw_indirect_count(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn push_debug_group(state: &mut State, string_data: &[u8], len: usize) {
|
||||
state.debug_scope_depth += 1;
|
||||
if !state
|
||||
.general
|
||||
.device
|
||||
.instance_flags
|
||||
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
|
||||
{
|
||||
let label =
|
||||
str::from_utf8(&string_data[state.string_offset..state.string_offset + len]).unwrap();
|
||||
|
||||
api_log!("RenderPass::push_debug_group {label:?}");
|
||||
unsafe {
|
||||
state.general.raw_encoder.begin_debug_marker(label);
|
||||
}
|
||||
}
|
||||
state.string_offset += len;
|
||||
}
|
||||
|
||||
fn pop_debug_group(state: &mut State) -> Result<(), RenderPassErrorInner> {
|
||||
api_log!("RenderPass::pop_debug_group");
|
||||
|
||||
if state.debug_scope_depth == 0 {
|
||||
return Err(RenderPassErrorInner::InvalidPopDebugGroup);
|
||||
}
|
||||
state.debug_scope_depth -= 1;
|
||||
if !state
|
||||
.general
|
||||
.device
|
||||
.instance_flags
|
||||
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
|
||||
{
|
||||
unsafe {
|
||||
state.general.raw_encoder.end_debug_marker();
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn insert_debug_marker(state: &mut State, string_data: &[u8], len: usize) {
|
||||
if !state
|
||||
.general
|
||||
.device
|
||||
.instance_flags
|
||||
.contains(wgt::InstanceFlags::DISCARD_HAL_LABELS)
|
||||
{
|
||||
let label =
|
||||
str::from_utf8(&string_data[state.string_offset..state.string_offset + len]).unwrap();
|
||||
api_log!("RenderPass::insert_debug_marker {label:?}");
|
||||
unsafe {
|
||||
state.general.raw_encoder.insert_debug_marker(label);
|
||||
}
|
||||
}
|
||||
state.string_offset += len;
|
||||
}
|
||||
|
||||
fn execute_bundle(
|
||||
state: &mut State,
|
||||
indirect_draw_validation_resources: &mut crate::indirect_validation::DrawResources,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user