Skip to main content

HostBuffer

Struct HostBuffer 

Source
pub struct HostBuffer { /* private fields */ }
Expand description

HostBuffer bump-allocates per-draw uniforms and transient vertex data.

Each frame writes into CPU scratch; Self::flush copies touched blocks with one queue.write_buffer each. wgpu stages those writes, so the ring needs no fences. A 3-frame ring of persistent buffers means warm frames create nothing — the cost that matters most on wasm.

Uniforms bind once per block via a dynamic offset. Vertex data (stencil fans, stroke strips) lands in a second family of blocks. All uploads go through the alloc/flush seam so a mapped staging backend can replace this implementation without touching call sites.

Implementations§

Source§

impl HostBuffer

Source

pub fn new(device: &Device) -> Self

new creates an empty host buffer for device.

Uniform stride is at least the per-draw record size and at least the device’s min_uniform_buffer_offset_alignment.

Source

pub fn bind_group_layout(&self) -> &BindGroupLayout

bind_group_layout returns the group-0 layout for per-draw uniforms.

Binding 0 is a dynamic-offset uniform buffer. Pipeline layouts are built from this layout.

Source

pub fn begin_frame(&mut self)

begin_frame rotates to the next arena and resets its cursors.

Blocks are retained so warm frames never create buffers. Trailing unused blocks from a spike drain after a few idle ring passes so a recurring large mesh does not recreate them every frame.

Source

pub fn flush(&mut self, queue: &Queue) -> (u64, u64)

flush uploads this frame’s used scratch to the GPU.

One write_buffer runs per touched block. Returns (uniform_bytes, vertex_bytes) written, for frame statistics.

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