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: BufferThe underlying GPU buffer.
Implementations§
Source§impl RingBuffer
impl RingBuffer
Sourcepub fn new(device: &Device, initial_bytes: usize, alignment: u64) -> Self
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.
Sourcepub fn reset(&mut self)
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().
Sourcepub fn upload(
&mut self,
device: &Device,
queue: &Queue,
data: &[u8],
) -> Result<RingAllocation, UiError>
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.
Sourcepub fn grow(&mut self, device: &Device, min_size: usize) -> Result<(), UiError>
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).
Sourcepub fn stats(&self) -> RingBufferStats
pub fn stats(&self) -> RingBufferStats
Return a snapshot of the ring buffer’s lifetime statistics.
Auto Trait Implementations§
impl !RefUnwindSafe for RingBuffer
impl !UnwindSafe for RingBuffer
impl Freeze for RingBuffer
impl Send for RingBuffer
impl Sync for RingBuffer
impl Unpin for RingBuffer
impl UnsafeUnpin for RingBuffer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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