Skip to content

Commit

Permalink
[dxvk] Add setupapi as a Windows WSI dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
doitsujin committed Feb 2, 2025
1 parent 5569274 commit 031c912
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
5 changes: 4 additions & 1 deletion src/wsi/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ wsi_src = [

wsi_deps = [ dep_displayinfo ]

if platform != 'windows'
if platform == 'windows'
lib_setupapi = cpp.find_library('setupapi')
wsi_deps += [ lib_setupapi ]
else
wsi_deps += [
lib_sdl3.partial_dependency(compile_args: true, includes: true),
lib_sdl2.partial_dependency(compile_args: true, includes: true),
Expand Down
17 changes: 4 additions & 13 deletions src/wsi/win32/wsi_monitor_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,29 +312,20 @@ namespace dxvk::wsi {

WsiEdidData Win32WsiDriver::getMonitorEdid(HMONITOR hMonitor) {
static constexpr GUID GUID_DEVINTERFACE_MONITOR = { 0xe6f07b5f, 0xee97, 0x4a90, 0xb0, 0x76, 0x33, 0xf5, 0x7b, 0xf4, 0xea, 0xa7 };
static auto pfnSetupDiGetClassDevsW = reinterpret_cast<decltype(SetupDiGetClassDevsW)*> (::GetProcAddress(::GetModuleHandleW(L"setupapi.dll"), "SetupDiGetClassDevsW"));
static auto pfnSetupDiEnumDeviceInterfaces = reinterpret_cast<decltype(SetupDiEnumDeviceInterfaces)*> (::GetProcAddress(::GetModuleHandleW(L"setupapi.dll"), "SetupDiEnumDeviceInterfaces"));
static auto pfnSetupDiGetDeviceInterfaceDetailW = reinterpret_cast<decltype(SetupDiGetDeviceInterfaceDetailW)*>(::GetProcAddress(::GetModuleHandleW(L"setupapi.dll"), "SetupDiGetDeviceInterfaceDetailW"));
static auto pfnSetupDiOpenDevRegKey = reinterpret_cast<decltype(SetupDiOpenDevRegKey)*> (::GetProcAddress(::GetModuleHandleW(L"setupapi.dll"), "SetupDiOpenDevRegKey"));
static auto pfnSetupDiGetDeviceInstanceIdW = reinterpret_cast<decltype(SetupDiGetDeviceInstanceIdW)*> (::GetProcAddress(::GetModuleHandleW(L"setupapi.dll"), "SetupDiGetDeviceInstanceIdW"));
if (!pfnSetupDiGetClassDevsW || !pfnSetupDiEnumDeviceInterfaces || !pfnSetupDiGetDeviceInterfaceDetailW || !pfnSetupDiOpenDevRegKey || !pfnSetupDiGetDeviceInstanceIdW) {
Logger::err("getMonitorEdid: Failed to load functions from setupapi.");
return {};
}

std::wstring monitorDevicePath = getMonitorDevicePath(hMonitor);
if (monitorDevicePath.empty()) {
Logger::err("getMonitorEdid: Failed to get monitor device path.");
return {};
}

const HDEVINFO devInfo = pfnSetupDiGetClassDevsW(&GUID_DEVINTERFACE_MONITOR, nullptr, nullptr, DIGCF_DEVICEINTERFACE);
const HDEVINFO devInfo = ::SetupDiGetClassDevsW(&GUID_DEVINTERFACE_MONITOR, nullptr, nullptr, DIGCF_DEVICEINTERFACE);

SP_DEVICE_INTERFACE_DATA interfaceData;
memset(&interfaceData, 0, sizeof(interfaceData));
interfaceData.cbSize = sizeof(interfaceData);

for (DWORD monitorIdx = 0; pfnSetupDiEnumDeviceInterfaces(devInfo, nullptr, &GUID_DEVINTERFACE_MONITOR, monitorIdx, &interfaceData); monitorIdx++) {
for (DWORD monitorIdx = 0; ::SetupDiEnumDeviceInterfaces(devInfo, nullptr, &GUID_DEVINTERFACE_MONITOR, monitorIdx, &interfaceData); monitorIdx++) {
DxvkDeviceInterfaceDetail detailData;
// Josh: I'm taking no chances here. I don't trust this API at all.
memset(&detailData, 0, sizeof(detailData));
Expand All @@ -344,7 +335,7 @@ namespace dxvk::wsi {
memset(&devInfoData, 0, sizeof(devInfoData));
devInfoData.cbSize = sizeof(devInfoData);

if (!pfnSetupDiGetDeviceInterfaceDetailW(devInfo, &interfaceData, &detailData.base, sizeof(detailData), nullptr, &devInfoData))
if (!::SetupDiGetDeviceInterfaceDetailW(devInfo, &interfaceData, &detailData.base, sizeof(detailData), nullptr, &devInfoData))
continue;

// Check that this monitor matches the same one we are looking for.
Expand All @@ -354,7 +345,7 @@ namespace dxvk::wsi {
if (_wcsicmp(monitorDevicePath.c_str(), detailData.base.DevicePath) != 0)
continue;

HKEY deviceRegKey = pfnSetupDiOpenDevRegKey(devInfo, &devInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ);
HKEY deviceRegKey = ::SetupDiOpenDevRegKey(devInfo, &devInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ);
if (deviceRegKey == INVALID_HANDLE_VALUE) {
Logger::err("getMonitorEdid: Failed to open monitor device registry key.");
return {};
Expand Down

0 comments on commit 031c912

Please sign in to comment.