-
Notifications
You must be signed in to change notification settings - Fork 3
Graphics Device API
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
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 |
Name | Type | Description |
---|---|---|
supported_mssa_levels |
vector<UINT8> |
Array containing all the MSAA sample counts that the device supports |
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 |
GraphicsDevice()
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.
...
DXR::GraphicsDevice device;
...
GraphicsDevice(UINT8 DeviceIndex);
Constructor for the Graphics Device, the GPU used in this device is selected by its index.
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 |
...
DXR::GraphicsDevice device(1);
...
ID3D12Device* operator->() const
Allows us to interface directly with the Direct3D device COM interface API through the usage of the drill-down behavior present in operator->.
- Type:
ID3D12Device*
- Description: returns the Direct3D Device COM interface associated with the device instance.
...
DXR::GraphicsDevice device;
device->GetNodeCount();
...
IDXGIFactory2* GetDXGIFactory() const
Getter for the DXGI factory the device has created
- Type:
IDXGIFactory2*
- Description:DXGI Factory the device has created
...
DXR::GraphicsDevice device;
IDXGIFactory2* factory = device.GetDXGIFactory();
...
DescriptorSizes GetDescriptorSizes()const;
Fetches the sizes in bytes of the descriptors for the GPU in usage
- Type:
DescriptorSizes
- Description: Struct containing the size in bytes of the various descriptors
...
DXR::GraphicsDevice device;
DXR::DescriptorSizes sizes = device.GetDescriptorSizes();
UINT64 RTV_descriptor_size = sizes.RTV;
...
void CheckSupportedMSAALevels(DXGI_FORMAT backbufferFormat);
Checks the GPU MSAA sample count support for a given backbuffer format. Results are accessible through the public vector containing supported MSAA sample counts.
Parameter Name | Type | Description |
---|---|---|
backbufferFormat |
DXGI_FORMAT |
Backbuffer format against whom MSAA sample count support is checked against |
...
device.CheckSupportedMSAALevels(DXGI_FORMAT_R8G8B8A8_UNORM);
std::vector<UINT8> supported_quality_levels = device.supported_mssa_levels;
...
CommandQueue* GetGraphicsCommandQueue();
Obtains a pointer to the main graphics command queue object of the GPU.
- Type:
CommandQueue*
- Description: Pointer to a CommandQueue object which is an abstraction around the Direct3D 12 command queue.
...
DXR::CommandQueue* queue = device.GetGraphicsCommandQueue();
...
Fence CreateFence(UINT64 initialValue);
Creates a Fence object which abstracts a Direct3D 12 fence.
Parameter Name | Type | Description |
---|---|---|
initialValue |
UINT64 |
Initial value the fence will be created with |
- Type:
Fence
- Description: Fence object used for synchronization
...
DXR::Fence fence = device.CreateFence(0);
fence.Advance();
fence.Signal();
...
GraphicsCommandList CreateGraphicsCommandList();
Create a GraphicsCommandList object which is an abstraction around the Direc3D 12 graphics command list.
- Type:
GraphicsCommandList
- Description: GraphicsCommandList object which is used to send graphics related commands to the GPU.
...
DXR::GraphicsCommandList command_list = device.CreateGraphicsCommandList();
...
Swapchain CreateSwapchain(Window& window, UINT refreshRate, GraphicsCommandList& commandList);
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.
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 |
- Type:
Swapchain
- Description: Swapchain object, which is an implementation of the swapchain effect
...
DXR::Swapchain swapchain = device.CreateSwapchain(window,60,command_list);
...
DescriptorHeap CreateRenderTargetViewDescriptorHeap(const UINT descriptorCount);
Creates a DescriptorHeap object that will contain render target descriptors. DescriptorHeap is an abstraction around the Direct3D 12 Descriptor Heap interface.
Parameter Name | Type | Description |
---|---|---|
descriptorCount |
UINT |
Number of slots for descriptors the descriptor heap will contain |
- Type:
DescriptorHeap
- Description: DescriptorHeap object specialized to contain only render target descriptors.
...
DXR::DescriptorHeap RTV_heap = device.CreateRenderTargetViewDescriptorHeap(2);
...
DescriptorHeap CreateDepthStencilBufferDescriptorHeap(const UINT descriptorCount);
Creates a DescriptorHeap object that will contain depth stencil buffer descriptors. DescriptorHeap is an abstraction around the Direct3D 12 Descriptor Heap interface.
Parameter Name | Type | Description |
---|---|---|
descriptorCount |
UINT |
Number of slots for descriptors the descriptor heap will contain |
- Type:
DescriptorHeap
- Description: DescriptorHeap object specialized to contain only depth stencil buffer descriptors.
...
DXR::DescriptorHeap DSV_heap = device.CreateDepthStencilBufferDescriptorHeap(1);
...
DescriptorHeap CreateConstantBufferDescriptorHeap(const UINT descriptorCount, D3D12_DESCRIPTOR_HEAP_FLAGS flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE);
Creates a DescriptorHeap object that will contain constant buffer descriptors. DescriptorHeap is an abstraction around the Direct3D 12 Descriptor Heap interface.
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 |
- Type:
DescriptorHeap
- Description:DescriptorHeap object specialized to contain only constant buffer descriptors.
...
DXR::DescriptorHeap CB_heap = device.CreateConstantBufferDescriptorHeap(1);
...
void CreateDXGIFactory();
Handles creating the DXGI factory contained in the member variable m_dxgi_factory
.
...
this->CreateDXGIFactory();
this->m_dxgi_factory->...;
...
void CreateDefaultD3D12Device();
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.
...
this->CreateDefaultD3D12Device();
this->m_device->...;
...
void CreateD3D12Device(UINT8 deviceIndex);
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.
Parameter Name | Type | Description |
---|---|---|
deviceIndex |
UINT8 |
Index of the GPU to use to create the device |
...
this->CreateD3D12Device(0);
this->m_device->...;
...
std::vector<WRL::ComPtr<IDXGIAdapter>> GetGraphicsAdapterList() const;
Fetches the list of GPU adapters present in the system.
- 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.
...
std::vector<WRL::ComPtr<IDXGIAdapter>> adapters = this->GetGraphicsAdapterList();
for(WRL::ComPtr<IDXGIAdapter>& adapter:adapters)
{
adapter->...;
}
...
void QueryAllDescriptorSizes();
Handles creating the member variable descriptor_sizes
which contains the size in bytes of the various descriptor types.
...
this->QueryAllDescriptorSizes();
UINT64 RTV_size = this->descriptor_sizes.RTV;
...
UINT64 QueryDescriptorSize(D3D12_DESCRIPTOR_HEAP_TYPE descriptorType) const;
Fetches the size in bytes of a specific descriptor type.
Parameter Name | Type | Description |
---|---|---|
descriptorType |
D3D12_DESCRIPTOR_HEAP_TYPE |
Type of descriptor to fetch the size of |
- Type: UINT64
- Description: Size in bytes of the requested descriptor
...
UINT64 RTV_size = this->QueryDescriptorSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
...
inline void CreateGraphicsCommandQueue();
Handle creating the GPU graphics command queue stored in the member variable m_graphics_command_queue
.
...
this->CreateGraphicsCommandQueue();
this->m_graphics_command_queue->...;
...