pub struct BufferPool { /* private fields */ }Expand description
A pool that recycles GPU buffers to avoid frequent allocation/deallocation.
When a buffer is “released” back to the pool it is not deleted, but stored for reuse. When a buffer of the same size and usage is requested, it is returned from the pool instead of allocating a new one.
Implementations§
Source§impl BufferPool
impl BufferPool
Sourcepub fn new(tracker: Arc<MemoryTracker>, max_pool_size: usize) -> Self
pub fn new(tracker: Arc<MemoryTracker>, max_pool_size: usize) -> Self
Create a new buffer pool.
Sourcepub fn acquire(
&mut self,
gl: &Context,
size_bytes: usize,
usage: BufferUsage,
) -> BufferHandle
pub fn acquire( &mut self, gl: &Context, size_bytes: usize, usage: BufferUsage, ) -> BufferHandle
Acquire a buffer of at least size_bytes with the given usage.
Returns an existing pooled buffer if one matches, otherwise allocates new.
Sourcepub fn release(&mut self, gl: &Context, handle: BufferHandle)
pub fn release(&mut self, gl: &Context, handle: BufferHandle)
Release a buffer back to the pool for reuse.
Sourcepub fn destroy(self, gl: &Context)
pub fn destroy(self, gl: &Context)
Destroy the entire pool including in-use buffers. Caller must ensure no in-use buffers are still referenced.
Sourcepub fn available_count(&self) -> usize
pub fn available_count(&self) -> usize
Number of available (pooled) buffers.
Sourcepub fn in_use_count(&self) -> usize
pub fn in_use_count(&self) -> usize
Number of buffers currently in use.
Sourcepub fn pooled_bytes(&self) -> usize
pub fn pooled_bytes(&self) -> usize
Total pooled memory in bytes (available buffers only).
Auto Trait Implementations§
impl Freeze for BufferPool
impl RefUnwindSafe for BufferPool
impl Send for BufferPool
impl Sync for BufferPool
impl Unpin for BufferPool
impl UnsafeUnpin for BufferPool
impl UnwindSafe for BufferPool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.