问题
I've written to the first mipmap level of a texture using GL_ARB_shader_image_load_store. The documentation states that I need to call glMemoryBarrier before I use the contents of this image in other operations, in order to flush the caches appropriately.
For instance, before I do a glTexSubImage2D operation, I need to issue GL_TEXTURE_UPDATE_BARRIER_BIT, and before I issue a draw call using a shader that samples that texture, I need to issue GL_TEXTURE_FETCH_BARRIER_BIT.
However, which barrier do I need to issue before I am ensured that glGenerateMipmap will use the most recently written data?
回答1:
The OpenGL 4.6 specification clarifies this:
Any synchronization required before performing this reduction will be done within the
Generate*Mipmap
commands themselves.
So you don't need any kind of synchronization. If you have caused data to be written to the base mipmap level in any way, glGenerateMipmap
will perform sufficient synchronization to make reads work.
Given that, it's probably a really good idea not to call this in the middle of rendering a frame.
Prior specifications had no answer, though information from this bug report suggests that prior implementations did exactly the above.
来源:https://stackoverflow.com/questions/24693861/which-memory-barrier-does-glgeneratemipmap-require