pub enum TypeInner {
Show 13 variants
Scalar(Scalar),
Vector {
size: VectorSize,
scalar: Scalar,
},
Matrix {
columns: VectorSize,
rows: VectorSize,
scalar: Scalar,
},
Atomic(Scalar),
Pointer {
base: Handle<Type>,
space: AddressSpace,
},
ValuePointer {
size: Option<VectorSize>,
scalar: Scalar,
space: AddressSpace,
},
Array {
base: Handle<Type>,
size: ArraySize,
stride: u32,
},
Struct {
members: Vec<StructMember>,
span: u32,
},
Image {
dim: ImageDimension,
arrayed: bool,
class: ImageClass,
},
Sampler {
comparison: bool,
},
AccelerationStructure {
vertex_return: bool,
},
RayQuery {
vertex_return: bool,
},
BindingArray {
base: Handle<Type>,
size: ArraySize,
},
}Expand description
Enum with additional information, depending on the kind of type.
Comparison using == is not reliable in the case of Pointer,
ValuePointer, or Struct variants. For these variants,
use TypeInner::non_struct_equivalent or compare_types.
Variants§
Scalar(Scalar)
Number of integral or floating-point kind.
Vector
Vector of numbers.
Matrix
Matrix of numbers.
Atomic(Scalar)
Atomic scalar.
Pointer
Pointer to another type.
Pointers to scalars and vectors should be treated as equivalent to
ValuePointer types. Use either TypeInner::non_struct_equivalent
or compare_types to compare types in a way that treats pointers
correctly.
§Pointers to non-SIZED types
The base type of a pointer may be a non-SIZED type like a
dynamically-sized Array, or a Struct whose last member is a
dynamically sized array. Such pointers occur as the types of
GlobalVariable or AccessIndex expressions referring to
dynamically-sized arrays.
However, among pointers to non-SIZED types, only pointers to Structs
are DATA. Pointers to dynamically sized Arrays cannot be passed as
arguments, stored in variables, or held in arrays or structures. Their
only use is as the types of AccessIndex expressions.
ValuePointer
Pointer to a scalar or vector.
A ValuePointer type is equivalent to a Pointer whose base is a
Scalar or Vector type. This is for use in TypeResolution::Value
variants; see the documentation for TypeResolution for details.
Use TypeInner::non_struct_equivalent or compare_types to compare
types that could be pointers, to ensure that Pointer and
ValuePointer types are recognized as equivalent.
Array
Homogeneous list of elements.
The base type must be a SIZED, DATA type.
§Dynamically sized arrays
An Array is SIZED unless its size is Dynamic.
Dynamically-sized arrays may only appear in a few situations:
-
They may appear as the type of a
GlobalVariable, or as the last member of aStruct. -
They may appear as the base type of a
Pointer. AnAccessIndexexpression referring to a struct’s final unsized array member would have such a pointer type. However, such pointer types may only appear as the types of such intermediate expressions. They are notDATA, and cannot be stored in variables, held in arrays or structs, or passed as parameters.
Struct
User-defined structure.
There must always be at least one member.
A Struct type is DATA, and the types of its members must be
DATA as well.
Member types must be SIZED, except for the final member of a
struct, which may be a dynamically sized Array. The
Struct type itself is SIZED when all its members are SIZED.
Two structure types with different names are not equivalent. Because
this variant does not contain the name, it is not possible to use it
to compare struct types. Use compare_types to compare two types
that may be structs.
Image
Possibly multidimensional array of texels.
Sampler
Can be used to sample values from images.
AccelerationStructure
Opaque object representing an acceleration structure of geometry.
RayQuery
Locally used handle for ray queries.
BindingArray
Array of bindings.
A BindingArray represents an array where each element draws its value
from a separate bound resource. The array’s element type base may be
Image, Sampler, or any type that would be permitted for a global
in the Uniform or Storage address spaces. Only global variables
may be binding arrays; on the host side, their values are provided by
TextureViewArray, SamplerArray, or BufferArray
bindings.
Since each element comes from a distinct resource, a binding array of
images could have images of varying sizes (but not varying dimensions;
they must all have the same Image type). Or, a binding array of
buffers could have elements that are dynamically sized arrays, each with
a different length.
Binding arrays are in the same address spaces as their underlying type.
As such, referring to an array of images produces an Image value
directly (as opposed to a pointer). The only operation permitted on
BindingArray values is indexing, which works transparently: indexing
a binding array of samplers yields a Sampler, indexing a pointer to the
binding array of storage buffers produces a pointer to the storage struct.
Unlike textures and samplers, binding arrays are not ARGUMENT, so
they cannot be passed as arguments to functions.
Naga’s WGSL front end supports binding arrays with the type syntax
binding_array<T, N>.
Implementations§
Source§impl TypeInner
impl TypeInner
Sourcepub fn pointer_automatically_convertible_scalar(
&self,
types: &UniqueArena<Type>,
) -> Option<Scalar>
pub fn pointer_automatically_convertible_scalar( &self, types: &UniqueArena<Type>, ) -> Option<Scalar>
Return the leaf scalar type of pointer.
pointer must be a TypeInner representing a pointer type.
Source§impl TypeInner
impl TypeInner
Sourcepub fn indexable_length(
&self,
module: &Module,
) -> Result<IndexableLength, IndexableLengthError>
pub fn indexable_length( &self, module: &Module, ) -> Result<IndexableLength, IndexableLengthError>
Return the length of a subscriptable type.
The self parameter should be a handle to a vector, matrix, or array
type, a pointer to one of those, or a value pointer. Arrays may be
fixed-size, dynamically sized, or sized by a specializable constant.
This function does not handle struct member references, as with
AccessIndex.
The value returned is appropriate for bounds checks on subscripting.
Return an error if self does not describe a subscriptable type at all.
Sourcepub fn indexable_length_pending(
&self,
module: &Module,
) -> Result<IndexableLength, IndexableLengthError>
pub fn indexable_length_pending( &self, module: &Module, ) -> Result<IndexableLength, IndexableLengthError>
Return the length of self, assuming overrides are yet to be supplied.
Return the number of elements in self:
-
If
selfis a runtime-sized array, then returnIndexableLength::Dynamic. -
If
selfis an override-sized array, then assume that override values have not yet been supplied, and returnIndexableLength::Dynamic. -
Otherwise, the type simply tells us the length of
self, so returnIndexableLength::Known.
If self is not an indexable type at all, return an error.
The difference between this and indexable_length_resolved is that we
treat override-sized arrays and dynamically-sized arrays both as
Dynamic, on the assumption that our callers want to treat both cases
as “not yet possible to check”.
Sourcepub fn indexable_length_resolved(
&self,
module: &Module,
) -> Result<IndexableLength, IndexableLengthError>
pub fn indexable_length_resolved( &self, module: &Module, ) -> Result<IndexableLength, IndexableLengthError>
Return the length of self, assuming overrides have been resolved.
Return the number of elements in self:
-
If
selfis a runtime-sized array, then returnIndexableLength::Dynamic. -
If
selfis an override-sized array, then assume that the override’s value is a fully-evaluated constant expression, and returnIndexableLength::Known. Otherwise, return an error. -
Otherwise, the type simply tells us the length of
self, so returnIndexableLength::Known.
If self is not an indexable type at all, return an error.
The difference between this and indexable_length_pending is
that if self is override-sized, we require the override’s
value to be known.
Source§impl TypeInner
impl TypeInner
Sourcepub const fn scalar(&self) -> Option<Scalar>
pub const fn scalar(&self) -> Option<Scalar>
Return the scalar type of self.
If inner is a scalar, vector, or matrix type, return
its scalar type. Otherwise, return None.
Note that this doesn’t inspect Array types, as required
for automatic conversions. For that, see scalar_for_conversions.
pub fn scalar_kind(&self) -> Option<ScalarKind>
Sourcepub fn scalar_width(&self) -> Option<u8>
pub fn scalar_width(&self) -> Option<u8>
Returns the scalar width in bytes
Sourcepub fn scalar_for_conversions(
&self,
types: &UniqueArena<Type>,
) -> Option<Scalar>
pub fn scalar_for_conversions( &self, types: &UniqueArena<Type>, ) -> Option<Scalar>
pub const fn pointer_space(&self) -> Option<AddressSpace>
Sourcepub const fn pointer_base_type(&self) -> Option<TypeResolution>
pub const fn pointer_base_type(&self) -> Option<TypeResolution>
If self is a pointer type, return its base type.
pub fn is_atomic_pointer(&self, types: &UniqueArena<Type>) -> bool
Sourcepub fn canonical_form(&self, types: &UniqueArena<Type>) -> Option<TypeInner>
pub fn canonical_form(&self, types: &UniqueArena<Type>) -> Option<TypeInner>
Return the canonical form of self, or None if it’s already in
canonical form.
Certain types have multiple representations in TypeInner. This
function converts all forms of equivalent types to a single
representative of their class, so that simply applying Eq to the
result indicates whether the types are equivalent, as far as Naga IR is
concerned.
Sourcepub fn non_struct_equivalent(
&self,
rhs: &TypeInner,
types: &UniqueArena<Type>,
) -> bool
pub fn non_struct_equivalent( &self, rhs: &TypeInner, types: &UniqueArena<Type>, ) -> bool
Compare value type self and rhs as types.
This is mostly the same as <TypeInner as Eq>::eq, but it treats
ValuePointer and Pointer types as equivalent. This method
cannot be used for structs, because it cannot distinguish two
structs with different names but the same members. For structs,
use compare_types.
When you know that one side of the comparison is never a pointer or
struct, it’s fine to not bother with canonicalization, and just
compare TypeInner values with ==.
§Panics
If both self and rhs are structs.
pub fn is_dynamically_sized(&self, types: &UniqueArena<Type>) -> bool
pub fn components(&self) -> Option<u32>
pub fn component_type(&self, index: usize) -> Option<TypeResolution>
Sourcepub const fn vector_size_and_scalar(
&self,
) -> Option<(Option<VectorSize>, Scalar)>
pub const fn vector_size_and_scalar( &self, ) -> Option<(Option<VectorSize>, Scalar)>
If the type is a Vector or a Scalar return a tuple of the vector size (or None for Scalars), and the scalar kind. Returns (None, None) for other types.
Sourcepub fn is_abstract(&self, types: &UniqueArena<Type>) -> bool
pub fn is_abstract(&self, types: &UniqueArena<Type>) -> bool
Return true if self is an abstract type.
Use types to look up type handles. This is necessary to
recognize abstract arrays.
Sourcepub fn automatically_converts_to(
&self,
goal: &Self,
types: &UniqueArena<Type>,
) -> Option<(Scalar, Scalar)>
pub fn automatically_converts_to( &self, goal: &Self, types: &UniqueArena<Type>, ) -> Option<(Scalar, Scalar)>
Determine whether self automatically converts to goal.
If Naga IR’s automatic conversions will convert self to
goal, then return a pair (from, to), where from and to
are the scalar types of the leaf values of self and goal.
If self and goal are the same type, this will simply return
a pair (S, S).
If the automatic conversions cannot convert self to goal,
return None.
Naga IR’s automatic conversions will convert:
-
AbstractIntscalars toAbstractFloator any numeric scalar type -
AbstractFloatscalars to any floating-point scalar type -
A
Vector{ size, scalar: S }to{ size, scalar: T }if they would convertStoT -
An
Array{ base: S, size, stride }to{ base: T, size, stride }if they would convertStoT
Trait Implementations§
Source§impl ForDebugWithTypes for &TypeInner
impl ForDebugWithTypes for &TypeInner
Source§fn for_debug(
self,
types: &UniqueArena<Type>,
) -> DiagnosticDebug<(Self, &UniqueArena<Type>)>
fn for_debug( self, types: &UniqueArena<Type>, ) -> DiagnosticDebug<(Self, &UniqueArena<Type>)>
core::fmt::Debug. Read moreimpl Eq for TypeInner
impl StructuralPartialEq for TypeInner
Auto Trait Implementations§
impl Freeze for TypeInner
impl RefUnwindSafe for TypeInner
impl Send for TypeInner
impl Sync for TypeInner
impl Unpin for TypeInner
impl UnwindSafe for TypeInner
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.