use std::{ops::Range, thread::ThreadId};
use crate::profiler::{
GpuTimerQueryTreeHandle, QueryPairUsageState, ReservedTimerQueryPair, ROOT_QUERY_HANDLE,
};
#[derive(Debug, Clone)]
pub struct GpuTimerQueryResult {
pub label: String,
pub pid: u32,
pub tid: ThreadId,
pub time: Option<Range<f64>>,
pub nested_queries: Vec<GpuTimerQueryResult>,
}
pub struct GpuProfilerQuery {
pub label: String,
pub pid: u32,
pub tid: ThreadId,
pub(crate) timer_query_pair: Option<ReservedTimerQueryPair>,
pub(crate) handle: GpuTimerQueryTreeHandle,
pub(crate) parent_handle: GpuTimerQueryTreeHandle,
pub(crate) has_debug_group: bool,
#[cfg(feature = "tracy")]
pub(crate) tracy_scope: Option<tracy_client::GpuSpan>,
}
impl GpuProfilerQuery {
pub fn render_pass_timestamp_writes(&self) -> Option<wgpu::RenderPassTimestampWrites<'_>> {
self.timer_query_pair.as_ref().and_then(|query| {
(query.usage_state == QueryPairUsageState::ReservedForPassTimestampWrites).then(|| {
wgpu::RenderPassTimestampWrites {
query_set: &query.pool.query_set,
beginning_of_pass_write_index: Some(query.start_query_idx),
end_of_pass_write_index: Some(query.start_query_idx + 1),
}
})
})
}
pub fn compute_pass_timestamp_writes(&self) -> Option<wgpu::ComputePassTimestampWrites<'_>> {
self.timer_query_pair.as_ref().and_then(|query| {
(query.usage_state == QueryPairUsageState::ReservedForPassTimestampWrites).then(|| {
wgpu::ComputePassTimestampWrites {
query_set: &query.pool.query_set,
beginning_of_pass_write_index: Some(query.start_query_idx),
end_of_pass_write_index: Some(query.start_query_idx + 1),
}
})
})
}
#[inline]
pub fn with_parent(self, parent: Option<&GpuProfilerQuery>) -> Self {
Self {
parent_handle: parent.map_or(ROOT_QUERY_HANDLE, |p| p.handle),
..self
}
}
}