Vsync and timer problems

It seems that using a PresentInterval of one in windowed mode causes my application to miss frames periodically. About 1/10th of a second every couple of seconds. This doesn't happen in full screen mode. Now what's really weird is that if I hibernate my computer with the program running, when it comes back the windowed mode doesn't vsync at all. I get about 30 FPS with lots of tearing, and Present() taking lots of time (sometimes 40 milliseconds). Full screen mode still works. Switching back to windowed mode (tearing down the DirectX device, and creating a new one) doesn't solve the problem. It still doesn't sync. Re-running the application fixes the problem.
So I decided to write my own sync in a high priority thread. Come to find out that Thread.Sleep() has a resolution of 1 millisecond until I hibernate the computer. When the computer comes back to life, Thread.Sleep() now has a resolution of 10 milliseconds. This happens even if I use timeBeginPeriod(1) and timeEndPeriod().
My guess is that DirectX (in windowed mode only) uses a high resolution timer to synchronize, and then fails miserably when the timer switches back to a resolution of 10 milliseconds.
So anyone know what's going on, and how to get DirectX to synchronize to frames in Windowed mode without having these problems Or, point me to a better forum if this isn't the right place
Thanks,
Jeremy


Answer this question

Vsync and timer problems

  • veeta

    Are you sure you're using ONE instead of DEFAULT for the present interval DEFAULT uses a low-resolution timer to do the SYNC, so it can cause the problems you describe. Make sure it's ONE also when resetting the device.

    If you do use ONE for both, I don't know -- sounds weird to me. Does hibernation affect the timer resolution for your application only, or for all applications (Try launching a new app that tests the timer). Hibernation requires driver support, so maybe some driver isn't restoring its state correctly.


  • Vsync and timer problems