SSBO double buffering with compute shaders

I wrote a compute shader which reads from one ssbo and writes to another ssbo. I’m executing the same compute shader a few times using the ssbo as a double buffer.

between each execution I’m doing the following:

  • swapping between the read buffer and the write buffer with glBindBufferBase
  • synchronizing the reading/writing to the buffers using GL_BUFFER_UPDATE_BARRIER_BIT barrier.

Basically in my case, different executions bind the same buffer differently: some as readonly, some as writeonly. These executions can be running concurrently, however, there should be no collisions between actual reads and writes because I’m using the barrier, so each execution starts after the previously Dispatched execution finishes accessing the buffers.

My question is, should this work at all? Can I bind the same buffer as read and write on different executions that run in parallel?

I ran the application on few Nvidia cards; on some it works, while on others I get garbage while reading the buffers.

In addition, I changed the code to work with one readwrite ssbo instead of two buffers and that seems to be working.