subgroupElect
Function
An election is true in exactly one lane of the subgroup, the active lane with the lowest id, and false in the others.
Compare examples
Lane 0 is elected in the fixture. On one lane the election is always true.
Model assumptionssubgroup of 4 lanes; x = [3, 1, 4, 1]; p = [true, false, true, true]
Example 1subgroupElect()
- Result
[true, false, false, false] by lane
Example 2subgroupElect()
- Result
one lane (WebGL2, CPU oracle): true
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 to let one lane do a subgroup's shared work, such as one atomicAdd of a fold.
Inputs and limits
Every lane must reach the call together. Which lane is elected depends on which lanes are active.
For shader input rules and precision, consult WGSL and GLSL ES 3.00.
Related functions
The signature, the sentence and any message are the compiler's own text at commit af54ddad5.
Returns true in the lowest active lane of the subgroup and false in every other.
Syntax
declare function subgroupElect(): boolReturn value
Description
On the CPU oracle and on WebGL2 a subgroup is one invocation (Rule 11.21), so it gives the lane's own value.
Targets
- WGSL
-
subgroupElect() - GLSL ES 3.00
-
subgroupElectis lowered to one lane before the GLSL writer runs (Rule 11.21)