pub struct BufferPool { /* private fields */ }Expand description
A simple free-list pool that recycles wgpu::Buffers across dispatches
to avoid per-frame reallocation.
Buffers are bucketed by (rounded_size, BufferUsages). The size is
rounded up to the next power of two (minimum 256) on both acquire and
release so that similarly-sized buffers can be reused interchangeably.
§Limitations
The pool does not destroy idle buffers; callers that need memory-bounded
recycling should call BufferPool::available_count and drop excess
buffers manually.
Implementations§
Source§impl BufferPool
impl BufferPool
Sourcepub fn acquire(
&mut self,
device: &Device,
size: u64,
usage: BufferUsages,
) -> Buffer
pub fn acquire( &mut self, device: &Device, size: u64, usage: BufferUsages, ) -> Buffer
Acquire a buffer of at least size bytes with the given usage.
Returns a recycled buffer from the pool when one is available, or
allocates a new one. The actual buffer size may be larger than size
due to power-of-two rounding.
Sourcepub fn release(&mut self, size: u64, usage: BufferUsages, buffer: Buffer)
pub fn release(&mut self, size: u64, usage: BufferUsages, buffer: Buffer)
Return a buffer to the pool so it can be reused by future acquire
calls.
size should be the logical size the caller used for acquire; the
pool applies the same rounding so the buffer lands in the correct
bucket.
Sourcepub fn available_count(&self, size: u64, usage: BufferUsages) -> usize
pub fn available_count(&self, size: u64, usage: BufferUsages) -> usize
Number of idle buffers in the (size, usage) bucket.