Lecture #12. DX12 initialization

Computer graphics in Game development

Ivan Belyavtsev

21.10.2022

Initialization plan

  • Enable a validation layer
  • Enumerate hardware adapters
  • Create a device object
  • Create a command queue
  • Create a swap chain and bind it to window

Validation layer

Validation layer is a way to check a correctness of API usage.

To engage API validation:

  1. Call D3D12GetDebugInterface function to get debug controller
  2. Call EnableDebugLayer method of the debug controller
  3. Use DXGI_CREATE_FACTORY_DEBUG flag in further DXGI factory creation [1]

Where to find validation layer messages

Visual studio: Output window, Show output from Debug

CLion: Debugger, LLDB window

Enumeration of hardware adapters

  • Use CreateDXGIFactory* function to create a DXGI factory (don’t forget about flags)
  • Call EnumAdapters* method to find HW
  • EnumAdapters for adapter #0 gives us a pointer to the primary display adapter [1]

Device creation

Device is a represenation of GPU in DirectX API

To create a device:

  • Call D3D12CreateDevice function to create a DX12 device
  • Make sure that minimum future level is D3D_FEATURE_LEVEL_11_0

Command queue

Command queue accumulates command lists to execute on GPU. GPU is able to maintain several commands queue for different purposes. Direct queue is the most powerful type of queues.

  • Call CreateCommandQueue method of DX12 device to create a direct queue [1]

Swap chain idea

Swap chain idea

Swap chain

  • Call CreateSwapChainForHwnd method of the DXGI factory with Direct queue, window handler and swap chain descriptor
  • Call MakeWindowAssociation method of the DXGI factory with window handler and DXGI_MWA_NO_ALT_ENTER
  • Cast the swap chain pointer to required COM interface [1]

Lab: 3.02. load_pipeline: init DX12 and swap chain

  1. Enable a validation layer
  2. Enumerate hardware adapters
  3. Create a device object
  4. Create a command queue
  5. Create a swap chain and bind it to window
  6. Bring everything together in load_pipeline method

References

1.
Satran M. et al. Direct3D 12 programming guide [Electronic resource]. 2019. URL: https://docs.microsoft.com/en-us/windows/win32/direct3d12/directx-12-programming-guide.