v145 · Web APIs · WGSL Reference
WGSL Reference
Subgroup built-in functions available in WGSL, what uniformity analysis checks, and which patterns the subgroup_uniformity extension enables.
subgroup built-in functions
| Function | Description | Uniformity affected |
|---|---|---|
subgroupBroadcast(value, id) |
Broadcasts a value from lane id to all lanes in the subgroup. |
Strict: id must be uniform |
subgroupAdd(value) |
Reduction: sum of value across subgroup. |
No uniformity requirement on value |
subgroupAll(predicate) |
True if predicate is true in all lanes. |
No uniformity requirement |
subgroupAny(predicate) |
True if predicate is true in any lane. |
No uniformity requirement |
subgroupElect() |
Returns true in exactly one lane (the "elected" lane). | No uniformity requirement |
subgroupShuffle(value, id) |
Reads value from a specific lane. |
Strict: id must be uniform |
what subgroup_uniformity relaxes
// Without subgroup_uniformity (strict analysis):
// subgroupBroadcast requires the `id` argument to be provably uniform.
// This fails even when you know it's always 0:
@compute @workgroup_size(64)
fn strict_fail(@builtin(local_invocation_index) lid: u32) {
// Error in strict mode: `lid` is not uniform across lanes
let x = subgroupBroadcast(lid, 0u); // ✗ may fail strict analysis
}
// With enable subgroup_uniformity (Chrome 145+):
enable subgroups;
enable subgroup_uniformity;
@compute @workgroup_size(64)
fn relaxed_ok(@builtin(local_invocation_index) lid: u32) {
let x = subgroupBroadcast(lid, 0u); // ✓ relaxed analysis accepts this
}
// Note: enabling subgroup_uniformity opts the shader out of the safety
// guarantee — the developer takes responsibility for correctness.
see also
scenario focus
Select a scenario to focus its rendered example and summary.