1
$\begingroup$

I have a rgba16f texture that I fill with values using nvidia GL_NV_shader_atomic_fp16_vector extension, which allows to perform imageAtomicAdd on half float RGBA images, with multiple shader threads using same index. However, it doesn't support rgba32f.

Can I use imageLoad/imageStore to perform same thing with such image buffer as written below?

vec4 prevVal = imageLoad(tex, index);
prevVal += currVal;
imageStore(tex, index, prevVal);

I'm not sure how correctly set the coherency of such operations with correct barriers usage because I have not found any example. Or if it is even possible.

$\endgroup$
2
  • $\begingroup$ I would not expect that to work reliably if different threads are going to be touching the same pixels; that’s why an atomic add is a distinct operation, because it provides that guarantee. It should be fine (albeit probably slow) if you can ensure that each pixel is only touched by one thread in a given dispatch. $\endgroup$ Commented Nov 13, 2020 at 20:56
  • $\begingroup$ Yes, setting local sizes as 1 is an option because its still quite fast. It gets the performance drop abouth 6 times though. $\endgroup$
    – mdkdy
    Commented Nov 13, 2020 at 21:07

2 Answers 2

2
$\begingroup$

If you could use imageLoad/Store to do atomic operations, there would be no need for atomic operations as a distinct class of operations. So no, you can't. There is no correct set of barriers or other properties that will allow this to work generally the way atomic operations do.

$\endgroup$
1
  • $\begingroup$ In my shader x are destination texels and y are different directions of samples. I changed local_size_y to 1 so threads don't overlap for each texel and each workgroup works on single y row, but the behaviour is still incorrect. $\endgroup$
    – mdkdy
    Commented Nov 15, 2020 at 9:26
0
$\begingroup$

Instead of using compute shader with atomic operations, I used instanced draw call with additive blending. In compute shader I had X as destination texels and Y as different sample directions for each texel. Now in instanced screen quad draw each instance is sample direction added to output texture.

$\endgroup$
1
  • 1
    $\begingroup$ Can you provide a little bit more information about what you did? I think that your current answer is not of much use to somebody who has the same or a related question. $\endgroup$
    – wychmaster
    Commented Nov 19, 2020 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.