Instance

Enum Instance 

Source
pub enum Instance {
    Literal(LiteralInstance),
    Struct(StructInstance),
    Array(ArrayInstance),
    Vec(VecInstance),
    Mat(MatInstance),
    Ptr(PtrInstance),
    Ref(RefInstance),
    Atomic(AtomicInstance),
    Deferred(Type),
}
Expand description

Instance of a plain type.

Reference: https://www.w3.org/TR/WGSL/#plain-types-section

Variants§

§

Literal(LiteralInstance)

§

Struct(StructInstance)

§

Array(ArrayInstance)

§

Vec(VecInstance)

§

Mat(MatInstance)

§

Ptr(PtrInstance)

§

Ref(RefInstance)

§

Atomic(AtomicInstance)

§

Deferred(Type)

For instances that cannot be computed currently, we store the type. TODO: remove this

Implementations§

Source§

impl Instance

Source

pub fn to_buffer(&self) -> Option<Vec<u8>>

Memory representation of host-shareable instances.

Returns None if the type is not host-shareable.

Source

pub fn from_buffer(buf: &[u8], ty: &Type) -> Option<Self>

Load an instance from a byte buffer.

Returns None if the type is not host-shareable, or if the buffer is too small. The buffer can be larger than the type; extra bytes will be ignored.

Source§

impl Instance

Source

pub fn zero_value(ty: &Type) -> Result<Self, Error>

Zero-value initialize an instance of a given type.

Source§

impl Instance

Source

pub fn op_not(&self) -> Result<Self, Error>

Source§

impl Instance

Source

pub fn op_neg(&self) -> Result<Self, Error>

Source

pub fn op_or(&self, rhs: &Self) -> Result<Self, Error>

Source

pub fn op_and(&self, rhs: &Self) -> Result<Self, Error>

Source

pub fn op_add(&self, rhs: &Self, stage: ShaderStage) -> Result<Self, Error>

Source

pub fn op_sub(&self, rhs: &Self, stage: ShaderStage) -> Result<Self, Error>

Source

pub fn op_mul(&self, rhs: &Self, stage: ShaderStage) -> Result<Self, Error>

Source

pub fn op_div(&self, rhs: &Self, stage: ShaderStage) -> Result<Self, Error>

Source

pub fn op_rem(&self, rhs: &Self, stage: ShaderStage) -> Result<Self, Error>

Source§

impl Instance

Source

pub fn op_eq(&self, rhs: &Self) -> Result<Self, Error>

Source

pub fn op_ne(&self, rhs: &Self) -> Result<Self, Error>

Source

pub fn op_lt(&self, rhs: &Self) -> Result<Self, Error>

Source

pub fn op_le(&self, rhs: &Self) -> Result<Self, Error>

Source

pub fn op_gt(&self, rhs: &Self) -> Result<Self, Error>

Source

pub fn op_ge(&self, rhs: &Self) -> Result<Self, Error>

Source§

impl Instance

Source

pub fn op_bitnot(&self) -> Result<Self, Error>

Source

pub fn op_bitor(&self, rhs: &Self) -> Result<Self, Error>

Note: this is both the “bitwise OR” and “logical OR” operator.

Source

pub fn op_bitand(&self, rhs: &Self) -> Result<Self, Error>

Note: this is both the “bitwise AND” and “logical AND” operator.

Source

pub fn op_bitxor(&self, rhs: &Self) -> Result<Self, Error>

Source

pub fn op_shl(&self, rhs: &Self, stage: ShaderStage) -> Result<Self, Error>

Source

pub fn op_shr(&self, rhs: &Self, stage: ShaderStage) -> Result<Self, Error>

Source§

impl Instance

Source

pub fn op_ref(&self) -> Result<Instance, Error>

Source

pub fn op_deref(&self) -> Result<Instance, Error>

Source§

impl Instance

Source

pub fn is_convertible_to(&self, ty: &Type) -> bool

Source

pub fn loaded(self) -> Result<Self, Error>

Apply the load rule.

Reference: https://www.w3.org/TR/WGSL/#load-rule

Source§

impl Instance

Source§

impl Instance

Source

pub fn view(&self, view: &MemView) -> Result<&Instance, Error>

Get an instance representing a memory view.

There are two ways to create a memory view:

  • Accessing a struct component (struct.member)
  • Indexing an array, vec, or mat (arr[n])

Reference: https://www.w3.org/TR/WGSL/#memory-views

Source

pub fn view_mut(&mut self, view: &MemView) -> Result<&mut Instance, Error>

Get an instance representing a memory view.

See Self::view

Source

pub fn write(&mut self, value: Instance) -> Result<Instance, Error>

Mutate the instance.

This is the operation performed by the assignment operator.

Trait Implementations§

Source§

impl Clone for Instance

Source§

fn clone(&self) -> Instance

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Convert for Instance

Source§

fn convert_to(&self, ty: &Type) -> Option<Self>

Convert an instance to another type, if a feasible conversion exists. Read more
Source§

fn convert_inner_to(&self, ty: &Type) -> Option<Self>

Convert an instance by changing its inner type to another. Read more
Source§

fn concretize(&self) -> Option<Self>

Convert an abstract instance to a concrete type. Read more
Source§

impl Debug for Instance

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Instance

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<ArrayInstance> for Instance

Source§

fn from(value: ArrayInstance) -> Self

Converts to this type from the input type.
Source§

impl From<AtomicInstance> for Instance

Source§

fn from(value: AtomicInstance) -> Self

Converts to this type from the input type.
Source§

impl From<LiteralInstance> for Instance

Source§

fn from(value: LiteralInstance) -> Self

Converts to this type from the input type.
Source§

impl From<MatInstance> for Instance

Source§

fn from(value: MatInstance) -> Self

Converts to this type from the input type.
Source§

impl From<PtrInstance> for Instance

Source§

fn from(value: PtrInstance) -> Self

Converts to this type from the input type.
Source§

impl From<RefInstance> for Instance

Source§

fn from(value: RefInstance) -> Self

Converts to this type from the input type.
Source§

impl From<StructInstance> for Instance

Source§

fn from(value: StructInstance) -> Self

Converts to this type from the input type.
Source§

impl From<Type> for Instance

Source§

fn from(value: Type) -> Self

Converts to this type from the input type.
Source§

impl From<VecInstance> for Instance

Source§

fn from(value: VecInstance) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Instance

Source§

fn from(value: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for Instance

Source§

fn from(value: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Instance

Source§

fn from(value: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Instance

Source§

fn from(value: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Instance

Source§

fn from(value: i64) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Instance

Source§

fn from(value: u32) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Instance

Source§

fn eq(&self, other: &Instance) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Ty for Instance

Source§

fn ty(&self) -> Type

get the type of an instance.
Source§

fn inner_ty(&self) -> Type

get the inner type of an instance (not recursive). Read more
Source§

impl StructuralPartialEq for Instance

Auto Trait Implementations§

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

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.