Intrinsics1 min read

wave_min

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

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

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 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_min function returns the minimum value of the input across all active lanes in a wave/subgroup.

Signature

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

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

Parameters

ParameterTypeDescription
xTValue to compare

Return Value

Returns the minimum value of x across all active lanes.

Example

bwsl
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

bwsl
// Ray tracing: find closest intersection
float hitDist = traceRay(ray);
float minDist = wave_min(hitDist);
bool isClosest = (hitDist == minDist);

Bounding Box Computation

bwsl
// Compute min corner of bounding box
float3 position = getPosition(input.local_index);
float3 minCorner = wave_min(position);

Error/Depth Computation

bwsl
// Find minimum depth in wave for Hi-Z
float depth = getDepth(pixelId);
float minDepth = wave_min(depth);

Dynamic LOD Selection

bwsl
// Use closest distance for LOD
float dist = distance(objectPos, cameraPos);
float closestDist = wave_min(dist);
int lod = computeLOD(closestDist);

Debugging/Validation

bwsl
// Find minimum value for range checking
float value = computedValue;
float minVal = wave_min(value);
// Verify minVal meets requirements

Finding 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:

glsl
// Requires GL_KHR_shader_subgroup_arithmetic
subgroupMin(x)

When compiled to HLSL:

hlsl
WaveActiveMin(x)

When compiled to SPIR-V:

Uses OpGroupNonUniformFMin (float) or OpGroupNonUniformSMin/UMin (int) with Reduce operation.

See Also