Skip to main content

TimestampRing

Struct TimestampRing 

Source
pub struct TimestampRing { /* private fields */ }
Expand description

A ring of per-frame GPU timestamp query sets — see the module header.

Implementations§

Source§

impl TimestampRing

Source

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.

Source

pub fn with_capacity( device: &Device, queue: &Queue, spans: usize, passes: usize, label: &str, ) -> Self

Self::new with an explicit per-frame pass capacity.

Source

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.

Source

pub fn is_active(&self) -> bool

Whether this ring holds real query sets, i.e. whether a frame line should report gpu_q=1.

Source

pub fn spans(&self) -> usize

How many named spans a frame is split into.

Source

pub fn timestamp_period_ns(&self) -> f32

Nanoseconds per timestamp tick, 0.0 on an inert ring.

Source

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.

Source

pub fn harvested(&self) -> u64

How many frame readings this ring has harvested.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for TimestampRing

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,