pub struct GpuBufferPool { /* private fields */ }Expand description
Reusable GPU storage buffers keyed by byte length.
Buffers are recycled through WgpuRuntime::recycle_storage or
GpuBufferPool::recycle. Prefer the runtime helpers for typical use;
access the pool directly when implementing custom kernels. Use each pool with
one runtime/device only. Recycle only after submitting every encoder using
the buffer and relinquishing all other handles to it. New acquisitions are
uninitialized: kernels must overwrite or explicitly clear what they read.
Retention defaults to 64 MiB with at most eight buffers per size. This budget does not limit live allocations. Full pools drop incoming buffers; reducing the budget below current retention clears the cache.
Implementations§
Source§impl GpuBufferPool
impl GpuBufferPool
Sourcepub fn with_budget(budget_bytes: u64) -> Self
pub fn with_budget(budget_bytes: u64) -> Self
Creates a pool with a retained-byte budget; zero disables retention.
Sourcepub fn set_budget(&self, budget_bytes: u64)
pub fn set_budget(&self, budget_bytes: u64)
Changes the retention budget, clearing cached buffers if needed.
Sourcepub fn stats(&self) -> GpuResourcePoolStats
pub fn stats(&self) -> GpuResourcePoolStats
Returns retained bytes/resources and lifetime allocation/reuse counters.
Sourcepub fn acquire_storage(
&self,
runtime: &WgpuRuntime,
label: &'static str,
byte_len: u64,
) -> Buffer
pub fn acquire_storage( &self, runtime: &WgpuRuntime, label: &'static str, byte_len: u64, ) -> Buffer
Acquires an uninitialized reusable storage buffer of the requested size.
Sourcepub fn upload_pod_storage<T: Pod>(
&self,
runtime: &WgpuRuntime,
label: &'static str,
data: &[T],
) -> SpatialResult<Buffer>
pub fn upload_pod_storage<T: Pod>( &self, runtime: &WgpuRuntime, label: &'static str, data: &[T], ) -> SpatialResult<Buffer>
Uploads a POD slice into a pooled storage buffer.
Sourcepub fn upload_f32_storage(
&self,
runtime: &WgpuRuntime,
label: &'static str,
data: &[f32],
) -> SpatialResult<Buffer>
pub fn upload_f32_storage( &self, runtime: &WgpuRuntime, label: &'static str, data: &[f32], ) -> SpatialResult<Buffer>
Uploads f32 values into a pooled storage buffer.
Sourcepub fn upload_u32_storage(
&self,
runtime: &WgpuRuntime,
label: &'static str,
data: &[u32],
) -> SpatialResult<Buffer>
pub fn upload_u32_storage( &self, runtime: &WgpuRuntime, label: &'static str, data: &[u32], ) -> SpatialResult<Buffer>
Uploads u32 values into a pooled storage buffer.
Sourcepub fn recycle(&self, byte_len: u64, buffer: Buffer)
pub fn recycle(&self, byte_len: u64, buffer: Buffer)
Returns a storage buffer after all users have submitted their work.
Buffers with a mismatched size or incompatible usage are discarded. The caller must relinquish every other handle and use this pool only with the runtime/device that created the buffer.
Sourcepub fn clear(&self)
pub fn clear(&self)
Drops cached handles while preserving lifetime counters and the budget. Actual device memory release follows wgpu’s outstanding-work lifetimes.
Sourcepub fn cached_buffer_count(&self) -> usize
pub fn cached_buffer_count(&self) -> usize
Returns the number of buffers currently held in the pool.