OpenGL, when can I start issuing commands again

Standards refer to rendering, starting with my first gl command and continuing along with further commands. Some functions, such as glBufferSubData , indicate that loading may occur during rendering while the object is not currently in use. This introduces the logical concept of a β€œframe”, although it is never mentioned in the standard.

So my question is what defines this logical frame? That is, which causes the demarcation of the game, so that I can start calling gl again without interfering with the previous frame?

For example, using EGL, you end up calling eglSwapBuffers (most implementations have some kind of swap command). Logically, this is the boundary between one frame and the next. However, this causes the blocks to support v-sync, that is, you cannot issue new commands until they return. However, the documentation implies that you can start issuing new commands before returning to another stream (provided that you do not touch the buffers used).

How can I start issuing commands to the next buffer even when the swap command is still blocking the previous buffer? I would like to start streaming data for the next frame, while the GPU is working on the old frame (in particular, I will have two vertex buffers that will be replaced with each frame specifically for this purpose and mentioned in the OpenGL documentation).

+4
source share
1 answer

OpenGL does not have the concept of a "frame", logical or otherwise.

OpenGL is actually very simple: each command is executed as if all previous commands were executed before the start.

Pay attention to the key phrase "as if". Let's say you render from a buffer object, and then immediately modify its data. Like this:

 glBindVertexArray(someVaoThatUsesBufferX); glDrawArrays(...); glBindBuffer(GL_ARRAY_BUFFER, BufferX); glBufferSubData(GL_ARRAY_BUFFER, ...); 

This is 100% eligible to participate in OpenGL. There are no reservations, questions, problems, etc. About how it will function. This call to glBufferSubData will execute as if the glDrawArrays command glDrawArrays completed.

The only thing you need to consider is that the specification does not indicate: performance.

Realization within your rights allows you to detect that you are modifying a buffer that can be used, and therefore stop the CPU in glBufferSubData until the rendering from this buffer is complete. An implementation of OpenGL requires either this or another, which prevents the actual source buffer from being modified during its use.

Thus, OpenGL implementations execute commands asynchronously, wherever possible, in accordance with the specification. While the outside world cannot say that glDrawArrays has not finished drawing, the implementation can do whatever it wants. If you select glReadPixels immediately after the draw command, the pipeline should stop. You can do this, but there is no guarantee of effectiveness.

This is why OpenGL is defined as a closed box as it is. This gives implementations a lot of freedom to be asynchronous where possible. Each access to OpenGL data requires a call to the OpenGL function, which allows you to check whether this data is really available. If not, he stops.

Getting rid of stalls is one of the reasons why the invalidity of the object-object is possible; it effectively tells OpenGL that you want to overpower the buffer data store. This is the reason why buffer objects can be used to transmit pixels ; It allows you to transmit asynchronously. This is the reason why fence synchronization objects exist, so you can determine if the resource is being used (possibly to display the GL_UNSYNCHRONIZED_BIT buffer). Etc.

However, this calls up blocks to support v-sync, meaning you cannot issue new commands until you return.

Who says? The buffer replacement command may stop. This is not true. This is determined by the implementation and can be modified with specific commands . The documentation for eglSwapBuffers only says that it runs a flash, which can lead to a processor stop, but not necessarily.

+12
source

All Articles