pub struct ArrayPool {
array: Array,
label: Option<String>,
allocator: Allocator,
data: Vec<u8>,
dirty: bool,
replaced: bool,
}Expand description
One array sub-allocated into element ranges, with a CPU mirror of its bytes.
See the module documentation for what a pool is for and how growing works.
Fields§
§array: ArrayThe array every range lives in.
label: Option<String>The label the array is created with, reused when it is replaced.
allocator: AllocatorWhere the free elements are.
data: Vec<u8>The array’s bytes, element for element, kept so a slice can be written without re-reading the GPU resource.
dirty: boolWhether the mirror holds bytes the array has not received yet.
replaced: boolWhether the array was replaced since the last Self::upload.
A replacement is what a caller has to act on: every bind group built from the old handle is stale. Reporting it from the upload keeps the check and the copy in one place, so a caller cannot upload without learning that the array moved.
Implementations§
Source§impl ArrayPool
impl ArrayPool
Sourcepub fn new(
device: &Device,
label: &str,
element_size: u64,
initial_elements: u32,
max_dimension: Option<u32>,
) -> Self
pub fn new( device: &Device, label: &str, element_size: u64, initial_elements: u32, max_dimension: Option<u32>, ) -> Self
Create a pool whose array holds initial_elements elements of
element_size bytes each.
max_dimension is Some of the device’s
[wgpu::Limits::max_texture_dimension_2d] to hold the elements in a
texture, or None to hold them in a storage buffer.
§Panics
Under the conditions Array::new panics.
Sourcepub fn handle(&self) -> ArrayHandle
pub fn handle(&self) -> ArrayHandle
The bindable handle to the pool’s array.
Cloned rather than borrowed so a caller can move it into the resource graph, which is what makes a replaced array mark the bind groups built from it dirty.
Sourcepub fn allocate(&mut self, device: &Device, count: u32) -> Option<ArrayRange>
pub fn allocate(&mut self, device: &Device, count: u32) -> Option<ArrayRange>
Reserves count elements, growing the array if they do 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).
Growing replaces the array, so a caller that holds a handle has to read
it again — and has to upload before the GPU sees the
data the mirror holds.
§Panics
If count is zero, since a range covers at least one element.
Sourcepub fn release(&mut self, allocation: Allocation)
pub fn release(&mut self, allocation: Allocation)
Sourcepub fn write(&mut self, range: ArrayRange, bytes: &[u8])
pub fn write(&mut self, range: ArrayRange, bytes: &[u8])
Sourcepub fn upload(&mut self, device: &Device, encoder: &mut CommandEncoder) -> bool
pub fn upload(&mut self, device: &Device, encoder: &mut CommandEncoder) -> bool
Copy the CPU mirror to the array, recording the copy into encoder.
Returns whether the array had to be replaced since the caller last read its handle, which is what says every bind group built from the old one is stale. An upload of an unchanged pool does nothing.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for ArrayPool
impl !UnwindSafe for ArrayPool
impl Forget for ArrayPool
impl Freeze for ArrayPool
impl Send for ArrayPool
impl Sync for ArrayPool
impl Unpin for ArrayPool
impl UnsafeUnpin for ArrayPool
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