From fbce28226dfe6a50670aa53999fe4d47fed82f40 Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Thu, 4 Jun 2026 22:31:15 +0500 Subject: [PATCH] change(HardwareInfo/Windows): sort GPUs by performance, use smart pointers, log errors better Signed-off-by: Octol1ttle (cherry picked from commit f99a0883af9201f2acc76673a15b4f3fdfef2c73) --- launcher/HardwareInfo.cpp | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/launcher/HardwareInfo.cpp b/launcher/HardwareInfo.cpp index 425f07a09..36b6f7783 100644 --- a/launcher/HardwareInfo.cpp +++ b/launcher/HardwareInfo.cpp @@ -65,8 +65,11 @@ bool readFromOutput(const char* command, F function) #endif #include -#include "dxgi.h" -#include "windows.h" +#include +#include + +#include +using Microsoft::WRL::ComPtr; QString HardwareInfo::cpuInfo() { @@ -104,29 +107,28 @@ uint64_t HardwareInfo::availableRamMiB() QStringList HardwareInfo::gpuInfo() { - IDXGIFactory* factory = nullptr; - if (CreateDXGIFactory(__uuidof(IDXGIFactory), reinterpret_cast(&factory)) != S_OK) { // NOLINT(*-pro-type-reinterpret-cast) - qWarning() << "Could not create DXGI factory"; + ComPtr factory; + HRESULT hr = CreateDXGIFactory1(IID_PPV_ARGS(&factory)); + if (FAILED(hr)) { + qWarning() << "Could not create DXGI factory:" << Qt::hex << hr; return { "GPU discovery failed: could not create DXGI factory" }; } UINT i = 0; - IDXGIAdapter* adapter = nullptr; + ComPtr adapter; QStringList out; - - while (factory->EnumAdapters(i, &adapter) != DXGI_ERROR_NOT_FOUND) { + while (factory->EnumAdapterByGpuPreference(i, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, IID_PPV_ARGS(&adapter)) != DXGI_ERROR_NOT_FOUND) { DXGI_ADAPTER_DESC desc; - if (adapter->GetDesc(&desc) != S_OK) { - qWarning() << "Could not get DXGI adapter description"; - } else { + hr = adapter->GetDesc(&desc); + if (SUCCEEDED(hr)) { out << "GPU: " + QString::fromWCharArray(desc.Description); // NOLINT(*-pro-bounds-array-to-pointer-decay, *-no-array-decay) + } else { + qWarning() << "Could not get DXGI adapter description:" << Qt::hex << hr; } - adapter->Release(); ++i; } - factory->Release(); return out; }