browser.gpu.wgsl
A kernel of browser.gpu.kernel printed as WGSL, WebGPU’s: its buffers bound
at @group(0), in order, then the entry point, its body printed by a
handler of stmt (co’s Handler) whose state is the next
fresh name and the lines printed. An expression is printed by pure
functions, an operator’s operands in parentheses. Import it by a
name, import browser.gpu.wgsl as WGSL.
The names a kernel has are its buffers’ (a, b, c), the
invocation’s (id) and those named in its body (v0, v1, …):
an entry point is to be named none of them.
symbol
symbol : Kernel.BinaryOp -> StringPlace
data Place = Inside | OutsideWhere an expression is: an operand of an operator, or the whole of what is printed (a statement’s, an index, an argument).
enclosed
enclosed : Place -> String -> Stringwritten
written : Place -> Kernel.Expr -> StringThe expression as WGSL writes it.
>>> written Outside (Kernel.exprOf (Kernel.lit (1 : UInt32) + Kernel.lit 2 * Kernel.lit 3))"1u + (2u * 3u)"whole
whole : Kernel.Expr -> StringPrinting
type Printing = { fresh : Int, depth : Int, lines : List String }What is printed so far: the next fresh name’s number, how deep in blocks the statements are, the lines (the last first).
Printer
type Printer a = Printing -> (Printing, a)The printer’s monad: a state.
emitted
emitted : String -> Printing -> PrintingfreshName
freshName : Printing -> Stringtaken
taken : Printing -> Printingblock
block : Printer Unit -> Printing -> Printingspliced
spliced : Printing -> Printing -> Printingotherwise
otherwise : Printer Unit -> Printing -> Printingprinted
printed : {a : Type} -> Kernel.StmtF (\x -> Printer x) a -> Printer aafter
after : {a b : Type} -> (Printing, a) -> (a -> Printer b) -> (Printing, b)printer
printer : Handler Kernel.stmtThe printer, as a handler of a kernel’s statements.
declaration
declaration : Int -> Kernel.Param -> Stringsource
source : Kernel.Kernel -> StringThe kernel as WGSL.
source1
source1 : {a : Type} -> Kernel.Kernel1 a -> StringA kernel of one buffer as WGSL.
source2
source2 : {a b : Type} -> Kernel.Kernel2 a b -> String… of two.
source3
source3 : {a b c : Type} -> Kernel.Kernel3 a b c -> String… of three.