0
\$\begingroup\$

EDIT: This is part of an upgrade from DirectX10 to DX11.

When I create a DirectX 11 device with D3D11CreateDevice(), it chooses a video adapter for me. I access this object like so:

// removed HRESULT checks for brevity- normally I print errors on failed hr

IDXGIDevice1*  pDXGIDevice = NULL;
HRESULT hr = mpDXDevice->QueryInterface( &pDXGIDevice );

IDXGIAdapter* pAdapter = NULL;
pDXGIDevice->GetAdapter( &pAdapter );

// save pAdapter

However, later, when I enumerate the adapters, this adapter is not on the list:

IDXGIDevice*  pDXGIDevice = NULL;
HRESULT hr = mpDXDevice->QueryInterface( &pDXGIDevice );

IDXGIAdapter* pAdapter;
hr = pDXGIDevice->GetParent(__uuidof(IDXGIAdapter), (void **)&pAdapter);

// so far so good: pAdapter matches my current adapter I saved from above

IDXGIFactory* pFactory;
pAdapter->GetParent(__uuidof(IDXGIFactory), (void **)&pFactory);

UINT i = 0;
while( SUCCEEDED( hr ) && hr != DXGI_ERROR_NOT_FOUND )
{
    IDXGIAdapter* padapter;
    hr = pFactory->EnumAdapters1( i, &padapter );

    // none of these padapters matches the current adapter!!
    i++;
}

After this section, I have a list of the enumerated adapters. My current adapter is not in the list! Instead there is a DIFFERENT adapter with the same name as my current one.

Most importantly (this is the part I actually need) if I call D3D11CreateDevice() with this enumerated (different) adapter specified, I get E_INVALIDARG.

What am I doing wrong to generate these alternative, invalid adapters?

\$\endgroup\$
4
  • \$\begingroup\$ How are you comparing the adapters? \$\endgroup\$ Aug 25 '16 at 6:40
  • \$\begingroup\$ Pointer equality! Maybe that's a mistake - hope it's still relevant though :D \$\endgroup\$
    – Raptormeat
    Aug 25 '16 at 7:59
  • \$\begingroup\$ Maybe you can explain why are you doing this? You already have the adapter so you can just query it directly for information without having to look it up in the enumeration. Pointer equality is unreliable with COM objects. The only way to really tell if two DXGI adapters are the same thing is to compare the DXGI_ADAPTER_DESC.AdapterLuid. \$\endgroup\$ Aug 25 '16 at 16:38
  • \$\begingroup\$ The critical part is being able to create a D3D11Device with a specified adapter. My customers need this as an option in case they want to be able to switch from the default one chosen. Sounds like the pointer comparison is a red herring. \$\endgroup\$
    – Raptormeat
    Aug 25 '16 at 19:39
0
\$\begingroup\$

Ok I got it. Sorry for the misleading question but the major problem turned out to be creating a D3D Device with a supplied adapter. The point about the enumerated adapters being "different" was wrong on my part.

Per the documentation on D3D11CreateDevice:

If you set the pAdapter parameter to a non-NULL value, you must also set the DriverType parameter to the D3D_DRIVER_TYPE_UNKNOWN value. If you set the pAdapter parameter to a non-NULL value and the DriverType parameter to the D3D_DRIVER_TYPE_HARDWARE value, D3D11CreateDevice returns an HRESULT of E_INVALIDARG.

Setting the driver type to unknown fixed this problem!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.