Skip to content

Graphics Device API

Tiago Jose Sousa Magalhães edited this page Dec 22, 2019 · 25 revisions

This page contains all information regarding the Graphics Device abstraction API.

This interface creates an abstraction layer around a Direct3D device and the data associated with it, on a fundamental level it stores and has methods for interfacing with the device. However, it also keeps data directly associated with it such as command queues and descriptors sizes, the decision to include this kind of data was made on the basis of the fact that these structures are unique to the GPU/device that created them and as such there is an underlying thigh coupling between these components.

Namespace:DXR

Header:Core/Components/GraphicsDevice.hpp

Structures

DescriptorSizes

struct DescriptorSizes
{
	UINT64 RTV;
	UINT64 CBV_SRV_UAV;
	UINT64 DSV;
	UINT64 Sampler;
};
Name Type Description
RTV UINT64 Size in bytes of a Render Target View Descriptor
CBV_SRV_UAV UINT64 Size in bytes of a Constant Buffer View Descriptor, Shader Resource View Descriptor or Unordered Access View Descriptor
DSV UINT64 Size in bytes of a Depth Stencil View Descriptor
Sampler UINT64 Size in bytes of a Sampler Descriptor

Public Member Data

Name Type Description
supported_mssa_levels vector<UINT8> Array containing all the MSAA sample counts that the device supports

Private Member Data

Name Type Description
m_minimum_feature_level D3D_FEATURE_LEVEL Direct3D feature level that the system will use, by this default feature level 11.0 is used
m_dxgi_factory ComPtr<IDXGIFactory2> Smart COM Interface Pointer to a DXGI Factory
m_device ComPtr<ID3D12Device> Smart COM Interface Pointer to a Direct3D 12 Device, this device is the one that all methods will operate on
descriptorSizes DescriptorSizes Structure containing the sizes in bytes of the descriptors of the GPU in usage
m_graphics_command_queue CommandQueue* Owning pointer to a command queue, this particular command queue is the one associated with graphics operations

Public Methods

Default Constructor

Prototype

GraphicsDevice()

Description

Default constructor for the Graphics Device, GPU is auto-selected by the framework. Currently, GPU auto-selection relies on picking the GPU Windows has assigned as default, this is usually the GPU that handles the rendering of the desktop.

Usage

...
DXR::GraphicsDevice device;
...

GPU Selection Non-default constructor

Prototype

GraphicsDevice(UINT8 DeviceIndex);

Description

Constructor for the Graphics Device, the GPU used in this device is selected by its index.

Parameters

Parameter Name Type Description
DeviceIndex UINT8 Controls the index of the GPU the device is created with, 0 is the default system GPU, anything else will depend on the system hardware configuration

Usage

...
DXR::GraphicsDevice device(1);
...

operator->

Prototype

ID3D12Device* operator->() const

Description

Allows us to interface directly with the Direct3D device COM interface API through the usage of the drill-down behavior present in operator->.

Return Value

  • Type:ID3D12Device*
  • Description: returns the Direct3D Device COM interface associated with the device instance.

Usage

...
DXR::GraphicsDevice device;
device->GetNodeCount();
...

GetDXGIFactory

Prototype

IDXGIFactory2* GetDXGIFactory() const

Description

Getter for the DXGI factory the device has created

Return Value

  • Type:IDXGIFactory2*
  • Description:DXGI Factory the device has created

Usage

...
DXR::GraphicsDevice device;
IDXGIFactory2* factory = device.GetDXGIFactory();
...

GetDescriptorSizes

Prototype

DescriptorSizes GetDescriptorSizes()const;

Description

Fetches the sizes in bytes of the descriptors for the GPU in usage

Return Value

  • Type:DescriptorSizes
  • Description: Struct containing the size in bytes of the various descriptors

Usage

...
DXR::GraphicsDevice device;
DXR::DescriptorSizes sizes = device.GetDescriptorSizes();
UINT64 RTV_descriptor_size = sizes.RTV;
...

CheckSupportedMSAALevels

Prototype

void CheckSupportedMSAALevels(DXGI_FORMAT backbufferFormat);

Description

Checks the GPU MSAA sample count support for a given backbuffer format. Results are accessible through the public vector containing supported MSAA sample counts.

Parameters

Parameter Name Type Description
backbufferFormat DXGI_FORMAT Backbuffer format against whom MSAA sample count support is checked against

Usage

...
device.CheckSupportedMSAALevels(DXGI_FORMAT_R8G8B8A8_UNORM);
std::vector<UINT8> supported_quality_levels = device.supported_mssa_levels;
...

GetGraphicsCommandQueue

Prototype

CommandQueue* GetGraphicsCommandQueue();

Description

Obtains a pointer to the main graphics command queue object of the GPU.

Return Value

  • Type:CommandQueue*
  • Description: Pointer to a CommandQueue object which is an abstraction around the Direct3D 12 command queue.

Usage

...
DXR::CommandQueue* queue = device.GetGraphicsCommandQueue();
...

CreateFence

Prototype

Fence CreateFence(UINT64 initialValue);

Description

Creates a Fence object which abstracts a Direct3D 12 fence.

Parameters

Parameter Name Type Description
initialValue UINT64 Initial value the fence will be created with

Return Value

  • Type:Fence
  • Description: Fence object used for synchronization

Usage

...
DXR::Fence fence = device.CreateFence(0);
fence.Advance();
fence.Signal();
...

CreateGraphicsCommandList

Prototype

GraphicsCommandList CreateGraphicsCommandList();

Description

Create a GraphicsCommandList object which is an abstraction around the Direc3D 12 graphics command list.

Return Value

  • Type: GraphicsCommandList
  • Description: GraphicsCommandList object which is used to send graphics related commands to the GPU.

Usage

...
DXR::GraphicsCommandList command_list = device.CreateGraphicsCommandList();
...

CreateSwapchain

Prototype

Swapchain CreateSwapchain(Window& window, UINT refreshRate, GraphicsCommandList& commandList);

Description

Used to create a Swapchain, the swapchain handles switching rendering buffers to avoid flickering caused by rendering mid frame draw. The Swapchain object is an abstraction around several Direct3D 12 and DXGI constructs that are required for the usage of such an effect.

Parameters

Parameter Name Type Description
window Window Windows window the swapchain will be associated with
refreshRate UINT Refresh rate the swapchain should run at
commandList GraphicsCommandList Command list used to issue commands to the GPU that are required for the creation of the swapchain and its resources

Return Value

  • Type:Swapchain
  • Description: Swapchain object, which is an implementation of the swapchain effect

Usage

...
DXR::Swapchain swapchain = device.CreateSwapchain(window,60,command_list);
...

CreateRenderTargetViewDescriptorHeap

Prototype

DescriptorHeap CreateRenderTargetViewDescriptorHeap(const UINT descriptorCount);

Description

Creates a DescriptorHeap object that will contain render target descriptors. DescriptorHeap is an abstraction around the Direct3D 12 Descriptor Heap interface.

Parameters

Parameter Name Type Description
descriptorCount UINT Number of slots for descriptors the descriptor heap will contain

Return Value

  • Type:DescriptorHeap
  • Description: DescriptorHeap object specialized to contain only render target descriptors.

Usage

...
DXR::DescriptorHeap RTV_heap = device.CreateRenderTargetViewDescriptorHeap(2);
...

CreateDepthStencilBufferDescriptorHeap

Prototype

DescriptorHeap CreateDepthStencilBufferDescriptorHeap(const UINT descriptorCount);

Description

Creates a DescriptorHeap object that will contain depth stencil buffer descriptors. DescriptorHeap is an abstraction around the Direct3D 12 Descriptor Heap interface.

Parameters

Parameter Name Type Description
descriptorCount UINT Number of slots for descriptors the descriptor heap will contain

Return Value

  • Type:DescriptorHeap
  • Description: DescriptorHeap object specialized to contain only depth stencil buffer descriptors.

Usage

...
DXR::DescriptorHeap DSV_heap = device.CreateDepthStencilBufferDescriptorHeap(1);
...

CreateConstantBufferDescriptorHeap

Prototype

DescriptorHeap CreateConstantBufferDescriptorHeap(const UINT descriptorCount, D3D12_DESCRIPTOR_HEAP_FLAGS flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE);

Description

Creates a DescriptorHeap object that will contain constant buffer descriptors. DescriptorHeap is an abstraction around the Direct3D 12 Descriptor Heap interface.

Parameters

Parameter Name Type Description
descriptorCount UINT Number of slots for descriptors the descriptor heap will contain
flags D3D12_DESCRIPTOR_HEAP_FLAGS Flags used for the creation of the descriptor heap, by default the flag D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE is used, this flag configures the constant buffers to be visible inside of shaders

Return Value

  • Type:DescriptorHeap
  • Description:DescriptorHeap object specialized to contain only constant buffer descriptors.

Usage

...
DXR::DescriptorHeap CB_heap = device.CreateConstantBufferDescriptorHeap(1);
...

Private Methods

CreateDXGIFactory

Prototype

void CreateDXGIFactory();

Description

Handles creating the DXGI factory contained in the member variable m_dxgi_factory.

Usage

...
this->CreateDXGIFactory();
this->m_dxgi_factory->...;
...

CreateDefaultD3D12Device

Prototype

void CreateDefaultD3D12Device();

Description

Handles crating the Direct3D Device contained in the member variable m_device. The device present in system slot 0 is selected when this method is used.

Usage

...
this->CreateDefaultD3D12Device();
this->m_device->...;
...

CreateD3D12Device

Prototype

void CreateD3D12Device(UINT8 deviceIndex);

Description

Handles crating the Direct3D device contained in the member variable m_device. The device is selected through its index, with it being passed into this function via the parameter.

Parameters

Parameter Name Type Description
deviceIndex UINT8 Index of the GPU to use to create the device

Usage

...
this->CreateD3D12Device(0);
this->m_device->...;
...

GetGraphicsAdapterList

Prototype

std::vector<WRL::ComPtr<IDXGIAdapter>> GetGraphicsAdapterList() const;

Description

Fetches the list of GPU adapters present in the system.

Return Value

  • Type: std::vector<WRL::ComPtr<IDXGIAdapter>>
  • Description: Vector of COM interface smart pointers to DXGI adapters, these are the GPU adapters present in the system.

Usage

...
std::vector<WRL::ComPtr<IDXGIAdapter>> adapters = this->GetGraphicsAdapterList();
for(WRL::ComPtr<IDXGIAdapter>& adapter:adapters)
{
	adapter->...;
}
...

QueryAllDescriptorSizes

Prototype

void QueryAllDescriptorSizes();

Description

Handles creating the member variable descriptor_sizes which contains the size in bytes of the various descriptor types.

Usage

...
this->QueryAllDescriptorSizes();
UINT64 RTV_size = this->descriptor_sizes.RTV;
...

QueryDescriptorSize

Prototype

UINT64 QueryDescriptorSize(D3D12_DESCRIPTOR_HEAP_TYPE descriptorType) const;

Description

Fetches the size in bytes of a specific descriptor type.

Parameters

Parameter Name Type Description
descriptorType D3D12_DESCRIPTOR_HEAP_TYPE Type of descriptor to fetch the size of

Return Value

  • Type: UINT64
  • Description: Size in bytes of the requested descriptor

Usage

...
UINT64 RTV_size = this->QueryDescriptorSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
...

CreateGraphicsCommandQueue

Prototype

inline void CreateGraphicsCommandQueue();

Description

Handle creating the GPU graphics command queue stored in the member variable m_graphics_command_queue.

Usage

...
this->CreateGraphicsCommandQueue();
this->m_graphics_command_queue->...;
...
Clone this wiki locally