pub struct StreamBuffer { /* private fields */ }Expand description
A growable, ring-reset GPU buffer for streaming vertex or index data across contiguous batches within a single frame.
Capacity growth requires &mut self; the per-batch write path only
needs &self thanks to a Cell<u64> cursor, so it composes cleanly
with methods that borrow other parts of the renderer immutably.
Implementations§
Source§impl StreamBuffer
impl StreamBuffer
pub fn new(usage: BufferUsages, label: &'static str) -> Self
Sourcepub fn reset(&self)
pub fn reset(&self)
Reset the write cursor to the start of the buffer.
Call once at the top of render() — previous frame’s contents
are orphaned and overwritten in place.
Sourcepub fn ensure_capacity(&mut self, device: &Device, required_bytes: u64)
pub fn ensure_capacity(&mut self, device: &Device, required_bytes: u64)
Grow the underlying buffer if required_bytes exceeds the current
capacity. Growth rounds up to the next power of two (minimum 1 KiB)
to amortize reallocation. If the existing buffer already fits, this
is a no-op.
Sourcepub fn write(&self, queue: &Queue, data: &[u8]) -> Option<(&Buffer, u64, u64)>
pub fn write(&self, queue: &Queue, data: &[u8]) -> Option<(&Buffer, u64, u64)>
Upload data at the current write cursor and advance the cursor.
Returns Some((buffer, offset, len_bytes)) on success, or None
if ensure_capacity was never called OR
the write would overflow the buffer’s capacity. The caller should
slice the returned buffer at offset..offset + len when binding.
An overflow means the frame-start sizing undercounted this
pipeline’s quads (see stream_quad_counts in renderer.rs).
Debug builds assert with the accounting details; release builds
skip the batch — a dropped draw is recoverable, whereas
forwarding an out-of-bounds write_buffer to wgpu is a
validation error that kills the device.