subgroupXor
Performs a bitwise XOR reduction of the input e across all active invocations in the current subgroup and returns that result to each invocation.
Core Advantages
Constant‑time parity/flag reduction within a GPU subgroup—no shared memory or barriers—typically faster than looping with atomics or workgroup memory.
Common Uses
Parity vote: map a boolean to 0/1 and XOR-reduce to test if the number of true invocations is odd.
Subgroup-wide switches/dithering masks: aggregate per-lane 0/1 flags into a single control bit.
Bit-flag reduction: XOR-reduce lane-local bitmasks into a subgroup-level control mask.
Stylized/noise patterns: combine with frame counters or coordinates to build blue‑noise‑like binary masks.
How to adjust
Accepts integer (int/uint) scalars or vectors; vector components are reduced independently. Map booleans to 0/1 before calling. Requires backend subgroup support (e.g., WGSL/WebGPU). Only active invocations participate, so results depend on control‑flow masks.
Code Examples
1// Example: use subgroup parity as a binary toggle
2const predicate = positionView.z.lessThan( -5.0 );
3const vote = predicate.cond( uint(1), uint(0) );
4const parity = subgroupXor( vote ); // 0 = even, 1 = odd
5const isOdd = parity.equal( uint(1) );
6material.emissiveNode = isOdd.cond( vec3(1.0), vec3(0.0) );