subgroupBroadcast
Broadcasts value e from the invocation whose subgroup_invocation_id equals id to all active invocations in the subgroup. Signature: subgroupBroadcast(e, id).
Core Advantages
Shares data within a subgroup without explicit barriers or shared memory, reducing duplicate work.
Common Uses
Compute once per subgroup and reuse (e.g., random/noise/material params)
Leader-lane broadcast in reductions and scans
Tiled lighting and screen-space passes
Building wave/warp-level primitives
How to adjust
e is the value to broadcast; id selects the source invocation index. Keep id in [0, subgroupSize-1]. The source invocation must be active or the result is undefined. Scope is the current subgroup only, not across workgroups. Subgroup size and scheduling can vary, so avoid relying on a fixed id for stable visuals. Works only when the backend enables subgroups; provide a fallback where unsupported (e.g., use e directly). Implemented via nodeProxyIntent(SubgroupFunctionNode, SUBGROUP_BROADCAST) with parameter length 2.
Code Examples
1<Canvas>
2 <mesh>
3 <sphereGeometry args={[0.5, 128, 128]} />
4 <meshStandardNodeMaterial
5 // Broadcast lane 0 luminance to the whole subgroup
6 roughnessNode={ subgroupBroadcast( clamp( dot( normalView, vec3(0, 0, 1) ), 0.0, 1.0 ), 0 ) }
7 />
8 </mesh>
9</Canvas>