Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions DVServerUMD/DVServer/DVServercommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,15 @@
#define DISP_INFO L"Global\\DISP_INFO"
#define PRIMARY_IDD_INDEX 0

//MTL Device ID Lists
#define DEV_ID_7D40 0x7D40
#define DEV_ID_7D45 0x7D45
#define DEV_ID_7D55 0x7D55
#define DEV_ID_7D60 0x7D60
#define DEV_ID_7D67 0x7D67
#define DEV_ID_7DD5 0x7DD5

constexpr auto DEVICE_ID_REGEX_PATTERN = R"(DEV_([0-9A-Fa-f]{4}))";
constexpr int MAX_ENUM_ATTEMPTS = 100; // Prevent infinite loops

#endif /* __DVSERVER_COMMON_H__ */
84 changes: 76 additions & 8 deletions DVServerUMD/DVServer/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,15 +750,33 @@ void SwapChainProcessor::RunCore()
ERR("IddCxSwapChainSetDevice failed, screen = %d, err = %s\n", m_screen_num, err);
return;
}
if (IDD_IS_FUNCTION_AVAILABLE(IddCxSetRealtimeGPUPriority))
{
IDARG_IN_SETREALTIMEGPUPRIORITY SetPriority = {};
SetPriority.pDevice = DxgiDevice.Get();
hr = IddCxSetRealtimeGPUPriority(m_hSwapChain, &SetPriority);
if (FAILED(hr)) {
ERR("IddCxSetRealtimeGPUPriority failed\n");
DWORD gpuDeviceId = GetGpuDeviceId();
if (gpuDeviceId != 0)
DBGPRINT("GPU PCI Device ID: 0x%04X\n", gpuDeviceId);
else
DBGPRINT("No GPU PCI Device ID found.\n");

switch (gpuDeviceId) {
case DEV_ID_7D40:
case DEV_ID_7D45:
case DEV_ID_7D55:
case DEV_ID_7D60:
case DEV_ID_7D67:
case DEV_ID_7DD5:
DBGPRINT("IddCxSetRealtimeGPUPriority skipped");
break;
default:
DBGPRINT("IddCxSetRealtimeGPUPriority engaged");
if (IDD_IS_FUNCTION_AVAILABLE(IddCxSetRealtimeGPUPriority)) {
IDARG_IN_SETREALTIMEGPUPRIORITY SetPriority = {};
SetPriority.pDevice = DxgiDevice.Get();
hr = IddCxSetRealtimeGPUPriority(m_hSwapChain, &SetPriority);
if (FAILED(hr)) {
ERR("IddCxSetRealtimeGPUPriority failed\n");
}
}
break;
}
}

//reset the resolution flag whenever there is a resolution change
m_resolution_changed = TRUE;
Expand Down Expand Up @@ -1995,4 +2013,54 @@ bool IsWindows11OrLater()
return true;
}

DWORD GetGpuDeviceId()
{
HDEVINFO deviceInfoSet = SetupDiGetClassDevs(&GUID_DEVCLASS_DISPLAY, nullptr, nullptr, DIGCF_PRESENT);
if (deviceInfoSet == INVALID_HANDLE_VALUE) {
ERR("SetupDiGetClassDevs failed.\n");
return 0;
}

DWORD deviceIdFromPci = 0;
SP_DEVINFO_DATA deviceInfoData = {};
deviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);

std::regex deviceIdRegex(DEVICE_ID_REGEX_PATTERN);
std::smatch match;

for (DWORD i = 0; i < MAX_ENUM_ATTEMPTS; ++i) {
if (!SetupDiEnumDeviceInfo(deviceInfoSet, i, &deviceInfoData))
break;

TCHAR deviceInstanceId[MAX_DEVICE_ID_LEN];
if (CM_Get_Device_ID(deviceInfoData.DevInst, deviceInstanceId, MAX_DEVICE_ID_LEN, 0) == CR_SUCCESS) {
std::wstring instanceId(deviceInstanceId);

// Convert wide string to UTF-8
int size_needed = WideCharToMultiByte(CP_UTF8, 0, instanceId.c_str(), -1, nullptr, 0, nullptr, nullptr);
std::string instanceIdStr(size_needed, 0);
WideCharToMultiByte(CP_UTF8, 0, instanceId.c_str(), -1, &instanceIdStr[0], size_needed, nullptr, nullptr);


if (std::regex_search(instanceIdStr, match, deviceIdRegex)) {
try {
deviceIdFromPci = std::stoul(match[1].str(), nullptr, 16);
// Validate range (for safety, PCI Device IDs are 16-bit)
if (deviceIdFromPci > 0xFFFF) {
ERR("Invalid Device ID extracted: 0x%08X\n", deviceIdFromPci);
deviceIdFromPci = 0;
}
break;
}
catch (const std::exception&) {
ERR("Error parsing Device ID from string: %s\n", match[1].str().c_str());
}
}
}
}

SetupDiDestroyDeviceInfoList(deviceInfoSet);

return deviceIdFromPci;
}
#pragma endregion
6 changes: 6 additions & 0 deletions DVServerUMD/DVServer/Driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
#include <memory>
#include <vector>

#include <devguid.h>
#include <string>
#include <regex>
#include <cfgmgr32.h>

#include "Trace.h"
#include "DVServeredid.h"
#include "..\..\DVServerKMD\Public.h"
Expand Down Expand Up @@ -197,6 +202,7 @@ namespace Microsoft
int hpd_event_create(IDDCX_ADAPTER AdapterObject);
int get_hpd_data(HANDLE devHandle, struct hp_info* data);
bool IsWindows11OrLater();
DWORD GetGpuDeviceId();
struct disp_info {
int disp_count;
HANDLE mutex;
Expand Down