Skip to main content

HostBuffer

Struct HostBuffer 

Source
pub struct HostBuffer<B = Buffer> { /* private fields */ }
Expand description

One growable GPU buffer plus the CPU-side staging vector a frame bump- allocates into.

Generic over the buffer type (B) for the same reason crate::texture::Texture is generic over its texture: the bump pointer, alignment, growth and flush behavior are exercised on a host with a stand-in value. The engine always uses the default HostBuffer<wgpu::Buffer>.

Implementations§

Source§

impl<B> HostBuffer<B>

Source

pub fn new(caps: &TierCaps) -> Self

An empty arena aligned for caps’ adapter. No GPU buffer exists until the first Self::flush that has bytes to upload.

Source

pub fn with_label(caps: &TierCaps, label: &str) -> Self

Self::new with a caller-chosen debug label on the GPU buffer, for a host that runs more than one arena and wants to tell them apart in a graphics debugger.

Source

pub fn alloc(&mut self, bytes: &[u8], align: u32) -> BufferSlice

Appends bytes to this frame’s data and returns the slice they occupy.

The offset is rounded up to max(align, min_uniform_buffer_offset_alignment), so a caller passes the alignment its own use needs (a vertex stride, 1 for “no opinion”) and never has to know the adapter’s. Padding bytes are zero-filled.

Source

pub fn reset(&mut self)

Rewinds the bump pointer for a new frame, keeping the GPU buffer and its capacity.

Every BufferSlice handed out before this call is stale afterwards — the next frame’s allocations reuse those offsets.

Source

pub fn flush<U>(&mut self, uploader: &U) -> Option<&B>
where U: BufferUploader<Buffer = B>,

Uploads this frame’s bytes in one write_buffer, growing (or creating) the GPU buffer first if the frame outgrew it, and returns the buffer the frame’s BufferSlice offsets refer to.

Answers None only when nothing has ever been allocated, so there is no buffer to name. Call once per frame, after the frame’s last Self::alloc and before submitting commands that read it.

Source

pub fn buffer(&self) -> Option<&B>

The GPU buffer backing the arena, once one exists.

Source

pub fn used(&self) -> u64

Bytes allocated so far this frame, padding included.

Source

pub fn capacity(&self) -> u64

The GPU buffer’s current size in bytes, 0 before the first flush.

Source

pub fn high_water_mark(&self) -> u64

The largest single frame the arena has ever held, in bytes — what a host would size an initial capacity against.

Source

pub fn buffer_allocations(&self) -> u64

How many times a GPU buffer has been created: one for the first non-empty frame, plus one per growth. A steady-state frame loop leaves this constant.

Source

pub fn flush_count(&self) -> u64

How many uploads the arena has issued — one per non-empty flush.

Source

pub fn min_alignment(&self) -> u32

The alignment floor every slice is rounded up to, from the adapter’s min_uniform_buffer_offset_alignment.

Trait Implementations§

Source§

impl<B: Debug> Debug for HostBuffer<B>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<B> Freeze for HostBuffer<B>
where Option<B>: Freeze,

§

impl<B> RefUnwindSafe for HostBuffer<B>

§

impl<B> Send for HostBuffer<B>
where Option<B>: Send,

§

impl<B> Sync for HostBuffer<B>
where Option<B>: Sync,

§

impl<B> Unpin for HostBuffer<B>
where Option<B>: Unpin,

§

impl<B> UnsafeUnpin for HostBuffer<B>
where Option<B>: UnsafeUnpin,

§

impl<B> UnwindSafe for HostBuffer<B>
where Option<B>: UnwindSafe,

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> 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, !>

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> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

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