Intrinsics1 min read

all

Returns true if every component of a boolean vector is true.

Reading Time
1 min
Word Count
167
Sections
10
Try It Live

Test all in a live shader

Open the playground, start from a visual preset, and wire all 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 all function reduces a boolean vector to a single boolean by returning true only if every component is true.

Signature

bwsl
all :: (bvecN x) -> bool {...}

Where bvecN is bool2, bool3, or bool4.

Parameters

ParameterTypeDescription
xbvecNBoolean vector to reduce

Return Value

Returns true if every component of x is true, otherwise returns false. Equivalent to x[0] && x[1] && ....

Example

bwsl
pipeline InUnitCube {
fragment {
float3 p = input.worldPos;
// Keep fragments strictly inside a unit cube.
bool3 inside = bool3(abs(p.x) < 1.0, abs(p.y) < 1.0, abs(p.z) < 1.0);
if (!all(inside)) {
discard;
}
output.color = float4(p * 0.5 + 0.5, 1.0);
}
}

Common Use Cases

Inclusive Range Check

bwsl
bool2 inRange = bool2(uv.x >= 0.0 && uv.x <= 1.0, uv.y >= 0.0 && uv.y <= 1.0);
if (!all(inRange)) discard;

Validating Multiple Conditions

bwsl
// Enable feature only when every requirement is met.
bool4 ready = bool4(sceneLoaded, shadowsReady, assetsStreamed, frameStable);
float factor = all(ready) ? 1.0 : 0.0;

Masked Write

bwsl
// Write to output only if every channel of a validity mask passes.
bool3 valid = bool3(color.r >= 0.0, color.g >= 0.0, color.b >= 0.0);
if (all(valid)) {
output.color = float4(color, 1.0);
}

Short-Circuit Semantics

all evaluates the whole vector — there is no short-circuit. Build up the bvecN from the conditions you want to test, then call all once.

Complement of any

all(x) is equivalent to !any(!x) (De Morgan's law). Pick the form that reads most naturally for the thing you're testing.

Compiled Output

When compiled to GLSL:

glsl
all(bvec3(a, b, c))

When compiled to HLSL:

hlsl
all(x)

When compiled to Metal:

msl
all(x)

When compiled to SPIR-V:

Uses the OpAll instruction directly.

See Also

  • any - True if at least one component is true
  • select - Branchless conditional selection
  • wave_all - True if every lane in the wave is true