wave_min
Finds the minimum value across all active lanes in a wave.
Test wave_min in a live shader
Open the playground, start from a visual preset, and wire wave_min into the fragment stage to see how it behaves with real values.
Open PlaygroundLive Demo Pending
The wave_min function returns the minimum value of the input across all active lanes in a wave/subgroup.
Signature
wave_min :: (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 minimum value of x across all active lanes.
Example
pipeline ClosestHit {
pass "Main" {
compute "Main" [64, 1, 1] {
uint localIdx = input.local_index;
// Each lane has a distance to test
float distance = computeRayHit(ray, localIdx);
// Find closest hit across wave
float closestDist = wave_min(distance);
// Check if this lane has the closest hit
if (distance == closestDist) {
// This lane processes the hit
processClosestHit(localIdx);
}
}
}
}Common Use Cases
Find Closest Object
// Ray tracing: find closest intersection
float hitDist = traceRay(ray);
float minDist = wave_min(hitDist);
bool isClosest = (hitDist == minDist);Bounding Box Computation
// Compute min corner of bounding box
float3 position = getPosition(input.local_index);
float3 minCorner = wave_min(position);Error/Depth Computation
// Find minimum depth in wave for Hi-Z
float depth = getDepth(pixelId);
float minDepth = wave_min(depth);Dynamic LOD Selection
// Use closest distance for LOD
float dist = distance(objectPos, cameraPos);
float closestDist = wave_min(dist);
int lod = computeLOD(closestDist);Debugging/Validation
// Find minimum value for range checking
float value = computedValue;
float minVal = wave_min(value);
// Verify minVal meets requirementsFinding the Lane
To find which lane has the minimum value, compare the result with each lane's value: bool isMinLane = (value == wave_min(value));. Be aware of ties.
Vector Types
For vector types, the operation is performed component-wise. Each component's minimum is computed independently.
Compiled Output
When compiled to GLSL:
// Requires GL_KHR_shader_subgroup_arithmetic
subgroupMin(x)
When compiled to HLSL:
WaveActiveMin(x)
When compiled to SPIR-V:
Uses OpGroupNonUniformFMin (float) or OpGroupNonUniformSMin/UMin (int) with Reduce operation.