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< ErrorreleaseInternalResources () override
 
virtual std::optional< ErrorrestoreInternalResources () override
 
- Protected Member Functions inherited from ne::Pipeline
 Pipeline (Renderer *pRenderer, PipelineManager *pPipelineManager, std::unique_ptr< PipelineConfiguration > pPipelineConfiguration)
 
virtual std::optional< ErrorreleaseInternalResources ()=0
 
virtual std::optional< ErrorrestoreInternalResources ()=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.

◆ releaseInternalResources()

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

Releases internal resources such as root signature or descriptor layout, internal pipeline object and etc.

Warning
Expects that the GPU is not referencing this Pipeline (command queue is empty) and that no drawing will occur until restoreInternalResources is called.
Remarks
Typically used before (!) changing something in the pipeline. Often it's a shader configuration change due to a change in some settings, for example when a material that uses this pipeline requested to use a diffuse texture, thus we need to define a "use diffuse texture" shader macro and for that we change the shader variant.
Returns
Error if something went wrong.

Implements ne::Pipeline.

◆ restoreInternalResources()

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

Creates internal resources using the current shader configuration.

Remarks
Called after releaseInternalResources to create resources that will now reference changed (new) resources.
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: