ATOMICADD(3G)
πΈ NAME πΈ
atomicAdd β bestie, it does an atomic addition to a variable π
β¨ DECLARATION β¨
okay so here's the exact shape of it, no cap:
int atomicAdd(inout int mem, int data);
uint atomicAdd(inout uint mem, uint data);
two flavors, both iconic π
π PARAMETERS π
memβ the variable that's the target of the operation. it's the one getting the glow-up πdataβ the data getting added tomem. it's the little gift π
π DESCRIPTION π
so atomicAdd does an atomic addition of data to whatever's inside mem, and then β plot twist β it returns the original contents of mem from before the addition occurred. like, the you-before-the-makeover version. the before pic. πΈ
and the reason this slaps is the guarantee: the contents of the memory being updated by the atomic operation are guaranteed not to be modified by any other assignment or atomic memory function in any shader invocation between the time the original value is read and the time the new value is written. fr fr. nobody's cutting in on your dance, it's your moment, periodt. π«Ά
lowkey important though: atomic memory functions are supported only for a limited set of variables. a shader will fail to compile if the value you pass to the mem argument of an atomic memory function doesn't correspond to a buffer or shared variable. π so like, don't do that.
but bestie, it is acceptable to pass an element of an array or a single component of a vector to the mem argument of an atomic memory function β as long as the underlying array or vector is a buffer or shared variable. slay. that's totally fine. go off. β¨
π VERSION SUPPORT π
the vibe check across OpenGL Shading Language Versions β atomicAdd was not invited to the early parties π:
1.10β-(nope)1.20β-(still nope)1.30β-(nope)1.40β-(nope)1.50β-(nope)3.30β-(nope)4.00β-(nope)4.10β-(nope)4.20β-(nope)4.30ββ(FINALLY, main character energy π₯)4.40ββ(here for it)4.50ββ(ate, no crumbs)
π¦ SEE ALSO π¦
the rest of the atomic friend group, they're all in the group chat together:
atomicAnd()atomicOr()atomicXor()atomicMin()atomicMax()atomicExchange()atomicCompSwap()
π COPYRIGHT π
Copyright Β© 2011-2014 Khronos Group. This material may be distributed subject to the terms and conditions set forth in the Open Publication License, v 1.0, 8 June 1999. http://opencontent.org/openpub/ π«‘
π COPYRIGHT π (yes, again π)
Copyright Β© 2012-2014 Khronos Group
and that's the whole page bestie!! πβ¨ this came from the source marked [FIXME: source], dated 01/03/2018, and it lives in section ATOMICADD(3G) β mwah, ily, go write some shaders πππ¦
π¦ where this page comes from
- ubuntu jammy: opengl-4-man-doc 1.0~svn33624-1 Β· SGI-Free-Software-B-License-2
- ubuntu noble: opengl-4-man-doc 1.0~svn33624-1 Β· SGI-Free-Software-B-License-2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms