pub struct BufferPool { /* private fields */ }Expand description
Implementations§
Source§impl BufferPool
impl BufferPool
Sourcepub fn new(max_pool_bytes: usize) -> Self
pub fn new(max_pool_bytes: usize) -> Self
Create a new pool that will hold at most max_pool_bytes of backing
storage before refusing new allocations.
Sourcepub fn acquire(&mut self, size_bytes: usize, alignment: usize) -> Option<u64>
pub fn acquire(&mut self, size_bytes: usize, alignment: usize) -> Option<u64>
Check out a buffer of at least size_bytes with at least alignment.
Strategy: find the smallest existing compatible free buffer to minimise fragmentation. If none exists, allocate a new one (provided the pool is below its byte budget).
Returns the buffer id on success, or None if no buffer is available
and allocating a new one would exceed the pool’s byte budget.
Sourcepub fn release(&mut self, id: u64) -> bool
pub fn release(&mut self, id: u64) -> bool
Return a buffer to the pool by id.
The buffer is kept for future reuse but marked as available.
Returns true if the buffer was found and released, false otherwise.
Sourcepub fn get_mut(&mut self, id: u64) -> Option<&mut GpuBuffer>
pub fn get_mut(&mut self, id: u64) -> Option<&mut GpuBuffer>
Mutably borrow the buffer with the given id.
Sourcepub fn defragment(&mut self)
pub fn defragment(&mut self)
Evict all free buffers that have not been used for more than 60 seconds.
In-use buffers are never evicted.
Sourcepub fn total_allocated_bytes(&self) -> usize
pub fn total_allocated_bytes(&self) -> usize
Total bytes currently under management.
Sourcepub fn max_pool_bytes(&self) -> usize
pub fn max_pool_bytes(&self) -> usize
Maximum pool capacity in bytes.
Trait Implementations§
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more