Enum wgpu::naga::Expression
source · 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,
},
}
wgpu_core
or naga
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
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
Splat
Splat scalar into a vector.
Swizzle
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
Load a value indirectly.
For TypeInner::Atomic
the result is a corresponding scalar.
For other types behind the pointer<T>
, the result is T
.
Fields
pointer: Handle<Expression>
ImageSample
Sample a point from a sampled or a depth image.
Fields
image: Handle<Expression>
sampler: Handle<Expression>
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
level: SampleLevel
depth_ref: Option<Handle<Expression>>
ImageLoad
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.
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>
array_index: Option<Handle<Expression>>
ImageQuery
Query information from an image.
Unary
Apply an unary operator.
Binary
Apply a binary operator.
Select
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.
Fields
condition: Handle<Expression>
Boolean expression
accept: Handle<Expression>
reject: Handle<Expression>
Derivative
Compute the derivative on an axis.
Relational
Call a relational function.
Math
Call a math function
Fields
fun: MathFunction
arg: Handle<Expression>
arg1: Option<Handle<Expression>>
arg2: Option<Handle<Expression>>
arg3: Option<Handle<Expression>>
As
Cast a simple type to another kind.
Fields
expr: Handle<Expression>
Source expression, which can only be a scalar or a vector.
kind: ScalarKind
Target scalar kind.
CallResult(Handle<Function>)
Result of calling another function.
AtomicResult
Result of an atomic operation.
WorkGroupUniformLoadResult
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
RayQueryGetIntersection
Return an intersection found by query
.
If committed
is true, return the committed result available when
Implementations§
source§impl Expression
impl Expression
sourcepub const fn needs_pre_emit(&self) -> bool
Available on wgpu_core
only.
pub const fn needs_pre_emit(&self) -> bool
wgpu_core
only.Returns true if the expression is considered emitted at the start of a function.
sourcepub fn is_dynamic_index(&self, module: &Module) -> bool
Available on wgpu_core
only.
pub fn is_dynamic_index(&self, module: &Module) -> bool
wgpu_core
only.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§
source§impl Clone for Expression
impl Clone for Expression
source§fn clone(&self) -> Expression
fn clone(&self) -> Expression
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for Expression
impl Debug for Expression
source§impl<'de> Deserialize<'de> for Expression
impl<'de> Deserialize<'de> for Expression
source§fn deserialize<__D>(
__deserializer: __D
) -> Result<Expression, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<Expression, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
source§impl PartialEq for Expression
impl PartialEq for Expression
source§fn eq(&self, other: &Expression) -> bool
fn eq(&self, other: &Expression) -> bool
self
and other
values to be equal, and is used
by ==
.