How to enfoce vsync on windows?

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.

Edited by BlahBlah on
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.

Edited by Mārtiņš Možeiko on
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

Edited by BlahBlah on