pub struct FrameReader { /* private fields */ }Expand description
Ring of staging buffers reading back a width x height target with 4 bytes per texel
(Rgba8Unorm, Bgra8Unorm, …). Make a new one when the size changes.
Implementations§
Source§impl FrameReader
impl FrameReader
Sourcepub fn new(device: &Device, width: u32, height: u32, depth: usize) -> Self
pub fn new(device: &Device, width: u32, height: u32, depth: usize) -> Self
A reader with depth staging buffers (at least 1; 3 keeps the GPU busy without dropping
frames at a steady frame rate).
pub fn width(&self) -> u32
pub fn height(&self) -> u32
Sourcepub fn frame_len(&self) -> usize
pub fn frame_len(&self) -> usize
Bytes one frame takes in the output of the read functions: tightly packed rows, row 0 on top.
Sourcepub fn copy(&mut self, encoder: &mut CommandEncoder, texture: &Texture) -> bool
pub fn copy(&mut self, encoder: &mut CommandEncoder, texture: &Texture) -> bool
Record a copy of texture (the reader’s size) into a free staging buffer. A finished frame
nobody read yet is given up for it, the oldest first. Returns false, recording nothing, when
every buffer still waits for the GPU: the frame is then not captured. Call
Self::submitted once encoder has been submitted.
Sourcepub fn submitted(&mut self)
pub fn submitted(&mut self)
Request the mapping of the buffers Self::copy recorded into. Call after submitting the
encoder holding those copies.
Sourcepub fn read_latest(
&mut self,
device: &Device,
out: &mut [u8],
) -> Result<bool, String>
pub fn read_latest( &mut self, device: &Device, out: &mut [u8], ) -> Result<bool, String>
Write the newest frame the GPU has finished into out (at least Self::frame_len bytes)
without waiting. Ok(false) when no new frame is ready since the last read. Older finished
frames are dropped. A failed map is reported once; the buffer is reused afterwards.
Sourcepub fn read_blocking(
&mut self,
device: &Device,
out: &mut [u8],
) -> Result<bool, String>
pub fn read_blocking( &mut self, device: &Device, out: &mut [u8], ) -> Result<bool, String>
Wait for every submitted copy, then write the newest frame into out like
Self::read_latest. Ok(false) only when nothing was copied since the last read.