LiteFX 0.3.1.2022
Computer Graphics Engine
LiteFX::Rendering::Backends::DirectX12Device Class Reference

Implements a DirectX 12 graphics device. More...

#include <dx12.hpp>

Inherits LiteFX::Rendering::GraphicsDevice< DirectX12GraphicsFactory, DirectX12Surface, DirectX12GraphicsAdapter, DirectX12SwapChain, DirectX12Queue, DirectX12RenderPass, DirectX12ComputePipeline, DirectX12Barrier >, and LiteFX::Resource< THandle >.

Classes

class  DirectX12DeviceImpl
 

Public Member Functions

 DirectX12Device (const DirectX12Backend &backend, const DirectX12GraphicsAdapter &adapter, UniquePtr< DirectX12Surface > &&surface)
 Creates a new device instance. More...
 
 DirectX12Device (const DirectX12Backend &backend, const DirectX12GraphicsAdapter &adapter, UniquePtr< DirectX12Surface > &&surface, const Format &format, const Size2d &frameBufferSize, const UInt32 &frameBuffers, const UInt32 &globalBufferHeapSize=524287, const UInt32 &globalSamplerHeapSize=2048)
 Creates a new device instance. More...
 
 DirectX12Device (const DirectX12Device &)=delete
 
 DirectX12Device (DirectX12Device &&)=delete
 
virtual ~DirectX12Device () noexcept
 
virtual const DirectX12Backendbackend () const noexcept
 Returns the backend from which the device got created. More...
 
virtual const ID3D12DescriptorHeap * globalBufferHeap () const noexcept
 Returns the global descriptor heap. More...
 
virtual const ID3D12DescriptorHeap * globalSamplerHeap () const noexcept
 Returns the global sampler heap. More...
 
virtual void allocateGlobalDescriptors (const DirectX12DescriptorSet &descriptorSet, UInt32 &bufferOffset, UInt32 &samplerOffset) const
 Allocates a range of descriptors in the global descriptor heaps for the provided descriptorSet . More...
 
virtual void releaseGlobalDescriptors (const DirectX12DescriptorSet &descriptorSet) const noexcept
 Releases a range of descriptors from the global descriptor heaps. More...
 
virtual void updateBufferDescriptors (const DirectX12DescriptorSet &descriptorSet, const UInt32 &firstDescriptor, const UInt32 &descriptors) const noexcept
 Updates a range of descriptors in the global buffer descriptor heap with the descriptors from descriptorSet . More...
 
virtual void updateSamplerDescriptors (const DirectX12DescriptorSet &descriptorSet, const UInt32 &firstDescriptor, const UInt32 &descriptors) const noexcept
 Updates a sampler descriptors in the global buffer descriptor heap with a descriptor from descriptorSet . More...
 
virtual void bindDescriptorSet (const DirectX12CommandBuffer &commandBuffer, const DirectX12DescriptorSet &descriptorSet, const DirectX12PipelineState &pipeline) const noexcept
 Binds the descriptors of the descriptor set to the global descriptor heaps. More...
 
virtual void bindGlobalDescriptorHeaps (const DirectX12CommandBuffer &commandBuffer) const noexcept
 Binds the global descriptor heap. More...
 
virtual DirectX12ComputePipelineblitPipeline () const noexcept
 Returns the compute pipeline that can be invoked to blit an image resource. More...
 
virtual DeviceStatestate () const noexcept override
 Returns the device state that can be used to manage resources. More...
 
virtual const DirectX12SwapChainswapChain () const noexcept override
 Returns the swap chain, that contains the back and front buffers used for presentation. More...
 
virtual DirectX12SwapChainswapChain () noexcept override
 Returns the swap chain, that contains the back and front buffers used for presentation. More...
 
virtual const DirectX12Surfacesurface () const noexcept override
 Returns the surface, the device draws to. More...
 
virtual const DirectX12GraphicsAdapteradapter () const noexcept override
 Returns the graphics adapter, the device uses for drawing. More...
 
virtual const DirectX12GraphicsFactoryfactory () const noexcept override
 Returns the factory instance, used to create instances from the device. More...
 
virtual const DirectX12QueuegraphicsQueue () const noexcept override
 Returns the instance of the queue, used to process draw calls. More...
 
virtual const DirectX12QueuetransferQueue () const noexcept override
 Returns the instance of the queue used for device-device transfers (e.g. between render-passes). More...
 
virtual const DirectX12QueuebufferQueue () const noexcept override
 Returns the instance of the queue used for host-device transfers. More...
 
virtual const DirectX12QueuecomputeQueue () const noexcept override
 Returns the instance of the queue used for compute calls. More...
 
virtual UniquePtr< DirectX12BarriermakeBarrier () const noexcept override
 
virtual MultiSamplingLevel maximumMultiSamplingLevel (const Format &format) const noexcept override
 
virtual void wait () const override
 Waits until the device is idle. More...
 
- Public Member Functions inherited from LiteFX::Rendering::GraphicsDevice< DirectX12GraphicsFactory, DirectX12Surface, DirectX12GraphicsAdapter, DirectX12SwapChain, DirectX12Queue, DirectX12RenderPass, DirectX12ComputePipeline, DirectX12Barrier >
virtual ~GraphicsDevice () noexcept=default
 
virtual const surface_typesurface () const noexcept=0
 Returns the surface, the device draws to. More...
 
virtual const adapter_typeadapter () const noexcept=0
 Returns the graphics adapter, the device uses for drawing. More...
 
virtual const swap_chain_typeswapChain () const noexcept=0
 Returns the swap chain, that contains the back and front buffers used for presentation. More...
 
virtual swap_chain_typeswapChain () noexcept=0
 Returns the swap chain, that contains the back and front buffers used for presentation. More...
 
virtual const factory_typefactory () const noexcept=0
 Returns the factory instance, used to create instances from the device. More...
 
virtual const command_queue_typegraphicsQueue () const noexcept=0
 Returns the instance of the queue, used to process draw calls. More...
 
virtual const command_queue_typetransferQueue () const noexcept=0
 Returns the instance of the queue used for device-device transfers (e.g. between render-passes). More...
 
virtual const command_queue_typebufferQueue () const noexcept=0
 Returns the instance of the queue used for host-device transfers. More...
 
virtual const command_queue_typecomputeQueue () const noexcept=0
 Returns the instance of the queue used for compute calls. More...
 
virtual UniquePtr< barrier_typemakeBarrier () const noexcept=0
 
- Public Member Functions inherited from LiteFX::Rendering::IGraphicsDevice
virtual ~IGraphicsDevice () noexcept=default
 
virtual DeviceStatestate () const noexcept=0
 Returns the device state that can be used to manage resources. More...
 
virtual const ISurfacesurface () const noexcept=0
 Returns the surface, the device draws to. More...
 
virtual const IGraphicsAdapteradapter () const noexcept=0
 Returns the graphics adapter, the device uses for drawing. More...
 
virtual const ISwapChainswapChain () const noexcept=0
 Returns the swap chain, that contains the back and front buffers used for presentation. More...
 
virtual ISwapChainswapChain () noexcept=0
 Returns the swap chain, that contains the back and front buffers used for presentation. More...
 
virtual const IGraphicsFactoryfactory () const noexcept=0
 Returns the factory instance, used to create instances from the device. More...
 
virtual const ICommandQueuegraphicsQueue () const noexcept=0
 Returns the instance of the queue, used to process draw calls. More...
 
virtual const ICommandQueuetransferQueue () const noexcept=0
 Returns the instance of the queue used for device-device transfers (e.g. between render-passes). More...
 
virtual const ICommandQueuebufferQueue () const noexcept=0
 Returns the instance of the queue used for host-device transfers. More...
 
virtual const ICommandQueuecomputeQueue () const noexcept=0
 Returns the instance of the queue used for compute calls. More...
 
UniquePtr< IBarriermakeBarrier () const noexcept
 Creates a memory barrier instance. More...
 
virtual MultiSamplingLevel maximumMultiSamplingLevel (const Format &format) const noexcept=0
 Queries the device for the maximum supported number of multi-sampling levels. More...
 
virtual void wait () const =0
 Waits until the device is idle. More...
 
- Public Member Functions inherited from LiteFX::Resource< THandle >
 Resource (const Resource &)=delete
 
 Resource (Resource &&)=delete
 
virtual ~Resource () noexcept=default
 
const THandle & handle () const noexcept override
 Returns the resource managed by the class. More...
 
- Public Member Functions inherited from LiteFX::IResource< THandle >
virtual ~IResource () noexcept=default
 
virtual const THandle & handle () const noexcept=0
 Returns the resource managed by the class. More...
 

Additional Inherited Members

- Public Types inherited from LiteFX::Rendering::GraphicsDevice< DirectX12GraphicsFactory, DirectX12Surface, DirectX12GraphicsAdapter, DirectX12SwapChain, DirectX12Queue, DirectX12RenderPass, DirectX12ComputePipeline, DirectX12Barrier >
using surface_type = DirectX12Surface
 
using adapter_type = DirectX12GraphicsAdapter
 
using swap_chain_type = DirectX12SwapChain
 
using command_queue_type = DirectX12Queue
 
using command_buffer_type = command_queue_type::command_buffer_type
 
using factory_type = DirectX12GraphicsFactory
 
using barrier_type = DirectX12Barrier
 
using descriptor_layout_type = factory_type::descriptor_layout_type
 
using vertex_buffer_type = factory_type::vertex_buffer_type
 
using index_buffer_type = factory_type::index_buffer_type
 
using buffer_type = factory_type::buffer_type
 
using image_type = factory_type::image_type
 
using sampler_type = factory_type::sampler_type
 
using render_pass_type = DirectX12RenderPass
 
using frame_buffer_type = render_pass_type::frame_buffer_type
 
using render_pipeline_type = render_pass_type::render_pipeline_type
 
using compute_pipeline_type = DirectX12ComputePipeline
 
using pipeline_layout_type = render_pipeline_type::pipeline_layout_type
 
using shader_program_type = render_pipeline_type::shader_program_type
 
using shader_program_type = render_pipeline_type::shader_program_type
 
using input_assembler_type = render_pipeline_type::input_assembler_type
 
using rasterizer_type = render_pipeline_type::rasterizer_type
 
- Protected Member Functions inherited from LiteFX::Resource< THandle >
 Resource (const THandle handle) noexcept
 Initializes the managed resource. More...
 
THandle & handle () noexcept override
 Returns the resource managed by the class. More...
 
virtual THandle & handle () noexcept=0
 Returns the resource managed by the class. More...
 

Detailed Description

Implements a DirectX 12 graphics device.

Constructor & Destructor Documentation

◆ DirectX12Device() [1/4]

DirectX12Device::DirectX12Device ( const DirectX12Backend backend,
const DirectX12GraphicsAdapter adapter,
UniquePtr< DirectX12Surface > &&  surface 
)
explicit

Creates a new device instance.

Parameters
backendThe backend from which the device got created.
adapterThe adapter the device uses for drawing.
surfaceThe surface, the device should draw to.

◆ DirectX12Device() [2/4]

DirectX12Device::DirectX12Device ( const DirectX12Backend backend,
const DirectX12GraphicsAdapter adapter,
UniquePtr< DirectX12Surface > &&  surface,
const Format &  format,
const Size2d frameBufferSize,
const UInt32 frameBuffers,
const UInt32 globalBufferHeapSize = 524287,
const UInt32 globalSamplerHeapSize = 2048 
)
explicit

Creates a new device instance.

Parameters
backendThe backend from which the device got created.
adapterThe adapter the device uses for drawing.
surfaceThe surface, the device should draw to.
formatThe initial surface format, device uses for drawing.
frameBufferSizeThe initial size of the frame buffers.
frameBuffersThe initial number of frame buffers.
globalBufferHeapSizeThe size of the global heap for constant buffers, shader resources and images.
globalSamplerHeapSizeThe size of the global heap for samplers.

◆ DirectX12Device() [3/4]

LiteFX::Rendering::Backends::DirectX12Device::DirectX12Device ( const DirectX12Device )
delete

◆ DirectX12Device() [4/4]

LiteFX::Rendering::Backends::DirectX12Device::DirectX12Device ( DirectX12Device &&  )
delete

◆ ~DirectX12Device()

DirectX12Device::~DirectX12Device ( )
virtualdefaultnoexcept

Member Function Documentation

◆ adapter()

◆ allocateGlobalDescriptors()

void DirectX12Device::allocateGlobalDescriptors ( const DirectX12DescriptorSet descriptorSet,
UInt32 bufferOffset,
UInt32 samplerOffset 
) const
virtual

Allocates a range of descriptors in the global descriptor heaps for the provided descriptorSet .

Parameters
descriptorSetThe descriptor set containing the descriptors to update.
bufferOffsetThe offset of the descriptor range in the buffer heap.
samplerOffsetThe offset of the descriptor range in the sampler heap.

◆ backend()

const DirectX12Backend & DirectX12Device::backend ( ) const
virtualnoexcept

Returns the backend from which the device got created.

Returns
The backend from which the device got created.

◆ bindDescriptorSet()

void DirectX12Device::bindDescriptorSet ( const DirectX12CommandBuffer commandBuffer,
const DirectX12DescriptorSet descriptorSet,
const DirectX12PipelineState pipeline 
) const
virtualnoexcept

Binds the descriptors of the descriptor set to the global descriptor heaps.

Note that after binding the descriptor set, the descriptors must not be updated anymore, unless they are elements on unbounded descriptor arrays, in which case you have to ensure manually to not update them, as long as they may still be in use!

Parameters
commandBufferThe command buffer to bind the descriptor set on.
descriptorSetThe descriptor set to bind.
pipelineThe pipeline to bind the descriptor set to.

◆ bindGlobalDescriptorHeaps()

void DirectX12Device::bindGlobalDescriptorHeaps ( const DirectX12CommandBuffer commandBuffer) const
virtualnoexcept

Binds the global descriptor heap.

Parameters
commandBufferThe command buffer to issue the bind command on.

◆ blitPipeline()

DirectX12ComputePipeline & DirectX12Device::blitPipeline ( ) const
virtualnoexcept

Returns the compute pipeline that can be invoked to blit an image resource.

Blitting is used by DirectX12Texture to generate mip maps.

Returns
The compute pipeline that can be invoked to blit an image resource.
See also
DirectX12Texture::generateMipMaps

◆ bufferQueue()

const DirectX12Queue & DirectX12Device::bufferQueue ( ) const
overridevirtualnoexcept

◆ computeQueue()

◆ factory()

const DirectX12GraphicsFactory & DirectX12Device::factory ( ) const
overridevirtualnoexcept

◆ globalBufferHeap()

const ID3D12DescriptorHeap * DirectX12Device::globalBufferHeap ( ) const
virtualnoexcept

Returns the global descriptor heap.

The DirectX 12 device uses a global heap of descriptors and samplers in a ring-buffer fashion. The heap itself is managed by the device.

Returns
A pointer to the global descriptor heap.

◆ globalSamplerHeap()

const ID3D12DescriptorHeap * DirectX12Device::globalSamplerHeap ( ) const
virtualnoexcept

Returns the global sampler heap.

Returns
A pointer to the global sampler heap.
See also
globalBufferHeap

◆ graphicsQueue()

const DirectX12Queue & DirectX12Device::graphicsQueue ( ) const
overridevirtualnoexcept

◆ makeBarrier()

◆ maximumMultiSamplingLevel()

MultiSamplingLevel DirectX12Device::maximumMultiSamplingLevel ( const Format &  format) const
overridevirtualnoexcept

Queries the device for the maximum supported number of multi-sampling levels.

Implements LiteFX::Rendering::IGraphicsDevice.

◆ releaseGlobalDescriptors()

void DirectX12Device::releaseGlobalDescriptors ( const DirectX12DescriptorSet descriptorSet) const
virtualnoexcept

Releases a range of descriptors from the global descriptor heaps.

This is done, if a descriptor set layout is destroyed, of a descriptor set, which contains an unbounded array is freed. It will cause the global descriptor heaps to fragment, which may result in inefficient future descriptor allocations and should be avoided. Consider caching descriptor sets with unbounded arrays instead. Also avoid relying on creating and releasing pipeline layouts during runtime. Instead, it may be more efficient to write shaders that support multiple pipeline variations, that can be kept alive for the lifetime of the whole application.

◆ state()

DeviceState & DirectX12Device::state ( ) const
overridevirtualnoexcept

Returns the device state that can be used to manage resources.

Implements LiteFX::Rendering::IGraphicsDevice.

◆ surface()

◆ swapChain() [1/2]

const DirectX12SwapChain & DirectX12Device::swapChain ( ) const
overridevirtualnoexcept

◆ swapChain() [2/2]

DirectX12SwapChain & DirectX12Device::swapChain ( )
overridevirtualnoexcept

◆ transferQueue()

const DirectX12Queue & DirectX12Device::transferQueue ( ) const
overridevirtualnoexcept

◆ updateBufferDescriptors()

void DirectX12Device::updateBufferDescriptors ( const DirectX12DescriptorSet descriptorSet,
const UInt32 firstDescriptor,
const UInt32 descriptors 
) const
virtualnoexcept

Updates a range of descriptors in the global buffer descriptor heap with the descriptors from descriptorSet .

Parameters
descriptorSetThe descriptor set to copy the descriptors from.
firstDescriptorThe index of the first descriptor to copy.
descriptorsThe number of descriptors to copy.

◆ updateSamplerDescriptors()

void DirectX12Device::updateSamplerDescriptors ( const DirectX12DescriptorSet descriptorSet,
const UInt32 firstDescriptor,
const UInt32 descriptors 
) const
virtualnoexcept

Updates a sampler descriptors in the global buffer descriptor heap with a descriptor from descriptorSet .

Parameters
descriptorSetThe descriptor set to copy the descriptors from.
firstDescriptorThe index of the first descriptor to copy.
descriptorsThe number of descriptors to copy.

◆ wait()

void DirectX12Device::wait ( ) const
overridevirtual

Waits until the device is idle.

Implements LiteFX::Rendering::IGraphicsDevice.