Skip to content

(pass-graph …) / (pass …)

(pass …) is sugar for a fullscreen shader: write the fragment body and the pngine/pass-v1 lowering hook, the compiler step that expands sugar into ordinary forms, generates every resource around it (uniform buffer, output texture, sampler, pipeline, bind group, render pass and frame), creating only what the WGSL actually references.

Passes live inside a (pass-graph …) container, which the hook lowers as a unit. That matters as soon as one pass samples another: the container sees every pass at once, so cross-pass texture ids sequence coherently.

(pass-graph
(pass :name <name>
:code "<WGSL fragment source>"
:feedback true ; optional: ping-pong texture for feedback
:format rgba16float ; optional: intermediate texture format
:scale 0.5 ; optional: canvas-relative output size
:reads [otherPass] ; optional: explicit texture dependencies
:imports [common] ; optional: WGSL fragments
:file ["a.wasm" "b.wasm"] ; optional: WASM data files → D0, D1, …
:init "<WGSL compute source>")) ; optional: one-shot compute init

Takes (pass …) children positionally. The passes run in document order; the last one renders to the canvas, and earlier ones render to textures the later passes can sample by name. A (pass …) written outside a (pass-graph …) is refused with a located diagnostic naming the graph as its parent (it used to validate, generate nothing, and leave the payload empty).

An unnamed graph owns the document’s frame, with optional :before and :after work around its passes. A graph with :name instead emits a reusable step group; the document writes the (frame …) and can compose it with other graphs and hand-written passes. :expose [name] adds an optional canvas blit for inspecting an intermediate without making that blit run by default.

Key Type Required Description
:name symbol Yes Pass name; also the texture name later passes sample
:code string Yes WGSL fragment (or compute) source
:feedback boolean No Ping-pong texture pair; the previous frame is readable as prev_<name>. Not on the last pass: it renders to the canvas, which has no previous texture to read
:format symbol No Intermediate texture format, default rgba8unorm; the canvas pass takes only the preferred canvas format
:scale number No Canvas-relative intermediate size, such as 0.5; needs a non-canvas pass
:reads array No Prior pass outputs this pass actually reads, making fan-in explicit
:imports array No (wgsl …) fragments assembled into this pass’s shader
:init string No One-shot WGSL compute source, run once per loaded payload
:file array No WASM file paths → D0, D1, … storage buffers

The hook scans the WGSL and injects @binding(N) declarations for whatever it finds referenced; you never write the bindings yourself:

Resource Injected when Binding
Uniform buffer (pngine) The code references pngine 0
Pointer buffer (pointer) The code references pointer next
Controls (controls) The document declares (control …) and the code references controls next
Sampler (samp) The code names samp (textureSample(tex, samp, uv)); a textureLoad read binds none next
Dep textures A prior (pass …) output is referenced by name next
Feedback texture (prev_<name>) :feedback true next
Data buffers (D0, D1, …) :file present next

pngine carries the same fields as the built-in pngine-inputs uniform: time, width, height, aspect. Data buffers are injected as var<storage, read> D0: array<f32>.

Controls are injected in (control …) declaration order as f32 members. The host sets them with setUniform, or the CLI with --control name=value; the same value can also guard frame steps. See Frame programs.

(pass-graph
(pass :name main :code """
@fragment fn fs(@builtin(position) pos: vec4f) -> @location(0) vec4f {
let uv = pos.xy / vec2f(pngine.width, pngine.height);
return vec4f(uv, sin(pngine.time) * .5 + .5, 1);
}
"""))

That is the whole document: no pipeline, bind group, pass or frame to declare.

pass0 samples its own previous frame through prev_pass0; main samples pass0’s output by name and renders to the canvas. Both passes belong to the same (pass-graph …), which is what keeps their pooled texture ids in step. The feedback has to sit on the earlier pass: the last pass renders to the canvas, and WebGPU keeps no previous canvas texture, so :feedback true on it is refused with the message below.

(pass-graph
(pass :name pass0 :feedback true :code """
@fragment fn fs(@builtin(position) pos: vec4f) -> @location(0) vec4f {
let uv = pos.xy / vec2f(pngine.width, pngine.height);
let history = textureSample(prev_pass0, samp, uv).rgb;
let t = pngine.time;
let c = vec2f(sin(t) * .3 + .5, cos(t * .7) * .3 + .5);
let glow = smoothstep(.15, .0, length(uv - c));
let col = .5 + .5 * cos(t * 2. + vec3f(0., 2., 4.));
return vec4f(mix(col * glow, history, 0.92), 1);
}
""")
(pass :name main :code """
@fragment fn fs(@builtin(position) pos: vec4f) -> @location(0) vec4f {
let uv = pos.xy / vec2f(pngine.width, pngine.height);
let scene = textureSample(pass0, samp, uv).rgb;
let vignette = smoothstep(1.2, 0.3, length(uv - 0.5));
return vec4f(scene * vignette, 1);
}
"""))
; invalid: renders to the canvas and cannot feed back
(pass-graph
(pass :name trail :feedback true :code """
@fragment fn fs(@builtin(position) pos: vec4f) -> @location(0) vec4f {
return textureLoad(prev_trail, vec2i(pos.xy), 0) * 0.98;
}
"""))

:file embeds binary data from WASM modules as storage buffers, which avoids long WGSL const array declarations. Each file becomes D0, D1, … in order:

(pass-graph
(pass :name main :file ["colors.wasm"] :code """
// D0 auto-injected: var<storage, read> D0: array<f32>;
fn gv(i: u32) -> vec3f {
let b = i * 3u;
return vec3f(D0[b], D0[b + 1u], D0[b + 2u]);
}
@fragment fn fs(@builtin(position) pos: vec4f) -> @location(0) vec4f {
return vec4f(gv(0u), 1);
}
"""))

The module convention is the same one audio payloads use:

Export Type Required Description
m memory Yes Contains the data
l i32 global Yes Byte length of the data
s i32 global No Start offset in memory (default 0)
gen function No Called before the memory is read

array<f32> has a stride of 4 (packed). array<vec3f> has a stride of 16, a third of it padding, so index a flat array<f32> manually when size matters.

(pass …) covers fullscreen fragment and compute work: shader art, post-processing, feedback, and scaled HDR intermediates. It has no vertex buffers, meshes, or instancing. For geometry, write the ordinary (render-pipeline …) + (render-pass …) forms, or use a (draw-graph …) when one geometry set needs several stage variants.

Named graphs compose in a hand-written frame. That is the escape from a single fullscreen chain into a scene plus post-processing, without changing the executor or hiding the order in which work runs.

Rule Error
A (pass …) needs :code missing_required_key
The WGSL must declare an @fragment or @compute function lowering_hook_failed, pass main: its WGSL declares no entry point
Pass names must be unique within the graph duplicate_cross_ref_target on the generated resources (main__tex, main__pipe, …)
:file paths resolve against the source file’s directory cannot read 'colors.wasm': FileNotFound
WGSL errors are reported against the injected source located WGSL diagnostic

The hook names what it generates after the pass: <name>__shader, <name>__tex, <name>__pipe, <name>__bg, and a render pass called <name> itself. That is why two passes with one name collide on the generated forms rather than on the (pass …) forms.

Every key and value on this page traced to the WebGPU name it stands for, with a link to the definition. How the tracing is made, and what keeps it from rotting, is the subject of Where the Words Come From.

(pass-graph …) is PNGine’s own. The container and schedule for (pass …) forms.

Key WebGPU Note
:name PNGine’s own the graph name
:before PNGine’s own operations scheduled before the passes
:expose PNGine’s own resources exposed by the graph

(pass …) is PNGine’s own. The shader-art sugar, lowered by the pngine/pass-v1 hook into ordinary forms (a fullscreen pipeline, its bind group, a uniform buffer, textures for feedback). What it lowers to is where the WebGPU words are.

Key WebGPU Note
:name PNGine’s own the pass name, and the texture name other passes sample
:code GPUShaderModuleDescriptor.code the fragment shader; the vertex stage is generated
:feedback PNGine’s own a ping-pong texture pair so the pass can read its own previous frame
:format PNGine’s own the output texture format
:init PNGine’s own a compute shader run once to seed the pass’s buffer
:file PNGine’s own WASM modules whose exports fill storage buffers
:scale PNGine’s own output size relative to the canvas
:reads PNGine’s own other passes sampled by this pass
:imports PNGine’s own named WGSL fragments assembled into the shader

texture-format (:format on (pass …)) spells the GPUTextureFormat enum.

102 values
Value WebGPU Note
rgba8unorm "rgba8unorm"
rgba8snorm "rgba8snorm"
bgra8unorm "bgra8unorm"
rgba16float "rgba16float"
rgba32float "rgba32float"
depth24plus "depth24plus"
depth24plus-stencil8 "depth24plus-stencil8"
depth32float "depth32float"
stencil8 "stencil8"
depth16unorm "depth16unorm"
r8unorm "r8unorm"
rg8unorm "rg8unorm"
r16float "r16float"
rg16float "rg16float"
r32float "r32float"
r32uint "r32uint"
rgba8unorm-srgb "rgba8unorm-srgb"
rgba8uint "rgba8uint"
rgba8sint "rgba8sint"
r8snorm "r8snorm"
r8uint "r8uint"
r8sint "r8sint"
rg8snorm "rg8snorm"
rg8uint "rg8uint"
rg8sint "rg8sint"
r16uint "r16uint"
r16sint "r16sint"
rg16uint "rg16uint"
rg16sint "rg16sint"
r32sint "r32sint"
rg32uint "rg32uint"
rg32sint "rg32sint"
rg32float "rg32float"
rgba16uint "rgba16uint"
rgba16sint "rgba16sint"
rgba32uint "rgba32uint"
rgba32sint "rgba32sint"
rgb10a2unorm "rgb10a2unorm"
rgb10a2uint "rgb10a2uint"
rg11b10ufloat "rg11b10ufloat"
rgb9e5ufloat "rgb9e5ufloat"
bgra8unorm-srgb "bgra8unorm-srgb"
r16unorm "r16unorm"
r16snorm "r16snorm"
rg16unorm "rg16unorm"
rg16snorm "rg16snorm"
rgba16unorm "rgba16unorm"
rgba16snorm "rgba16snorm"
depth32float-stencil8 "depth32float-stencil8"
bc1-rgba-unorm "bc1-rgba-unorm"
bc1-rgba-unorm-srgb "bc1-rgba-unorm-srgb"
bc2-rgba-unorm "bc2-rgba-unorm"
bc2-rgba-unorm-srgb "bc2-rgba-unorm-srgb"
bc3-rgba-unorm "bc3-rgba-unorm"
bc3-rgba-unorm-srgb "bc3-rgba-unorm-srgb"
bc4-r-unorm "bc4-r-unorm"
bc4-r-snorm "bc4-r-snorm"
bc5-rg-unorm "bc5-rg-unorm"
bc5-rg-snorm "bc5-rg-snorm"
bc6h-rgb-ufloat "bc6h-rgb-ufloat"
bc6h-rgb-float "bc6h-rgb-float"
bc7-rgba-unorm "bc7-rgba-unorm"
bc7-rgba-unorm-srgb "bc7-rgba-unorm-srgb"
etc2-rgb8unorm "etc2-rgb8unorm"
etc2-rgb8unorm-srgb "etc2-rgb8unorm-srgb"
etc2-rgb8a1unorm "etc2-rgb8a1unorm"
etc2-rgb8a1unorm-srgb "etc2-rgb8a1unorm-srgb"
etc2-rgba8unorm "etc2-rgba8unorm"
etc2-rgba8unorm-srgb "etc2-rgba8unorm-srgb"
eac-r11unorm "eac-r11unorm"
eac-r11snorm "eac-r11snorm"
eac-rg11unorm "eac-rg11unorm"
eac-rg11snorm "eac-rg11snorm"
astc-4x4-unorm "astc-4x4-unorm"
astc-4x4-unorm-srgb "astc-4x4-unorm-srgb"
astc-5x4-unorm "astc-5x4-unorm"
astc-5x4-unorm-srgb "astc-5x4-unorm-srgb"
astc-5x5-unorm "astc-5x5-unorm"
astc-5x5-unorm-srgb "astc-5x5-unorm-srgb"
astc-6x5-unorm "astc-6x5-unorm"
astc-6x5-unorm-srgb "astc-6x5-unorm-srgb"
astc-6x6-unorm "astc-6x6-unorm"
astc-6x6-unorm-srgb "astc-6x6-unorm-srgb"
astc-8x5-unorm "astc-8x5-unorm"
astc-8x5-unorm-srgb "astc-8x5-unorm-srgb"
astc-8x6-unorm "astc-8x6-unorm"
astc-8x6-unorm-srgb "astc-8x6-unorm-srgb"
astc-8x8-unorm "astc-8x8-unorm"
astc-8x8-unorm-srgb "astc-8x8-unorm-srgb"
astc-10x5-unorm "astc-10x5-unorm"
astc-10x5-unorm-srgb "astc-10x5-unorm-srgb"
astc-10x6-unorm "astc-10x6-unorm"
astc-10x6-unorm-srgb "astc-10x6-unorm-srgb"
astc-10x8-unorm "astc-10x8-unorm"
astc-10x8-unorm-srgb "astc-10x8-unorm-srgb"
astc-10x10-unorm "astc-10x10-unorm"
astc-10x10-unorm-srgb "astc-10x10-unorm-srgb"
astc-12x10-unorm "astc-12x10-unorm"
astc-12x10-unorm-srgb "astc-12x10-unorm-srgb"
astc-12x12-unorm "astc-12x12-unorm"
astc-12x12-unorm-srgb "astc-12x12-unorm-srgb"
preferred-canvas-format PNGine’s own the runtime’s negotiated canvas format; see References

Checked against the WebGPU specification at revision d178d91; the links go to the current draft.