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)
master
Lin 2021-03-21 20:40:23 -07:00 committed by Jim
parent 1e106c8bb8
commit c83eaaa51c
2 changed files with 41 additions and 0 deletions

View File

@ -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<uint32_t> adapterOrder;
ComPtr<IDXGIAdapter> 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);

View File

@ -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);