Nameless Engine
Loading...
Searching...
No Matches
ne::DirectXRenderer Class Reference

#include <DirectXRenderer.h>

Inheritance diagram for ne::DirectXRenderer:
ne::Renderer

Public Member Functions

 DirectXRenderer (const DirectXRenderer &)=delete
 
DirectXRendereroperator= (const DirectXRenderer &)=delete
 
virtual std::vector< std::string > getSupportedGpuNames () const override
 
virtual std::variant< std::set< std::pair< unsigned int, unsigned int > >, ErrorgetSupportedRenderResolutions () const override
 
virtual std::variant< std::set< std::pair< unsigned int, unsigned int > >, ErrorgetSupportedRefreshRates () const override
 
virtual std::string getCurrentlyUsedGpuName () const override
 
virtual void waitForGpuToFinishWorkUpToThisPoint () override
 
virtual RendererType getType () const override
 
virtual std::string getUsedApiVersion () const override
 
ID3D12Device * getD3dDevice () const
 
ID3D12GraphicsCommandList * getD3dCommandList ()
 
ID3D12CommandQueue * getD3dCommandQueue ()
 
IDXGIAdapter3 * getVideoAdapter () const
 
UINT getMsaaQualityLevel () const
 
virtual GpuResourcegetDepthTextureNoMultisampling () override
 
virtual std::pair< unsigned int, unsigned int > getRenderTargetSize () const override
 
- Public Member Functions inherited from ne::Renderer
 Renderer (const Renderer &)=delete
 
Rendereroperator= (const Renderer &)=delete
 
virtual std::vector< std::string > getSupportedGpuNames () const =0
 
virtual std::variant< std::set< std::pair< unsigned int, unsigned int > >, ErrorgetSupportedRenderResolutions () const =0
 
virtual std::variant< std::set< std::pair< unsigned int, unsigned int > >, ErrorgetSupportedRefreshRates () const =0
 
virtual RendererType getType () const =0
 
virtual std::string getUsedApiVersion () const =0
 
std::pair< std::recursive_mutex *, RenderSettings * > getRenderSettings ()
 
RenderStatisticsgetRenderStatistics ()
 
virtual std::string getCurrentlyUsedGpuName () const =0
 
size_t getTotalVideoMemoryInMb () const
 
size_t getUsedVideoMemoryInMb () const
 
virtual void waitForGpuToFinishWorkUpToThisPoint ()=0
 
virtual std::pair< unsigned int, unsigned int > getRenderTargetSize () const =0
 
WindowgetWindow () const
 
GameManagergetGameManager () const
 
ShaderManagergetShaderManager () const
 
PipelineManagergetPipelineManager () const
 
GpuResourceManagergetResourceManager () const
 
FrameResourceManagergetFrameResourceManager () const
 
ShaderCpuWriteResourceBindingManagergetShaderCpuWriteResourceManager () const
 
ShaderTextureResourceBindingManagergetShaderTextureResourceManager () const
 
LightingShaderResourceManagergetLightingShaderResourceManager () const
 
GlobalShaderResourceBindingManagergetGlobalShaderResourceBindingManager () const
 
std::recursive_mutex * getRenderResourcesMutex ()
 
virtual GpuResourcegetDepthTextureNoMultisampling ()=0
 

Static Public Member Functions

static std::variant< std::unique_ptr< Renderer >, std::pair< Error, std::string > > create (GameManager *pGameManager, const std::vector< std::string > &vBlacklistedGpuNames)
 
static constexpr DXGI_FORMAT getBackBufferFormat ()
 
static constexpr DXGI_FORMAT getDepthStencilBufferFormat ()
 
static constexpr DXGI_FORMAT getDepthBufferFormatNoMultisampling ()
 
static constexpr DXGI_FORMAT getShadowMapFormat ()
 
static constexpr DXGI_FORMAT getShadowMappingPointLightColorTargetFormat ()
 
- Static Public Member Functions inherited from ne::Renderer
static constexpr float getMinDepth ()
 
static constexpr float getMaxDepth ()
 
static std::variant< std::unique_ptr< Renderer >, Errorcreate (GameManager *pGameManager, std::optional< RendererType > preferredRenderer)
 

Protected Member Functions

 DirectXRenderer (GameManager *pGameManager)
 
virtual void drawShadowMappingPass (FrameResource *pCurrentFrameResource, size_t iCurrentFrameResourceIndex, GraphicsPipelineRegistry *pGraphicsPipelines) override
 
virtual void drawMeshesDepthPrepass (FrameResource *pCurrentFrameResource, size_t iCurrentFrameResourceIndex, const std::vector< Renderer::MeshesInFrustum::PipelineInFrustumInfo > &vOpaquePipelines) override
 
virtual void executeComputeShadersOnGraphicsQueue (FrameResource *pCurrentFrameResource, size_t iCurrentFrameResourceIndex, ComputeExecutionStage stage) override
 
virtual void drawMeshesMainPass (FrameResource *pCurrentFrameResource, size_t iCurrentFrameResourceIndex, const std::vector< Renderer::MeshesInFrustum::PipelineInFrustumInfo > &vOpaquePipelines, const std::vector< Renderer::MeshesInFrustum::PipelineInFrustumInfo > &vTransparentPipelines) override
 
virtual void present (FrameResource *pCurrentFrameResource, size_t iCurrentFrameResourceIndex) override
 
void drawMeshesMainPassSpecificPipelines (DirectXFrameResource *pCurrentFrameResource, size_t iCurrentFrameResourceIndex, const std::vector< Renderer::MeshesInFrustum::PipelineInFrustumInfo > &pipelinesOfSpecificType, D3D12_GPU_DESCRIPTOR_HANDLE directionalShadowMapsHandle, D3D12_GPU_DESCRIPTOR_HANDLE spotShadowMapsHandle, D3D12_GPU_DESCRIPTOR_HANDLE pointShadowMapsGpuHandle, const bool bIsDrawingTransparentMeshes)
 
virtual std::optional< ErroronRenderSettingsChangedDerived () override
 
virtual void waitForGpuToFinishUsingFrameResource (FrameResource *pFrameResource) override
 
virtual std::variant< std::optional< AntialiasingQuality >, ErrorgetMaxSupportedAntialiasingQuality () const override
 
virtual bool isInitialized () const override
 
- Protected Member Functions inherited from ne::Renderer
 Renderer (GameManager *pGameManager)
 
std::optional< ErrorcompileEngineShaders () const
 
void updateFrameConstantsBuffer (FrameResource *pCurrentFrameResource, CameraProperties *pCameraProperties)
 
void resetGpuResourceManager ()
 
void resetPipelineManager ()
 
void resetFrameResourceManager ()
 
void resetLightingShaderResourceManager ()
 
virtual std::variant< std::optional< AntialiasingQuality >, ErrorgetMaxSupportedAntialiasingQuality () const =0
 
void onFramebufferSizeChanged (int iWidth, int iHeight)
 
virtual void onFramebufferSizeChangedDerived (int iWidth, int iHeight)
 
void drawNextFrame ()
 
virtual void prepareRenderTargetForNextFrame ()
 
virtual void prepareForDrawingNextFrame (CameraProperties *pCameraProperties, FrameResource *pCurrentFrameResource)=0
 
virtual void drawShadowMappingPass (FrameResource *pCurrentFrameResource, size_t iCurrentFrameResourceIndex, GraphicsPipelineRegistry *pGraphicsPipelines)=0
 
virtual void drawMeshesDepthPrepass (FrameResource *pCurrentFrameResource, size_t iCurrentFrameResourceIndex, const std::vector< Renderer::MeshesInFrustum::PipelineInFrustumInfo > &vOpaquePipelines)=0
 
virtual void executeComputeShadersOnGraphicsQueue (FrameResource *pCurrentFrameResource, size_t iCurrentFrameResourceIndex, ComputeExecutionStage stage)=0
 
virtual void drawMeshesMainPass (FrameResource *pCurrentFrameResource, size_t iCurrentFrameResourceIndex, const std::vector< Renderer::MeshesInFrustum::PipelineInFrustumInfo > &vOpaquePipelines, const std::vector< Renderer::MeshesInFrustum::PipelineInFrustumInfo > &vTransparentPipelines)=0
 
virtual void present (FrameResource *pCurrentFrameResource, size_t iCurrentFrameResourceIndex)=0
 
std::optional< ErroronRenderSettingsChanged (bool bShadowMapSizeChanged=false)
 
virtual std::optional< ErroronRenderSettingsChangedDerived ()=0
 
virtual void waitForGpuToFinishUsingFrameResource (FrameResource *pFrameResource)=0
 
virtual bool isInitialized () const =0
 
std::optional< ErrorinitializeRenderer ()
 
std::optional< ErrorinitializeResourceManagers ()
 
std::optional< ErrorclampSettingsToMaxSupported ()
 
std::optional< ErrorrecalculateLightTileFrustums ()
 
MeshesInFrustumgetMeshesInCameraFrustum (CameraProperties *pActiveCameraProperties, GraphicsPipelineRegistry *pGraphicsPipelines)
 
void cullLightsOutsideCameraFrustum (CameraProperties *pActiveCameraProperties, size_t iCurrentFrameResourceIndex)
 
std::pair< std::mutex, FrameConstants > * getFrameConstants ()
 
std::atomic< size_t > * getDrawCallCounter ()
 

Private Member Functions

std::optional< Errorinitialize (const std::vector< std::string > &vBlacklistedGpuNames)
 
std::optional< ErrorcreateDepthStencilBuffer ()
 
std::optional< ErrorpickVideoAdapter (const std::vector< std::string > &vBlacklistedGpuNames)
 
std::optional< ErrorsetOutputAdapter ()
 
std::optional< ErrorcreateCommandQueue ()
 
std::optional< ErrorcreateCommandList ()
 
std::optional< ErrorcreateSwapChain ()
 
std::optional< ErrorinitializeDirectX (const std::vector< std::string > &vBlacklistedGpuNames)
 
virtual void prepareForDrawingNextFrame (CameraProperties *pCameraProperties, FrameResource *pCurrentFrameResource) override
 
void resetCommandListForGraphics (DirectXFrameResource *pCurrentFrameResource)
 
void executeGraphicsCommandList (ID3D12GraphicsCommandList *pCommandListToExecute)
 
std::optional< ErrorupdateMsaaQualityLevelCount ()
 
void waitForFenceValue (UINT64 iFenceToWaitFor)
 
void dispatchComputeShadersOnGraphicsQueue (ID3D12CommandAllocator *pCommandAllocator, std::unordered_map< Pipeline *, std::unordered_set< ComputeShaderInterface * > > &computePipelinesToSubmit)
 
std::variant< std::vector< DXGI_MODE_DESC >, ErrorgetSupportedDisplayModes () const
 
DirectXResourcegetCurrentBackBufferResource ()
 

Static Private Member Functions

static size_t rateGpuSuitability (DXGI_ADAPTER_DESC1 adapterDesc)
 

Private Attributes

ComPtr< IDXGIFactory4 > pFactory
 
ComPtr< ID3D12Device > pDevice
 
ComPtr< IDXGIAdapter3 > pVideoAdapter
 
ComPtr< IDXGIOutput > pOutputAdapter
 
ComPtr< IDXGISwapChain3 > pSwapChain
 
ComPtr< ID3D12CommandQueue > pCommandQueue
 
ComPtr< ID3D12GraphicsCommandList > pCommandList
 
ComPtr< ID3D12GraphicsCommandList > pComputeCommandList
 
ComPtr< ID3D12Fence > pFence
 
std::pair< std::recursive_mutex, UINT64 > mtxCurrentFenceValue
 
std::vector< std::unique_ptr< DirectXResource > > vSwapChainBuffers
 
std::unique_ptr< DirectXResourcepDepthStencilBuffer
 
std::unique_ptr< DirectXResourcepDepthBufferNoMultisampling
 
float backBufferFillColor [4] = {0.0F, 0.0F, 0.0F, 1.0F}
 
std::unique_ptr< DirectXResourcepMsaaRenderBuffer
 
std::vector< std::string > vSupportedGpuNames
 
std::pair< unsigned int, unsigned int > renderTargetSize = {0, 0}
 
UINT iMsaaQualityLevelsCount = 0
 
D3D12_VIEWPORT screenViewport
 
D3D12_RECT scissorRect
 
std::string sUsedVideoAdapter
 
UINT iPresentSyncInterval = 0
 
UINT iPresentFlags = 0
 
bool bIsUsingMsaaRenderTarget = true
 
bool bIsDirectXInitialized = false
 

Static Private Attributes

static constexpr DXGI_FORMAT backBufferFormat = DXGI_FORMAT_R8G8B8A8_UNORM
 
static constexpr DXGI_FORMAT depthStencilBufferFormat = DXGI_FORMAT_D32_FLOAT
 
static constexpr DXGI_FORMAT shadowMapFormat = DXGI_FORMAT_D32_FLOAT
 
static constexpr DXGI_FORMAT shadowMappingPointLightColorTargetFormat = DXGI_FORMAT_R32_FLOAT
 
static constexpr DXGI_FORMAT depthBufferNoMultisamplingFormat = DXGI_FORMAT_R32_FLOAT
 
static constexpr DXGI_MODE_SCALING usedScaling = DXGI_MODE_SCALING_UNSPECIFIED
 
static constexpr DXGI_MODE_SCANLINE_ORDER usedScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE
 
static constexpr D3D_FEATURE_LEVEL rendererD3dFeatureLevel
 

Additional Inherited Members

- Static Protected Member Functions inherited from ne::Renderer
static consteval unsigned int getRecommendedSwapChainBufferCount ()
 
static void getDirectionalLightNodeShadowMappingInfo (DirectionalLightNode *pNode, ShadowMapHandle *&pShadowMapHandle, unsigned int &iShadowPassLightInfoArrayIndex)
 
static void getSpotlightNodeShadowMappingInfo (SpotlightNode *pNode, ShadowMapHandle *&pShadowMapHandle, unsigned int &iShadowPassLightInfoArrayIndex)
 
static unsigned int getPointLightShadowPassLightInfoArrayIndex (PointLightNode *pNode, size_t iCubemapFaceIndex)
 
static ShadowMapHandlegetPointLightNodeShadowMapHandle (PointLightNode *pNode)
 

Detailed Description

Renderer made with DirectX 12 API.

Constructor & Destructor Documentation

◆ DirectXRenderer()

ne::DirectXRenderer::DirectXRenderer ( GameManager pGameManager)
protected

Creates an empty (uninitialized) renderer.

Remarks
Use initialize to initialize the renderer.
Parameters
pGameManagerGameManager object that owns this renderer.

Member Function Documentation

◆ create()

std::variant< std::unique_ptr< Renderer >, std::pair< Error, std::string > > ne::DirectXRenderer::create ( GameManager pGameManager,
const std::vector< std::string > &  vBlacklistedGpuNames 
)
static

Creates a new DirectX renderer.

Parameters
pGameManagerGameManager object that owns this renderer.
vBlacklistedGpuNamesNames of GPUs that should not be used, generally this means that these GPUs were previously used to create the renderer but something went wrong.
Returns
Created renderer if successful, otherwise multiple values in a pair: error and a name of the GPU that the renderer tried to use (can be empty if failed before picking a GPU or if all supported GPUs are blacklisted).

◆ createCommandList()

std::optional< Error > ne::DirectXRenderer::createCommandList ( )
private

Creates and initializes command list.

Remarks
Requires frame resources to be created.
Returns
Error if something went wrong.

◆ createCommandQueue()

std::optional< Error > ne::DirectXRenderer::createCommandQueue ( )
private

Creates and initializes command queue.

Returns
Error if something went wrong.

◆ createDepthStencilBuffer()

std::optional< Error > ne::DirectXRenderer::createDepthStencilBuffer ( )
private

(Re)creates the depth/stencil buffer with the "depth write" initial state and binds a DSV to it.

Remarks
Make sure that the old depth/stencil buffer (if was) is not used by the GPU before calling this function.
Returns
Error if something went wrong.

◆ createSwapChain()

std::optional< Error > ne::DirectXRenderer::createSwapChain ( )
private

Creates and initializes the swap chain.

Returns
Error if something went wrong.

◆ dispatchComputeShadersOnGraphicsQueue()

void ne::DirectXRenderer::dispatchComputeShadersOnGraphicsQueue ( ID3D12CommandAllocator *  pCommandAllocator,
std::unordered_map< Pipeline *, std::unordered_set< ComputeShaderInterface * > > &  computePipelinesToSubmit 
)
private

Submits compute dispatch commands using pCommandQueue.

Parameters
pCommandAllocatorCommand allocator to reset pComputeCommandList.
computePipelinesToSubmitCompute shaders and their pipelines to dispatch.

◆ drawMeshesDepthPrepass()

void ne::DirectXRenderer::drawMeshesDepthPrepass ( FrameResource pCurrentFrameResource,
size_t  iCurrentFrameResourceIndex,
const std::vector< Renderer::MeshesInFrustum::PipelineInFrustumInfo > &  vOpaquePipelines 
)
overrideprotectedvirtual

Submits commands to draw meshes and the specified depth only (vertex shader only) pipelines.

Parameters
pCurrentFrameResourceFrame resource of the frame being submitted.
iCurrentFrameResourceIndexIndex of the current frame resource.
vOpaquePipelinesOpaque pipelines (depth pipeline will be retrieved from them).

Implements ne::Renderer.

◆ drawMeshesMainPass()

void ne::DirectXRenderer::drawMeshesMainPass ( FrameResource pCurrentFrameResource,
size_t  iCurrentFrameResourceIndex,
const std::vector< Renderer::MeshesInFrustum::PipelineInFrustumInfo > &  vOpaquePipelines,
const std::vector< Renderer::MeshesInFrustum::PipelineInFrustumInfo > &  vTransparentPipelines 
)
overrideprotectedvirtual

Submits commands to draw meshes for main (color) pass.

Parameters
pCurrentFrameResourceFrame resource of the frame being submitted.
iCurrentFrameResourceIndexIndex of the current frame resource.
vOpaquePipelinesOpaque pipelines to draw.
vTransparentPipelinesTransparent pipelines to draw.

Implements ne::Renderer.

◆ drawMeshesMainPassSpecificPipelines()

void ne::DirectXRenderer::drawMeshesMainPassSpecificPipelines ( DirectXFrameResource pCurrentFrameResource,
size_t  iCurrentFrameResourceIndex,
const std::vector< Renderer::MeshesInFrustum::PipelineInFrustumInfo > &  pipelinesOfSpecificType,
D3D12_GPU_DESCRIPTOR_HANDLE  directionalShadowMapsHandle,
D3D12_GPU_DESCRIPTOR_HANDLE  spotShadowMapsHandle,
D3D12_GPU_DESCRIPTOR_HANDLE  pointShadowMapsGpuHandle,
const bool  bIsDrawingTransparentMeshes 
)
protected

Submits commands to draw meshes and pipelines of specific types (only opaque or transparent).

Parameters
pCurrentFrameResourceFrame resource of the frame being submitted.
iCurrentFrameResourceIndexIndex of the current frame resource.
pipelinesOfSpecificTypePipelines to use.
directionalShadowMapsHandleGPU handle to array of directional shadow maps.
spotShadowMapsHandleGPU handle to array of spot shadow maps.
pointShadowMapsGpuHandleGPU handle to array of point shadow maps.
bIsDrawingTransparentMeshestrue if transparent pipelines are used, false otherwise.

◆ drawShadowMappingPass()

void ne::DirectXRenderer::drawShadowMappingPass ( FrameResource pCurrentFrameResource,
size_t  iCurrentFrameResourceIndex,
GraphicsPipelineRegistry pGraphicsPipelines 
)
overrideprotectedvirtual

Submits commands to draw world from the perspective of all spawned light sources to capture shadow maps.

Parameters
pCurrentFrameResourceFrame resource of the frame being submitted.
iCurrentFrameResourceIndexIndex of the current frame resource.
pGraphicsPipelinesGraphics pipelines to draw.

Implements ne::Renderer.

◆ executeComputeShadersOnGraphicsQueue()

void ne::DirectXRenderer::executeComputeShadersOnGraphicsQueue ( FrameResource pCurrentFrameResource,
size_t  iCurrentFrameResourceIndex,
ComputeExecutionStage  stage 
)
overrideprotectedvirtual

Executes compute shaders of the specified stage.

Warning
Expects that mutex for compute shaders is locked.
Parameters
pCurrentFrameResourceFrame resource of the frame being submitted.
iCurrentFrameResourceIndexIndex of the current frame resource.
stageStage of compute shaders to execute.

Implements ne::Renderer.

◆ executeGraphicsCommandList()

void ne::DirectXRenderer::executeGraphicsCommandList ( ID3D12GraphicsCommandList *  pCommandListToExecute)
private

Closes and executes the specified command list on pCommandQueue.

Parameters
pCommandListToExecuteCommand list to execute.

◆ getBackBufferFormat()

static constexpr DXGI_FORMAT ne::DirectXRenderer::getBackBufferFormat ( )
inlinestaticconstexpr

Returns used back buffer format.

Returns
Back buffer format.

◆ getCurrentBackBufferResource()

DirectXResource * ne::DirectXRenderer::getCurrentBackBufferResource ( )
private

Returns current buffer to draw to: either MSAA render buffer of swap chain's buffer.

Returns
GPU resource.

◆ getCurrentlyUsedGpuName()

std::string ne::DirectXRenderer::getCurrentlyUsedGpuName ( ) const
overridevirtual

Returns the name of the GPU that is being currently used.

Returns
Name of the GPU.

Implements ne::Renderer.

◆ getD3dCommandList()

ID3D12GraphicsCommandList * ne::DirectXRenderer::getD3dCommandList ( )

Returns DirectX command list.

Returns
Do not delete (free) this pointer. Render's internal command list.

◆ getD3dCommandQueue()

ID3D12CommandQueue * ne::DirectXRenderer::getD3dCommandQueue ( )

Returns DirectX command queue.

Returns
Do not delete (free) this pointer. Render's internal command queue.

◆ getD3dDevice()

ID3D12Device * ne::DirectXRenderer::getD3dDevice ( ) const

Returns DirectX device.

Returns
Do not delete (free) this pointer. Render's internal device.

◆ getDepthBufferFormatNoMultisampling()

static constexpr DXGI_FORMAT ne::DirectXRenderer::getDepthBufferFormatNoMultisampling ( )
inlinestaticconstexpr

Returns used depth buffer format for resolved depth buffer.

Returns
Depth buffer format.

◆ getDepthStencilBufferFormat()

static constexpr DXGI_FORMAT ne::DirectXRenderer::getDepthStencilBufferFormat ( )
inlinestaticconstexpr

Returns used depth/stencil buffer format.

Returns
Depth/stencil buffer format.

◆ getDepthTextureNoMultisampling()

GpuResource * ne::DirectXRenderer::getDepthTextureNoMultisampling ( )
overridevirtual

Returns pointer to the texture resource that represents renderer's depth texture without multisampling (resolved resource).

Warning
If MSAA is enabled this function will return one resource (pointer to a separate depth resolved resource), if it's disabled it will return the other resource (pointer to depth texture). So it may be a good idea to query this pointer every time you need it instead of saving it and reusing it because every frame this pointer may change (due to other reasons such as render target resize and etc).
Returns
Pointer to depth texture.

Implements ne::Renderer.

◆ getMaxSupportedAntialiasingQuality()

std::variant< std::optional< AntialiasingQuality >, Error > ne::DirectXRenderer::getMaxSupportedAntialiasingQuality ( ) const
overrideprotectedvirtual

Returns the maximum anti-aliasing quality that can be used on the picked GPU (getCurrentlyUsedGpuName).

Remarks
Note that the maximum supported AA quality can differ depending on the used GPU/renderer.
Returns
Error if something went wrong, otherwise empty if AA is not supported.

Implements ne::Renderer.

◆ getMsaaQualityLevel()

UINT ne::DirectXRenderer::getMsaaQualityLevel ( ) const

Returns quality level count for the current MSAA sample count.

Returns
MSAA quality level count.

◆ getRenderTargetSize()

std::pair< unsigned int, unsigned int > ne::DirectXRenderer::getRenderTargetSize ( ) const
overridevirtual

Returns size of the render target (size of the underlying render image).

Returns
Render image size in pixels (width and height).

Implements ne::Renderer.

◆ getShadowMapFormat()

static constexpr DXGI_FORMAT ne::DirectXRenderer::getShadowMapFormat ( )
inlinestaticconstexpr

Returns texture format used for shadow maps.

Returns
Shadow map format.

◆ getShadowMappingPointLightColorTargetFormat()

static constexpr DXGI_FORMAT ne::DirectXRenderer::getShadowMappingPointLightColorTargetFormat ( )
inlinestaticconstexpr

Returns texture format used for point lights as "color" target (does not actually store color) during shadow pass.

Returns
Shadow map format.

◆ getSupportedDisplayModes()

std::variant< std::vector< DXGI_MODE_DESC >, Error > ne::DirectXRenderer::getSupportedDisplayModes ( ) const
private

Returns a vector of display modes that the current output adapter supports for current back buffer format.

Returns
Error if something went wrong, vector of display modes otherwise.

◆ getSupportedGpuNames()

std::vector< std::string > ne::DirectXRenderer::getSupportedGpuNames ( ) const
overridevirtual

Looks for video adapters (GPUs) that support this renderer.

Remarks
Note that returned array might differ depending on the used renderer.
Returns
Empty array if no GPU supports used renderer, otherwise array with GPU names that can be used for this renderer.

Implements ne::Renderer.

◆ getSupportedRefreshRates()

std::variant< std::set< std::pair< unsigned int, unsigned int > >, Error > ne::DirectXRenderer::getSupportedRefreshRates ( ) const
overridevirtual

Returns a list of supported screen refresh rates (pairs of numerator and denominator).

Remarks
The list of supported refresh rates depends on the currently used GPU, so if changing used GPU this list might return different values.
Returns
Error if something went wrong, otherwise refresh rates.

Implements ne::Renderer.

◆ getSupportedRenderResolutions()

std::variant< std::set< std::pair< unsigned int, unsigned int > >, Error > ne::DirectXRenderer::getSupportedRenderResolutions ( ) const
overridevirtual

Returns a list of supported render resolution (pairs of width and height).

Returns
Error if something went wrong, otherwise render mode.

Implements ne::Renderer.

◆ getType()

RendererType ne::DirectXRenderer::getType ( ) const
overridevirtual

Returns renderer's type.

Returns
Renderer's type.

Implements ne::Renderer.

◆ getUsedApiVersion()

std::string ne::DirectXRenderer::getUsedApiVersion ( ) const
overridevirtual

Returns API version or a feature level that the renderer uses.

For example DirectX renderer will return used feature level and Vulkan renderer will return used Vulkan API version.

Returns
Used API version.

Implements ne::Renderer.

◆ getVideoAdapter()

IDXGIAdapter3 * ne::DirectXRenderer::getVideoAdapter ( ) const

Returns DirectX video adapter.

Returns
Do not delete (free) this pointer. Video adapter.

◆ initialize()

std::optional< Error > ne::DirectXRenderer::initialize ( const std::vector< std::string > &  vBlacklistedGpuNames)
private

Initializes the renderer.

Remarks
This function is usually called after constructing a new empty (uninitialized) DirectX renderer.
Parameters
vBlacklistedGpuNamesNames of GPUs that should not be used, generally this means that these GPUs were previously used to create the renderer but something went wrong.
Returns
Error if something went wrong (for ex. if the hardware does not support this renderer).

◆ initializeDirectX()

std::optional< Error > ne::DirectXRenderer::initializeDirectX ( const std::vector< std::string > &  vBlacklistedGpuNames)
private

Initializes DirectX.

Parameters
vBlacklistedGpuNamesNames of GPUs that should not be used, generally this means that these GPUs were previously used to create the renderer but something went wrong.
Returns
Error if something went wrong.

◆ isInitialized()

bool ne::DirectXRenderer::isInitialized ( ) const
overrideprotectedvirtual

Tells whether the renderer is initialized or not.

Initialized renderer means that the hardware supports it and it's safe to use renderer functionality such as onRenderSettingsChanged.

Returns
Whether the renderer is initialized or not.

Implements ne::Renderer.

◆ onRenderSettingsChangedDerived()

std::optional< Error > ne::DirectXRenderer::onRenderSettingsChangedDerived ( )
overrideprotectedvirtual

Called after some render setting is changed to recreate internal resources to match the current settings.

Returns
Error if something went wrong.

Implements ne::Renderer.

◆ pickVideoAdapter()

std::optional< Error > ne::DirectXRenderer::pickVideoAdapter ( const std::vector< std::string > &  vBlacklistedGpuNames)
private

Rates available GPUs and picks the best one to be used (also considers GPU specified in RenderSettings).

Parameters
vBlacklistedGpuNamesNames of GPUs that should not be used, generally this means that these GPUs were previously used to create the renderer but something went wrong.
Returns
Error if something went wrong.

◆ prepareForDrawingNextFrame()

void ne::DirectXRenderer::prepareForDrawingNextFrame ( CameraProperties pCameraProperties,
FrameResource pCurrentFrameResource 
)
overrideprivatevirtual

Setups everything for render commands to be recorded (resets command buffers and etc.).

Warning
Expects that render resources mutex is locked.
Remarks
When this function is called this means that the current frame resource is no longer used by the GPU.
Parameters
pCameraPropertiesCamera properties to use.
pCurrentFrameResourceFrame resource of the frame being submitted.

Implements ne::Renderer.

◆ present()

void ne::DirectXRenderer::present ( FrameResource pCurrentFrameResource,
size_t  iCurrentFrameResourceIndex 
)
overrideprotectedvirtual

Does the final frame rendering logic to present the frame on the screen.

Parameters
pCurrentFrameResourceFrame resource of the frame being submitted.
iCurrentFrameResourceIndexIndex of the current frame resource.

Implements ne::Renderer.

◆ rateGpuSuitability()

size_t ne::DirectXRenderer::rateGpuSuitability ( DXGI_ADAPTER_DESC1  adapterDesc)
staticprivate

Rates the specified GPU and gives it a suitability score.

Parameters
adapterDescGPU description.
Returns
0 if the GPU is not suitable for the renderer, otherwise GPU's suitability score.

◆ resetCommandListForGraphics()

void ne::DirectXRenderer::resetCommandListForGraphics ( DirectXFrameResource pCurrentFrameResource)
private

Resets pCommandList and adds initial commands like set descriptor heaps for graphics commands.

Parameters
pCurrentFrameResourceFrame resource for the current frame.

◆ setOutputAdapter()

std::optional< Error > ne::DirectXRenderer::setOutputAdapter ( )
private

Sets first found output adapter (monitor).

Returns
Error if something went wrong or no output adapter was found.

◆ updateMsaaQualityLevelCount()

std::optional< Error > ne::DirectXRenderer::updateMsaaQualityLevelCount ( )
private

Queries the current render settings for MSAA quality and updates iMsaaQualityLevelsCount.

Returns
Error if something went wrong.

◆ waitForFenceValue()

void ne::DirectXRenderer::waitForFenceValue ( UINT64  iFenceToWaitFor)
private

Waits until the GPU has completed commands up to the specified fence point.

Parameters
iFenceToWaitForFence value to wait for.

◆ waitForGpuToFinishUsingFrameResource()

void ne::DirectXRenderer::waitForGpuToFinishUsingFrameResource ( FrameResource pFrameResource)
overrideprotectedvirtual

Blocks the current thread until the GPU is finished using the specified frame resource.

Remarks
Generally the current frame resource will be passed and so the current frame resource mutex will be locked at the time of calling and until the function is not finished it will not be unlocked.
Parameters
pFrameResourceFrame resource to wait for.

Implements ne::Renderer.

◆ waitForGpuToFinishWorkUpToThisPoint()

void ne::DirectXRenderer::waitForGpuToFinishWorkUpToThisPoint ( )
overridevirtual

Blocks the current thread until the GPU finishes executing all queued commands up to this point.

Implements ne::Renderer.

Member Data Documentation

◆ backBufferFillColor

float ne::DirectXRenderer::backBufferFillColor[4] = {0.0F, 0.0F, 0.0F, 1.0F}
private

Default back buffer fill color.

◆ backBufferFormat

constexpr DXGI_FORMAT ne::DirectXRenderer::backBufferFormat = DXGI_FORMAT_R8G8B8A8_UNORM
staticconstexprprivate

Back buffer format.

◆ bIsDirectXInitialized

bool ne::DirectXRenderer::bIsDirectXInitialized = false
private

Whether initializeDirectX was finished without errors or not.

◆ bIsUsingMsaaRenderTarget

bool ne::DirectXRenderer::bIsUsingMsaaRenderTarget = true
private

Whether MSAA enabled and we use pMsaaRenderBuffer as render buffer or not and we use pSwapChain as render buffer.

◆ depthBufferNoMultisamplingFormat

constexpr DXGI_FORMAT ne::DirectXRenderer::depthBufferNoMultisamplingFormat = DXGI_FORMAT_R32_FLOAT
staticconstexprprivate

Depth buffer format for pDepthBufferNoMultisampling.

Remarks
This format is based on depthStencilBufferFormat but we need to consider some additional things such as:
  • MSAA resolve is only supported for non-integer and non-stencil types (use X8_TYPELESS or similar with stencil),
  • replace the depth component with the red component.

◆ depthStencilBufferFormat

constexpr DXGI_FORMAT ne::DirectXRenderer::depthStencilBufferFormat = DXGI_FORMAT_D32_FLOAT
staticconstexprprivate

Depth/stencil buffer format.

◆ iMsaaQualityLevelsCount

UINT ne::DirectXRenderer::iMsaaQualityLevelsCount = 0
private

The number of supported quality levels for the current MSAA sample count.

◆ iPresentFlags

UINT ne::DirectXRenderer::iPresentFlags = 0
private

Used to prevent tearing when VSync is enabled.

◆ iPresentSyncInterval

UINT ne::DirectXRenderer::iPresentSyncInterval = 0
private

Synchronize presentation for at least N vertical blanks. Used when VSync is enabled.

◆ mtxCurrentFenceValue

std::pair<std::recursive_mutex, UINT64> ne::DirectXRenderer::mtxCurrentFenceValue
private

Fence counter.

◆ pCommandList

ComPtr<ID3D12GraphicsCommandList> ne::DirectXRenderer::pCommandList
private

Contains commands for the GPU.

◆ pCommandQueue

ComPtr<ID3D12CommandQueue> ne::DirectXRenderer::pCommandQueue
private

GPU command queue.

◆ pComputeCommandList

ComPtr<ID3D12GraphicsCommandList> ne::DirectXRenderer::pComputeCommandList
private

◆ pDepthBufferNoMultisampling

std::unique_ptr<DirectXResource> ne::DirectXRenderer::pDepthBufferNoMultisampling
private

Depth buffer without multisampling (for light culing compute shader).

Warning
When pDepthStencilBuffer does not use multisampling this buffer is not used and does not store contents of pDepthStencilBuffer.
Remarks
Stores non-multisampled depth data from pDepthStencilBuffer for shaders.

◆ pDepthStencilBuffer

std::unique_ptr<DirectXResource> ne::DirectXRenderer::pDepthStencilBuffer
private

Depth stencil buffer.

◆ pDevice

ComPtr<ID3D12Device> ne::DirectXRenderer::pDevice
private

D3D12 Device.

◆ pFactory

ComPtr<IDXGIFactory4> ne::DirectXRenderer::pFactory
private

DXGI Factory.

◆ pFence

ComPtr<ID3D12Fence> ne::DirectXRenderer::pFence
private

Fence object.

◆ pMsaaRenderBuffer

std::unique_ptr<DirectXResource> ne::DirectXRenderer::pMsaaRenderBuffer
private

Render target when MSAA is enabled because our swap chain does not support multisampling.

◆ pOutputAdapter

ComPtr<IDXGIOutput> ne::DirectXRenderer::pOutputAdapter
private

Monitor.

◆ pSwapChain

ComPtr<IDXGISwapChain3> ne::DirectXRenderer::pSwapChain
private

Swap chain.

◆ pVideoAdapter

ComPtr<IDXGIAdapter3> ne::DirectXRenderer::pVideoAdapter
private

GPU.

◆ rendererD3dFeatureLevel

constexpr D3D_FEATURE_LEVEL ne::DirectXRenderer::rendererD3dFeatureLevel
staticconstexprprivate
Initial value:
=
D3D_FEATURE_LEVEL::D3D_FEATURE_LEVEL_12_1

D3D feature level that we use (required feature level).

◆ renderTargetSize

std::pair<unsigned int, unsigned int> ne::DirectXRenderer::renderTargetSize = {0, 0}
private

Last set size of the underlying swap chain buffer.

◆ scissorRect

D3D12_RECT ne::DirectXRenderer::scissorRect
private

Scissor rectangle for viewport.

◆ screenViewport

D3D12_VIEWPORT ne::DirectXRenderer::screenViewport
private

Screen viewport size and depth range.

◆ shadowMapFormat

constexpr DXGI_FORMAT ne::DirectXRenderer::shadowMapFormat = DXGI_FORMAT_D32_FLOAT
staticconstexprprivate

Format used for shadow maps.

◆ shadowMappingPointLightColorTargetFormat

constexpr DXGI_FORMAT ne::DirectXRenderer::shadowMappingPointLightColorTargetFormat = DXGI_FORMAT_R32_FLOAT
staticconstexprprivate

Format used for point lights as "color" target (does not actually store color) during shadow pass.

◆ sUsedVideoAdapter

std::string ne::DirectXRenderer::sUsedVideoAdapter
private

Name of the GPU we are currently using.

◆ usedScaling

constexpr DXGI_MODE_SCALING ne::DirectXRenderer::usedScaling = DXGI_MODE_SCALING_UNSPECIFIED
staticconstexprprivate

Use only display modes that use this scaling.

◆ usedScanlineOrdering

constexpr DXGI_MODE_SCANLINE_ORDER ne::DirectXRenderer::usedScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE
staticconstexprprivate

Use only display modes that use this scanline ordering.

◆ vSupportedGpuNames

std::vector<std::string> ne::DirectXRenderer::vSupportedGpuNames
private

List of supported GPUs, filled during pickVideoAdapter.

◆ vSwapChainBuffers

std::vector<std::unique_ptr<DirectXResource> > ne::DirectXRenderer::vSwapChainBuffers
private

Swap chain buffer.


The documentation for this class was generated from the following files: