atomicAnd
Performs a thread-safe bitwise AND operation on a shared integer in memory (usually a Storage Buffer), primarily used to safely clear one or more status flags in a bitmask during parallel computation.
Core Advantages
Provides a hardware-guaranteed, thread-safe bitwise AND operation, enabling fine-grained state management with bitmasks in highly parallel environments and completely avoiding logic errors caused by race conditions.
Common Uses
Collaboratively clearing specific flags in a shared status word, such as a lighting flag in voxelization.
Safely releasing resources in a parallel resource pool by clearing bits in a status mask.
Acting as a parallel logic gate to check if multiple sub-conditions are met simultaneously.
How to adjust
Its effect is entirely controlled by the `valueNode` (mask) parameter and requires a subsequent rendering pass for visualization. For example, in a system where bits represent color layers, using a mask of `~0x1u` will precisely erase the 'red' layer without affecting others. Changing the mask to `~0x4u` would erase the 'blue' layer instead. Providing a mask of `0u` will clear all bits, thus erasing all layers.
Code Examples
1// Create a mask where only the 'red' bit is zero
2const MASK_NOT_RED = ~0x1u;
3// Atomically apply the mask to clear the red flag
4atomicAnd( pixelState.element( pixelIndex ), MASK_NOT_RED );