Skip to main content

StreamBuffer

Struct StreamBuffer 

Source
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

Source

pub fn new(usage: BufferUsages, label: &'static str) -> Self

Source

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.

Source

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.

Source

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.

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

Source§

fn downcast(&self) -> &T

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, <T as TryFrom<U>>::Error>

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

Source§

fn upcast(&self) -> Option<&T>

Source§

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