diff --git a/DDrawCompat/D3dDdi/KernelModeThunks.cpp b/DDrawCompat/D3dDdi/KernelModeThunks.cpp index 7dffd28..fe5bd2c 100644 --- a/DDrawCompat/D3dDdi/KernelModeThunks.cpp +++ b/DDrawCompat/D3dDdi/KernelModeThunks.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -31,6 +32,7 @@ namespace Compat::SrwLock g_lastOpenAdapterInfoSrwLock; std::string g_lastDDrawCreateDcDevice; + std::atomic g_qpcLastVsync = 0; UINT g_vsyncCounter = 0; CONDITION_VARIABLE g_vsyncCounterCv = CONDITION_VARIABLE_INIT; Compat::SrwLock g_vsyncCounterSrwLock; @@ -235,6 +237,7 @@ namespace while (true) { waitForVerticalBlank(); + g_qpcLastVsync = Time::queryPerformanceCounter(); { Compat::ScopedSrwLockExclusive lock(g_vsyncCounterSrwLock); @@ -298,6 +301,11 @@ namespace D3dDdi return g_lastOpenAdapterInfo.monitorRect; } + long long getQpcLastVsync() + { + return g_qpcLastVsync; + } + UINT getVsyncCounter() { Compat::ScopedSrwLockShared lock(g_vsyncCounterSrwLock); diff --git a/DDrawCompat/D3dDdi/KernelModeThunks.h b/DDrawCompat/D3dDdi/KernelModeThunks.h index 3906794..02361b8 100644 --- a/DDrawCompat/D3dDdi/KernelModeThunks.h +++ b/DDrawCompat/D3dDdi/KernelModeThunks.h @@ -7,6 +7,7 @@ namespace D3dDdi namespace KernelModeThunks { RECT getMonitorRect(); + long long getQpcLastVsync(); UINT getVsyncCounter(); void installHooks(); void setDcFormatOverride(UINT format); diff --git a/DDrawCompat/D3dDdi/Resource.cpp b/DDrawCompat/D3dDdi/Resource.cpp index d08edeb..4229931 100644 --- a/DDrawCompat/D3dDdi/Resource.cpp +++ b/DDrawCompat/D3dDdi/Resource.cpp @@ -396,7 +396,7 @@ namespace D3dDdi { surfaceInfo[i].Width = m_fixedData.pSurfList[i].Width; surfaceInfo[i].Height = m_fixedData.pSurfList[i].Height; - surfaceInfo[i].SysMemPitch = (surfaceInfo[i].Width * m_formatInfo.bytesPerPixel + 7) & ~7; + surfaceInfo[i].SysMemPitch = (surfaceInfo[i].Width * m_formatInfo.bytesPerPixel + 3) & ~3; if (i != 0) { std::uintptr_t offset = reinterpret_cast(surfaceInfo[i - 1].pSysMem) + diff --git a/DDrawCompat/DDraw/RealPrimarySurface.cpp b/DDrawCompat/DDraw/RealPrimarySurface.cpp index 0d81ac8..7e420d2 100644 --- a/DDrawCompat/DDraw/RealPrimarySurface.cpp +++ b/DDrawCompat/DDraw/RealPrimarySurface.cpp @@ -36,7 +36,6 @@ namespace bool g_isUpdatePending = false; bool g_waitingForPrimaryUnlock = false; std::atomic g_qpcLastUpdate = 0; - long long g_qpcFlipEnd = 0; UINT g_flipEndVsyncCount = 0; UINT g_presentEndVsyncCount = 0; @@ -228,7 +227,10 @@ namespace DDraw::ScopedThreadLock lock; if (g_isUpdatePending && !isPresentPending()) { - if (Time::qpcToMs(Time::queryPerformanceCounter() - g_qpcFlipEnd) < 1) + auto qpcNow = Time::queryPerformanceCounter(); + auto qpcLastVsync = D3dDdi::KernelModeThunks::getQpcLastVsync(); + if (Time::qpcToMs(qpcNow - qpcLastVsync) < 1 || + Time::qpcToMs(qpcNow - g_qpcLastUpdate) < 1 && Time::qpcToMs(qpcNow - qpcLastVsync) <= 3) { skipWaitForVsync = true; } @@ -429,10 +431,7 @@ namespace DDraw return !isFlipPending(); } - if (D3dDdi::KernelModeThunks::waitForVsyncCounter(g_flipEndVsyncCount)) - { - g_qpcFlipEnd = Time::queryPerformanceCounter(); - } + D3dDdi::KernelModeThunks::waitForVsyncCounter(g_flipEndVsyncCount); return true; } }