ExtendedTools: Add workaround for upstream PresentMon memory corruption on Windows 8.1
@@ -1348,6 +1348,39 @@ void HandleDWMEvent(EVENT_RECORD* pEventRecord)
break;
}
+ if (PhWindowsVersion > WINDOWS_7 && PhWindowsVersion < WINDOWS_10)
+ {
+ EventDataDesc desc[] = {
+ { L"ulFlipChain" },
+ { L"ulSerialNumber" },
+ { L"hwnd" },
+ };
+ mMetadata.GetEventData(pEventRecord, desc, _countof(desc));
+ auto ulFlipChain = desc[0].GetData<uint64_t>();
+ auto ulSerialNumber = desc[1].GetData<uint64_t>();
+ auto hwnd = desc[2].GetData<uint64_t>();
+
+ // Lookup the present using the 64-bit token data from the PHT
+ // submission, which is actually two 32-bit data chunks corresponding
+ // to a flip chain id and present id.
+ auto tokenData = ((uint64_t)ulFlipChain << 32ull) | ulSerialNumber;
+ auto flipIter = mPresentByDxgkPresentHistoryTokenData.find(tokenData);
+ if (flipIter != mPresentByDxgkPresentHistoryTokenData.end()) {
+ auto present = flipIter->second;
+
+ TRACK_PRESENT_PATH(present);
+
+ //DebugModifyPresent(present.get());
+ present->DxgkPresentHistoryTokenData = 0;
+ present->DwmNotified = true;
+
+ mLastPresentByWindow[hwnd] = present;
+
+ mPresentByDxgkPresentHistoryTokenData.erase(flipIter);
+ }
+ }
+ else
+ {
EventDataDesc desc[] = {
{ L"ulFlipChain" },
{ L"ulSerialNumber" },
@@ -1376,9 +1409,34 @@ void HandleDWMEvent(EVENT_RECORD* pEventRecord)
mPresentByDxgkPresentHistoryTokenData.erase(flipIter);
}
- break;
}
+ }
+ break;
case Microsoft_Windows_Dwm_Core::SCHEDULE_SURFACEUPDATE_Info::Id:
+ {
+ if (PhWindowsVersion > WINDOWS_7 && PhWindowsVersion < WINDOWS_10)
+ {
+ EventDataDesc desc[] = {
+ { L"luidSurface" },
+ { L"OutOfFrameDirectFlipPresentCount" },
+ { L"bindId" },
+ };
+ mMetadata.GetEventData(pEventRecord, desc, _countof(desc));
+ auto luidSurface = desc[0].GetData<uint64_t>();
+ auto PresentCount = desc[1].GetData<uint64_t>();
+ auto bindId = desc[2].GetData<uint64_t>();
+
+ Win32KPresentHistoryToken key(luidSurface, PresentCount, bindId);
+ auto eventIter = mPresentByWin32KPresentHistoryToken.find(key);
+ if (eventIter != mPresentByWin32KPresentHistoryToken.end() && eventIter->second->SeenInFrameEvent) {
+ TRACK_PRESENT_PATH(eventIter->second);
+ //DebugModifyPresent(eventIter->second.get());
+ eventIter->second->DwmNotified = true;
+ mPresentsWaitingForDWM.emplace_back(eventIter->second);
+ eventIter->second->PresentInDwmWaitingStruct = true;
+ }
+ }
+ else
{
EventDataDesc desc[] = {
{ L"luidSurface" },
@@ -1399,8 +1457,9 @@ void HandleDWMEvent(EVENT_RECORD* pEventRecord)
mPresentsWaitingForDWM.emplace_back(eventIter->second);
eventIter->second->PresentInDwmWaitingStruct = true;
}
- break;
}
+ }
+ break;
default:
//assert(!mFilteredEvents || // Assert that filtering is working if expected
// hdr.ProviderId == Microsoft_Windows_Dwm_Core::Win7::GUID);
