handmade.network » Forums » How to enfoce vsync on windows?
Marmot
Cairn
4 posts
#14655 How to enfoce vsync on windows?
5 months, 4 weeks ago Edited by Cairn on March 23, 2018, 1:26 a.m.

Is there a guaranteed way to wait for the vblank interval on windows? I was watching stream 241 and Casey gives the impression that, depending on how windows/drivers are configured, there is no way to guarantee vsync. In the case where the video card does flip in the blanking interval, what is the correct way to time buffer swapping?

I posted a question on stack overflow but didn't really get an answer. I was hoping someone here might know or be able to point me at a specific HH episode.

Thanks.
mmozeiko
Mārtiņš Možeiko
1789 posts / 1 project
#14657 How to enfoce vsync on windows?
5 months, 4 weeks ago Edited by Mārtiņš Možeiko on March 23, 2018, 3:23 a.m.

Yes, there is. But that works only for windowed application and if compositor is enabled (meaning Windows
7 Aero theme or Windows 8+). If these two conditions are true, then DwmFlush() will give you vsync.
Marmot
Cairn
4 posts
#14658 How to enfoce vsync on windows?
5 months, 4 weeks ago Edited by Cairn on March 23, 2018, 5:06 a.m.

mmozeiko
Yes, there is.

What is it?
Is the method described by the stack overflow question correct?

IE
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
if (DWM.isEnabled()) 
{ 
    present(); 
    DwmFlush(); 
} 
else 
{
    waitForVBlank(); 
    present(); 
}


where waitForVBlank is one of :
1
2
3
IDXGIOutput::WaitForVBlank
D3DKMTWaitForVerticalBlankEvent
IDirectDraw7::WaitForVerticalBlank