pub struct SubAllocator { /* private fields */ }Expand description
Bump-allocates aligned sub-regions from a single large wgpu::Buffer.
Useful when many small uniform or storage allocations would each require a
separate wgpu::Buffer — instead, one large buffer is created once and
sliced into named regions, reducing BindGroup churn and allocator
overhead.
§Limitations
SubAllocator is a bump allocator — individual regions cannot be freed.
Call reset to reclaim the entire capacity at once.
Implementations§
Source§impl SubAllocator
impl SubAllocator
Sourcepub fn new(buffer: Buffer, capacity: u64, alignment: u64) -> Self
pub fn new(buffer: Buffer, capacity: u64, alignment: u64) -> Self
Create a SubAllocator wrapping buffer with the given capacity and
minimum alignment (must be a power of two; clamped to 1 if zero).
Sourcepub fn alloc(&mut self, size: u64) -> Option<SubRegion>
pub fn alloc(&mut self, size: u64) -> Option<SubRegion>
Allocate a contiguous region of size bytes, aligned to
self.alignment.
Returns None when the remaining capacity is insufficient.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset the cursor to zero, making all previously allocated regions available again. The backing buffer is not cleared.
Sourcepub fn inner(&self) -> &Buffer
pub fn inner(&self) -> &Buffer
Access the underlying wgpu::Buffer.