GameCodeR
GameCodeR

Reputation: 33

How to give an option to select graphics adapter in a DirectX 11 application?

I think I know how it should work - only it does not. I have a lenovo laptop with a 860m and an intel integrated card.

I can run my application from outside with both gpu, and everything works fine: the selected gpu will be the adapter with index 0, it has the laptop screen as output, etc.

However if I try to use the adapter with index 1 (if I run the app normally, that is the nvidia, if I run it with the nvidia gpu, that is the intel), IDXGIOutput::EnumOutputs does not find anything, so I can't configure the display settings properly.

I was thinking about simply skipping the configuration, or using the output from the other adapter - but then there is no way to filter out adapters without real output - e.g. my pc has an integrated card too, but it does not have a monitor physically connected, so using that should not be possible.

I also tried to find what exactly the "Run with graphical processor" context menu button does, but I could not find anything.

Goal is to give the user the ability to select adapter inside the application, his/her choices is saved to a config file, and would be used after restart - but I can't find the way to filter the possible adapters.

Upvotes: 3

Views: 2734

Answers (1)

Chuck Walbourn
Chuck Walbourn

Reputation: 41057

You likely have a 'heterogenous adapter' system (a.k.a. NVIDIA Optimus or AMD PowerXPress). These solutions have the driver manipulate the default adapter and the device enumeration to control which card is used. You really don't have any programmatic control over this, but you can inject something into your Win32 'classic' desktop application which will encourage the driver to select the discrete part:

// Indicates to hybrid graphics systems to prefer the discrete part by default
extern "C"
{
    __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
    __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
}

UPDATE With Windows 10 April 2018 Update (17134) or later, you can use the DXGI 1.6 interface EnumAdapterByGpuPreference. See GitHub for some example usage.

Upvotes: 6

Related Questions