pub struct Array {
storage: ArrayStorage,
element_size: u64,
max_dimension: Option<u32>,
}Expand description
A growable flat array of fixed-size elements, held in whichever resource the device can read.
This is the device-independent front end to the module: a caller
sizes an array by its element count, uploads the same packed bytes on either
path, and binds it through Self::handle without knowing which resource
it landed in. Pass Some(max_texture_dimension_2d) to put it in a texture
and None to put it in a storage buffer.
Fields§
§storage: ArrayStorageThe resource the elements live in.
element_size: u64Bytes per element.
max_dimension: Option<u32>The texture limit on the texel path, None on the buffer path.
Implementations§
Source§impl Array
impl Array
Sourcepub fn new(
device: &Device,
label: Option<&str>,
element_size: u64,
capacity: u64,
max_dimension: Option<u32>,
) -> Self
pub fn new( device: &Device, label: Option<&str>, element_size: u64, capacity: u64, max_dimension: Option<u32>, ) -> Self
Allocate an array with room for capacity elements of element_size
bytes.
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 TexelArray::new panics, on the texel path.
Sourcepub fn element_size(&self) -> u64
pub fn element_size(&self) -> u64
Bytes per element.
Sourcepub fn is_texel(&self) -> bool
pub fn is_texel(&self) -> bool
Whether the elements are held in a texture rather than a buffer.
Sourcepub fn handle(&self) -> ArrayHandle
pub fn handle(&self) -> ArrayHandle
The bindable handle to the current resource.
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 grow_to(
&mut self,
device: &Device,
label: Option<&str>,
capacity: u64,
) -> bool
pub fn grow_to( &mut self, device: &Device, label: Option<&str>, capacity: u64, ) -> bool
Grow to hold at least capacity elements, returning whether the
resource was replaced.
A replacement is what a caller has to publish: every bind group built from the old handle is stale and has to be rebuilt. A no-op when the array already has the room.
§Panics
Under the conditions TexelArray::new panics, on the texel path.
Sourcepub fn upload(
&mut self,
device: &Device,
encoder: &mut CommandEncoder,
elements: &[u8],
)
pub fn upload( &mut self, device: &Device, encoder: &mut CommandEncoder, elements: &[u8], )
Upload elements — whole elements, laid out as the storage buffer would
have held them — recording the copy into encoder.
§Panics
If elements is not a whole number of elements, or holds more than
Self::capacity of them.
Sourcepub fn write(&mut self, queue: &Queue, elements: &[u8])
pub fn write(&mut self, queue: &Queue, elements: &[u8])
Upload elements immediately, for an array written once rather than
every frame.
This mirrors [wgpu::Queue::write_buffer] and
[wgpu::Queue::write_texture]: the bytes reach the resource through a
temporary buffer wgpu allocates and submits for the caller, so there is
no encoder to batch into. Prefer Self::upload for data that changes
every frame, where a reused staging buffer costs nothing per frame.
§Panics
If elements is not a whole number of elements, or holds more than
Self::capacity of them.
Auto Trait Implementations§
impl !RefUnwindSafe for Array
impl !UnwindSafe for Array
impl Forget for Array
impl Freeze for Array
impl Send for Array
impl Sync for Array
impl Unpin for Array
impl UnsafeUnpin for Array
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