Intrinsics1 min read

wave_product

Computes the product of a value across all active lanes in a wave.

Reading Time
1 min
Word Count
137
Sections
11
Try It Live

Test wave_product in a live shader

Open the playground, start from a visual preset, and wire wave_product 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_product function calculates the product of a value across all active lanes in a wave/subgroup.

Signature

bwsl
wave_product :: (T x) -> T {...}

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

Parameters

ParameterTypeDescription
xTValue to multiply across lanes

Return Value

Returns the product of x from all active lanes in the wave.

Example

bwsl
pipeline CumulativeGain {
pass "Main" {
compute "Main" [64, 1, 1] {
uint localIdx = input.local_index;
// Each lane has a multiplier
float multiplier = getLaneMultiplier(localIdx);
// Compute product across wave
float totalMultiplier = wave_product(multiplier);
// All lanes now have the combined multiplier
float result = baseValue * totalMultiplier;
float _ = result;
}
}
}

Common Use Cases

Cumulative Probability

bwsl
// Calculate joint probability across samples
float probability = computeProbability(sample);
float jointProb = wave_product(probability);

Chained Transformations

bwsl
// Combine scale factors
float scale = getScaleFactor(input.local_index);
float combinedScale = wave_product(scale);

Ray Transmission

bwsl
// Calculate combined transmission through materials
float transmission = 1.0 - absorption;
float totalTransmission = wave_product(transmission);

Boolean Combination

bwsl
// Check if all lanes pass condition (product of 1s = 1)
float pass = condition ? 1.0 : 0.0;
float allPass = wave_product(pass); // 0.0 if any fail

Numerical Stability

Products of many values can quickly overflow (if > 1) or underflow (if < 1). Consider using wave_sum(log(x)) and exp(result) for better numerical stability with many factors.

Alternative for AND

For boolean AND across wave, wave_all(condition) is clearer and more efficient than product-based approaches.

Compiled Output

When compiled to GLSL:

glsl
// Requires GL_KHR_shader_subgroup_arithmetic
subgroupMul(x)

When compiled to HLSL:

hlsl
WaveActiveProduct(x)

When compiled to SPIR-V:

Uses OpGroupNonUniformFMul with Reduce operation.

See Also