pub struct BufferPool {
buffer: Buffer,
label: &'static str,
usage: BufferUsages,
allocator: Allocator,
}Expand description
One GPU buffer sub-allocated into many ranges.
See the module documentation for what a pool is for.
Fields§
§buffer: BufferThe buffer every range lives in.
label: &'static strThe label the buffer is created with, reused when it is replaced.
usage: BufferUsagesThe usages the buffer is created with.
allocator: AllocatorWhere the free space is.
Implementations§
Source§impl BufferPool
impl BufferPool
Sourcepub fn new(
device: &Device,
label: &'static str,
usage: BufferUsages,
size: u64,
) -> Self
pub fn new( device: &Device, label: &'static str, usage: BufferUsages, size: u64, ) -> Self
Creates a pool over a buffer of size bytes with the given usages.
The buffer is created immediately. size is rounded up to a multiple
of COPY_BUFFER_ALIGNMENT.
§Panics
Panics if the usages do not include [wgpu::BufferUsages::COPY_DST],
which the pool needs to grow.
Sourcepub fn buffer(&self) -> &Buffer
pub fn buffer(&self) -> &Buffer
The buffer every range lives in.
This changes when the pool grows, so read it again instead of holding one: a range stays valid across a grow, but names no buffer of its own to read it from.
Sourcepub fn free_space(&self) -> u32
pub fn free_space(&self) -> u32
The free space left, in bytes.
Sourcepub fn allocation_size(&self, allocation: Allocation) -> u32
pub fn allocation_size(&self, allocation: Allocation) -> u32
The size reserved for allocation, in bytes.
This is the requested size rounded up to the alignment.
Sourcepub fn allocate(
&mut self,
device: &Device,
queue: &Queue,
size: u32,
) -> Option<BufferRange>
pub fn allocate( &mut self, device: &Device, queue: &Queue, size: u32, ) -> Option<BufferRange>
Reserves a range of size bytes, growing the pool if it does not fit.
Returns None only if the pool cannot grow any further (its size would
overflow a u32, or it has run out of node slots for its ranges). The
returned range’s offset is a multiple of COPY_BUFFER_ALIGNMENT, and
its allocation covers size rounded up to it.
Growing allocates a new buffer 1.5x the pool’s size, copies the old
contents into it, and appends the difference to the allocator. Existing
ranges keep their offsets, but the buffer they name changes, so a
caller holding one must re-read BufferPool::buffer.
Sourcepub fn release(&mut self, allocation: Allocation)
pub fn release(&mut self, allocation: Allocation)
Sourcefn range(&self, allocation: Allocation) -> BufferRange
fn range(&self, allocation: Allocation) -> BufferRange
Builds the handle for a fresh allocation.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for BufferPool
impl !UnwindSafe for BufferPool
impl Forget for BufferPool
impl Freeze for BufferPool
impl Send for BufferPool
impl Sync for BufferPool
impl Unpin for BufferPool
impl UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§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