PDA

View Full Version : Ensure swapbuffer at every vsync?



neoxu
03-18-2012, 06:44 PM
I am using openGL to playback an image sequence on a 60fps monitor. All images are preloaded in memory. Vsync enabled. Double buffering. Windows 7-64bit.

The problem I have is as most times the swapbuffer are called every 16.7ms, once a while I have a delay, i.e., the time between two swapbuffers increased to 33.3ms, or even longer, so I have a dropped frame rate and thus a glitch in playback.

The rendering part takes much less than 16ms to finish, so my guess is that some background process takes some time and blocked the swapbuffers. Anyone knows how to ensure calling swapbuffers at every vsync?

Aleksandar
03-19-2012, 09:50 AM
First ensure that your drawing code takes less than 16ms. I could bet it takes longer from time to time causing the problem. Try to measure execution time on both CPU and GPU.

kyle_
03-19-2012, 10:59 AM
Also, have a look at WGL_EXT_swap_control_tear.

neoxu
03-19-2012, 08:36 PM
Yes, I did measured the drawing time and they are much less than 16ms, even for the same drawing when the those unexpected swapbuffers delay happens.

On average, if I disable the vsync, the frame rate gets as high as 400fps.

I also tried to just draw a single square in each drawing and perceived the same swapbuffer delay.

ZbuffeR
03-20-2012, 12:33 AM
In a modern non-realtime OS it is hard to make guarantees time guarantees. I suppose you have disabled all services you don't need (indexation of disks, anti-virus, automatic wifi, etc) ?

If you disable vsync, do you still sometimes have such delays ?

If you can try WGL_EXT_swap_control_tear indeed it sounds like a good idea.

Or use glFinish() right before or right after the swap (or both). It will somewhat reduce the performance (less parallelism) but I observed that it makes it more even.

neoxu
03-20-2012, 09:51 AM
Those are great suggestions.

The background services are exactly what I worried about...and I can only try to disable as much as I can. The good news is that when I switched from my laptop (Dell precision M6500 with Quadro FX2800M) to a much more powerful workstation with Xeon and Quadro FX5800, I don't see this swapbuffers delay anymore.

As suggested, I also tried to see whether there is delay when vsync is disabled... On my laptop, I do see the delay once a while, as typical time between swapbuffers is around 2.5ms, once a while I see a gap more than 10 times longer than that.