Image atomic addition in a compute shader


I have the following compute shader:

#version 430

layout(std430, binding=0) buffer wks{
    ivec2 w[];

layout(r32i, binding=1) uniform writeonly iimage2D pathTex;

layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;

void main(){
    imageAtomicAdd(pathTex, w[0], 1); // line 12

That gives me this error:

0(12) : error C1317: qualified actual parameter #1 cannot be converted to less qualified parameter ("im")

I can’t find what I’m doing wrong according to the OpenGL wiki

What happens if you replace the texture coordinate with a constant value (like [var]ivec2(0, 0)[/var])?

I got an answer:

According to the GLSL 4.50 spec, imageAtomicAdd() requires a image variable with the coherent memory qualifier.

This makes sense because an atomic add needs to read the old value, add a value to it, and write back the result. Therefore, it needs to be able to both read and write the image.

To make this work, you need to change the declaration to:

layout(r32i, binding=1) uniform coherent iimage2D pathTex;

As the name indicates, writeonly will only work for image operations that exclusively write to the image, like imageStore().

Thanks for your time anyway!

Friends i see your question here. But i do not understand last answer that you say “You Got Answer”. But i am not understand how can you calculate it ?

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.