Reputation: 21956
My code calls D3D11CreateDevice
like that:
HRESULT hr = D3D11CreateDevice( nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr,
flags, levels.data(), levelsCount, D3D11_SDK_VERSION,
&g_device, &g_featureLevel, &g_context );
The documentation says about the first argument “Pass NULL to use the default adapter”, so far so good.
Recently I received a bug report from a user who has 3 adapters (2 discrete ones, and one integrated in the CPU), with a very reasonable complain they can’t select which of them is used by my software.
How does Windows selects which of them is the default, and how can user affect that setting?
Upvotes: 0
Views: 289
Reputation: 41127
The default device is typically controlled by settings from the user.
For "Hybrid graphics" scenarios typically on a laptop, the decision is up to the hardware vendor's software to pick the 'default' which changes from app to app. To influence this, you can export special variables from your program but this only provides the defaults as the hardware vendor settings can override it.
// Indicates to hybrid graphics systems to prefer the discrete part by default
extern "C"
{
__declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
__declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
}
With Windows 10 (15063) or later you can use IDXGIFactory6::EnumAdapterByGpuPreference
to enumerate by DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE
or DXGI_GPU_PREFERENCE_MINIMUM_POWER
rather than rely on the 'default' logic.
Upvotes: 1