atomicOr
Performs a thread-safe bitwise OR operation on a shared integer in memory (usually a Storage Buffer), primarily used to safely set or merge one or more status flags in parallel computations.
Core Advantages
Provides a hardware-guaranteed, thread-safe method for setting flags. It allows hundreds of threads to contribute their information (as bits) to a shared state in an additive-only manner, ensuring all information is completely merged.
Common Uses
Safely marking 'visited' nodes in parallel graph algorithms.
Aggregating multiple properties for a voxel in multi-attribute voxelization (e.g., marking as both 'water' and 'fire').
Creating custom stencil or material ID masks to record all material types rendered to a pixel.
How to adjust
Its effect is controlled by the `valueNode` (bitmask) parameter, which defines the flags to 'light up' or set. For example, in a voxel painting app, using `COLOR_RED` (0x1) as the mask adds red. If applied to a voxel already containing `COLOR_BLUE` (0x4), the result becomes `0x5` (purple), achieving a non-destructive merge of colors. Changing the `valueNode` is like switching to a different 'paint color' or 'setName'.
Code Examples
1// Define bitmasks for different attributes
2const MASK_WATER = 0x1u;
3const MASK_FIRE = 0x2u;
4
5// Atomically add the 'water' attribute to a voxel
6atomicOr( voxelState.element( voxelIndex ), MASK_WATER );