WGSL Code Generation #
Complete code generation from ShaderM monad to WGSL modules.
Features:
- Automatic binding assignment for storage buffers
- Workgroup variable declarations
- Struct definitions
- Function generation with attributes
- Extension and diagnostic directives
- Complete module assembly
Usage:
def myShader : ShaderM Unit := do
-- ... shader code ...
let module := generateModule "myKernel" {x := 256, y := 1, z := 1} [] myShader
IO.println module.toWGSL
Function parameter with optional built-in binding
- name : String
- ty : WGSLType
- builtin : Option BuiltinBinding
Instances For
Generate WGSL parameter declaration
Equations
- One or more equations did not get rendered due to their size.
Instances For
Generate complete WGSL function
Equations
- One or more equations did not get rendered due to their size.
Instances For
Complete shader module with all declarations
- storageBuffers : List StorageBuffer
- workgroupVars : List WorkgroupVar
- functions : List FunctionDecl
Instances For
Generate storage buffer declaration with binding
Equations
- One or more equations did not get rendered due to their size.
Instances For
Generate workgroup variable declaration
Equations
Instances For
Generate struct definition
Equations
- One or more equations did not get rendered due to their size.
Instances For
Generate complete WGSL module
Equations
- One or more equations did not get rendered due to their size.
Instances For
def
Hesper.WGSL.CodeGen.generateComputeModule
(funcName : String)
(workgroupSize : WorkgroupSize)
(extensions : List String := [])
(computation : Monad.ShaderM Unit)
:
Generate a compute shader module from ShaderM monad
Equations
- One or more equations did not get rendered due to their size.
Instances For
def
Hesper.WGSL.CodeGen.generateComputeModuleWithDiagnostics
(funcName : String := "main")
(workgroupSize : WorkgroupSize := { x := 256 })
(extensions : List String := [])
(diagnostics : List (String × String) := [])
(computation : Monad.ShaderM Unit)
:
Generate compute shader module with diagnostics support
Equations
- One or more equations did not get rendered due to their size.
Instances For
def
Hesper.WGSL.CodeGen.generateWGSL
(funcName : String := "main")
(workgroupSize : WorkgroupSize := { x := 256 })
(extensions : List String := [])
(diagnostics : List (String × String) := [])
(computation : Monad.ShaderM Unit)
:
Convenience function: Generate WGSL string from ShaderM computation
Equations
- One or more equations did not get rendered due to their size.
Instances For
Generate WGSL with default parameters
Equations
- Hesper.WGSL.CodeGen.generateWGSLSimple computation = Hesper.WGSL.CodeGen.generateWGSL "main" { x := 256 } [] [] computation