Skip to content

Commit 58dd8bd

Browse files
malayakusraman4
authored andcommitted
ZC v2223 : Skip IddCxSetRealtimeGPUPriority for MTL
Signed-off-by: Malaya Kumar Parida <malaya.kumar.parida@intel.com>
1 parent 79580f6 commit 58dd8bd

File tree

3 files changed

+93
-8
lines changed

3 files changed

+93
-8
lines changed

DVServerUMD/DVServer/DVServercommon.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,15 @@
2323
#define DISP_INFO L"Global\\DISP_INFO"
2424
#define PRIMARY_IDD_INDEX 0
2525

26+
//MTL Device ID Lists
27+
#define DEV_ID_7D40 0x7D40
28+
#define DEV_ID_7D45 0x7D45
29+
#define DEV_ID_7D55 0x7D55
30+
#define DEV_ID_7D60 0x7D60
31+
#define DEV_ID_7D67 0x7D67
32+
#define DEV_ID_7DD5 0x7DD5
33+
34+
constexpr auto DEVICE_ID_REGEX_PATTERN = R"(DEV_([0-9A-Fa-f]{4}))";
35+
constexpr int MAX_ENUM_ATTEMPTS = 100; // Prevent infinite loops
36+
2637
#endif /* __DVSERVER_COMMON_H__ */

DVServerUMD/DVServer/Driver.cpp

Lines changed: 76 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -750,15 +750,33 @@ void SwapChainProcessor::RunCore()
750750
ERR("IddCxSwapChainSetDevice failed, screen = %d, err = %s\n", m_screen_num, err);
751751
return;
752752
}
753-
if (IDD_IS_FUNCTION_AVAILABLE(IddCxSetRealtimeGPUPriority))
754-
{
755-
IDARG_IN_SETREALTIMEGPUPRIORITY SetPriority = {};
756-
SetPriority.pDevice = DxgiDevice.Get();
757-
hr = IddCxSetRealtimeGPUPriority(m_hSwapChain, &SetPriority);
758-
if (FAILED(hr)) {
759-
ERR("IddCxSetRealtimeGPUPriority failed\n");
753+
DWORD gpuDeviceId = GetGpuDeviceId();
754+
if (gpuDeviceId != 0)
755+
DBGPRINT("GPU PCI Device ID: 0x%04X\n", gpuDeviceId);
756+
else
757+
DBGPRINT("No GPU PCI Device ID found.\n");
758+
759+
switch (gpuDeviceId) {
760+
case DEV_ID_7D40:
761+
case DEV_ID_7D45:
762+
case DEV_ID_7D55:
763+
case DEV_ID_7D60:
764+
case DEV_ID_7D67:
765+
case DEV_ID_7DD5:
766+
DBGPRINT("IddCxSetRealtimeGPUPriority skipped");
767+
break;
768+
default:
769+
DBGPRINT("IddCxSetRealtimeGPUPriority engaged");
770+
if (IDD_IS_FUNCTION_AVAILABLE(IddCxSetRealtimeGPUPriority)) {
771+
IDARG_IN_SETREALTIMEGPUPRIORITY SetPriority = {};
772+
SetPriority.pDevice = DxgiDevice.Get();
773+
hr = IddCxSetRealtimeGPUPriority(m_hSwapChain, &SetPriority);
774+
if (FAILED(hr)) {
775+
ERR("IddCxSetRealtimeGPUPriority failed\n");
776+
}
777+
}
778+
break;
760779
}
761-
}
762780

763781
//reset the resolution flag whenever there is a resolution change
764782
m_resolution_changed = TRUE;
@@ -1995,4 +2013,54 @@ bool IsWindows11OrLater()
19952013
return true;
19962014
}
19972015

2016+
DWORD GetGpuDeviceId()
2017+
{
2018+
HDEVINFO deviceInfoSet = SetupDiGetClassDevs(&GUID_DEVCLASS_DISPLAY, nullptr, nullptr, DIGCF_PRESENT);
2019+
if (deviceInfoSet == INVALID_HANDLE_VALUE) {
2020+
ERR("SetupDiGetClassDevs failed.\n");
2021+
return 0;
2022+
}
2023+
2024+
DWORD deviceIdFromPci = 0;
2025+
SP_DEVINFO_DATA deviceInfoData = {};
2026+
deviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
2027+
2028+
std::regex deviceIdRegex(DEVICE_ID_REGEX_PATTERN);
2029+
std::smatch match;
2030+
2031+
for (DWORD i = 0; i < MAX_ENUM_ATTEMPTS; ++i) {
2032+
if (!SetupDiEnumDeviceInfo(deviceInfoSet, i, &deviceInfoData))
2033+
break;
2034+
2035+
TCHAR deviceInstanceId[MAX_DEVICE_ID_LEN];
2036+
if (CM_Get_Device_ID(deviceInfoData.DevInst, deviceInstanceId, MAX_DEVICE_ID_LEN, 0) == CR_SUCCESS) {
2037+
std::wstring instanceId(deviceInstanceId);
2038+
2039+
// Convert wide string to UTF-8
2040+
int size_needed = WideCharToMultiByte(CP_UTF8, 0, instanceId.c_str(), -1, nullptr, 0, nullptr, nullptr);
2041+
std::string instanceIdStr(size_needed, 0);
2042+
WideCharToMultiByte(CP_UTF8, 0, instanceId.c_str(), -1, &instanceIdStr[0], size_needed, nullptr, nullptr);
2043+
2044+
2045+
if (std::regex_search(instanceIdStr, match, deviceIdRegex)) {
2046+
try {
2047+
deviceIdFromPci = std::stoul(match[1].str(), nullptr, 16);
2048+
// Validate range (for safety, PCI Device IDs are 16-bit)
2049+
if (deviceIdFromPci > 0xFFFF) {
2050+
ERR("Invalid Device ID extracted: 0x%08X\n", deviceIdFromPci);
2051+
deviceIdFromPci = 0;
2052+
}
2053+
break;
2054+
}
2055+
catch (const std::exception&) {
2056+
ERR("Error parsing Device ID from string: %s\n", match[1].str().c_str());
2057+
}
2058+
}
2059+
}
2060+
}
2061+
2062+
SetupDiDestroyDeviceInfoList(deviceInfoSet);
2063+
2064+
return deviceIdFromPci;
2065+
}
19982066
#pragma endregion

DVServerUMD/DVServer/Driver.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
#include <memory>
1616
#include <vector>
1717

18+
#include <devguid.h>
19+
#include <string>
20+
#include <regex>
21+
#include <cfgmgr32.h>
22+
1823
#include "Trace.h"
1924
#include "DVServeredid.h"
2025
#include "..\..\DVServerKMD\Public.h"
@@ -197,6 +202,7 @@ namespace Microsoft
197202
int hpd_event_create(IDDCX_ADAPTER AdapterObject);
198203
int get_hpd_data(HANDLE devHandle, struct hp_info* data);
199204
bool IsWindows11OrLater();
205+
DWORD GetGpuDeviceId();
200206
struct disp_info {
201207
int disp_count;
202208
HANDLE mutex;

0 commit comments

Comments
 (0)