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::pair< std::recursive_mutex, InternalResources > * getInternalResources ()
 
- Public Member Functions inherited from ne::Pipeline
 Pipeline (const Pipeline &)=delete
 
Pipelineoperator= (const Pipeline &)=delete
 
std::string getVertexShaderName ()
 
std::string getPixelShaderName ()
 
std::string getComputeShaderName ()
 
std::optional< std::set< ShaderMacro > > getCurrentShaderConfiguration (ShaderType shaderType)
 
bool isUsingPixelBlending () const
 
bool isDepthBiasEnabled () const
 
bool isUsedForPointLightsShadowMapping () const
 
std::pair< std::mutex, std::unordered_set< Material * > > * getMaterialsThatUseThisPipeline ()
 
std::string getPipelineIdentifier () const
 
RenderergetRenderer () const
 
std::set< ShaderMacro > getAdditionalVertexShaderMacros () const
 
std::set< ShaderMacro > getAdditionalPixelShaderMacros () 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< PipelineCreationSettings > pPipelineCreationSettings)
 
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 (const std::string &sVertexShaderName, const std::string &sPixelShaderName)
 

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, const std::string &sVertexShaderName, const std::set< ShaderMacro > &additionalVertexShaderMacros, const std::string &sPixelShaderName="", const std::set< ShaderMacro > &additionalPixelShaderMacros={}, const std::string &sComputeShaderName="", bool bEnableDepthBias=false, bool bIsUsedForPointLightsShadowMapping=false, bool bUsePixelBlending=false)
 
void saveUsedShaderConfiguration (ShaderType shaderType, std::set< ShaderMacro > &&fullConfiguration)
 
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)
 
std::optional< ShaderPack * > getShader (ShaderType shaderType)
 

Private Member Functions

 DirectXPso (Renderer *pRenderer, PipelineManager *pPipelineManager, const std::string &sVertexShaderName, const std::set< ShaderMacro > &additionalVertexShaderMacros, const std::string &sPixelShaderName, const std::set< ShaderMacro > &additionalPixelShaderMacros={}, const std::string &sComputeShaderName="", bool bEnableDepthBias=false, bool bIsUsedForPointLightsShadowMapping=false, bool bUsePixelBlending=false)
 
std::optional< ErrorgenerateGraphicsPso ()
 
std::optional< ErrorgenerateComputePso ()
 

Private Attributes

std::pair< std::recursive_mutex, InternalResourcesmtxInternalResources
 

Detailed Description

DirectX pipeline state object (PSO) wrapper.

Constructor & Destructor Documentation

◆ DirectXPso()

ne::DirectXPso::DirectXPso ( Renderer pRenderer,
PipelineManager pPipelineManager,
const std::string &  sVertexShaderName,
const std::set< ShaderMacro > &  additionalVertexShaderMacros,
const std::string &  sPixelShaderName,
const std::set< ShaderMacro > &  additionalPixelShaderMacros = {},
const std::string &  sComputeShaderName = "",
bool  bEnableDepthBias = false,
bool  bIsUsedForPointLightsShadowMapping = false,
bool  bUsePixelBlending = false 
)
explicitprivate

Constructs uninitialized pipeline.

Parameters
pRendererUsed renderer.
pPipelineManagerPipeline manager that owns this PSO.
sVertexShaderNameName of the compiled vertex shader to use (empty if not used).
additionalVertexShaderMacrosAdditional macros to enable for vertex shader configuration.
sPixelShaderNameName of the compiled pixel shader to use (empty if not used).
additionalPixelShaderMacrosAdditional macros to enable for pixel shader configuration.
sComputeShaderNameName of the compiled compute shader to use (empty if not used).
bEnableDepthBiasWhether depth bias (offset) is enabled or not.
bIsUsedForPointLightsShadowMappingWhether this pipeline is used for shadow mapping of point lights or not.
bUsePixelBlendingWhether the pixels of the mesh that uses this PSO should blend with existing pixels on back buffer or not (for transparency).

Member Function Documentation

◆ 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< PipelineCreationSettings pPipelineCreationSettings 
)
static

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

Parameters
pRendererUsed renderer.
pPipelineManagerPipeline manager that owns this PSO.
pPipelineCreationSettingsSettings 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.

◆ releaseInternalResources()

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

Releases internal resources such as root signature, internal PSO, etc.

Warning
Expects that the GPU is not referencing this PSO and that no drawing will occur until restoreInternalResources is called.
Remarks
Typically used before changing something (for ex. shader configuration), so that no PSO will reference old resources, to later call restoreInternalResources.
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: