diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 000f04cab..8884ab35d 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -651,8 +651,14 @@ impl Global { query_index, } => { let scope = PassErrorScope::WriteTimestamp; - write_timestamp(&mut state, cmd_buf.as_ref(), query_set, query_index) - .map_pass_err(scope)?; + pass::write_timestamp::( + &mut state.general, + cmd_buf.as_ref(), + None, + query_set, + query_index, + ) + .map_pass_err(scope)?; } ArcComputeCommand::BeginPipelineStatisticsQuery { query_set, @@ -1043,25 +1049,6 @@ fn insert_debug_marker(state: &mut State, string_data: &[u8], len: usize) { state.string_offset += len; } -fn write_timestamp( - state: &mut State, - cmd_buf: &CommandBuffer, - query_set: Arc, - query_index: u32, -) -> Result<(), ComputePassErrorInner> { - query_set.same_device_as(cmd_buf)?; - - state - .general - .device - .require_features(wgt::Features::TIMESTAMP_QUERY_INSIDE_PASSES)?; - - let query_set = state.general.tracker.query_sets.insert_single(query_set); - - query_set.validate_and_write_timestamp(state.general.raw_encoder, query_index, None)?; - Ok(()) -} - // Recording a compute pass. // // The only error that should be returned from these methods is diff --git a/wgpu-core/src/command/pass.rs b/wgpu-core/src/command/pass.rs index 334e8b0bd..20cabc182 100644 --- a/wgpu-core/src/command/pass.rs +++ b/wgpu-core/src/command/pass.rs @@ -3,12 +3,12 @@ use crate::binding_model::{BindError, BindGroup, PushConstantUploadError}; use crate::command::bind::Binder; use crate::command::memory_init::{CommandBufferTextureMemoryActions, SurfacesInDiscardState}; -use crate::command::CommandBuffer; -use crate::device::{Device, DeviceError}; +use crate::command::{CommandBuffer, QueryResetMap, QueryUseError}; +use crate::device::{Device, DeviceError, MissingFeatures}; use crate::init_tracker::BufferInitTrackerAction; use crate::pipeline::LateSizedBufferGroup; use crate::ray_tracing::AsAction; -use crate::resource::{DestroyedResourceError, Labeled, ParentDevice}; +use crate::resource::{DestroyedResourceError, Labeled, ParentDevice, QuerySet}; use crate::snatch::SnatchGuard; use crate::track::{ResourceUsageCompatibilityError, Tracker, UsageScope}; use crate::{api_log, binding_model}; @@ -263,3 +263,30 @@ where } Ok(()) } + +pub(crate) fn write_timestamp( + state: &mut BaseState, + cmd_buf: &CommandBuffer, + pending_query_resets: Option<&mut QueryResetMap>, + query_set: Arc, + query_index: u32, +) -> Result<(), E> +where + E: From + From + From, +{ + api_log!( + "Pass::write_timestamps {query_index} {}", + query_set.error_ident() + ); + + query_set.same_device_as(cmd_buf)?; + + state + .device + .require_features(wgt::Features::TIMESTAMP_QUERY_INSIDE_PASSES)?; + + let query_set = state.tracker.query_sets.insert_single(query_set); + + query_set.validate_and_write_timestamp(state.raw_encoder, query_index, pending_query_resets)?; + Ok(()) +} diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index fc91281a7..ff6ccb2f6 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -2050,10 +2050,10 @@ impl Global { query_index, } => { let scope = PassErrorScope::WriteTimestamp; - write_timestamp( - &mut state, + pass::write_timestamp::( + &mut state.general, cmd_buf.as_ref(), - &mut cmd_buf_data.pending_query_resets, + Some(&mut cmd_buf_data.pending_query_resets), query_set, query_index, ) @@ -2892,35 +2892,6 @@ fn insert_debug_marker(state: &mut State, string_data: &[u8], len: usize) { state.string_offset += len; } -fn write_timestamp( - state: &mut State, - cmd_buf: &CommandBuffer, - pending_query_resets: &mut QueryResetMap, - query_set: Arc, - query_index: u32, -) -> Result<(), RenderPassErrorInner> { - api_log!( - "RenderPass::write_timestamps {query_index} {}", - query_set.error_ident() - ); - - query_set.same_device_as(cmd_buf)?; - - state - .general - .device - .require_features(wgt::Features::TIMESTAMP_QUERY_INSIDE_PASSES)?; - - let query_set = state.general.tracker.query_sets.insert_single(query_set); - - query_set.validate_and_write_timestamp( - state.general.raw_encoder, - query_index, - Some(pending_query_resets), - )?; - Ok(()) -} - fn execute_bundle( state: &mut State, indirect_draw_validation_resources: &mut crate::indirect_validation::DrawResources,