From 49f2900e1f0f6882d0cce619fea69d2dbd9aaeee Mon Sep 17 00:00:00 2001 From: Stenzek Date: Wed, 22 Feb 2023 00:48:44 +1000 Subject: [PATCH] GS/D3D: Combine driver version lookup for D3D11+D3D12 --- pcsx2/Frontend/D3D11HostDisplay.cpp | 46 ++------------------------ pcsx2/Frontend/D3D12HostDisplay.cpp | 47 ++------------------------- pcsx2/GS/Renderers/DX11/D3D.cpp | 50 +++++++++++++++++++++++++++++ pcsx2/GS/Renderers/DX11/D3D.h | 3 ++ 4 files changed, 58 insertions(+), 88 deletions(-) diff --git a/pcsx2/Frontend/D3D11HostDisplay.cpp b/pcsx2/Frontend/D3D11HostDisplay.cpp index af72cee10e..767cdd7bf9 100644 --- a/pcsx2/Frontend/D3D11HostDisplay.cpp +++ b/pcsx2/Frontend/D3D11HostDisplay.cpp @@ -16,6 +16,7 @@ #include "PrecompiledHeader.h" #include "Frontend/D3D11HostDisplay.h" +#include "GS/Renderers/DX11/D3D.h" #include "imgui.h" #include "imgui_impl_dx11.h" @@ -439,49 +440,6 @@ void D3D11HostDisplay::DestroySurface() m_swap_chain.reset(); } -static std::string GetDriverVersionFromLUID(const LUID& luid) -{ - std::string ret; - - HKEY hKey; - if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\DirectX", 0, KEY_READ, &hKey) == ERROR_SUCCESS) - { - DWORD max_key_len = 0, adapter_count = 0; - if (RegQueryInfoKeyW(hKey, nullptr, nullptr, nullptr, &adapter_count, &max_key_len, - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr) == ERROR_SUCCESS) - { - std::vector current_name(max_key_len + 1); - for (DWORD i = 0; i < adapter_count; ++i) - { - DWORD subKeyLength = static_cast(current_name.size()); - if (RegEnumKeyExW(hKey, i, current_name.data(), &subKeyLength, nullptr, nullptr, nullptr, nullptr) == ERROR_SUCCESS) - { - LUID current_luid = {}; - DWORD current_luid_size = sizeof(uint64_t); - if (RegGetValueW(hKey, current_name.data(), L"AdapterLuid", RRF_RT_QWORD, nullptr, ¤t_luid, ¤t_luid_size) == ERROR_SUCCESS && - current_luid.HighPart == luid.HighPart && current_luid.LowPart == luid.LowPart) - { - LARGE_INTEGER driver_version = {}; - DWORD driver_version_size = sizeof(driver_version); - if (RegGetValueW(hKey, current_name.data(), L"DriverVersion", RRF_RT_QWORD, nullptr, &driver_version, &driver_version_size) == ERROR_SUCCESS) - { - WORD nProduct = HIWORD(driver_version.HighPart); - WORD nVersion = LOWORD(driver_version.HighPart); - WORD nSubVersion = HIWORD(driver_version.LowPart); - WORD nBuild = LOWORD(driver_version.LowPart); - ret = StringUtil::StdStringFromFormat("%u.%u.%u.%u", nProduct, nVersion, nSubVersion, nBuild); - } - } - } - } - } - - RegCloseKey(hKey); - } - - return ret; -} - std::string D3D11HostDisplay::GetDriverInfo() const { std::string ret = "Unknown Feature Level"; @@ -518,7 +476,7 @@ std::string D3D11HostDisplay::GetDriverInfo() const ret += StringUtil::WideStringToUTF8String(desc.Description); ret += "\n"; - const std::string driver_version(GetDriverVersionFromLUID(desc.AdapterLuid)); + const std::string driver_version(D3D::GetDriverVersionFromLUID(desc.AdapterLuid)); if (!driver_version.empty()) { ret += "Driver Version: "; diff --git a/pcsx2/Frontend/D3D12HostDisplay.cpp b/pcsx2/Frontend/D3D12HostDisplay.cpp index 7b5206a4c7..fccf538c81 100644 --- a/pcsx2/Frontend/D3D12HostDisplay.cpp +++ b/pcsx2/Frontend/D3D12HostDisplay.cpp @@ -16,6 +16,8 @@ #include "PrecompiledHeader.h" #include "Frontend/D3D12HostDisplay.h" +#include "GS/Renderers/DX11/D3D.h" + #include "common/Assertions.h" #include "common/Console.h" #include "common/D3D12/Context.h" @@ -343,49 +345,6 @@ void D3D12HostDisplay::DestroySurface() m_swap_chain.reset(); } -static std::string GetDriverVersionFromLUID(const LUID& luid) -{ - std::string ret; - - HKEY hKey; - if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\DirectX", 0, KEY_READ, &hKey) == ERROR_SUCCESS) - { - DWORD max_key_len = 0, adapter_count = 0; - if (RegQueryInfoKey(hKey, nullptr, nullptr, nullptr, &adapter_count, &max_key_len, - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr) == ERROR_SUCCESS) - { - std::vector current_name(max_key_len + 1); - for (DWORD i = 0; i < adapter_count; ++i) - { - DWORD subKeyLength = static_cast(current_name.size()); - if (RegEnumKeyExW(hKey, i, current_name.data(), &subKeyLength, nullptr, nullptr, nullptr, nullptr) == ERROR_SUCCESS) - { - LUID current_luid = {}; - DWORD current_luid_size = sizeof(uint64_t); - if (RegGetValueW(hKey, current_name.data(), L"AdapterLuid", RRF_RT_QWORD, nullptr, ¤t_luid, ¤t_luid_size) == ERROR_SUCCESS && - current_luid.HighPart == luid.HighPart && current_luid.LowPart == luid.LowPart) - { - LARGE_INTEGER driver_version = {}; - DWORD driver_version_size = sizeof(driver_version); - if (RegGetValueW(hKey, current_name.data(), L"DriverVersion", RRF_RT_QWORD, nullptr, &driver_version, &driver_version_size) == ERROR_SUCCESS) - { - WORD nProduct = HIWORD(driver_version.HighPart); - WORD nVersion = LOWORD(driver_version.HighPart); - WORD nSubVersion = HIWORD(driver_version.LowPart); - WORD nBuild = LOWORD(driver_version.LowPart); - ret = StringUtil::StdStringFromFormat("%u.%u.%u.%u", nProduct, nVersion, nSubVersion, nBuild); - } - } - } - } - } - - RegCloseKey(hKey); - } - - return ret; -} - std::string D3D12HostDisplay::GetDriverInfo() const { std::string ret = "Unknown Feature Level"; @@ -417,7 +376,7 @@ std::string D3D12HostDisplay::GetDriverInfo() const ret += StringUtil::WideStringToUTF8String(desc.Description); ret += "\n"; - const std::string driver_version(GetDriverVersionFromLUID(desc.AdapterLuid)); + const std::string driver_version(D3D::GetDriverVersionFromLUID(desc.AdapterLuid)); if (!driver_version.empty()) { ret += "Driver Version: "; diff --git a/pcsx2/GS/Renderers/DX11/D3D.cpp b/pcsx2/GS/Renderers/DX11/D3D.cpp index 9af1b7c227..689331f50b 100644 --- a/pcsx2/GS/Renderers/DX11/D3D.cpp +++ b/pcsx2/GS/Renderers/DX11/D3D.cpp @@ -17,8 +17,12 @@ #include "GS/Renderers/DX11/D3D.h" #include "GS/GSExtra.h" +#include "common/StringUtil.h" + #include +#include "fmt/format.h" + namespace D3D { wil::com_ptr_nothrow CreateFactory(bool debug) @@ -69,6 +73,52 @@ namespace D3D return adapter; } + std::string GetDriverVersionFromLUID(const LUID& luid) + { + std::string ret; + + HKEY hKey; + if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\DirectX", 0, KEY_READ, &hKey) == ERROR_SUCCESS) + { + DWORD max_key_len = 0, adapter_count = 0; + if (RegQueryInfoKeyW(hKey, nullptr, nullptr, nullptr, &adapter_count, &max_key_len, nullptr, nullptr, + nullptr, nullptr, nullptr, nullptr) == ERROR_SUCCESS) + { + std::vector current_name(max_key_len + 1); + for (DWORD i = 0; i < adapter_count; ++i) + { + DWORD subKeyLength = static_cast(current_name.size()); + if (RegEnumKeyExW(hKey, i, current_name.data(), &subKeyLength, nullptr, nullptr, nullptr, + nullptr) == ERROR_SUCCESS) + { + LUID current_luid = {}; + DWORD current_luid_size = sizeof(uint64_t); + if (RegGetValueW(hKey, current_name.data(), L"AdapterLuid", RRF_RT_QWORD, nullptr, + ¤t_luid, ¤t_luid_size) == ERROR_SUCCESS && + current_luid.HighPart == luid.HighPart && current_luid.LowPart == luid.LowPart) + { + LARGE_INTEGER driver_version = {}; + DWORD driver_version_size = sizeof(driver_version); + if (RegGetValueW(hKey, current_name.data(), L"DriverVersion", RRF_RT_QWORD, nullptr, + &driver_version, &driver_version_size) == ERROR_SUCCESS) + { + WORD nProduct = HIWORD(driver_version.HighPart); + WORD nVersion = LOWORD(driver_version.HighPart); + WORD nSubVersion = HIWORD(driver_version.LowPart); + WORD nBuild = LOWORD(driver_version.LowPart); + ret = fmt::format("{}.{}.{}.{}", nProduct, nVersion, nSubVersion, nBuild); + } + } + } + } + } + + RegCloseKey(hKey); + } + + return ret; + } + u8 Vendor() { auto factory = CreateFactory(false); diff --git a/pcsx2/GS/Renderers/DX11/D3D.h b/pcsx2/GS/Renderers/DX11/D3D.h index 3b8bdcff66..ba7b0a0ee8 100644 --- a/pcsx2/GS/Renderers/DX11/D3D.h +++ b/pcsx2/GS/Renderers/DX11/D3D.h @@ -32,6 +32,9 @@ namespace D3D // however in the event that the adapter is not found due to the above, use the default wil::com_ptr_nothrow GetAdapterFromIndex(IDXGIFactory2* factory, int index); + // returns the driver version from the registry as a string + std::string GetDriverVersionFromLUID(const LUID& luid); + // this is sort of a legacy thing that doesn't have much to do with d3d (just the easiest way) // checks to see if the adapter at 0 is NV and thus we should prefer OpenGL enum VendorID