Skip to content

Instantly share code, notes, and snippets.

Created Mar 20, 2015
Embed
What would you like to do?
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