Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between glTextureBarrier() and glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT)

glMemoryBarrier is available in GL 4.2 and higher while glTextureBarrier is available in GL 4.5

glTextureBarrier allows to simultaneously render into the same texture while the fragment shader is fetching from it, IFF every texel of the texture is hit by the texturefetches exactly once.

I wonder whether glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT) allows this too? If not, is there an OpenGL ES equivalent to glTextureBarrier?

like image 943
matthias_buehlmann Avatar asked May 25 '16 22:05

matthias_buehlmann


1 Answers

glTextureBarrier allows to simultaneously render into the same texture while the fragment shader is fetching from it, IFF every texel of the texture is hit by the texturefetches exactly once.

No, it doesn't.

glTextureBarrier is a function. ARB_texture_barrier is an extension (and part of GL 4.5). As part of the changes to the specification, the ARB_texture_barrier extension permits a single read/modify/write over an attached image.

Now, calling glTextureBarrier will permit you a second read/modify/write pass. And you can call it again to get another pass. But glTextureBarrier itself is not what gives you read/modify/write privileges. It's the extension as a whole.

Also, note that these two functions have nothing in common.

glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT) only applies to writes by incoherent memory operations (SSBOs/image load/store). That particular barrier bit means that incoherent writes issued before this function will become visible to texture sample operations issued after this function.

glTextureBarrier applies specifically to writes to framebuffer attached images and subsequent reads from them in the shader. Framebuffer writes are not incoherent memory operations, and thus they are not governed by the glMemoryBarrier call.

If not, is there an OpenGL ES equivalent to glTextureBarrier?

Not as of yet. And considering the kind of hardware that tends to implement ES, it's unlikely to ever get there. While the general idea has merit for tile-based renderers, it's just the wrong abstraction for them.

Vulkan's input attachments and pipeline barriers are a much better fit for doing this sort of thing in a TBR.

like image 143
Nicol Bolas Avatar answered Oct 03 '22 20:10

Nicol Bolas