Intrinsics1 min read

atomic_or

Atomically performs a bitwise OR operation.

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

Test atomic_or in a live shader

Open the playground, start from a visual preset, and wire atomic_or 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 atomic_or function atomically performs a bitwise OR between the current value and the input, storing the result. Returns the original value.

Signature

bwsl
atomic_or(dest, value)

Parameters

ParameterDescription
destInteger lvalue to modify atomically
valueInteger value to OR with

Return Value

Returns the original value at dest before the operation.

Example

bwsl
pipeline VisibilityMask {
pass "ComputePass" {
compute "Main" [1, 1, 1] {
// Each thread sets its bit if object is visible
if (isVisible(objectId)) {
int bitMask = 1 << (objectId % 32);
int wordIndex = objectId / 32;
atomic_or(visibilityBuffer[wordIndex], bitMask);
}
}
}
}

Common Use Cases

Set Flags

bwsl
// Set specific flag bit
int flagBit = 1 << flagIndex;
atomic_or(stateFlags, flagBit);

Visibility Bitmask

bwsl
// Mark object as visible
int objectBit = 1 << (objectId & 31);
atomic_or(visibilityMask[objectId >> 5], objectBit);

Feature Accumulation

bwsl
// Accumulate all features found
int featureMask = detectFeatures(position);
atomic_or(tileFeatures[tileId], featureMask);

Dirty Flags

bwsl
// Mark tile as needing update
int tileBit = 1 << tileIndex;
atomic_or(dirtyTiles, tileBit);

Collision Layers

bwsl
// Mark which collision layers are active
int layerMask = getCollisionLayer(objectId);
atomic_or(activeCollisionLayers, layerMask);

Set vs Clear

Use atomic_or to set bits. Use atomic_and with inverted mask to clear bits.

Initialization

When accumulating with OR, initialize to 0 so only bits explicitly set appear in the result.

Compiled Output

When compiled to GLSL:

glsl
atomicOr(dest, value)

When compiled to HLSL:

hlsl
InterlockedOr(dest, value, originalValue)

When compiled to SPIR-V:

Uses OpAtomicOr instruction.

See Also