Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

IR Types

The wgsl_rs::ir module exposes the intermediate representation that extensions and the linker operate on.

Top-Level Types

TypeDescription
ir::ModuleRoot node: { name, items: Vec<Item>, attrs: Vec<Attribute> }
ir::ItemEnum of top-level module items (see below)
ir::TypeEnum of all WGSL type expressions (see below)
ir::ExprExpression node
ir::StmtStatement node
ir::BlockSequence of statements
ir::FnArgFunction parameter with attributes and type
ir::FieldStruct field with attributes and type
ir::Attribute{ path: String, args: Vec<String> } — preserved Rust attribute
ir::FnAttrsDedicated function-level decorators (entry point, workgroup size)
ir::BuiltInWGSL built-in value identifiers
ir::InterStageIoInter-stage I/O descriptor (location, interpolation, blend_src)
ir::ReturnTypeFunction return type representation
ir::WorkgroupSize{ x, y, z } for compute entry points
ir::ScalarTypeScalar type enum (f32, i32, u32, f16, bool)
ir::AddressSpaceAddress space enum (uniform, storage, workgroup, function, private)
ir::StorageAccessStorage buffer access (read, write)
ir::TextureKindSampled texture type kind
ir::TextureDepthKindDepth texture kind
ir::TextureStorageKindStorage texture kind (1D, 2D, 2DArray, 3D)
ir::TexelFormatStorage texture texel format (Rgba8unorm, R32float, ...)

ir::Item Variants

VariantWGSL construct
ConstModule-scope const declaration
UniformUniform buffer declaration
StorageStorage buffer declaration
WorkgroupWorkgroup variable declaration
SamplerSampler declaration
TextureTexture declaration
FnFunction (including entry points)
StructStruct declaration
ImplImpl block (transpiled to free functions)
EnumEnum declaration

ir::Type Variants

VariantWGSL type
Scalarf32, i32, u32, f16, bool
VectorvecN<T>
MatrixmatNxM<T>
Arrayarray<T, N>
RuntimeArrayarray<T> (runtime-sized)
Atomicatomic<T>
StructUser-defined struct
Ptrptr<AS, T, AM>
Samplersampler
SamplerComparisonsampler_comparison
TextureSampled texture
TextureDepthDepth texture
TextureStorageStorage texture (texture_storage_* with format + access)
TypeParamGeneric type parameter (substituted at instantiation)
PhantomPhantomData<T> marker — retained in IR, omitted from WGSL

ir::Stmt Variants (extension-relevant)

Extensions walking function bodies via modify_ir encounter these statement variants:

VariantDescription
Locallet / let mut binding
ConstFunction-scoped const
Assignmentlhs = rhs
CompoundAssignmentlhs += rhs etc.
Whilewhile loop
Looploop { } infinite loop
Forfor loop (lowered from Rust range)
Ifif / else / else if
Switchmatch (transpiled to WGSL switch)
BlockNested block
Breakbreak
Continuecontinue
Returnreturn (optional expr)
ExprExpression statement (trailing expr without ; = implicit return)
Discarddiscard!()
SlabReadslab_copy! (slab → local)
SlabWriteslab_copy! (local → slab)
MacroUnrecognized statement macro — extension-lowered via MACROS