---
title: "workgroupBarrier / barrier: shader function guide"
description: "A barrier waits for the invocations of one workgroup and orders their accesses to workgroup memory."
url: https://typeshade.dev/reference/functions/workgroupBarrier/
language: en
---

# `workgroupBarrier`

Function

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

**Related names in other languages**

These related operations can differ in arguments, support, and semantics. The foreign names are not accepted TypeShade aliases. Check the target forms and restrictions.

- GLSL: `barrier`
- HLSL: `GroupMemoryBarrierWithGroupSync`

[Targets](https://typeshade.dev/reference/functions/workgroupBarrier/#targets)

## Compare examples

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

**Model assumptions**`A, B ∈ workgroup W; C ∈ workgroup V; W ≠ V`

**Example 1`W: A.write → workgroupBarrier() → B.read`**

**Result**

`A.write ≺ B.read`

**Example 2`W: A.write → workgroupBarrier() → A.read`**

**Result**

`A.write ≺ A.read`

**Example 3`W.workgroupBarrier(); V.workgroupBarrier()`**

**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 workgroup 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](https://www.w3.org/TR/WGSL/) and [GLSL ES 3.00](https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf).

## Related functions

- [`storageBarrier`](https://typeshade.dev/reference/functions/storageBarrier/)
- [`textureBarrier`](https://typeshade.dev/reference/functions/textureBarrier/)
- [`workgroupUniformLoad`](https://typeshade.dev/reference/functions/workgroupUniformLoad/)

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 workgroup memory before it visible to every invocation after it.

## Syntax

```ts
declare function workgroupBarrier(): 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](https://typeshade.dev/reference/rules/8-24/)); the CPU oracle runs the workgroup in lockstep through `dispatch`.

## Targets

**WGSL**

`workgroupBarrier()`

**GLSL ES 3.00**

No form on this target.

## Examples

- [`path/parallel-sum/parallel-sum.shade.ts`](https://typeshade.dev/guide/examples/parallel-sum/)
- [`gallery/compute-sync/compute-sync.shade.ts`](https://typeshade.dev/guide/examples/compute-sync/)
- [`gallery/workgroup-override/workgroup-override.shade.ts`](https://typeshade.dev/guide/examples/workgroup-override/)
- [`gallery/workgroup-reduce/workgroup-reduce.shade.ts`](https://typeshade.dev/guide/examples/workgroup-reduce/)
- [`gallery/workgroup-tile-2d/workgroup-tile-2d.shade.ts`](https://typeshade.dev/guide/examples/workgroup-tile-2d/)

## See also

- [Functions](https://typeshade.dev/reference/functions/)
- [Builtin table](https://typeshade.dev/guide/language/builtins/#barriers)
