IMAGEATOMICCOMPSWAP(3G)
π IMAGEATOMICCOMPSWAP π
okay bestie, welcome to IMAGEATOMICCOMPSWAP(3G) β the manual page, but make it fashion. this is the GLSL glow-up you didn't know you needed. sit down, hydrate, let's go π«Ά
β¨ NAME β¨
imageAtomicCompSwap β atomically compares supplied data with that in memory and conditionally stores it to memory
like... it peeks at what's in memory, checks if it matches, and only then decides whether to write. commitment issues? no. it's just careful. π
π DECLARATION π
here's the full roster, no skips, no cuts. every single one of these is iconic in its own way:
uint imageAtomicCompSwap(gimage1D image, int P, uint compare,
uint data);
uint imageAtomicCompSwap(gimage2D image, ivec2 P, uint compare,
uint data);
uint imageAtomicCompSwap(gimage3D image, ivec3 P, uint compare,
uint data);
uint imageAtomicCompSwap(gimage2DRect image, ivec2 P, uint compare,
uint data);
uint imageAtomicCompSwap(gimageCube image, ivec3 P, uint compare,
uint data);
uint imageAtomicCompSwap(gbufferImage image, int P, uint compare,
uint data);
uint imageAtomicCompSwap(gimage1DArray image, ivec2 P, uint compare,
uint data);
uint imageAtomicCompSwap(gimage2DArray image, ivec3 P, uint compare,
uint data);
uint imageAtomicCompSwap(gimageCubeArray image, ivec3 P, uint compare,
uint data);
uint imageAtomicCompSwap(gimage2DMS image, ivec2 P, int sample,
uint compare, uint data);
uint imageAtomicCompSwap(gimage2DMSArray image, ivec3 P, int sample,
uint compare, uint data);
int imageAtomicCompSwap(gimage1D image, int P, int compare, int data);
int imageAtomicCompSwap(gimage2D image, ivec2 P, int compare, int data);
int imageAtomicCompSwap(gimage3D image, ivec3 P, int compare, int data);
int imageAtomicCompSwap(gimage2DRect image, ivec2 P, int compare,
int data);
int imageAtomicCompSwap(gimageCube image, ivec3 P, int compare,
int data);
int imageAtomicCompSwap(gbufferImage image, int P, int compare,
int data);
int imageAtomicCompSwap(gimage1DArray image, ivec2 P, int compare,
int data);
int imageAtomicCompSwap(gimage2DArray image, ivec3 P, int compare,
int data);
int imageAtomicCompSwap(gimageCubeArray image, ivec3 P, int compare,
int data);
int imageAtomicCompSwap(gimage2DMS image, ivec2 P, int sample,
int compare, int data);
int imageAtomicCompSwap(gimage2DMSArray image, ivec3 P, int sample,
int compare, int data);
twenty-two overloads. twenty-two. the range of image types is giving "collect them all" energy and honestly? we love the consistency. π
πΈ PARAMETERS πΈ
imageβ the image unit you're comparing into and conditionally storing data into. this is your main character. πPβ the coordinate where the comparing and the conditional storing happens. tell it where, bestie. πsampleβ when it's present, it names the sample within the image that you're comparing and conditionally storing into. only the multisampled ones get to have this. πcompareβ the value you're checking against whatever's already sitting in the image. the vibe check value. π§dataβ the value that gets stored into the image ifcompareis equal to the existing image content. otherwise it just... doesn't. π
π DESCRIPTION π
so here's the tea. imageAtomicCompSwap atomically compares the value of compare with that of the texel at coordinate P and sample (for the multisampled forms, obviously β they're the special ones) in the image bound to uint image.
if the values are equal β data gets stored into the texel. slay. β¨
if they're not equal β data is discarded. no cap, it just evaporates. gone. bye. π¦
and here's the part everyone forgets: it returns the original value of the texel regardless of the result of the comparison operation. so even when the swap doesn't happen, you still walk away knowing what was there before. it's giving generous. it's giving transparent communication. π
π VERSION SUPPORT π
here's the timeline of when imageAtomicCompSwap said "hi, i exist now" β and spoiler, it took a minute. literally every version before 4.20 is a -, and then it's straight ββββ to the end. late bloomer behavior, honestly iconic.
- OpenGL Shading Language 1.10 β
- - OpenGL Shading Language 1.20 β
- - OpenGL Shading Language 1.30 β
- - OpenGL Shading Language 1.40 β
- - OpenGL Shading Language 1.50 β
- - OpenGL Shading Language 3.30 β
- - OpenGL Shading Language 4.00 β
- - OpenGL Shading Language 4.10 β
- - OpenGL Shading Language 4.20 β β
- OpenGL Shading Language 4.30 β β
- OpenGL Shading Language 4.40 β β
- OpenGL Shading Language 4.50 β β
so if you're on anything below 4.20, this function is not available to you. sorry babe, that's just the lore. π
π¦ SEE ALSO π¦
go read these next, they're all in the same friend group:
imageLoad()imageStore()imageAtomicAdd()imageAtomicMin()imageAtomicMax()imageAtomicXor()imageAtomicOr()imageAtomicAnd()imageAtomicCompSwap()
(yes, it links to itself. self-love is important. π)
β 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 Β© 2011-2014 Khronos Group
okay that's the whole page, you ate it, you read it, you understood it. no notes. π
source situation: [FIXME: source], and this whole thing is dated 01/03/2018. shoutout to whoever wrote it, you're a legend, mwah. πβ¨
π¦ 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