glMemoryBarrier - When to use?


I’m currently reading Part 6 of the Superbible and struggle a bit with glMemoryBarrier.
While i do understand what a Memorybarrier is, i’m not totally sure when i need to use it.

So glMemoryBarrier is introduced in the Chapter about Storage Buffer Blocks and Atomic Counters. It’s quite clear that Barriers are necessary together with these writeable buffers, so that later shaders indeed see the results for sure.

But what about other cases without Storage Buffers or Atomic Counters?
Here are two examples:

  1. Transform Feedback. I’ve lately written a shader for skinning of models to speed things up. It works perfectely fine. The update-shader performs all the necessary calculations to animate the model and writes the values with transform feedback back into a buffer. Then this buffer is used as a vertex buffer to actually render the model.
    Do i need to call glMemoryBarrier (with MemoryBarrierFlags.VertexAttribArrayBarrierBit because the buffer will then be used as a vertex attribute) between both the update- and rendershader?

  2. Rendering to texture. There are several ways for rendering to a texture. Let’s say with a FBO and in the next renderpass this texture is glued on some geometry. Again, do i need to set a Barrier (with MemoryBarrierFlags.TextureFetchBarrierBit i guess) in this case?

(Consider: Both examples do not use Storage Buffers or Atomic Counters. But the book doesn’t say anything about other cases so far)

Some time ago I actually asked myself, before even knowing anything about GLs memorybarriers, if the necessary data are really available in cases like the both examples. Now, i’m even more puzzled.


The OpenGL wiki page on the OpenGL memory model covers when you have to use glMemoryBarrier. It’s only when you’re using operations that perform incoherent memory writes. In all other cases, OpenGL will take care of the details for you.

There are several ways for rendering to a texture.

No, there are not. There are several ways to write to a texture. But there is only one way to “render” to it. Rendering being the process of converting vertex data into primitives, which are rasterized and processed to produce fragments that are written to a framebuffer. That process being issuing a drawing command while using a Framebuffer Object to which images from a texture have been attached.

Thank you.

Btw. is it common in this Forum to write just a short “Thank you” answer or should I avoid it to not bump the thread again?