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

Macro Attributes

wgsl Container Attributes

AttributeSyntaxPurpose
Crate path#[wgsl(crate_path = path)]Override the path to the wgsl_rs crate (for re-exports)
Skip validation#[wgsl(skip_validation)]Disable compile-time WGSL validation for this module
Validate with instantiation types#[wgsl(validate_with_instantiation_types(T1, T2))]Validate template modules by instantiating with the given types
Extensions#[wgsl(extensions = [Ext1, Ext2])]Run WgslExtension impls on the IR before instantiation

Field / Item Attributes

AttributeApplies toPurpose
#[wgsl_ignore]Items, fieldsExclude this item/field from transpilation
#[wgsl_allow(non_literal_loop_bounds)]for loopsPermit non-literal loop bounds (requires runtime support)
#[wgsl_allow(non_literal_match_statement_patterns)]matchPermit non-literal match patterns

Entry-Point Attributes

AttributeApplies toPurpose
#[vertex]FunctionsMark a vertex entry point
#[fragment]FunctionsMark a fragment entry point
#[compute]FunctionsMark a compute entry point
#[workgroup_size(N)]Compute functionsSet workgroup size to N x 1 x 1
#[workgroup_size(x, y, z)]Compute functionsSet explicit 3D workgroup size

I/O Decorator Attributes

AttributeApplies toPurpose
#[builtin(name)]Fn args, struct fieldsBind to a WGSL built-in (position, vertex_index, etc.)
#[location(N)]Fn args, struct fieldsBind to inter-stage location N
#[interpolate(...)]Fn args, struct fieldsSet interpolation type/filter
#[blend_src(N)]Fn args, struct fieldsSet @blend_src for dual-source blending
#[invariant]Fn args, struct fieldsMark position output as @invariant

Derive Attributes

AttributeCratePurpose
#[derive(Wgsl)]wgsl-rsTranspile the annotated type into a WGSL struct
#[derive(Layout)]wgsl-rs-layout-macrosGenerate WgslLayout / Layout impls and inherent constants