OpenGL Vertical Rescan Time Search

My application performs fast rendering (usually 1-6 ms per frame), with double buffering and synchronization with vblank enabled. In my mainloop, I want to sleep for about 10 milliseconds, then read the data in real time and render as long as possible while keeping the frame updated to the deadline (for continuous 60 FPS rendering with minimal delay).

I can use glFinish after replacing the buffers, but unfortunately on some systems (at least Linux is not configured), it seems to wait not only until the next buffer exchange, but until the image is sent via the HDMI port (general waiting in 25 ms range and application running at 30 FPS). On other systems (compiled by Linux) this approach works just fine. Without glFinish, more work is buffered, causing a longer delay, so this is not good either.

What options do I have for more accurate frame synchronization? The main platforms are Windows, Linux, and OS X.

+4
source share
1 answer

I want to sleep for about 10 milliseconds, and then read some data in real time and render as long as possible, while keeping the frame updated to the deadline (for continuous 60-FPS rendering with minimal delay).

This is a very unreliable approach. I suggest you put all the rendering operations in your own stream, which will block the swap buffer until the exchange occurs. Perform all input processing in a separate thread, where all input is accumulated. Before performing a swap, you must raise a mutex or semaphore in the processing stream, which does this during the buffer change period.

Keep in mind that you should not delay rendering when using V-Sync very close, because this can lead to its miss. Instead, you should take about 75% at the beginning of the vertical time interval that you received for rendering your material, while the remaining 25% should be stored as a spare part. In addition, if you use the linker, this will also require a bit of GPU time.

There is no difference in visual result if you do it sooner or later. If your simulation time is bothering you: just assume that you are actually making a deadline and visualizing the simulation for the state it will have during V-Sync. Use the Kalman filter on any data input for modeling, so that the rendering is based on forecasts and "just" adjusts the new input.

I can use glFinish after replacing the buffers, but unfortunately on some systems (at least Linux is not configured), it seems to wait not only until the next buffer exchange, but until the image is sent via the HDMI port (general waiting in 25 ms range and application running at 30 FPS).

This will happen if your time skips V-Sync: SwapBuffers will wait for a full period of vertical return. Some timeout parameter should be added to IMHO SwapBuffers, but so far it hasn’t.

+2
source

Source: https://habr.com/ru/post/1403375/


All Articles