pub struct TexturePool { /* private fields */ }Expand description
A pool of GPU textures backed by a fixed memory budget and an optional count-based capacity limit.
Implementations§
Source§impl TexturePool
impl TexturePool
Sourcepub fn new(max_gb: f64) -> Self
pub fn new(max_gb: f64) -> Self
Create a pool with a budget of max_gb gigabytes and no count limit.
Sourcepub fn with_capacity(max: usize) -> Self
pub fn with_capacity(max: usize) -> Self
Create a pool with an explicit maximum texture count.
When the pool holds max live textures, allocate returns None.
Use evict_lru or allocate_with_lru_eviction to make room.
The byte budget is set to usize::MAX (effectively unlimited).
Sourcepub fn evict_lru(&mut self) -> usize
pub fn evict_lru(&mut self) -> usize
Evict all LRU textures until the pool is below its max_textures limit
(or until the pool is empty).
Returns the number of textures evicted.
Sourcepub fn allocate(&mut self, desc: TextureDescriptor) -> Option<usize>
pub fn allocate(&mut self, desc: TextureDescriptor) -> Option<usize>
Allocate a texture in the pool
Returns Some(handle) on success, or None if the byte budget or the
count capacity (max_textures) is exceeded.
Sourcepub fn allocate_with_lru_eviction(
&mut self,
desc: TextureDescriptor,
) -> Option<usize>
pub fn allocate_with_lru_eviction( &mut self, desc: TextureDescriptor, ) -> Option<usize>
Allocate a texture, evicting the LRU slot if the budget or count limit is exceeded.
Returns Some(handle) on success, or None if eviction cannot free
enough resources (e.g. a single remaining texture is larger than the
requested one’s byte budget).
Sourcepub fn lru_handle(&self) -> Option<usize>
pub fn lru_handle(&self) -> Option<usize>
Return the handle of the least-recently-used allocated texture, or
None if the pool is empty.
Sourcepub fn touch(&mut self, handle: usize)
pub fn touch(&mut self, handle: usize)
Update the access timestamp of handle to mark it as recently used.
Sourcepub fn utilization(&self) -> f64
pub fn utilization(&self) -> f64
Utilisation in [0.0, 1.0]
Sourcepub fn live_count(&self) -> usize
pub fn live_count(&self) -> usize
Number of live (allocated) textures
Sourcepub fn allocated_bytes(&self) -> usize
pub fn allocated_bytes(&self) -> usize
Currently allocated bytes
Auto Trait Implementations§
impl Freeze for TexturePool
impl RefUnwindSafe for TexturePool
impl Send for TexturePool
impl Sync for TexturePool
impl Unpin for TexturePool
impl UnsafeUnpin for TexturePool
impl UnwindSafe for TexturePool
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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