Intrinsics1 min read
wave_any
Returns true if a condition is true in any active lane.
Reading Time
1 min
Word Count
152
Sections
12
Try It Live
Test wave_any in a live shader
Open the playground, start from a visual preset, and wire wave_any into the fragment stage to see how it behaves with real values.
Open PlaygroundLive 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_any function returns true if the input boolean is true in at least one active lane of the wave.
Signature
bwsl
wave_any :: (bool x) -> bool {...}
Parameters
| Parameter | Type | Description |
|---|---|---|
x | bool | Condition to test |
Return Value
Returns true if x is true in any active lane, otherwise false.
Example
bwsl
pipeline CollisionDetection {
pass "Main" {
compute "Main" [64, 1, 1] {
// Check for collision at this thread's position
bool hasCollision = checkCollision(position);
// If any thread in wave has collision
if (wave_any(hasCollision)) {
// Wave needs to handle collision
if (hasCollision) {
resolveCollision(position);
}
}
}
}
}Common Use Cases
Collision/Hit Detection
bwsl
// Check if any ray in wave hits geometry
bool hit = rayIntersect(ray, geometry);
if (wave_any(hit)) {
// At least one hit - process accordingly
}Boundary Conditions
bwsl
// Check if any thread is at boundary
bool atBoundary = isAtBoundary(position);
if (wave_any(atBoundary)) {
// Handle boundary condition for wave
}Exception Handling
bwsl
// Check for any invalid values
bool invalid = isnan(value) || isinf(value);
if (wave_any(invalid)) {
// Handle error case
handleError();
}Sparse Data
bwsl
// Check if any lane has data to process
bool hasData = data[input.local_index] != 0;
if (wave_any(hasData)) {
processData();
}Early Continue
bwsl
// Check if any work needs to be done
bool needsWork = computeNeedsWork(input.local_index);
if (!wave_any(needsWork)) {
// No lanes need work, skip to next iteration
continue;
}Boolean OR
wave_any(x) is equivalent to a boolean OR across all active lanes. If any lane has true, the result is true.
Use with wave_all
Combine wave_any and wave_all for complex logic:
wave_all(x): All lanes truewave_any(x): At least one lane true!wave_any(x): No lanes truewave_any(x) && !wave_all(x): Some but not all lanes true
Compiled Output
When compiled to GLSL:
glsl
// Requires GL_KHR_shader_subgroup_vote
subgroupAny(x)
When compiled to HLSL:
hlsl
WaveActiveAnyTrue(x)
When compiled to SPIR-V:
Uses OpGroupNonUniformAny instruction.
See Also
- wave_all - True if all lanes are true
- wave_broadcast - Broadcast from one lane