Nameless Engine
|
#include <DirectXRenderer.h>
Public Member Functions | |
DirectXRenderer (const DirectXRenderer &)=delete | |
DirectXRenderer & | operator= (const DirectXRenderer &)=delete |
virtual std::vector< std::string > | getSupportedGpuNames () const override |
virtual std::variant< std::set< std::pair< unsigned int, unsigned int > >, Error > | getSupportedRenderResolutions () const override |
virtual std::variant< std::set< std::pair< unsigned int, unsigned int > >, Error > | getSupportedRefreshRates () 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 GpuResource * | getDepthTextureNoMultisampling () override |
virtual std::pair< unsigned int, unsigned int > | getRenderTargetSize () const override |
Public Member Functions inherited from ne::Renderer | |
Renderer (const Renderer &)=delete | |
Renderer & | operator= (const Renderer &)=delete |
virtual std::vector< std::string > | getSupportedGpuNames () const =0 |
virtual std::variant< std::set< std::pair< unsigned int, unsigned int > >, Error > | getSupportedRenderResolutions () const =0 |
virtual std::variant< std::set< std::pair< unsigned int, unsigned int > >, Error > | getSupportedRefreshRates () const =0 |
virtual RendererType | getType () const =0 |
virtual std::string | getUsedApiVersion () const =0 |
std::pair< std::recursive_mutex *, RenderSettings * > | getRenderSettings () |
RenderStatistics * | getRenderStatistics () |
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 |
Window * | getWindow () const |
GameManager * | getGameManager () const |
ShaderManager * | getShaderManager () const |
PipelineManager * | getPipelineManager () const |
GpuResourceManager * | getResourceManager () const |
FrameResourceManager * | getFrameResourceManager () const |
ShaderCpuWriteResourceBindingManager * | getShaderCpuWriteResourceManager () const |
ShaderTextureResourceBindingManager * | getShaderTextureResourceManager () const |
LightingShaderResourceManager * | getLightingShaderResourceManager () const |
GlobalShaderResourceBindingManager * | getGlobalShaderResourceBindingManager () const |
std::recursive_mutex * | getRenderResourcesMutex () |
virtual GpuResource * | getDepthTextureNoMultisampling ()=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 >, Error > | create (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< Error > | onRenderSettingsChangedDerived () override |
virtual void | waitForGpuToFinishUsingFrameResource (FrameResource *pFrameResource) override |
virtual std::variant< AntialiasingQuality, Error > | getMaxSupportedAntialiasingQuality () const override |
virtual bool | isInitialized () const override |
Protected Member Functions inherited from ne::Renderer | |
Renderer (GameManager *pGameManager) | |
std::optional< Error > | compileEngineShaders () const |
void | updateFrameConstantsBuffer (FrameResource *pCurrentFrameResource, CameraProperties *pCameraProperties) |
void | resetGpuResourceManager () |
void | resetPipelineManager () |
void | resetFrameResourceManager () |
void | resetLightingShaderResourceManager () |
virtual std::variant< AntialiasingQuality, Error > | getMaxSupportedAntialiasingQuality () 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< Error > | onRenderSettingsChanged (bool bShadowMapSizeChanged=false) |
virtual std::optional< Error > | onRenderSettingsChangedDerived ()=0 |
virtual void | waitForGpuToFinishUsingFrameResource (FrameResource *pFrameResource)=0 |
virtual bool | isInitialized () const =0 |
std::optional< Error > | initializeRenderer () |
std::optional< Error > | initializeResourceManagers () |
std::optional< Error > | clampSettingsToMaxSupported () |
std::optional< Error > | recalculateLightTileFrustums () |
MeshesInFrustum * | getMeshesInCameraFrustum (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< Error > | initialize (const std::vector< std::string > &vBlacklistedGpuNames) |
std::optional< Error > | createDepthStencilBuffer () |
std::optional< Error > | pickVideoAdapter (const std::vector< std::string > &vBlacklistedGpuNames) |
std::optional< Error > | setOutputAdapter () |
std::optional< Error > | createCommandQueue () |
std::optional< Error > | createCommandList () |
std::optional< Error > | createSwapChain () |
std::optional< Error > | initializeDirectX (const std::vector< std::string > &vBlacklistedGpuNames) |
virtual void | prepareForDrawingNextFrame (CameraProperties *pCameraProperties, FrameResource *pCurrentFrameResource) override |
void | resetCommandListForGraphics (DirectXFrameResource *pCurrentFrameResource) |
void | executeGraphicsCommandList (ID3D12GraphicsCommandList *pCommandListToExecute) |
std::optional< Error > | updateMsaaQualityLevelCount () |
void | waitForFenceValue (UINT64 iFenceToWaitFor) |
void | dispatchComputeShadersOnGraphicsQueue (ID3D12CommandAllocator *pCommandAllocator, std::unordered_map< Pipeline *, std::unordered_set< ComputeShaderInterface * > > &computePipelinesToSubmit) |
std::variant< std::vector< DXGI_MODE_DESC >, Error > | getSupportedDisplayModes () const |
DirectXResource * | getCurrentBackBufferResource () |
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< DirectXResource > | pDepthStencilBuffer |
std::unique_ptr< DirectXResource > | pDepthBufferNoMultisampling |
float | backBufferFillColor [4] = {0.0F, 0.0F, 0.0F, 1.0F} |
std::unique_ptr< DirectXResource > | pMsaaRenderBuffer |
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 ShadowMapHandle * | getPointLightNodeShadowMapHandle (PointLightNode *pNode) |
Renderer made with DirectX 12 API.
|
protected |
Creates an empty (uninitialized) renderer.
pGameManager | GameManager object that owns this renderer. |
|
static |
Creates a new DirectX renderer.
pGameManager | GameManager object that owns this renderer. |
vBlacklistedGpuNames | Names of GPUs that should not be used, generally this means that these GPUs were previously used to create the renderer but something went wrong. |
|
private |
Creates and initializes command list.
|
private |
Creates and initializes command queue.
|
private |
(Re)creates the depth/stencil buffer with the "depth write" initial state and binds a DSV to it.
|
private |
Creates and initializes the swap chain.
|
private |
Submits compute dispatch commands using pCommandQueue.
pCommandAllocator | Command allocator to reset pComputeCommandList. |
computePipelinesToSubmit | Compute shaders and their pipelines to dispatch. |
|
overrideprotectedvirtual |
Submits commands to draw meshes and the specified depth only (vertex shader only) pipelines.
pCurrentFrameResource | Frame resource of the frame being submitted. |
iCurrentFrameResourceIndex | Index of the current frame resource. |
vOpaquePipelines | Opaque pipelines (depth pipeline will be retrieved from them). |
Implements ne::Renderer.
|
overrideprotectedvirtual |
Submits commands to draw meshes for main (color) pass.
pCurrentFrameResource | Frame resource of the frame being submitted. |
iCurrentFrameResourceIndex | Index of the current frame resource. |
vOpaquePipelines | Opaque pipelines to draw. |
vTransparentPipelines | Transparent pipelines to draw. |
Implements ne::Renderer.
|
protected |
Submits commands to draw meshes and pipelines of specific types (only opaque or transparent).
pCurrentFrameResource | Frame resource of the frame being submitted. |
iCurrentFrameResourceIndex | Index of the current frame resource. |
pipelinesOfSpecificType | Pipelines to use. |
directionalShadowMapsHandle | GPU handle to array of directional shadow maps. |
spotShadowMapsHandle | GPU handle to array of spot shadow maps. |
pointShadowMapsGpuHandle | GPU handle to array of point shadow maps. |
bIsDrawingTransparentMeshes | true if transparent pipelines are used, false otherwise. |
|
overrideprotectedvirtual |
Submits commands to draw world from the perspective of all spawned light sources to capture shadow maps.
pCurrentFrameResource | Frame resource of the frame being submitted. |
iCurrentFrameResourceIndex | Index of the current frame resource. |
pGraphicsPipelines | Graphics pipelines to draw. |
Implements ne::Renderer.
|
overrideprotectedvirtual |
Executes compute shaders of the specified stage.
pCurrentFrameResource | Frame resource of the frame being submitted. |
iCurrentFrameResourceIndex | Index of the current frame resource. |
stage | Stage of compute shaders to execute. |
Implements ne::Renderer.
|
private |
Closes and executes the specified command list on pCommandQueue.
pCommandListToExecute | Command list to execute. |
|
inlinestaticconstexpr |
Returns used back buffer format.
|
private |
Returns current buffer to draw to: either MSAA render buffer of swap chain's buffer.
|
overridevirtual |
Returns the name of the GPU that is being currently used.
Implements ne::Renderer.
ID3D12GraphicsCommandList * ne::DirectXRenderer::getD3dCommandList | ( | ) |
Returns DirectX command list.
ID3D12CommandQueue * ne::DirectXRenderer::getD3dCommandQueue | ( | ) |
Returns DirectX command queue.
ID3D12Device * ne::DirectXRenderer::getD3dDevice | ( | ) | const |
Returns DirectX device.
|
inlinestaticconstexpr |
Returns used depth buffer format for resolved depth buffer.
|
inlinestaticconstexpr |
Returns used depth/stencil buffer format.
|
overridevirtual |
Returns pointer to the texture resource that represents renderer's depth texture without multisampling (resolved resource).
Implements ne::Renderer.
|
overrideprotectedvirtual |
Returns the maximum anti-aliasing quality that can be used on the picked GPU (getCurrentlyUsedGpuName).
DISABLED
if AA is not supported or the maximum supported AA quality. Implements ne::Renderer.
UINT ne::DirectXRenderer::getMsaaQualityLevel | ( | ) | const |
Returns quality level count for the current MSAA sample count.
|
overridevirtual |
Returns size of the render target (size of the underlying render image).
Implements ne::Renderer.
|
inlinestaticconstexpr |
Returns texture format used for shadow maps.
|
inlinestaticconstexpr |
Returns texture format used for point lights as "color" target (does not actually store color) during shadow pass.
|
private |
Returns a vector of display modes that the current output adapter supports for current back buffer format.
|
overridevirtual |
Looks for video adapters (GPUs) that support this renderer.
Implements ne::Renderer.
|
overridevirtual |
Returns a list of supported screen refresh rates (pairs of numerator and denominator).
Implements ne::Renderer.
|
overridevirtual |
Returns a list of supported render resolution (pairs of width and height).
Implements ne::Renderer.
|
overridevirtual |
|
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.
Implements ne::Renderer.
IDXGIAdapter3 * ne::DirectXRenderer::getVideoAdapter | ( | ) | const |
Returns DirectX video adapter.
|
private |
Initializes the renderer.
vBlacklistedGpuNames | Names of GPUs that should not be used, generally this means that these GPUs were previously used to create the renderer but something went wrong. |
|
private |
Initializes DirectX.
vBlacklistedGpuNames | Names of GPUs that should not be used, generally this means that these GPUs were previously used to create the renderer but something went wrong. |
|
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.
Implements ne::Renderer.
|
overrideprotectedvirtual |
Called after some render setting is changed to recreate internal resources to match the current settings.
Implements ne::Renderer.
|
private |
Rates available GPUs and picks the best one to be used (also considers GPU specified in RenderSettings).
vBlacklistedGpuNames | Names of GPUs that should not be used, generally this means that these GPUs were previously used to create the renderer but something went wrong. |
|
overrideprivatevirtual |
Setups everything for render commands to be recorded (resets command buffers and etc.).
pCameraProperties | Camera properties to use. |
pCurrentFrameResource | Frame resource of the frame being submitted. |
Implements ne::Renderer.
|
overrideprotectedvirtual |
Does the final frame rendering logic to present the frame on the screen.
pCurrentFrameResource | Frame resource of the frame being submitted. |
iCurrentFrameResourceIndex | Index of the current frame resource. |
Implements ne::Renderer.
|
staticprivate |
Rates the specified GPU and gives it a suitability score.
adapterDesc | GPU description. |
|
private |
Resets pCommandList and adds initial commands like set descriptor heaps for graphics commands.
pCurrentFrameResource | Frame resource for the current frame. |
|
private |
Sets first found output adapter (monitor).
|
private |
Queries the current render settings for MSAA quality and updates iMsaaQualityLevelsCount.
|
private |
Waits until the GPU has completed commands up to the specified fence point.
iFenceToWaitFor | Fence value to wait for. |
|
overrideprotectedvirtual |
Blocks the current thread until the GPU is finished using the specified frame resource.
pFrameResource | Frame resource to wait for. |
Implements ne::Renderer.
|
overridevirtual |
Blocks the current thread until the GPU finishes executing all queued commands up to this point.
Implements ne::Renderer.
|
private |
Default back buffer fill color.
|
staticconstexprprivate |
Back buffer format.
|
private |
Whether initializeDirectX was finished without errors or not.
|
private |
Whether MSAA enabled and we use pMsaaRenderBuffer as render buffer or not and we use pSwapChain as render buffer.
|
staticconstexprprivate |
Depth buffer format for pDepthBufferNoMultisampling.
|
staticconstexprprivate |
Depth/stencil buffer format.
|
private |
The number of supported quality levels for the current MSAA sample count.
|
private |
Used to prevent tearing when VSync is enabled.
|
private |
Synchronize presentation for at least N vertical blanks. Used when VSync is enabled.
|
private |
Fence counter.
|
private |
Contains commands for the GPU.
|
private |
GPU command queue.
|
private |
Command list for dispatchComputeShadersOnGraphicsQueue.
|
private |
Depth buffer without multisampling (for light culing compute shader).
|
private |
Depth stencil buffer.
|
private |
D3D12 Device.
|
private |
DXGI Factory.
|
private |
Fence object.
|
private |
Render target when MSAA is enabled because our swap chain does not support multisampling.
|
private |
Monitor.
|
private |
Swap chain.
|
private |
GPU.
|
staticconstexprprivate |
D3D feature level that we use (required feature level).
|
private |
Last set size of the underlying swap chain buffer.
|
private |
Scissor rectangle for viewport.
|
private |
Screen viewport size and depth range.
|
staticconstexprprivate |
Format used for shadow maps.
|
staticconstexprprivate |
Format used for point lights as "color" target (does not actually store color) during shadow pass.
|
private |
Name of the GPU we are currently using.
|
staticconstexprprivate |
Use only display modes that use this scaling.
|
staticconstexprprivate |
Use only display modes that use this scanline ordering.
|
private |
List of supported GPUs, filled during pickVideoAdapter.
|
private |
Swap chain buffer.