Intrinsics1 min read

wave_max

Finds the maximum value across all active lanes in a wave.

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

Test wave_max in a live shader

Open the playground, start from a visual preset, and wire wave_max 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_max function returns the maximum value of the input across all active lanes in a wave/subgroup.

Signature

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

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

Parameters

ParameterTypeDescription
xTValue to compare

Return Value

Returns the maximum value of x across all active lanes.

Example

bwsl
pipeline MaxLuminance {
pass "Main" {
compute "Main" [64, 1, 1] {
uint localIdx = input.local_index;
// Sample luminance at thread location
float lum = sample(luminanceTex, threadUV).r;
// Find maximum luminance in wave
float maxLum = wave_max(lum);
if (localIdx == 0u) {
float _ = maxLum;
}
}
}
}

Common Use Cases

Exposure Calculation

bwsl
// Find brightest pixel in wave
float brightness = dot(color.rgb, float3(0.299, 0.587, 0.114));
float maxBrightness = wave_max(brightness);

Bounding Box

bwsl
// Compute max corner of bounding box
float3 position = getPosition(input.local_index);
float3 maxCorner = wave_max(position);

Depth Buffer Pyramid

bwsl
// Find maximum depth for Hi-Z culling
float depth = getDepth(pixelId);
float maxDepth = wave_max(depth);

Peak Detection

bwsl
// Find peak value in data
float value = sampleData(input.local_index);
float peakValue = wave_max(value);
bool isPeak = (value == peakValue);

Resource Sizing

bwsl
// Determine max allocation needed
int required = computeRequiredSize(input.local_index);
int maxRequired = wave_max(required);
// Allocate based on maxRequired

Min and Max Together

Computing both wave_min and wave_max gives the range of values in the wave, useful for normalization or culling decisions.

Vector Types

For vector types, the operation is performed component-wise. Each component's maximum is computed independently.

Compiled Output

When compiled to GLSL:

glsl
// Requires GL_KHR_shader_subgroup_arithmetic
subgroupMax(x)

When compiled to HLSL:

hlsl
WaveActiveMax(x)

When compiled to SPIR-V:

Uses OpGroupNonUniformFMax (float) or OpGroupNonUniformSMax/UMax (int) with Reduce operation.

See Also