Statement-level DSL for complete WGSL shaders. Supports variable declarations, assignments, loops, conditionals, and shader structure.
WGSL Statements
- varDecl (name : String) (ty : WGSLType) (init : Option ((t : WGSLType) × Exp t)) : Stmt
- assign (name : String) (ty : WGSLType) (value : Exp ty) : Stmt
- assignIndex (arrName : String) (index : Exp (WGSLType.scalar ScalarType.u32)) (ty : WGSLType) (value : Exp ty) : Stmt
- assignIndexBuf (arrName : String) (bufIdx elemIdx : Exp (WGSLType.scalar ScalarType.u32)) (ty : WGSLType) (value : Exp ty) : Stmt
- forLoop (varName : String) (init : Exp (WGSLType.scalar ScalarType.u32)) (cond : Exp (WGSLType.scalar ScalarType.bool)) (update : Exp (WGSLType.scalar ScalarType.u32)) (body : List Stmt) : Stmt
- ifStmt (cond : Exp (WGSLType.scalar ScalarType.bool)) (thenBody elseBody : List Stmt) : Stmt
- exprStmt {t : WGSLType} (e : Exp t) : Stmt
- block (stmts : List Stmt) : Stmt
- varDeclLdV4U32 (n0 n1 n2 n3 bufName : String) (u32Idx : Exp (WGSLType.scalar ScalarType.u32)) : Stmt
Instances For
Built-in variable bindings in compute shader
- workgroupId : BuiltinBinding
- localInvocationId : BuiltinBinding
- globalInvocationId : BuiltinBinding
Instances For
Workgroup variable declaration (shared memory)
Instances For
Equations
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
Instances For
Equations
Complete compute shader structure
- buffers : List StorageBuffer
- workgroupVars : List WorkgroupVar
- workgroupSize : WorkgroupSize
- builtins : List BuiltinParam
Instances For
Convert builtin binding to WGSL string
Equations
- Hesper.WGSL.BuiltinBinding.workgroupId.toWGSL = "workgroup_id"
- Hesper.WGSL.BuiltinBinding.localInvocationId.toWGSL = "local_invocation_id"
- Hesper.WGSL.BuiltinBinding.globalInvocationId.toWGSL = "global_invocation_id"
Instances For
Convert statement to WGSL string with indentation
Generate WGSL struct definition
Equations
- One or more equations did not get rendered due to their size.
Instances For
Generate complete WGSL shader code from ComputeShader
Equations
- One or more equations did not get rendered due to their size.
Instances For
Declare a variable with optional initial value
Equations
- Hesper.WGSL.declareVar name ty init = Hesper.WGSL.Stmt.varDecl name ty init
Instances For
Assign to a variable
Equations
- Hesper.WGSL.assign name value = Hesper.WGSL.Stmt.assign name ty value
Instances For
Assign to array element
Equations
- Hesper.WGSL.assignAt arrName index value = Hesper.WGSL.Stmt.assignIndex arrName index ty value
Instances For
For loop statement
Equations
- Hesper.WGSL.forLoop varName init cond update body = Hesper.WGSL.Stmt.forLoop varName init cond update body
Instances For
Expression statement (e.g., function calls)
Equations
Instances For
Nested loops for 2D iteration
Equations
- Hesper.WGSL.nestedMap2D rows cols f = List.foldl (fun (acc : List α) (i : Nat) => acc ++ List.map (fun (j : Nat) => f i j) (List.range cols)) [] (List.range rows)
Instances For
HOAS-style loop construct. Instead of requiring a string variable name, takes a function that receives the loop variable as an Exp and returns the loop body.
Example: loop "i" 0 n 1 (fun i => [...statements using i...])
Equations
- One or more equations did not get rendered due to their size.
Instances For
Compile-time iteration over a list, generating statements for each element.
Similar to Haskell's staticFor - unrolls the loop at DSL compile time.
Example: staticFor [0, 1, 2, 3] (fun i => assignAt "arr" i someValue)
Equations
- Hesper.WGSL.staticFor items f = List.foldl (fun (acc : List Hesper.WGSL.Stmt) (item : α) => acc ++ f item) [] items
Instances For
Helper to iterate over a range with a body function
Equations
- Hesper.WGSL.staticForRange start end_ f = Hesper.WGSL.staticFor (List.map (fun (x : Nat) => x + start) (List.range (end_ - start))) f
Instances For
Helper to iterate with index and value from a list
Equations
- Hesper.WGSL.staticForIndexed items f = Hesper.WGSL.staticFor ((List.range items.length).zip items) fun (x : Nat × α) => match x with | (i, item) => f i item
Instances For
Load multiple matrices into an array variable
Equations
- One or more equations did not get rendered due to their size.
Instances For
Load multiple matrices (right operand) into an array variable
Equations
- One or more equations did not get rendered due to their size.
Instances For
Perform multiply-accumulate on 2D grid of matrices
Equations
- One or more equations did not get rendered due to their size.
Instances For
Store multiple result matrices from array to buffer
Equations
- One or more equations did not get rendered due to their size.