Sign in to follow this  
DustinB

[D3D12] Acquiring IDXGIAdapter3 Interface from D3D12Device

Recommended Posts

Many D3D12 guides on memory management best practices I have encountered thus far have recommend keeping track of available video/system memory using IDXGIAdapter3::QueryVideoMemoryInfo in order to prevent resource allocation on full heaps.  My current setup passes a ID3D12Device pointer to resource allocation classes.  It would be useful to be able to acquire the IDXGIAdapter3 interface directly from the D3D12Device, and indeed, the Microsoft documentation seems to suggest this is possible by first acquiring an IDXGIDevice interface from the D3D12Device, and then acquiring an IDXGIAdapter from the IDXGIDevice interface like so:

ID3D12Device * device = CreateD3D12Device();

IDXGIDevice * pDXGIDevice;
device.Get()->QueryInterface(IID_PPV_ARGS(&pDXGIDevice));  //<-- E_NOINTERFACE Error result.


//-- That's too bad because I would really like to do the following:
{
  IDXGIAdapter * pDXGIAdapter;
  pDXGIDevice->GetAdapter(&pDXGIAdapter);

  // Hopefully it's possible to acquire a IDXGIAdapter3 from our IDXGIAdapter interface?
  IDXGIAdapter3 * pDXGIAdapter3;
  pDXGIAdapter->QueryInterface(IID_PPV_ARGS(&pDXGIAdapter3);

  // Now I can query video/system memory usage.
  pDXGIAdapter3->QueryVideoMemoryInfo(...);
}


This doesn't seem to be possible, as no IDXGIDevice interface can be acquired from the D3D12Device.  Has anyone found a work around to acquiring the IDXGIAdapter3 interface from their D3D12Device?  Perhaps there is a global D3D function call to do this? 

 

There are only two other workarounds I know of, creating a new type that stuffs the IDXGIAdapter3 with the D3D12Device and pass that around to required resource allocating classes, or register an event handler to fire with IDXGIAdapter3::RegisterVideoMemoryBudgetChangeNotificationEvent, which is much more elegant than the previous method, but a little overkill at the moment.

 

Any suggestions?  Thanks. 

Edited by DustinB

Share this post


Link to post
Share on other sites

If you want to retrieve back the dxgi adapter you used to create the d3d12 device, you have to call ID3D12Device::GetAdapterLuid. Then you pass the LUID to IDXGIFactory4::EnumAdapterByLuid .

 

Please note the IDXGIFactory4::EnumAdapterByLuid remarks:

 

For Direct3D 12, it's no longer possible to backtrack from a device to the IDXGIAdapter that was used to create it. IDXGIFactory4::EnumAdapterByLuid enables an app to retrieve information about the adapter where a D3D12 device was created. IDXGIFactory4::EnumAdapterByLuid is designed to be paired withID3D12Device::GetAdapterLuid. For more information, see DXGI 1.4 Improvements.

Edited by Alessio1989

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this