@compute
On this page

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

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) => void
declare function compute(target: Function, context?: unknown): void

Parameters

  • workgroupSize readonly 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

See also

Edit this page Report a problem