subgroupAnd
Performs a bitwise AND reduction of the input across all active invocations in the GPU subgroup (warp/wave) and returns the result. Ideal for consensus checks and bitmask intersections without shared memory.
Core Advantages
Hardware-level subgroup reduction for low-latency ALL-true tests or mask intersection, cutting barriers and memory traffic. Useful for fast voting and stage gating in parallel kernels.
Common Uses
Boolean consensus within a subgroup (proceed only if every lane meets the condition)
Aggregating bitmasks (keep only flags set by all lanes)
Early-exit/short-circuit and stage gating in parallel pipelines
Local-window consistency decisions for image/particle workloads
How to adjust
Takes exactly one parameter. Use a boolean input for ALL-true voting; use integer/uint to intersect bitmasks. Behavior depends on the input e: booleans for consensus, uints for flags. Acts on active invocations only; pair with workgroup/storage barriers for multi-phase kernels.
Code Examples
1// Example: write 1u only if every lane in the subgroup isEdge
2const isEdge = grayscale( texture( imageTex, uv() ) ).greaterThan( 0.8 );
3const allEdge = subgroupAnd( isEdge );
4If(
5 allEdge,
6 outBuffer.element( dispatchThreadID.x ).assign( uint(1) ),
7 outBuffer.element( dispatchThreadID.x ).assign( uint(0) )
8);