I have read the OpenGL wiki on Implicit Synchronization: Synchronization - OpenGL Wiki, but I don’t quite comprehend it, so I post this thread here to double check my understanding.
What I want to know is when implicit synchronization takes effects when I use coherent persistent mapping for buffer update. Suppose the OpenGL (seudo-)code is as follows
glBufferStorage(GL_ARRAY_BUFFER, bufferSize, 0, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT);
pBufferData = glMapBufferRange(GL_ARRAY_BUFFER, 0, bufferSize, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT);
for(;;) {
//Generate new data and save them into pBufferData on CPU side
pBufferData[i++]=....;
glDrawArrays(GL_TRIANGLES, 0, triangleCount * 3);
}
According to the wiki, “Most attempts to write to a buffer object, either with glBufferSubData or mapping, will halt until all rendering commands using that part of the buffer object have completed.” Here I am using mapping to write buffer object, so the implicit synchronization should take effects so that I don’t need to worry about racing, right? That is, the assignment statement pBufferData[i++]=…; should halt. But so far as I know, the subject of implicit synchronization should be an OpenGL operation, i.e., an OpenGL API. Will simply assigning values to the mapped pointer cause implicit synchronization? I think not, for, how could OpenGL know that? If not, what does the above quoted sentence in the wiki mean? How does persistent mapping cause implicit synchronization? Furthermore, the wiki also says “If you use the GL_MAP_UNSYNCHRONIZED_BIT flag with glMapBufferRange, OpenGL will forgo any synchronization operations;” That means if I do not use GL_MAP_UNSYNCHRONIZED_BIT in glMapBufferRange, as I did in the above code, implicit synchronization should be in effect, right? So whether on earth does implicit synchronization take effects in the above code? Thank you.