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>
impl<B> HostBuffer<B>
Sourcepub fn new(caps: &TierCaps) -> Self
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.
Sourcepub fn with_label(caps: &TierCaps, label: &str) -> Self
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.
Sourcepub fn alloc(&mut self, bytes: &[u8], align: u32) -> BufferSlice
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.
Sourcepub fn reset(&mut self)
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.
Sourcepub fn flush<U>(&mut self, uploader: &U) -> Option<&B>where
U: BufferUploader<Buffer = B>,
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.
Sourcepub fn capacity(&self) -> u64
pub fn capacity(&self) -> u64
The GPU buffer’s current size in bytes, 0 before the first flush.
Sourcepub fn high_water_mark(&self) -> u64
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.
Sourcepub fn buffer_allocations(&self) -> u64
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.
Sourcepub fn flush_count(&self) -> u64
pub fn flush_count(&self) -> u64
How many uploads the arena has issued — one per non-empty flush.
Sourcepub fn min_alignment(&self) -> u32
pub fn min_alignment(&self) -> u32
The alignment floor every slice is rounded up to, from the adapter’s
min_uniform_buffer_offset_alignment.