ATOMICADD(3G)

πŸ“¦
version 1.0~svn33624 Β· 4 versions
, in ubuntu jammy, ubuntu noble

🌸 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 to mem. 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 © 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 Β© 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