We have an OpenGL solver. Given a list of many items, each has a coordinate and a float value. We run a compute shader of the size of those items that does the computation and adds the value to the existing values in the float image using the function imageAtomicAdd and the float extension. This way, the addition is guaranteed just in case 2 items happen to have the same coordinate value simultaneously.
Now, we need to move it to WebGPU using js. I tried looking for an atomic add function on float texture/buffer but with limited success. So, the code currently is like this
outputBuffer[coords] += floatValue; // TODO: fix!!
As expected, it works but without guarantees. Some pixels are flickering depending on which thread worked first.
So, how can I do it safely? either using a function like atomicAdd or something similar to CUDA's sync threads/barriers?