pub struct GpuMemoryPool {
pub capacity: usize,
pub allocated: usize,
/* private fields */
}Expand description
A simple slab-style GPU memory pool that sub-allocates CpuBuffers from
a fixed-capacity backing store.
The pool pre-allocates a large buffer and hands out non-overlapping slices
(as CpuBuffer views backed by offsets). On a real GPU this avoids per-
allocation overhead from vkAllocateMemory.
This CPU-side mock tracks allocations as (offset, size) pairs and
simulates fragmentation/free-list behaviour.
Fields§
§capacity: usizeTotal capacity of the pool in f32 elements.
allocated: usizeCurrently allocated f32 elements.
Implementations§
Source§impl GpuMemoryPool
impl GpuMemoryPool
Sourcepub fn alloc(&mut self, size: usize) -> Option<(usize, usize)>
pub fn alloc(&mut self, size: usize) -> Option<(usize, usize)>
Attempt to allocate size f32 elements from the pool.
Returns Some((offset, size)) on success, None if the pool is full.
Uses a first-fit strategy.
Sourcepub fn free(&mut self, offset: usize, size: usize) -> Result<(), &'static str>
pub fn free(&mut self, offset: usize, size: usize) -> Result<(), &'static str>
Free a previously allocated block (offset, size).
Returns Err if the block was never allocated (invalid free).
Sourcepub fn free_space(&self) -> usize
pub fn free_space(&self) -> usize
Remaining free f32 elements.
Sourcepub fn is_fully_free(&self) -> bool
pub fn is_fully_free(&self) -> bool
Returns true if the pool has no outstanding allocations.
Sourcepub fn fragmentation_count(&self) -> usize
pub fn fragmentation_count(&self) -> usize
Number of fragmented free-list entries (1 = perfectly contiguous).
Sourcepub fn alloc_buffer(
&mut self,
label: &str,
n: usize,
usage: BufferUsage,
) -> Option<(CpuBuffer, (usize, usize))>
pub fn alloc_buffer( &mut self, label: &str, n: usize, usage: BufferUsage, ) -> Option<(CpuBuffer, (usize, usize))>
Allocate a named CpuBuffer from the pool, returning the buffer
and the pool allocation handle (offset, size).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for GpuMemoryPool
impl RefUnwindSafe for GpuMemoryPool
impl Send for GpuMemoryPool
impl Sync for GpuMemoryPool
impl Unpin for GpuMemoryPool
impl UnsafeUnpin for GpuMemoryPool
impl UnwindSafe for GpuMemoryPool
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