ATOMICEXCHANGE(3G)
π 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 withmem. this is what's sliding intomem'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
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
- 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