<p>If you could use <code>imageLoad/Store</code> 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.</p>

CC BY-SA 4.0
2020-11-15T09:26:45.750Z
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.
mdkdy
CC BY-SA 4.0
2020-11-13T22:24:25.237Z
2020-11-13T22:24:25.237Z
Nicol Bolas
<p>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.</p>

CC BY-SA 4.0
2020-11-19T12:33:57.007Z
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.
wychmaster
CC BY-SA 4.0
2020-11-17T21:13:36.903Z
2020-11-19T17:07:35.663Z
2020-11-19T17:07:35.663Z
mdkdy
<p>I have a <code>rgba16f</code> texture that I fill with values using nvidia <code>GL_NV_shader_atomic_fp16_vector</code> extension, which allows to perform <code>imageAtomicAdd</code> on half float RGBA images, with multiple shader threads using same <code>index</code>. However, it doesn't support <code>rgba32f</code>.</p>
<p>Can I use <code>imageLoad</code>/<code>imageStore</code> to perform same thing with such image buffer as written below?</p>
<pre><code>vec4 prevVal = imageLoad(tex, index);
prevVal += currVal;
imageStore(tex, index, prevVal);
</code></pre>
<p>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.</p>

CC BY-SA 4.0
2020-11-13T20:56:32.453Z
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.
Noah Witherspoon
CC BY-SA 4.0
2020-11-13T21:07:21.913Z
Yes, setting local sizes as 1 is an option because its still quite fast. It gets the performance drop abouth 6 times though.
mdkdy
<opengl><glsl><compute-shader><image-load-store>
Using imageLoad/imageStore to perform atomic add
mdkdy
# Using imageLoad/imageStore to perform atomic add

(Asked by: username_0 on 2020-11-13)

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.

**Tags:** opengl, glsl, compute-shader, image-load-store

> **Comments:**
> **username_1**: 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.  
> **username_0**: Yes, setting local sizes as 1 is an option because its still quite fast. It gets the performance drop abouth 6 times though.  

---

## 2 answers

### Answer by username_2 on 2020-11-13. Score: 2 | Accepted answer

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.

> **Comments:**
> **username_0**: 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.  

---

### Answer by username_0 on 2020-11-17. Score: 0

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.

> **Comments:**
> **username_3**: 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.  

---

