pub enum TypeInner {
    Scalar {
        kind: ScalarKind,
        width: Bytes,
    },
    Vector {
        size: VectorSize,
        kind: ScalarKind,
        width: Bytes,
    },
    Matrix {
        columns: VectorSize,
        rows: VectorSize,
        width: Bytes,
    },
    Atomic {
        kind: ScalarKind,
        width: Bytes,
    },
    Pointer {
        base: Handle<Type>,
        space: AddressSpace,
    },
    ValuePointer {
        size: Option<VectorSize>,
        kind: ScalarKind,
        width: Bytes,
        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,
    },
    BindingArray {
        base: Handle<Type>,
        size: ArraySize,
    },
}
Expand description

Enum with additional information, depending on the kind of type.

Variants

Scalar

Fields

kind: ScalarKind
width: Bytes

Number of integral or floating-point kind.

Vector

Fields

size: VectorSize
kind: ScalarKind
width: Bytes

Vector of numbers.

Matrix

Fields

columns: VectorSize
rows: VectorSize
width: Bytes

Matrix of floats.

Atomic

Fields

kind: ScalarKind
width: Bytes

Atomic scalar.

Pointer

Fields

base: Handle<Type>
space: AddressSpace

Pointer to another type.

Pointers to scalars and vectors should be treated as equivalent to ValuePointer types. Use the TypeInner::equivalent method 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

Fields

kind: ScalarKind
width: Bytes
space: AddressSpace

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 the TypeInner::equivalent method to compare types that could be pointers, to ensure that Pointer and ValuePointer types are recognized as equivalent.

Array

Fields

base: Handle<Type>
size: ArraySize
stride: u32

Homogenous 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 a Struct.

  • They may appear as the base type of a Pointer. An AccessIndex expression 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 not DATA, and cannot be stored in variables, held in arrays or structs, or passed as parameters.

Struct

Fields

members: Vec<StructMember>
span: u32

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.

Image

Fields

arrayed: bool
class: ImageClass

Possibly multidimensional array of texels.

Sampler

Fields

comparison: bool

Can be used to sample values from images.

BindingArray

Fields

base: Handle<Type>
size: ArraySize

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 not DATA. This means that all binding array globals must be placed in the Handle address space. Referring to such a global produces a BindingArray value directly; there are never pointers to binding arrays. The only operation permitted on BindingArray values is indexing, which yields the element by value, not a pointer to the element. (This means that buffer array contents cannot be stored to; naga#1864 covers lifting this restriction.)

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

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.

Get the size of this type. Panics if the constants doesn’t contain a referenced handle. This may not happen in a properly validated IR module.

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.

Compare self and rhs as types.

This is mostly the same as <TypeInner as Eq>::eq, but it treats ValuePointer and Pointer types as equivalent.

When you know that one side of the comparison is never a pointer, it’s fine to not bother with canonicalization, and just compare TypeInner values with ==.

Trait Implementations

Generate an arbitrary value of Self from the given unstructured data. Read more

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Compare self to key and return true if they are equal.

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.