Respect high performance gpu

This commit is contained in:
momo5502 2023-02-18 10:42:48 +01:00
parent 25a6b128eb
commit 4c74c5ca4a
2 changed files with 23 additions and 1 deletions

View File

@ -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<IDXGIFactory6> factory{};
if (SUCCEEDED(CreateDXGIFactory1(__uuidof(IDXGIFactory6), reinterpret_cast<void**>(&factory))))
{
CComPtr<IDXGIAdapter> adapter{};
if (SUCCEEDED(
factory->EnumAdapterByGpuPreference(0, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, __uuidof(IDXGIAdapter),
reinterpret_cast<void**>(&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<const BYTE*>(data.data()),
static_cast<DWORD>((data.size() + 1u) * 2));

View File

@ -52,6 +52,7 @@
#include <wincrypt.h>
#include <shellscalingapi.h>
#include <d3d11.h>
#include <dxgi1_6.h>
// 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;