storageBarrier
On this page

storageBarrier

Function

A barrier waits for the invocations of one workgroup and orders their accesses to storage memory.

Compare examples

Compare the shared workgroup case with independent workgroups. Only invocations in the same workgroup rendezvous.

Model assumptionsA, B ∈ workgroup W; C ∈ workgroup V; W ≠ V

Example 1W: A.write → storageBarrier() → B.read
Result
A.write ≺ B.read
Example 2W: A.write → storageBarrier() → A.read
Result
A.write ≺ A.read
Example 3W.storageBarrier(); V.storageBarrier()
Result
scope(W) ≠ scope(V)

The examples are calculation models and do not run GPU work. The reference below gives the complete call signatures. 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 between a cooperative write phase and a read phase involving storage memory.

Inputs and limits

Every invocation of the workgroup must reach the barrier in uniform control flow. It is not a device-wide barrier. These compiler calls are compute-only and WebGPU-only.

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.

Waits until every invocation of the workgroup has reached this line, and makes every write to storage before it visible to every invocation after it.

Syntax

declare function storageBarrier(): void

Return value

void

Description

A statement, in a compute entry or a helper and never inside an if or switch. On WebGL2 it cuts a phase of the pass program, when the entry reaches no texture (Rule 8.24); the CPU oracle runs the workgroup in lockstep through dispatch.

Targets

WGSL
storageBarrier()
GLSL ES 3.00
No form on this target.

See also

Edit this page Report a problem