Skip to main content

RingBuffer

Struct RingBuffer 

Source
pub struct RingBuffer {
    pub buffer: Buffer,
    /* private fields */
}
Expand description

A streaming GPU vertex/index ring buffer.

Holds a single VERTEX | INDEX | COPY_DST GPU buffer; sub-ranges are handed out sequentially and the cursor wraps back to zero at the end of each frame (or when the remaining space is insufficient for an allocation).

Fields§

§buffer: Buffer

The underlying GPU buffer.

Implementations§

Source§

impl RingBuffer

Source

pub fn new(device: &Device, initial_bytes: usize, alignment: u64) -> Self

Create a new ring buffer with an initial capacity of max(initial_bytes, MIN_CAPACITY) bytes.

alignment is the byte alignment applied to every allocation. For vertex buffers 4 is typical; for uniform buffers use device.limits().min_uniform_buffer_offset_alignment.

Source

pub fn reset(&mut self)

Reset the write cursor to zero.

Must be called once per frame before any allocations for that frame. Does NOT wait for the GPU — the caller must ensure the previous frame’s GPU work has completed before calling reset().

Source

pub fn upload( &mut self, device: &Device, queue: &Queue, data: &[u8], ) -> Result<RingAllocation, UiError>

Allocate size bytes from the ring buffer and upload data into the allocation via queue.write_buffer.

Returns a RingAllocation describing the offset and size within self.buffer.

§Wrapping

If the remaining capacity after the cursor is insufficient, the cursor wraps to zero (one wrap per frame is normal; multiple wraps in a single frame indicate the buffer is undersized — consider calling grow).

§Growing

If even a fresh buffer at offset 0 cannot fit the requested size the buffer is automatically grown to max(capacity * 2, align_up(size)) and grow_count is incremented.

§Errors

Returns UiError::Render only if the allocation remains impossible after an attempted grow (e.g. device OOM). In practice this should not occur for reasonable data sizes.

Source

pub fn grow(&mut self, device: &Device, min_size: usize) -> Result<(), UiError>

Explicitly grow the ring buffer to at least min_size bytes.

The new capacity is max(capacity * 2, next_power_of_two(min_size)). The cursor is reset to zero after a grow.

§Errors

Returns UiError::Render on failure (typically OOM).

Source

pub fn stats(&self) -> RingBufferStats

Return a snapshot of the ring buffer’s lifetime statistics.

Source

pub fn capacity(&self) -> usize

Current byte capacity of the underlying GPU buffer.

Source

pub fn cursor(&self) -> usize

Current write cursor offset in bytes.

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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 = Infallible

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,

Source§

impl<T> WasmNotSendSync for T

Source§

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