Skip to content

Instantly share code, notes, and snippets.

Created March 20, 2015 12:24
Show Gist options
  • Save anonymous/4397e4909c524c939bee to your computer and use it in GitHub Desktop.
Save anonymous/4397e4909c524c939bee to your computer and use it in GitHub Desktop.
D3DKMTWaitForVerticalBlankEvent
DWORD WINAPI vsyncThread(LPVOID lpParam) {
dout( "+vsyncThread()" );
SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL );
LPFND3DKMT_OPENADAPTERFROMHDC lpfnKTOpenAdapterFromHdc = (LPFND3DKMT_OPENADAPTERFROMHDC)fnBind("gdi32","D3DKMTOpenAdapterFromHdc");
LPFND3DKMT_WAITFORVERTICALBLANKEVENT lpfnKTWaitForVerticalBlankEvent = (LPFND3DKMT_WAITFORVERTICALBLANKEVENT)fnBind("gdi32","D3DKMTWaitForVerticalBlankEvent");
if (lpfnKTOpenAdapterFromHdc && lpfnKTWaitForVerticalBlankEvent) {
D3DKMT_WAITFORVERTICALBLANKEVENT we;
bool bBound = false;
while (bRunningTests) {
if (!bBound) {
D3DKMT_OPENADAPTERFROMHDC oa;
oa.hDc = GetDC(NULL); // NULL = primary display monitor; NOT tested with multiple monitor setup; tested/works with hAppWnd
bBound = (S_OK==(*lpfnKTOpenAdapterFromHdc)(&oa));
if (bBound) {
we.hAdapter = oa.hAdapter;
we.hDevice = 0;
we.VidPnSourceId = oa.VidPnSourceId;
}
}
if (bBound && (S_OK==(*lpfnKTWaitForVerticalBlankEvent)(&we))) {
vsyncHaveNewTimingInfo( tick() );
vsyncSignalAllWaiters();
}
else {
bBound = false;
dout( "*** vsync service in recovery mode..." );
Sleep(1000);
}
}
}
dout( "-vsyncThread()" );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment