ATOMICEXCHANGE(3G)

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

πŸ‘‘ ATOMICEXCHANGE(3G) β€” bestie's guide to the glow-up swap πŸ’…

okay so welcome to ATOMICEXCHANGE(3G) ✨ section 3G of the manual, and yes she's a real one. this is the function that swaps your value in atomically, which is a fancy way of saying "nobody else can cut in while I'm doing this, periodt."


🌸 NAME

atomicExchange β€” perform an atomic exchange operation to a variable


πŸŽ€ DECLARATION

so here's the tea, there are two signatures and you gotta pick the one that matches your type:

int atomicExchange(inout int mem, int data);

uint atomicExchange(inout uint mem, uint data);

πŸ¦‹ PARAMETERS

  • mem β€” the variable you're targeting with this whole operation. she's the main character here, the one getting her value swapped out.
  • data β€” the data that's getting exchanged with mem. this is what's sliding into mem's spot.

πŸ’– DESCRIPTION

atomicExchange performs an atomic exhange of data with the contents of mem. the way it works is: the content of data gets written into mem, and the original contents of mem get returned to you. it's giving "you get the new thing, I keep the old thing, everyone's happy."

and here's the iconic part β€” 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. no cap. that window is locked down. πŸ”’

⚠️ but listen bestie, atomic memory functions are only supported 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 don't just hand it anything, she's picky.

good news tho: 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. so like, a slice of a valid thing is still valid. 🫢


✨ VERSION SUPPORT

so this is the part where we check which OpenGL Shading Language Versions are serving. here's the breakdown for atomicExchange across the eras:

  • 1.10 β€” - (nope, not yet babe 😭)
  • 1.20 β€” - (still no πŸ™ˆ)
  • 1.30 β€” - (crickets πŸ’€)
  • 1.40 β€” - (not happening)
  • 1.50 β€” - (girl, no)
  • 3.30 β€” - (we wait πŸ’œ)
  • 4.00 β€” - (patience)
  • 4.10 β€” - (almost…)
  • 4.20 β€” - (so close)
  • 4.30 β€” βœ” (SHE'S HERE πŸŽ‰)
  • 4.40 β€” βœ” (still slaying)
  • 4.50 β€” βœ” (ate, and left no crumbs πŸ‘‘)

so like, atomicExchange really said "I don't do the early seasons," and honestly? respect.


🌈 SEE ALSO

go check out her whole friend group, they're all atomic and all iconic:

  • atomicAdd()
  • atomicAnd()
  • atomicOr()
  • atomicXor()
  • atomicMin()
  • atomicMax()
  • 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


okay that's the whole page bestie, ily, go swap some values atomically πŸ’–

this was brought to you by [FIXME: source] πŸ’« dated 01/03/2018 🌸 and yes she's still filed under ATOMICEXCHANGE(3G) β€” iykyk βœ¨πŸ’…

πŸ“¦ where this page comes from