Skip to main content

CullStatsRing

Struct CullStatsRing 

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

A ring of host-readable buffers, one per frame in flight plus one.

Implementations§

Source§

impl CullStatsRing

Source

pub fn new( device: &dyn Device, frames_in_flight: usize, counts_clusters: bool, ) -> Option<Self>

Builds the ring, or None if the device will not give it its buffers.

counts_clusters is whether the caller built an amplification stage — ForwardRenderer::culls_clusters, not a device capability — because that is what decides whether the cluster word is a count or the zero the clearing pass left.

None is not an error: it is PassTimers::new’s answer to a device with no timestamps, for the same reason. The caller adds no copy pass and the panel says indirect.

Source

pub const fn latest(&self) -> Option<CullStats>

The most recent frame whose statistics have actually landed, or None until the first readback has answered.

Source

pub fn begin_frame(&mut self, device: &dyn Device)

Starts a frame: requests the readback the last frame’s copy earned, then polls everything outstanding.

Called once per frame, before add_copy_pass, and after the previous frame was submitted — which is the frame loop’s own order, since a frame is recorded, submitted and presented before the next one starts. See the module docs for why the request cannot happen at the copy.

Source

pub fn add_copy_pass(&mut self, graph: &mut RenderGraph<'_>, stats: BufferId)

Adds the copy that takes this frame’s statistics off the GPU.

stats is the id GeneratedDraws::visible_count_id handed back, so the graph moves the buffer into ResourceState::TransferSrc and back out again; there is not a hand-written barrier here, which is the whole difference between this and crcbl::screenshot’s copy.

Declare it last, after every pass that writes that buffer: the cull dispatch, the amplification stage and the light grid all add to it, and a copy scheduled between them reads a total half the frame has not contributed to yet.

Nothing is added on a frame that finds every slot still waiting on an answer. The alternative is a copy into a buffer a readback is still mapping, and a frame’s statistics are worth far less than that: the panel keeps the number it has, still stamped with the frame it came from, and the next frame after an answer lands records a copy again.

§The destination is in the graph too, and it has to be

A slot is written by a copy this frame and was written by a copy some frames ago — two writes, in two submissions, with nothing between them. That is a write-after-write hazard exactly like the one the graph already computes for the depth transient across a frame boundary, and it is not made safe by the readback’s completion point: a timeline gates the host’s read, which is a different edge from the GPU’s second write.

So the slot is imported with what the last frame on it left it in — Undefined the first time and TransferDst thereafter — and the copy declares ResourceState::TransferDst on it, which makes the graph emit TransferDst → TransferDst before the copy: a barrier whose source scope covers that earlier submission’s transfer write. An earlier version of this function left the destination out on the grounds that “nothing else in the frame touches it”, which is true and beside the point — the conflicting access is in another frame. CI’s validation layer reported it as SYNC-HAZARD-WRITE-AFTER-WRITE … write_barriers: 0; ours cannot see across submissions at all.

The state never changes after that, which is also what D3D12 requires: a resource on the READBACK heap is created in COPY_DEST and pinned there for its lifetime, so TransferDst is the only state this buffer may ever be declared in.

Source

pub fn destroy(self, device: &dyn Device)

Releases the ring. The device must be idle.

Trait Implementations§

Source§

impl Debug for CullStatsRing

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> HalThreadSafe for T
where T: Send + Sync,

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, 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.