pub enum Expression {
Show 28 variants Literal(Literal), Constant(Handle<Constant>), ZeroValue(Handle<Type>), Compose { ty: Handle<Type>, components: Vec<Handle<Expression>>, }, Access { base: Handle<Expression>, index: Handle<Expression>, }, AccessIndex { base: Handle<Expression>, index: u32, }, Splat { size: VectorSize, value: Handle<Expression>, }, Swizzle { size: VectorSize, vector: Handle<Expression>, pattern: [SwizzleComponent; 4], }, FunctionArgument(u32), GlobalVariable(Handle<GlobalVariable>), LocalVariable(Handle<LocalVariable>), Load { pointer: Handle<Expression>, }, ImageSample { image: Handle<Expression>, sampler: Handle<Expression>, gather: Option<SwizzleComponent>, coordinate: Handle<Expression>, array_index: Option<Handle<Expression>>, offset: Option<Handle<Expression>>, level: SampleLevel, depth_ref: Option<Handle<Expression>>, }, ImageLoad { image: Handle<Expression>, coordinate: Handle<Expression>, array_index: Option<Handle<Expression>>, sample: Option<Handle<Expression>>, level: Option<Handle<Expression>>, }, ImageQuery { image: Handle<Expression>, query: ImageQuery, }, Unary { op: UnaryOperator, expr: Handle<Expression>, }, Binary { op: BinaryOperator, left: Handle<Expression>, right: Handle<Expression>, }, Select { condition: Handle<Expression>, accept: Handle<Expression>, reject: Handle<Expression>, }, Derivative { axis: DerivativeAxis, ctrl: DerivativeControl, expr: Handle<Expression>, }, Relational { fun: RelationalFunction, argument: Handle<Expression>, }, Math { fun: MathFunction, arg: Handle<Expression>, arg1: Option<Handle<Expression>>, arg2: Option<Handle<Expression>>, arg3: Option<Handle<Expression>>, }, As { expr: Handle<Expression>, kind: ScalarKind, convert: Option<u8>, }, CallResult(Handle<Function>), AtomicResult { ty: Handle<Type>, comparison: bool, }, WorkGroupUniformLoadResult { ty: Handle<Type>, }, ArrayLength(Handle<Expression>), RayQueryProceedResult, RayQueryGetIntersection { query: Handle<Expression>, committed: bool, },
}
Available on crate feature wgpu only.
Expand description

An expression that can be evaluated to obtain a value.

This is a Single Static Assignment (SSA) scheme similar to SPIR-V.

Variants§

§

Literal(Literal)

Literal.

§

Constant(Handle<Constant>)

Constant value.

§

ZeroValue(Handle<Type>)

Zero value of a type.

§

Compose

Fields

§components: Vec<Handle<Expression>>

Composite expression.

§

Access

Array access with a computed index.

Typing rules

The base operand must be some composite type: Vector, Matrix, Array, a Pointer to one of those, or a ValuePointer with a size.

The index operand must be an integer, signed or unsigned.

Indexing a Vector or Array produces a value of its element type. Indexing a Matrix produces a Vector.

Indexing a Pointer to any of the above produces a pointer to the element/component type, in the same space. In the case of Array, the result is an actual Pointer, but for vectors and matrices, there may not be any type in the arena representing the component’s type, so those produce ValuePointer types equivalent to the appropriate Pointer.

Dynamic indexing restrictions

To accommodate restrictions in some of the shader languages that Naga targets, it is not permitted to subscript a matrix or array with a dynamically computed index unless that matrix or array appears behind a pointer. In other words, if the inner type of base is Array or Matrix, then index must be a constant. But if the type of base is a Pointer to an array or matrix or a ValuePointer with a size, then the index may be any expression of integer type.

You can use the Expression::is_dynamic_index method to determine whether a given index expression requires matrix or array base operands to be behind a pointer.

(It would be simpler to always require the use of AccessIndex when subscripting arrays and matrices that are not behind pointers, but to accommodate existing front ends, Naga also permits Access, with a restricted index.)

§

AccessIndex

Fields

§index: u32

Access the same types as Access, plus Struct with a known index.

§

Splat

Fields

Splat scalar into a vector.

§

Swizzle

Fields

§pattern: [SwizzleComponent; 4]

Vector swizzle.

§

FunctionArgument(u32)

Reference a function parameter, by its index.

A FunctionArgument expression evaluates to a pointer to the argument’s value. You must use a Load expression to retrieve its value, or a Store statement to assign it a new value.

§

GlobalVariable(Handle<GlobalVariable>)

Reference a global variable.

If the given GlobalVariable’s space is AddressSpace::Handle, then the variable stores some opaque type like a sampler or an image, and a GlobalVariable expression referring to it produces the variable’s value directly.

For any other address space, a GlobalVariable expression produces a pointer to the variable’s value. You must use a Load expression to retrieve its value, or a Store statement to assign it a new value.

§

LocalVariable(Handle<LocalVariable>)

Reference a local variable.

A LocalVariable expression evaluates to a pointer to the variable’s value. You must use a Load expression to retrieve its value, or a Store statement to assign it a new value.

§

Load

Fields

Load a value indirectly.

For TypeInner::Atomic the result is a corresponding scalar. For other types behind the pointer<T>, the result is T.

§

ImageSample

Fields

§gather: Option<SwizzleComponent>

If Some(), this operation is a gather operation on the selected component.

§coordinate: Handle<Expression>
§array_index: Option<Handle<Expression>>
§offset: Option<Handle<Expression>>

Expression handle lives in const_expressions

Sample a point from a sampled or a depth image.

§

ImageLoad

Fields

§image: Handle<Expression>

The image to load a texel from. This must have type Image. (This will necessarily be a GlobalVariable or FunctionArgument expression, since no other expressions are allowed to have that type.)

§coordinate: Handle<Expression>

The coordinate of the texel we wish to load. This must be a scalar for D1 images, a Bi vector for D2 images, and a Tri vector for D3 images. (Array indices, sample indices, and explicit level-of-detail values are supplied separately.) Its component type must be Sint.

§array_index: Option<Handle<Expression>>

The index into an arrayed image. If the arrayed flag in image’s type is true, then this must be Some(expr), where expr is a Sint scalar. Otherwise, it must be None.

§sample: Option<Handle<Expression>>

A sample index, for multisampled Sampled and Depth images.

§level: Option<Handle<Expression>>

A level of detail, for mipmapped images.

This must be present when accessing non-multisampled Sampled and Depth images, even if only the full-resolution level is present (in which case the only valid level is zero).

Load a texel from an image.

For most images, this returns a four-element vector of the same ScalarKind as the image. If the format of the image does not have four components, default values are provided: the first three components (typically R, G, and B) default to zero, and the final component (typically alpha) defaults to one.

However, if the image’s class is Depth, then this returns a Float scalar value.

§

ImageQuery

Fields

Query information from an image.

§

Unary

Apply an unary operator.

§

Binary

Apply a binary operator.

§

Select

Fields

§condition: Handle<Expression>

Boolean expression

Select between two values based on a condition.

Note that, because expressions have no side effects, it is unobservable whether the non-selected branch is evaluated.

§

Derivative

Compute the derivative on an axis.

§

Relational

Call a relational function.

§

Math

Call a math function

§

As

Fields

§expr: Handle<Expression>

Source expression, which can only be a scalar or a vector.

§kind: ScalarKind

Target scalar kind.

§convert: Option<u8>

If provided, converts to the specified byte width. Otherwise, bitcast.

Cast a simple type to another kind.

§

CallResult(Handle<Function>)

Result of calling another function.

§

AtomicResult

Fields

§comparison: bool

Result of an atomic operation.

§

WorkGroupUniformLoadResult

Fields

§ty: Handle<Type>

The type of the result

Result of a WorkGroupUniformLoad statement.

§

ArrayLength(Handle<Expression>)

Get the length of an array. The expression must resolve to a pointer to an array with a dynamic size.

This doesn’t match the semantics of spirv’s OpArrayLength, which must be passed a pointer to a structure containing a runtime array in its’ last field.

§

RayQueryProceedResult

Result of a Proceed RayQuery statement.

§

RayQueryGetIntersection

Fields

§committed: bool

Return an intersection found by query.

If committed is true, return the committed result available when

Implementations§

§

impl Expression

pub const fn needs_pre_emit(&self) -> bool

Returns true if the expression is considered emitted at the start of a function.

pub fn is_dynamic_index(&self, module: &Module) -> bool

Return true if this expression is a dynamic array index, for Access.

This method returns true if this expression is a dynamically computed index, and as such can only be used to index matrices and arrays when they appear behind a pointer. See the documentation for Access for details.

Note, this does not check the type of the given expression. It’s up to the caller to establish that the Access expression is well-typed through other means, like ResolveContext.

Trait Implementations§

§

impl Clone for Expression

§

fn clone(&self) -> Expression

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
§

impl Debug for Expression

§

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

Formats the value using the given formatter. Read more
§

impl PartialEq for Expression

§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

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

impl StructuralPartialEq for Expression

Auto Trait Implementations§

Blanket Implementations§

source§

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
where T: Real + Zero + Arithmetics + Clone, Swp: WhitePoint<T>, Dwp: WhitePoint<T>, D: AdaptFrom<S, Swp, Dwp, T>,

source§

fn adapt_into_using<M>(self, method: M) -> D
where M: TransformMatrix<T>,

Convert the source color to the destination color using the specified method.
source§

fn adapt_into(self) -> D

Convert the source color to the destination color using the bradford method by default.
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, C> ArraysFrom<C> for T
where C: IntoArrays<T>,

source§

fn arrays_from(colors: C) -> T

Cast a collection of colors into a collection of arrays.
source§

impl<T, C> ArraysInto<C> for T
where C: FromArrays<T>,

source§

fn arrays_into(self) -> C

Cast this collection of arrays into a collection of colors.
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<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for U
where T: FromCam16Unclamped<WpParam, U>,

§

type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar

The number type that’s used in parameters when converting.
source§

fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar> ) -> T

Converts self into C, using the provided parameters.
source§

impl<T, C> ComponentsFrom<C> for T
where C: IntoComponents<T>,

source§

fn components_from(colors: C) -> T

Cast a collection of colors into a collection of color components.
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FromAngle<T> for T

source§

fn from_angle(angle: T) -> T

Performs a conversion from angle.
source§

impl<T, U> FromStimulus<U> for T
where U: IntoStimulus<T>,

source§

fn from_stimulus(other: U) -> T

Converts other into Self, while performing the appropriate scaling, rounding and clamping.
§

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, U> IntoAngle<U> for T
where U: FromAngle<T>,

source§

fn into_angle(self) -> U

Performs a conversion into T.
source§

impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for U
where T: Cam16FromUnclamped<WpParam, U>,

§

type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar

The number type that’s used in parameters when converting.
source§

fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar> ) -> T

Converts self into C, using the provided parameters.
source§

impl<T, U> IntoColor<U> for T
where U: FromColor<T>,

source§

fn into_color(self) -> U

Convert into T with values clamped to the color defined bounds Read more
source§

impl<T, U> IntoColorUnclamped<U> for T
where U: FromColorUnclamped<T>,

source§

fn into_color_unclamped(self) -> U

Convert into T. The resulting color might be invalid in its color space Read more
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> IntoStimulus<T> for T

source§

fn into_stimulus(self) -> T

Converts self into T, while performing the appropriate scaling, rounding and clamping.
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

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

§

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, C> TryComponentsInto<C> for T
where C: TryFromComponents<T>,

§

type Error = <C as TryFromComponents<T>>::Error

The error for when try_into_colors fails to cast.
source§

fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>

Try to cast this collection of color components into a collection of colors. Read more
source§

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

§

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>,

§

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.
source§

impl<T, U> TryIntoColor<U> for T
where U: TryFromColor<T>,

source§

fn try_into_color(self) -> Result<U, OutOfBounds<U>>

Convert into T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. Read more
source§

impl<C, U> UintsFrom<C> for U
where C: IntoUints<U>,

source§

fn uints_from(colors: C) -> U

Cast a collection of colors into a collection of unsigned integers.
source§

impl<C, U> UintsInto<C> for U
where C: FromUints<U>,

source§

fn uints_into(self) -> C

Cast this collection of unsigned integers into a collection of colors.
§

impl<T> Upcast<T> for T

§

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

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

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

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

source§

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

§

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

§

impl<T> WasmNotSendSync for T

§

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