Rule 8.24
Chapter 8, Functions and entry points Test
An exported @compute entry is called from host code as entry(bindings, workgroups).
bindings has one property for each binding the entry reaches through its calls, and no other, each the binding’s host value (Rule 8.21); workgroups is the workgroup count, n or [x, y?, z?], dispatched as written with no bound added, or { indirect, offset? } (change 0075), the three counts x, y and z at element offset (a whole number, 0 when left out) of a Buffer<u32> that an earlier call may have written, read when the call runs and not when it is made (Rule 11.8); the call returns a promise, and when it resolves every storage binding the entry wrote has been read back into the caller’s value in place, or stays on the device in the Buffer passed for it (Rule 11.8). A call whose bindings object takes a Buffer or a Uniform (Rule 8.21) returns nothing and does not block, and a Buffer it writes keeps its values on the device until read(). In the body of a fuse scope (Rule 11.13) the call is recorded and forms a group of its own in the scope’s plan, with the bindings Rule 11.13 gives it; a call that takes a resource throws a TypeError at the call there.
The host view types workgroups as number | readonly [number, number?, number?] | { readonly indirect: Buffer<u32>; readonly offset?: number } in each of the entry’s signatures. The call refuses an indirect count before anything runs, with a TypeError that names the entry and workgroups.indirect or workgroups.offset: an indirect that is not a Buffer<u32>, an offset that is not a whole number from 0, an offset whose three counts run past the array (the message gives both numbers), a Buffer of another owner (Rule 11.8), a scratch array of a fuse scope (Rule 11.13), a disposed Buffer, and an array that is also a binding the entry writes or binds read_write, since WebGPU refuses a buffer that one dispatch reads its counts from and writes; an array the entry only reads may be a binding of the same call. An object with another key, or with no indirect, is refused as a wrong count is.
It runs on WebGPU where there is a device, the device of the runtime configure({ runtime }) names or else the one the call layer requests and the default program runtime shares (Rule 11.11), then on WebGL2 as the pass program of change 0054 (Rule 11.8), and otherwise on the CPU tier, in the order configure sets (Rule 11.8), every invocation of every workgroup in turn, z, then y, then x, with the workgroup memory zeroed for each workgroup; an entry that reaches a barrier is not supported yet on the CPU tier through the call. Where there is no WebGPU device and no WebGL2 context, the call is refused with a TypeError that names the barrier and its line. The oracle’s dispatch runs such an entry on the CPU (surface §25).
In vite dev, and in a production build whose plugin says console: 'always', an entry’s WGSL records its console.* calls (Rule 11.9), and the runtime prints the decoded events to the host’s console after the dispatch or the draw, in the CPU tier’s order; console: 'never' records in neither, and the default, 'dev', records in vite dev alone. Each printed line, from the GPU or the CPU tier, starts with its tier, the call’s file and line, and the invocation when the event has one, in the format string, with the event’s arguments after it and its method kept.
An exported @fragment entry that reads no builtin but position and front_facing and writes one @location(0) vec4 (its result, or a struct of that one field) is drawn as entry(target, bindings): one frame, with a full-screen triangle, into target, an HTMLCanvasElement or an OffscreenCanvas, filling its width by height; the draw returns a promise that resolves when the frame is submitted, and reads nothing back.
For such a fragment entry, bindings is optional exactly when its transitive read/write set contains no host-supplied binding (change 0125). entry(target), entry(target, undefined) and entry(target, {}) then have the same meaning. A declared but unreached binding does not count; a binding reached through a helper does. The runtime-owned _fp64 guard does not count, identified by its ownership metadata rather than its name; an authored binding named _fp64 or _console still counts. Console recording alone adds no host binding. An explicit bindings object still receives the existing validation; null, arrays, primitives, unknown keys, invalid targets and excess arguments remain refused. A fragment with any reached host binding keeps its required argument, and compute calls retain their leading bindings object.
It draws on WebGPU, then WebGL2 (the entry’s GLSL ES 3.00 fragment program, its rows copied so the first is the canvas’s top, as WGSL’s position counts them), then the CPU tier, pixel by pixel; the first draw into a canvas decides its tier, since a canvas keeps the first kind of context it hands out, and every later draw into it uses that tier; the frame is opaque on every tier.
An entry that reaches a texture, or a call the CPU tier does not compute yet, is not supported yet on the CPU tier. It needs a GPU tier. Where it has none, the call or the draw is refused with a TypeError naming why.
An entry that reaches a binding with no host value (a storage texture, a depth texture, a texture of another dimension, a matrix of f64), a fragment entry that reads what a vertex entry writes, and a vertex entry stay never in the host view, naming the work that adds it.
An imported compute entry also takes the optional third argument { constants } (change 0084), with the names, types, range checks and normalized values of program.compute (Rule 11.11). Omitted values keep their authored defaults. The selected values resolve the workgroup shape and workgroup-array lengths; the supplied workgroup count, including an indirect count, stays as written.
The rule text and the parts under it are the compiler's own English, as the design document writes them.
Rationale
an entry is the escape hatch below the loop that becomes a kernel (change 0013), and it runs as its author wrote it: WGSL’s unit, the author’s own bound check, no guard added.
The call replaces what a host otherwise writes by hand around compile() and reflect(): the device, the module, the layouts, the packing, the dispatch and the readback.
The workgroup memory and the order of invocations on the CPU tier are those of the interpreter’s own dispatch, so the two agree; the call does not run a barrier on the CPU tier yet.
An indirect count lets a kernel decide the size of the next call, so a host submits a chain of calls with no read between them (change 0075): WebGPU’s dispatchWorkgroupsIndirect reads the three counts from a buffer. The offset counts elements, so its byte offset, four times it, is always the multiple of 4 that WebGPU requires.
A fragment entry that reads only its pixel’s position needs no vertex data, so one triangle the runtime supplies draws it on every tier; one that reads interstage values needs a mesh, a vertex count and a topology, which is #204’s rendering design.
GLSL’s gl_FragCoord counts rows from the bottom and WGSL’s position from the top, so the WebGL2 tier draws into a framebuffer and copies it upside down, and one program gives one picture on both.
Derives from
change 0016 in changes/ (roadmap item 16, second half); change 0075 (the indirect count); Rule 8.21; docs/dx.md principle 6.
How it is verified
Checked by a test. A test, a gate script or a CI workflow names this rule, and the traceability check fails when a file listed below stops naming it.
Where the rule says the compiler enforces it:
callCompute in src/core/host-compute.ts, over the dispatch in src/core/host-entry.ts, and callDraw in src/runtime/host/draw.ts, what the generated module calls, and computeFace and fragmentFace in src/compiler/ts/host-face.ts, which write the entry’s layouts, its GLSL program and its view type; the printed line by consoleCalls in src/core/console-print.ts, and the console option by typeshade in src/vite.ts, pinned by src/core/console-print.test.ts and src/vite.test.ts; pinned by src/compiler/ts/host-entry.test.ts, which holds the CPU tier equal to the interpreter’s dispatch and checks each refusal’s text, and holds a call over an indirect count that an earlier call wrote to the same dispatch, reads the indirect form under tsc and an editor’s TypeScript language service, and reads the shader with the language service (change 0075), by src/fuse.test.ts, which records the indirect dispatch on a recording device and checks each refusal of an indirect count, by src/compiler/ts/host-draw.test.ts, which holds a CPU-tier frame to the reference and checks which fragment entries draw on which tier, by the import journey in scripts/user-journey.ts, which calls entries on WebGPU, one of them over an indirect count an earlier call wrote and held to the same calls on the CPU tier, and draws two on WebGPU, WebGL2 and the CPU in Chromium from the packed tarball, each frame against the reference, and by the compile gate’s entry-call leg (scripts/entry-calls.ts), which calls every callable entry of the .shade.ts examples, and the compute cases of scripts/compute-case.ts (a texture read on WebGL2), through its generated host module, a compute entry and a draw on WebGPU, WebGL2 and the CPU tier, each tier against WebGPU. An entry call that takes the exported bindings as resources is pinned by src/runtime/resource-call.test.ts on the CPU tier.
The files that verify it at commit af54ddad5, each at the first line that names the rule:
-
scripts/compute-case.ts:1 -
scripts/entry-calls.ts:1 -
scripts/user-journey.ts:334 -
src/compiler/ts/host-draw-bindings.test.ts:1 -
src/compiler/ts/host-draw.test.ts:1 -
src/compiler/ts/host-entry.test.ts:1 -
src/compiler/ts/host-face.ts:5 -
src/compiler/ts/host-override-calls.test.ts:1 -
src/compiler/ts/tiled-matmul.test.ts:1 -
src/core/console-print.test.ts:4 -
src/core/console-print.ts:1 -
src/core/host-compute.ts:1 -
src/core/host-entry.ts:2 -
src/fuse.test.ts:22 -
src/runtime/host/draw.ts:132 -
src/runtime/resource-call.test.ts:10 -
src/vite.test.ts:3 -
src/vite.ts:13
Explained in
The sections of the surface document that explain this rule, at commit af54ddad5:
Error codes that enforce it
The diagnostic codes the rule names under Enforced by, or whose registry text names the rule:
-
SD0111 - portable kernel outside the gather-only tier
See also
Source
The rule at commit af54ddad5:
docs/language-design.md:1142(the design document)reqs/rules/RULE-0824.md(its traceability item)