Skip to main content

Array

Struct Array 

Source
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: ArrayStorage

The resource the elements live in.

§element_size: u64

Bytes per element.

§max_dimension: Option<u32>

The texture limit on the texel path, None on the buffer path.

Implementations§

Source§

impl Array

Source

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.

Source

pub fn element_size(&self) -> u64

Bytes per element.

Source

pub fn capacity(&self) -> u64

How many elements fit without growing.

Source

pub fn is_texel(&self) -> bool

Whether the elements are held in a texture rather than a buffer.

Source

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.

Source

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.

Source

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.

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more