Skip to content
heff

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 -> String

Place

data Place = Inside | Outside

Where 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 -> String

written

written : Place -> Kernel.Expr -> String

The 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 -> String

Printing

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 -> Printing

freshName

freshName : Printing -> String

taken

taken : Printing -> Printing

block

block : Printer Unit -> Printing -> Printing

spliced

spliced : Printing -> Printing -> Printing

otherwise

otherwise : Printer Unit -> Printing -> Printing

printed

printed : {a : Type} -> Kernel.StmtF (\x -> Printer x) a -> Printer a

after

after : {a b : Type} -> (Printing, a) -> (a -> Printer b) -> (Printing, b)

printer

printer : Handler Kernel.stmt

The printer, as a handler of a kernel’s statements.

declaration

declaration : Int -> Kernel.Param -> String

source

source : Kernel.Kernel -> String

The kernel as WGSL.

source1

source1 : {a : Type} -> Kernel.Kernel1 a -> String

A 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.