subgroupShuffle
Reads value v from the subgroup invocation whose index equals id and returns it to the current invocation. Works within the active GPU subgroup (warp/wave). The result type matches v; id is an unsigned integer lane index. Synonyms: subgroup shuffle / warp shuffle / broadcast from lane.
Core Advantages
Subgroup-level communication with no shared memory or explicit barriers. Lower latency and higher throughput; exposed as a TSL node with exactly two parameters, making it easy to compose in node graphs.
Common Uses
Broadcast a leader value (e.g., lane 0) across the whole subgroup.
Neighbor exchange for finite differences, smoothing, or shuffle stages in sorting.
Building blocks for subgroup scans/reductions/bitonic-sort style algorithms.
How to adjust
v can be scalar or vector numeric; id is uint and should stay within [0, subgroupSize-1]. Reading from an inactive lane is undefined. Typical tuning is to choose which lane to broadcast (0u, a leaderId, etc.) or vary id in loops for staged exchanges. Requires a backend with subgroup support (e.g., WebGPU with device feature enabled).
Code Examples
1// Broadcast a threshold computed by lane 0 to all lanes
2const localVal = dot( normalView, vec3( 0, 0, 1 ) );
3const thresholdFromLeader = subgroupShuffle( localVal, 0u );
4const mask = step( thresholdFromLeader, localVal );
5material.emissiveNode = vec3( mask );