Is ping ponging necessary in this case?

I am using the fragment shader for a GPGPU algorithm. The algorithm requires the fragment shaders to read fragment output from previous steps, therefore I use the ping pong approach (two framebuffers where one is read and the other is written, and the two are swapped after each iteration).

As an experiment, I made the algorithm use the same buffer for reading and writing. The algorithm still works! Is this to be expected? Isn’t it wrong to read from a texture and write to it at the same time? Does this work only because my hardware/GL implementation allows it (GTX 275)?

Note that each fragment shader instance is embarrassingly parellel: it only reads and writes one fragment, and leaves its neighbors alone.

Thanks!

Is this to be expected?

No.

Isn’t it wrong to read from a texture and write to it at the same time?

Yes. The spec is very clear about this.

Does this work only because my hardware/GL implementation allows it (GTX 275)?

For all we know, it works because the moon was in a certain phase. You should not rely on this to work even so much as next week, let alone on different hardware.

There is an extension to avoid the ping ponging for your case on your hardware: GL_NV_texture_barrier and for GeForce4xx cards: GL_EXT_shader_image_load_store.

Are you doing a glSwapBuffers() or glFinish or glFlush between each iteration? If you are that is probably why it works for you. Likely if you ran it on an ATI part, the ATI part will (correctly) give some FBO errors, NVIDIA’s texture barrier extension removes some of the possible error conditions (to exactly allow to use a texture while rendering to it).