atomicFunc
An internal, generic factory function used to create all specific atomic operation nodes based on a specified `method` parameter (e.g., ADD, AND, MIN). It is primarily used within the TSL library for code reuse and consistency.
Core Advantages
Its core advantage is its abstraction as a universal factory. It centralizes the creation logic for all atomic operations, differentiating specific behaviors (like addition, bitwise AND, or finding the minimum) via a `method` parameter, which greatly enhances code reusability, extensibility, and consistency within the TSL library.
Common Uses
As the internal factory for `atomicAdd`, enabling accumulation tasks like particle density counting
As the internal factory for `atomicAnd` or `atomicOr`, enabling state bitmasking in multi-pass rendering
As the internal factory for `atomicMin` or `atomicMax`, enabling the safe finding of a global minimum or maximum value across parallel threads
As the universal implementation basis for all other atomic operations (`atomicXor`, etc.)
How to adjust
Adjusting `atomicFunc`'s effect means changing its `method` parameter, which fundamentally alters its mathematical behavior. For instance, with the same pointer and value (e.g., initial value 7, operation value 6), using `ATOMIC_ADD` yields 13 (7+6), while `ATOMIC_AND` yields 6 (binary 0111 & 0110), and `ATOMIC_MIN` yields 6 (min(7,6)). This demonstrates how just flipping the method switch can execute completely different operations, from arithmetic to logic to comparison.
Code Examples
1// Internal call example:
2// User calls atomicAdd(ptr, val) -> TSL internally implements:
3atomicFunc( AtomicFunctionNode.ATOMIC_ADD, ptr, val );
4
5// User calls atomicMin(ptr, val) -> TSL internally implements:
6atomicFunc( AtomicFunctionNode.ATOMIC_MIN, ptr, val );