pub struct TimestampRing { /* private fields */ }Expand description
A ring of per-frame GPU timestamp query sets — see the module header.
Implementations§
Source§impl TimestampRing
impl TimestampRing
Sourcepub fn new(device: &Device, queue: &Queue, spans: usize, label: &str) -> Self
pub fn new(device: &Device, queue: &Queue, spans: usize, label: &str) -> Self
A ring timing spans named spans per frame, over
DEFAULT_PASS_CAPACITY passes.
Inert — no GPU resource created at all — when device was not created
with wgpu::Features::TIMESTAMP_QUERY, which is every build that did
not compile perf-trace in and every adapter that does not offer the
feature.
Sourcepub fn with_capacity(
device: &Device,
queue: &Queue,
spans: usize,
passes: usize,
label: &str,
) -> Self
pub fn with_capacity( device: &Device, queue: &Queue, spans: usize, passes: usize, label: &str, ) -> Self
Self::new with an explicit per-frame pass capacity.
Sourcepub fn inert(spans: usize) -> Self
pub fn inert(spans: usize) -> Self
A ring that measures nothing, for a device without TIMESTAMP_QUERY
and for a caller that wants the gpu_q=0 shape without a GPU at all.
Sourcepub fn is_active(&self) -> bool
pub fn is_active(&self) -> bool
Whether this ring holds real query sets, i.e. whether a frame line
should report gpu_q=1.
Sourcepub fn timestamp_period_ns(&self) -> f32
pub fn timestamp_period_ns(&self) -> f32
Nanoseconds per timestamp tick, 0.0 on an inert ring.
Sourcepub fn latest(&self) -> Option<GpuFrameSpans>
pub fn latest(&self) -> Option<GpuFrameSpans>
The most recently harvested frame’s spans, or None before the first
reading lands (and forever on an inert ring).
The reading lags the CPU frame that asks for it by up to
RING_FRAMES frames — the price of never blocking on a map. In
steady state one fresh reading lands per frame, so the lag is a
constant offset rather than a gap in the series; Self::harvested
is how a consumer tells a repeat from a fresh reading.
Sourcepub fn begin_frame(&mut self, device: &Device)
pub fn begin_frame(&mut self, device: &Device)
Advances onto the next slot and harvests whatever the frame that last used it left mapped.
Polls device once, without blocking: a map that has not landed leaves
its slot alone and the frame goes untimed rather than stalling on it.
Sourcepub fn pass_writes(&self, span: usize) -> Option<RenderPassTimestampWrites<'_>>
pub fn pass_writes(&self, span: usize) -> Option<RenderPassTimestampWrites<'_>>
The timestamp_writes for one pass belonging to span.
Each call takes a fresh query pair, so a span made of several passes
(the frame’s own strip passes, a layer’s page rounds) sums correctly.
None — an untimed pass — when the ring is inert, the slot was not
free this frame, span is out of range, or the frame has already used
its pass capacity.
Sourcepub fn resolve(&self, encoder: &mut CommandEncoder)
pub fn resolve(&self, encoder: &mut CommandEncoder)
Records this frame’s query resolve and its copy into the mappable readback buffer, into the same encoder the timed passes were recorded into. The caller submits that encoder.
Only the pairs actually taken are resolved: an untouched query resolves to whatever the driver left there, and reading it back would be inventing a span rather than measuring one.
Sourcepub fn end_frame(&mut self)
pub fn end_frame(&mut self)
Requests the map that a later Self::begin_frame harvests. Call
after submitting the encoder Self::resolve was recorded into.
Sourcepub fn abandon_frame(&mut self)
pub fn abandon_frame(&mut self)
Closes a frame that was refused before its encoder was submitted.
Nothing was recorded and nothing will be, so the slot goes straight back to idle without a map — mapping a buffer no copy ever reached would harvest the previous frame’s ticks as if they were this one’s.