From c83eaaa51c260c3844baaf1cb76de63e0f096cea Mon Sep 17 00:00:00 2001 From: Lin Date: Sun, 21 Mar 2021 20:40:23 -0700 Subject: [PATCH] libobs-d3d11: Default to Intel IGPU on IGPU+DGPU systems On systems that have both Intel iGPU and Intel dGPU at the same time, default/prioritize running OBS the iGPU instead to improve performance. The user can still choose the dGPU if they change the adapter index, but the adapter index will now be the second value instead of the first value. (-Jim) --- libobs-d3d11/d3d11-subsystem.cpp | 40 ++++++++++++++++++++++++++++++++ libobs-d3d11/d3d11-subsystem.hpp | 1 + 2 files changed, 41 insertions(+) diff --git a/libobs-d3d11/d3d11-subsystem.cpp b/libobs-d3d11/d3d11-subsystem.cpp index 5b2c722c5..4c2b60258 100644 --- a/libobs-d3d11/d3d11-subsystem.cpp +++ b/libobs-d3d11/d3d11-subsystem.cpp @@ -243,6 +243,45 @@ void gs_device::InitFactory() throw UnsupportedHWError("Failed to create DXGIFactory", hr); } +#define VENDOR_ID_INTEL 0x8086 +#define IGPU_MEM (512 * 1024 * 1024) + +void gs_device::ReorderAdapters(uint32_t &adapterIdx) +{ + std::vector adapterOrder; + ComPtr adapter; + DXGI_ADAPTER_DESC desc; + uint32_t iGPUIndex = 0; + bool hasIGPU = false; + bool hasDGPU = false; + int idx = 0; + + while (SUCCEEDED(factory->EnumAdapters(idx, &adapter))) { + if (SUCCEEDED(adapter->GetDesc(&desc))) { + if (desc.VendorId == VENDOR_ID_INTEL) { + if (desc.DedicatedVideoMemory <= IGPU_MEM) { + hasIGPU = true; + iGPUIndex = (uint32_t)idx; + } else { + hasDGPU = true; + } + } + } + + adapterOrder.push_back((uint32_t)idx++); + } + + /* Intel specific adapter check for Intel integrated and Intel + * dedicated. If both exist, then change adapter priority so that the + * integrated comes first for the sake of improving overall + * performance */ + if (hasIGPU && hasDGPU) { + adapterOrder.erase(adapterOrder.begin() + iGPUIndex); + adapterOrder.insert(adapterOrder.begin(), iGPUIndex); + adapterIdx = adapterOrder[adapterIdx]; + } +} + void gs_device::InitAdapter(uint32_t adapterIdx) { HRESULT hr = factory->EnumAdapters1(adapterIdx, &adapter); @@ -791,6 +830,7 @@ gs_device::gs_device(uint32_t adapterIdx) InitCompiler(); InitFactory(); + ReorderAdapters(adapterIdx); InitAdapter(adapterIdx); InitDevice(adapterIdx); device_set_render_target(this, NULL, NULL); diff --git a/libobs-d3d11/d3d11-subsystem.hpp b/libobs-d3d11/d3d11-subsystem.hpp index 4efbae86d..86f42fe06 100644 --- a/libobs-d3d11/d3d11-subsystem.hpp +++ b/libobs-d3d11/d3d11-subsystem.hpp @@ -1005,6 +1005,7 @@ struct gs_device { void InitCompiler(); void InitFactory(); + void ReorderAdapters(uint32_t &adapterIdx); void InitAdapter(uint32_t adapterIdx); void InitDevice(uint32_t adapterIdx);