4

I hope I'm posting on the right forum for this!

Recently I have started programming with the Directx 11 June (2010) SDK on VC++ 2010, on a Dell LapTop with a NVidia GeForce GT 630M GPU and a Intel HD 4000 chip.

One of the things you do, is to try and enumerate available adapters and outputs, and so on. Here's an example:

    IDXGIFactory1 *factory;
    CreateDXGIFactory1(__uuidof(IDXGIFactory1), (LPVOID *)&factory);
    IDXGIAdapter *adapter;
    factory->EnumAdapters(0, &adapter);
    DXGI_ADAPTER_DESC desc;
    adapter->GetDesc(&desc);

When I run this, the desc structure contains the information for my Intel HD chip, and NOT the information for my GPU!

Now, when I open my NVidia control panel, and select the GPU as the preferred processor, and re-run the sample, I get the info for my GPU in desc - which is right! And also, when I then try to enumerate outputs for this adapter, I find that there is at least one.

My question is: Is there a way to accomplish this programmatically, like in the DirectX 11 SDK, so that I don't have to set the setting in my NVidia control panel?

I went through the SDK code (for EmptyProject11), and somehow they "grab" the GPU instead of the Intel chip. I commented out all the code in the WinMain function, and inserted the above code, and it still grabbed the GPU! Is it something to do with the Project Setup, environment variables, command line arguments, or....? I mean how do they do it!?!?!?

I would appreciate any insight into this matter.

Thanks

  • There is a similar question here but I'm not sure it was resolved http://stackoverflow.com/questions/10535950/forcing-nvidia-gpu-programmatically-in-optimus-laptops/10545107#10545107 – jcoder May 03 '13 at 08:40

1 Answers1

0

You can run through all of the adapters presents and get information on them by looping through all possible adapters using the same function that you're already using:

HRESULT r = S_OK;
unsigned int adapterindex = 0;
std::unique_ptr<IDXGIAdapter, ReleaseDirectX> dxgiadapter = null;
// Save the result of EnumAdapters to r, and then check if it's S_OK
while ( ( r = factory->EnumAdapters( adapterindex, &dxgiadapter ) ) == S_OK ) {
    ++adapterindex;
     /* Work with your adapter here, particularly DXGI_ADAPTER_DESC */
}

Usually, you will have to choose the default one automatically or enumerate all of them and in some kind of settings panel let the user choose. The other way to do it is use the Adapter Description which has the most video memory. It's not a foolproof heuristic, but it's one I use to get the "best" (used liberally) video card for the system. More often than not, however, the default is the default for a reason.

Good luck!