How GLSL subgroupAll Evaluates Active Lanes

In GLSL, the subgroupAll function is a collective vote operation that determines if a boolean condition holds true across all concurrently executing invocations within a subgroup. This article explains how GLSL determines lane activity, how hardware execution masks evaluate local boolean expressions, and how the final result is propagated uniformly across all active threads.

The Execution Model and Active Lanes

A subgroup (often corresponding to a warp on NVIDIA hardware or a wavefront on AMD hardware) consists of a fixed number of invocations executing in lockstep. However, control flow divergence—such as if-else branches or loops—can cause individual invocations to become inactive.

The execution state of a subgroup is tracked via an internal bitmask known as the active invocation mask (or execution mask). Each bit in this mask corresponds to a lane in the subgroup:

  • 1 indicates the lane is active and currently executing the instruction.
  • 0 indicates the lane is inactive (diverged or disabled).

Helper invocations, often found in fragment shaders executing outside primitive boundaries to compute derivatives, may also have designated states depending on subgroup extensions and hardware implementations.

Local Evaluation and the Ballot Mechanism

When an active invocation calls subgroupAll(bool value), the GPU executes the following sequence:

  1. Local Evaluation: Each active lane evaluates its local boolean expression (value), producing a true (1) or false (0) result.
  2. Subgroup Ballot Generation: The hardware collects these boolean states into a condition mask. In this mask, each bit represents the boolean result evaluated by the corresponding lane. Inactive lanes do not contribute valid data to this mask.
  3. Mask Comparison: The hardware compares the condition mask with the active invocation mask. The operation performs a bitwise check equivalent to verifying whether every bit enabled in the active mask is also enabled in the condition mask:

\[\text{AllTrue} = (\text{condition\_mask} \ \& \ \text{active\_mask}) == \text{active\_mask}\]

Resolution and Broadcast

If the condition mask matches the active mask, every active lane evaluated value to true, and the operation returns true. If even a single active lane evaluated value to false, the operation returns false. Inactive lanes are completely excluded from the evaluation; their local variables and conditions do not affect the outcome.

Once evaluated, the resulting scalar boolean value is uniformly broadcast to all participating active invocations in the subgroup. Because this is handled entirely at the hardware level using dedicated ballot or vote registers, subgroupAll executes in minimal clock cycles without requiring memory accesses or scratchpad memory.