@compute
Attribute
Marks a compute-stage entry point with its workgroup size, one to three extents, on the function declaration: @compute([64]) export function main(…) { … }.
@compute([x, y?, z?]) makes the function it marks a compute entry point and gives its workgroup size, one to three extents.
Compare examples
Compare three invocations of one dispatch. Each reads its own global_invocation_id and writes its own element.
Example programdeclare const out: storage<array<u32>, "read_write">;
@compute([64])
export function main(gid: builtin<"global_invocation_id">): void {
out[gid.x] = gid.x;
}
Example 1gid.x = 0
- Result
workgroup 0, lane 0
Example 2gid.x = 63
- Result
workgroup 0, lane 63
Example 3gid.x = 64
- Result
workgroup 1, lane 0
The examples are calculation models and do not run GPU work. The reference below gives the syntax of the attribute. Decimal results are rounded for display. The stated assumptions determine each example; actual shader results follow the target precision and execution rules.
When to use it
Use it for general GPU work over buffers and textures, outside any draw.
Inputs and limits
The size is the argument of the attribute, and a bare @compute takes 64. The host chooses how many workgroups a dispatch runs; the size says how many invocations each one holds.
For shader input rules and precision, consult WGSL and GLSL ES 3.00.
Related attributes
The signature, the sentence and any message are the compiler's own text at commit af54ddad5.
Syntax
declare function compute(workgroupSize: readonly number[]): (target: Function, context?: unknown) => voiddeclare function compute(target: Function, context?: unknown): voidParameters
-
workgroupSizereadonly number[]
It is also written on its own, with no arguments.
The declaration also names what the TypeScript decorator runtime hands a decorator, target and context. A call passes neither.
Description
A bare @compute takes 64.
Examples
path/double-array/double-array.shade.tspath/image-blur/image-blur.shade.tspath/parallel-sum/parallel-sum.shade.tspath/histogram/histogram.shade.tsgallery/array-length/array-length.shade.tsgallery/atomic-histogram/atomic-histogram.shade.tsgallery/compute-reduction-twin/compute-reduction-twin.shade.tsgallery/compute-sync/compute-sync.shade.tsgallery/gpu-console/gpu-console.shade.tsgallery/particle-step/particle-step.shade.tsgallery/storage-texture/storage-texture.shade.tsgallery/subgroup-reduce/subgroup-reduce.shade.tsgallery/workgroup-override/workgroup-override.shade.tsgallery/workgroup-reduce/workgroup-reduce.shade.tsgallery/workgroup-scratch/workgroup-scratch.shade.tsgallery/workgroup-tile-2d/workgroup-tile-2d.shade.ts