Intrinsics1 min read

wave_broadcast

Broadcasts a value from one lane to all lanes in the wave.

Reading Time
1 min
Word Count
173
Sections
12
Try It Live

Test wave_broadcast in a live shader

Open the playground, start from a visual preset, and wire wave_broadcast into the fragment stage to see how it behaves with real values.

Open Playground

Live Demo Pending

This intrinsic does not yet have a self-contained interactive preview. Compute-only and external-resource intrinsics need a different demo path than the current fragment and 3D showcases.

The wave_broadcast function reads a value from a specific lane and returns it to all lanes in the wave.

Signature

bwsl
wave_broadcast :: (T x, int lane) -> T {...}

Where T can be float, float2, float3, float4, int, or uint.

Parameters

ParameterTypeDescription
xTValue to broadcast
laneintLane index to broadcast from (must be uniform)

Return Value

Returns the value of x from the specified lane to all lanes.

Example

bwsl
pipeline SharedData {
pass "Main" {
compute "Main" [64, 1, 1] {
uint localIdx = input.local_index;
// Each lane computes a value
float value = computeValue(localIdx);
// Lane 0 has special "leader" data
float leaderValue = wave_broadcast(value, 0);
// All lanes now have lane 0's value
float normalized = value / leaderValue;
float _ = normalized;
}
}
}

Common Use Cases

Leader Lane Pattern

bwsl
// First lane reads shared data, broadcasts to others
float sharedValue = (input.local_index == 0u) ? loadSharedData() : 0.0;
float broadcast = wave_broadcast(sharedValue, 0);

Matrix Row Distribution

bwsl
// Each lane computes one element, broadcast to build row
float element = computeElement(input.local_index);
float row[4];
for (int i = 0; i < 4; i++) {
row[i] = wave_broadcast(element, i);
}

Reference Value

bwsl
// Use specific lane's value as reference
float myValue = computeValue(input.local_index);
float referenceValue = wave_broadcast(myValue, referenceLaneId);
float diff = myValue - referenceValue;

Pivot Selection

bwsl
// Broadcast pivot for sorting/partitioning
float pivotValue = wave_broadcast(values[input.local_index], pivotLane);
bool lessThanPivot = values[input.local_index] < pivotValue;

Coordinate Sharing

bwsl
// Share computed position from one lane
float3 position = computePosition(input.local_index);
float3 referencePos = wave_broadcast(position, 0);
float dist = distance(position, referencePos);

Uniform Lane Index

The lane parameter must be uniform across all lanes (same value in all lanes). Non-uniform lane indices result in undefined behavior.

Dynamic Lane Selection

For dynamic lane selection based on conditions, use wave_read_first instead, which reads from the first active lane.

Compiled Output

When compiled to GLSL:

glsl
// Requires GL_KHR_shader_subgroup_ballot
subgroupBroadcast(x, lane)

When compiled to HLSL:

hlsl
WaveReadLaneAt(x, lane)

When compiled to SPIR-V:

Uses OpGroupNonUniformBroadcast instruction.

See Also