Jump to content
  • Advertisement
Sign in to follow this  
DustinB

[D3D12] Acquiring IDXGIAdapter3 Interface from D3D12Device

This topic is 822 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!