subgroupShuffleDown
Within the current subgroup (wave/warp), fetch the value v from the invocation whose laneId equals current laneId + delta. The function takes two parameters: (v, delta).
Core Advantages
Enables fast intra-subgroup data exchange without shared memory or explicit barriers—ideal for reductions, scans, and neighborhood communication.
Common Uses
Subgroup reductions (sum/max/min) and prefix scans
Sliding-window/convolution-style neighbor reads
Block-level sorting, bucketing, histograms
Particle/image neighborhood ops (backend subgroup support required)
How to adjust
Parameter delta controls the downward offset (laneId + delta). When crossing the subgroup boundary, the return is implementation-defined/undefined; guard with subgroup size checks (e.g., use result only if laneId + delta < subgroupSize). Typically available only on backends that support subgroups (e.g., WGSL/WebGPU).
Code Examples
1// Ex.1: read from the right neighbor (delta = 1)
2const rightNeighbor = subgroupShuffleDown( value, 1 );
3
4// Ex.2: logarithmic-step subgroup reduction (illustrative)
5let sum = value;
6for ( let off = 16; off > 0; off >>= 1 ) {
7 sum = sum.add( subgroupShuffleDown( sum, off ) );
8}
9// Note: choose the initial 'off' according to the actual subgroup size (e.g., 32/64)
10