3

I am working with DXGI and DirectX 11 using C++. At the moment I experimenting with IDXGIFactory. After some research and reading the documentation I noticed there are different versions.

IDXGIFactory IDXGIFactory1 IDXGIFactory2 IDXGIFactory3 IDXGIFactory4 IDXGIFactory5

But I also noticed that there are only methods for creating such an instance for the first 3 IDXGIFactory versions but not for the last 3.

CreateDXGIFactory CreateDXGIFactory1 CreateDXGIFactory2

There is no CreateDXGIFactory3, CreateDXGIFactory4 or CreateDXGIFactory5.

So my question is how to create an IDXGIFactory5 instance?

Furthermore I am wondering if I cannot instantiate an instance of IDXGIFactory5 myself how I can force D3D11CreateDevice to create and use an IDXGIFactory5 internally so I can retrieve an reference from the resulting ID3D11Device?

EDIT:

OK now I understand the different CreateDXGIFactory functions and how to create an IDXGIFactory5 instance. But after understanding this I got the next problem. The documentation from IDXGIAdapter2 says I should use IDXGIFactory1::EnumAdapters1 to query an instance. But looking at the function signature I am only getting an IDXGIAdapter1.

HRESULT EnumAdapters1(
    UINT Adapter,
    [out] IDXGIAdapter1 **ppAdapter
);

How do I enumerate IDXGIAdapter2 instances?

Michael
  • 595
  • 5
  • 19
  • 1
    ``CreateDXGIFactory`` was the original DXGI 1.0 factory function for Direct3D 10. For Direct3D 11, you should always use ``CreateDXGIFactory1`` and create a ``IDXGIFactory1`` or later interface. For debug builds on Windows 8.1 and Windows 10, you can make use of ``CreateDXGIFactory2`` to create a debug version of ``IDXGIFactory1`` or later--see [this template](https://github.com/walbourn/directx-vs-templates/blob/master/d3d11game_uwp_dr/DeviceResources.cpp) for an example.. For DIrect3D 12, you can assume ``CreateDXGIFactory2`` and ``IDXGIFactory4`` or later is supported. – Chuck Walbourn Feb 21 '17 at 00:21

2 Answers2

4

The numbers on CreateDXGIFactory are related in changes to the signature of that function, not to the interfaces implemented by the returned COM object. In particular, CreateDXGIFactory2 added the Flags parameter.

You would obtain a reference to the desired interface in the same way as any other COM object. Either:

  1. Pass the IID of the desired interface as riid, then cast the returned object to that interface OR

  2. Pass the IID of an interface such as IUnknown. Call QueryInterface on the returned object to obtain the desired interface. This might be useful if you want to support several versions, as you could try version 5 and if that is not found fall back to version 4, for example.

For example, option 1 might look like:

IDXGIFactory2* factory;
HRESULT hr = CreateDXGIFactory2(0, IID_IDXGIFactory5, (void**)&factory);
if(SUCCEEDED(hr))
{
  // ...
}
Dark Falcon
  • 43,592
  • 5
  • 83
  • 98
4
  1. The IDXGIFactory5 interface inherits from IDXGIFactory4
  2. The IDXGIFactory4 interface inherits from IDXGIFactory3
  3. The IDXGIFactory3 interface inherits from IDXGIFactory2
  4. The IDXGIFactory2 interface inherits from IDXGIFactory1

You have to include the appropriate header for the interface type

#include <DXGI1_5.h>

And have declared an instance of the proper pointer type

IDXGIFactory5* outPtr = nullptr; \\this really should be a CComPtr

And call CreateDXGIFactory1(__uuidof(IDXGIFactory5),&outPtr);. If it succeeds you've got an IDXGIFactory5 that has all the methods that an IDXGIFactory4, IDXGIFactory3, IDXGIFactory2, and IDXGIFactory1 has, plus it's own method of CheckFeatureSupport. The CreateDXGIFactory1 and CreateDXGIFactory2 functions are just overloaded versions of CreateDXGIFactory for DXGI 1.1 - 1.5, however CreateDXGIFactory is for creating IDXGIFactory DXGI 1.0 objects. To create a DXGIFactory5 object you have to be using DXGI 1.5 (Windows 10 Direct3D 12). To get a better understanding of the purpose of the CheckFeatureSupport function and why you'd want it see this explanation of Direct3D 12 levels.

johnathan
  • 2,315
  • 13
  • 20