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

#include <DirectXPso.h>

Inheritance diagram for ne::DirectXPso:
ne::Pipeline ne::ShaderUser

Classes

struct  InternalResources
 

Public Member Functions

 DirectXPso (const DirectXPso &)=delete
 
DirectXPsooperator= (const DirectXPso &)=delete
 
std::variant< unsigned int, ErrorgetRootParameterIndex (const std::string &sShaderResourceName)
 
std::pair< std::recursive_mutex, InternalResources > * getInternalResources ()
 
- Public Member Functions inherited from ne::Pipeline
 Pipeline (const Pipeline &)=delete
 
Pipelineoperator= (const Pipeline &)=delete
 
std::variant< size_t, ErrorgetUintConstantOffset (const std::string &sConstantName)
 
std::pair< std::mutex, std::unordered_set< Material * > > * getMaterialsThatUseThisPipeline ()
 
std::string getPipelineIdentifier () const
 
RenderergetRenderer () const
 
const PipelineConfigurationgetConfiguration () const
 
std::pair< std::mutex, std::optional< ShaderConstantsData > > * getShaderConstants ()
 
- Public Member Functions inherited from ne::ShaderUser
 ShaderUser (const ShaderUser &)=delete
 
ShaderUseroperator= (const ShaderUser &)=delete
 

Static Public Member Functions

static std::variant< std::shared_ptr< DirectXPso >, ErrorcreateGraphicsPso (Renderer *pRenderer, PipelineManager *pPipelineManager, std::unique_ptr< PipelineConfiguration > pPipelineConfiguration)
 
static std::variant< std::shared_ptr< DirectXPso >, ErrorcreateComputePso (Renderer *pRenderer, PipelineManager *pPipelineManager, const std::string &sComputeShaderName)
 
- Static Public Member Functions inherited from ne::Pipeline
static std::string combineShaderNames (std::string_view sVertexShaderName, std::string_view sPixelShaderName, std::string_view sComputeShaderName="")
 

Protected Member Functions

virtual std::optional< ErrorrecreateInternalResources () override
 
- Protected Member Functions inherited from ne::Pipeline
 Pipeline (Renderer *pRenderer, PipelineManager *pPipelineManager, std::unique_ptr< PipelineConfiguration > pPipelineConfiguration)
 
virtual std::optional< ErrorrecreateInternalResources ()=0
 
void setShaderConstants (const std::unordered_map< std::string, size_t > &uintConstantsOffsets)
 
- Protected Member Functions inherited from ne::ShaderUser
 ShaderUser (ShaderManager *pShaderManager)
 
virtual ~ShaderUser ()
 
bool addShader (const std::string &sShaderName)
 
ShaderPackfindShader (ShaderType shaderType)
 

Private Member Functions

 DirectXPso (Renderer *pRenderer, PipelineManager *pPipelineManager, std::unique_ptr< PipelineConfiguration > pPipelineConfiguration)
 
void bindGlobalShaderResourceViews (const ComPtr< ID3D12GraphicsCommandList > &pCommandList, size_t iCurrentFrameResourceIndex) const
 
std::optional< ErrorgenerateGraphicsPso ()
 
std::optional< ErrorgenerateComputePso ()
 

Private Attributes

std::pair< std::recursive_mutex, InternalResourcesmtxInternalResources
 

Friends

class DirectXRenderer
 

Detailed Description

DirectX pipeline state object (PSO) wrapper.

Constructor & Destructor Documentation

◆ DirectXPso()

ne::DirectXPso::DirectXPso ( Renderer pRenderer,
PipelineManager pPipelineManager,
std::unique_ptr< PipelineConfiguration pPipelineConfiguration 
)
explicitprivate

Constructs uninitialized pipeline.

Parameters
pRendererUsed renderer.
pPipelineManagerPipeline manager that owns this PSO.
pPipelineConfigurationSettings and usage details.

Member Function Documentation

◆ bindGlobalShaderResourceViews()

void ne::DirectXPso::bindGlobalShaderResourceViews ( const ComPtr< ID3D12GraphicsCommandList > &  pCommandList,
size_t  iCurrentFrameResourceIndex 
) const
inlineprivate

Sets views of global shader resource bindings.

Warning
Expects that the pipeline's internal resources mutex is already locked by the caller.
Parameters
pCommandListCommand list to set views to.
iCurrentFrameResourceIndexIndex of the frame resource that is currently being used to submit a new frame.

◆ createComputePso()

std::variant< std::shared_ptr< DirectXPso >, Error > ne::DirectXPso::createComputePso ( Renderer pRenderer,
PipelineManager pPipelineManager,
const std::string &  sComputeShaderName 
)
static

Assigns compute shader to create a compute PSO.

Parameters
pRendererUsed renderer.
pPipelineManagerPipeline manager that owns this PSO.
sComputeShaderNameName of the compiled compute shader (see ShaderManager::compileShaders).
Returns
Error if shader was not found in ShaderManager or if failed to generate PSO, otherwise created PSO.

◆ createGraphicsPso()

std::variant< std::shared_ptr< DirectXPso >, Error > ne::DirectXPso::createGraphicsPso ( Renderer pRenderer,
PipelineManager pPipelineManager,
std::unique_ptr< PipelineConfiguration pPipelineConfiguration 
)
static

Assigns vertex and pixel shaders to create a graphics PSO (for usual rendering).

Parameters
pRendererUsed renderer.
pPipelineManagerPipeline manager that owns this PSO.
pPipelineConfigurationSettings that determine pipeline usage and usage details.
Returns
Error if one or both were not found in ShaderManager or if failed to generate PSO, otherwise created PSO.

◆ generateComputePso()

std::optional< Error > ne::DirectXPso::generateComputePso ( )
private

(Re)generates DirectX compute pipeline state object.

Warning
If a shader of some type was already added it will be replaced with the new one. When shader is replaced the old shader gets freed from the memory and a new PSO is immediately generated. Make sure the GPU is not using old shader/PSO.
Returns
Error if failed to generate PSO.

◆ generateGraphicsPso()

std::optional< Error > ne::DirectXPso::generateGraphicsPso ( )
private

(Re)generates DirectX graphics pipeline state object.

Warning
If a shader of some type was already added it will be replaced with the new one. When shader is replaced the old shader gets freed from the memory and a new PSO is immediately generated. Make sure the GPU is not using old shader/PSO.
Returns
Error if failed to generate PSO.

◆ getInternalResources()

std::pair< std::recursive_mutex, InternalResources > * ne::DirectXPso::getInternalResources ( )
inline

Returns internal resources that this PSO uses.

Returns
Internal resources.

◆ getRootParameterIndex()

std::variant< unsigned int, Error > ne::DirectXPso::getRootParameterIndex ( const std::string &  sShaderResourceName)

Looks for a root parameter that is used for a shader resource with the specified name.

Parameters
sShaderResourceNameShader resource name (from the shader code) to look for.
Returns
Error if something went wrong, otherwise root parameter index of the resource with the specified name.

◆ recreateInternalResources()

std::optional< Error > ne::DirectXPso::recreateInternalResources ( )
overrideprotectedvirtual

Releases all internal resources from this graphics pipeline and then recreates them to reference new resources/parameters from the renderer.

Warning
Expects that the GPU is not processing any frames and the rendering is paused (new frames are not submitted) while this function is being called.
Remarks
This function is used when all graphics pipelines reference old render resources/parameters to reference the new (changed) render resources/parameters. The typical workflow goes like this: pause the rendering, change renderer's resource/parameter that all graphics pipelines reference (like render target type (MSAA or not) or MSAA sample count), then call this function (all graphics pipelines will now query up-to-date rendering resources/parameters) and then you can continue rendering.
Returns
Error if something went wrong.

Implements ne::Pipeline.

Member Data Documentation

◆ mtxInternalResources

std::pair<std::recursive_mutex, InternalResources> ne::DirectXPso::mtxInternalResources
private

Internal resources. Must be used with mutex when changing.


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