2

I have an application where I use texture buffers bound using glBindImageTexture, and my GLSL code does various things and updates the buffers.

Recently I changed some of my image buffer formats from GL_R32UI to GL_RGBA32UI. So basically, one texel was 1 unsigned int before, and now it is 4 unsigned ints. Everything works fine when doing imageStores, imageLoads, and client-side things.

I get a few problems currently when using imageAtomic* functions. Let's take imageAtomicAdd. The last parameter always is integer-sized, regardless of the buffer format. Eg. it's not a uvec4, and remains a single uint. When I call imageAtomicAdd(some_uimageBuffer, some_address, 1u), what is supposed to happen exactly? Will GLSL increment all 4 texel components (x,y,z and w), or just one? Which one?

Thanks for your insight!

Martin Frank
  • 199
  • 1
  • 13

1 Answers1

2

Will GLSL increment all 4 texel components (x,y,z and w), or just one? Which one?

Neither; it is simply not permitted. From the specification:

Atomic memory operations are supported on only a subset of all image variable types; image must be either:

  • a signed integer image variable (type starts “iimage”) and a format qualifier of r32i, used with a data argument of type int, or
  • an unsigned image variable (type starts “uimage”) and a format qualifier of r32ui, used with a data argument of type uint.
Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • Thank you! No wonder my code is completely bogus. SSBO seem to be the way to go if I want to access things on a vec4 basis as well as atomically alter vec4 individual components. Will check this out. – Martin Frank May 11 '16 at 08:07
  • @MartinFrank: You should actually [read the GLSL specification](https://www.opengl.org/registry/) before making such statements. Because the SSBO atomic operations don't act on vectors *either*. You *cannot* do SIMD atomic operations. – Nicol Bolas May 11 '16 at 13:50
  • They can act on _individual_ vector components if I trust this OpenGL web site page : [link](https://www.opengl.org/wiki/Shader_Storage_Buffer_Object). Section "Atomic Operations": Quote: "_These only operate on uint​ or int​ types, but these can be members of aggregates (structs/arrays) **or vector elements (ie: you can atomically access uvec3.x**​)_". Are you saying this web page is incorrect? – Martin Frank May 11 '16 at 16:13
  • @MartinFrank: No, I'm saying you can't do `atomicAdd(someVec, someOtherVec)`. Doing 4 atomic operations is very different from doing a single atomic operation on 4 values. The latter is what is not possible. – Nicol Bolas May 11 '16 at 16:31
  • Ok. We are on the same line. Thanks again for your help. – Martin Frank May 11 '16 at 16:34