wave_max
Finds the maximum value across all active lanes in a wave.
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 PlaygroundLive Demo Pending
The wave_max function returns the maximum value of the input across all active lanes in a wave/subgroup.
Signature
wave_max :: (T x) -> T {...}
Where T can be float, float2, float3, float4, int, or uint.
Parameters
| Parameter | Type | Description |
|---|---|---|
x | T | Value to compare |
Return Value
Returns the maximum value of x across all active lanes.
Example
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
// Find brightest pixel in wave
float brightness = dot(color.rgb, float3(0.299, 0.587, 0.114));
float maxBrightness = wave_max(brightness);Bounding Box
// Compute max corner of bounding box
float3 position = getPosition(input.local_index);
float3 maxCorner = wave_max(position);Depth Buffer Pyramid
// Find maximum depth for Hi-Z culling
float depth = getDepth(pixelId);
float maxDepth = wave_max(depth);Peak Detection
// Find peak value in data
float value = sampleData(input.local_index);
float peakValue = wave_max(value);
bool isPeak = (value == peakValue);Resource Sizing
// Determine max allocation needed
int required = computeRequiredSize(input.local_index);
int maxRequired = wave_max(required);
// Allocate based on maxRequiredMin 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:
// Requires GL_KHR_shader_subgroup_arithmetic
subgroupMax(x)
When compiled to HLSL:
WaveActiveMax(x)
When compiled to SPIR-V:
Uses OpGroupNonUniformFMax (float) or OpGroupNonUniformSMax/UMax (int) with Reduce operation.