From 4c74c5ca4a3e23f7ac59a318887f11c623972851 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 18 Feb 2023 10:42:48 +0100 Subject: [PATCH] Respect high performance gpu --- src/client/main.cpp | 22 +++++++++++++++++++++- src/client/std_include.hpp | 2 ++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/client/main.cpp b/src/client/main.cpp index c6559941..dc49c219 100644 --- a/src/client/main.cpp +++ b/src/client/main.cpp @@ -225,8 +225,28 @@ namespace } const auto self = utils::nt::library::get_by_address(&trigger_high_performance_gpu_switch); + const auto path = self.get_path().make_preferred().wstring(); - const std::wstring data = L"GpuPreference=2;"; + /*if (RegQueryValueExW(key, path.data(), nullptr, nullptr, nullptr, nullptr) != ERROR_FILE_NOT_FOUND) + { + return; + }*/ + + auto preference = DXGI_GPU_PREFERENCE_UNSPECIFIED; + + CComPtr factory{}; + if (SUCCEEDED(CreateDXGIFactory1(__uuidof(IDXGIFactory6), reinterpret_cast(&factory)))) + { + CComPtr adapter{}; + if (SUCCEEDED( + factory->EnumAdapterByGpuPreference(0, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, __uuidof(IDXGIAdapter), + reinterpret_cast(&adapter))) && adapter) + { + preference = DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE; + } + } + + const std::wstring data = L"GpuPreference=" + std::to_wstring(preference) + L";"; RegSetValueExW(key, self.get_path().make_preferred().wstring().data(), 0, REG_SZ, reinterpret_cast(data.data()), static_cast((data.size() + 1u) * 2)); diff --git a/src/client/std_include.hpp b/src/client/std_include.hpp index bbb4779c..e64b1b8c 100644 --- a/src/client/std_include.hpp +++ b/src/client/std_include.hpp @@ -52,6 +52,7 @@ #include #include #include +#include // min and max is required by gdi, therefore NOMINMAX won't work #ifdef max @@ -103,5 +104,6 @@ #pragma comment(lib, "iphlpapi.lib") #pragma comment(lib, "Crypt32.lib") #pragma comment(lib, "d3d11.lib") +#pragma comment(lib, "dxgi.lib") using namespace std::literals;