Nameless Engine
Loading...
Searching...
No Matches
ne::Pipeline Class Referenceabstract

#include <Pipeline.h>

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

Classes

struct  ShaderConstantsData
 

Public Member Functions

 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::string combineShaderNames (const std::string &sVertexShaderName, const std::string &sPixelShaderName)
 

Protected Member Functions

 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

void onMaterialUsingPipeline (Material *pMaterial)
 
void onMaterialNoLongerUsingPipeline (Material *pMaterial)
 
void onComputeShaderUsingPipeline (ComputeShaderInterface *pComputeShaderInterface)
 
void onComputeShaderNoLongerUsingPipeline (ComputeShaderInterface *pComputeShaderInterface)
 

Static Private Member Functions

static std::variant< std::shared_ptr< Pipeline >, ErrorcreateGraphicsPipeline (Renderer *pRenderer, PipelineManager *pPipelineManager, std::unique_ptr< PipelineCreationSettings > pPipelineCreationSettings)
 
static std::variant< std::shared_ptr< Pipeline >, ErrorcreateComputePipeline (Renderer *pRenderer, PipelineManager *pPipelineManager, const std::string &sComputeShaderName)
 

Private Attributes

std::pair< std::mutex, std::unordered_set< Material * > > mtxMaterialsThatUseThisPipeline
 
std::pair< std::mutex, std::unordered_set< ComputeShaderInterface * > > mtxComputeShadersThatUseThisPipeline
 
std::pair< std::mutex, std::optional< ShaderConstantsData > > mtxShaderConstantsData
 
std::set< ShaderMacro > additionalVertexShaderMacros
 
std::set< ShaderMacro > additionalPixelShaderMacros
 
std::unordered_map< ShaderType, std::set< ShaderMacro > > usedShaderConfiguration
 
PipelineManagerpPipelineManager = nullptr
 
RendererpRenderer = nullptr
 
const std::string sVertexShaderName
 
const std::string sPixelShaderName
 
const std::string sComputeShaderName
 
bool bIsUsingPixelBlending = false
 
bool bEnableDepthBias = false
 
bool bIsUsedForPointLightsShadowMapping = false
 

Friends

class PipelineManager
 
class PipelineSharedPtr
 

Detailed Description

Base class for render specific pipeline objects.

Constructor & Destructor Documentation

◆ Pipeline()

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 
)
explicitprotected

Creates a new empty (no internal GPU resource is created) pipeline.

Parameters
pRendererCurrent renderer.
pPipelineManagerPipeline manager that owns this pipeline.
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 Pipeline should blend with existing pixels on back buffer or not (for transparency).

Member Function Documentation

◆ combineShaderNames()

std::string ne::Pipeline::combineShaderNames ( const std::string &  sVertexShaderName,
const std::string &  sPixelShaderName 
)
static

Combines shader names into one string.

Remarks
This function exists to avoid duplicating the shader name combination formatting.
Parameters
sVertexShaderNameName of the vertex shader that pipeline is using.
sPixelShaderNameName of the pixel shader that pipeline is using. If empty only vertex shader name will be returned.
Returns
A (not unique) pipeline identifier.

◆ createComputePipeline()

std::variant< std::shared_ptr< Pipeline >, Error > ne::Pipeline::createComputePipeline ( Renderer pRenderer,
PipelineManager pPipelineManager,
const std::string &  sComputeShaderName 
)
staticprivate

Assigns compute shader to create a render specific compute pipeline.

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

◆ createGraphicsPipeline()

std::variant< std::shared_ptr< Pipeline >, Error > ne::Pipeline::createGraphicsPipeline ( Renderer pRenderer,
PipelineManager pPipelineManager,
std::unique_ptr< PipelineCreationSettings pPipelineCreationSettings 
)
staticprivate

Assigns vertex and pixel shaders to create a render specific graphics pipeline (for usual rendering).

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

◆ getAdditionalPixelShaderMacros()

std::set< ShaderMacro > ne::Pipeline::getAdditionalPixelShaderMacros ( ) const

Returns additional macros that were specified during pipeline creation to be enabled for pixel/fragment shader configuration.

Returns
Additional macros to enable for pixel/fragment shader.

◆ getAdditionalVertexShaderMacros()

std::set< ShaderMacro > ne::Pipeline::getAdditionalVertexShaderMacros ( ) const

Returns additional macros that were specified during pipeline creation to be enabled for vertex shader configuration.

Returns
Additional macros to enable for vertex shader.

◆ getComputeShaderName()

std::string ne::Pipeline::getComputeShaderName ( )

Returns name of the compute shader that this pipeline is using.

Returns
Empty if not using compute shader, otherwise name of the used compute shader.

◆ getCurrentShaderConfiguration()

std::optional< std::set< ShaderMacro > > ne::Pipeline::getCurrentShaderConfiguration ( ShaderType  shaderType)

Returns a shader configuration of the currently used shader.

Parameters
shaderTypeShader type to get configuration of.
Returns
Empty if a shader of this type is not used by this Pipeline, otherwise shader configuration.

◆ getMaterialsThatUseThisPipeline()

std::pair< std::mutex, std::unordered_set< Material * > > * ne::Pipeline::getMaterialsThatUseThisPipeline ( )

Returns an array of materials that currently reference this Pipeline. Must be used with mutex.

Returns
Array of materials that currently reference this Pipeline.

◆ getPipelineIdentifier()

std::string ne::Pipeline::getPipelineIdentifier ( ) const

Constructs and returns a non unique identifier of this pipeline that contains used shader names.

Returns
A (not unique) pipeline identifier.

◆ getPixelShaderName()

std::string ne::Pipeline::getPixelShaderName ( )

Returns name of the pixel shader that this pipeline is using.

Returns
Empty if not using pixel shader, otherwise name of the used pixel shader.

◆ getRenderer()

Renderer * ne::Pipeline::getRenderer ( ) const

Returns renderer that owns this Pipeline.

Returns
Renderer.

◆ getShaderConstants()

std::pair< std::mutex, std::optional< Pipeline::ShaderConstantsData > > * ne::Pipeline::getShaderConstants ( )

Returns push/root constants used in the pipeline (if were specified in the shaders).

Warning
Do not delete (free) returned pointer.
Returns
Optional constants.

◆ getVertexShaderName()

std::string ne::Pipeline::getVertexShaderName ( )

Returns name of the vertex shader that this pipeline is using.

Returns
Empty if not using vertex shader, otherwise name of the used vertex shader.

◆ isDepthBiasEnabled()

bool ne::Pipeline::isDepthBiasEnabled ( ) const

Tells whether this pipeline has depth bias (offset) enabled.

Returns
Whether depth bias is enabled or not.

◆ isUsedForPointLightsShadowMapping()

bool ne::Pipeline::isUsedForPointLightsShadowMapping ( ) const

Tells whether this pipeline is used for shadow mapping of point lights.

Returns
true if used, false otherwise.

◆ isUsingPixelBlending()

bool ne::Pipeline::isUsingPixelBlending ( ) const

Tells whether this pipeline is using pixel blending or not.

Returns
Whether this pipeline is using pixel blending or not.

◆ onComputeShaderNoLongerUsingPipeline()

void ne::Pipeline::onComputeShaderNoLongerUsingPipeline ( ComputeShaderInterface pComputeShaderInterface)
private

Called to notify this pipeline that the shared pointer to this pipeline (that compute shader interface stores) is now nullptr.

Warning
Call this function after clearing (setting to nullptr) the shared pointer, not before.
Parameters
pComputeShaderInterfaceCompute shader interface that stopped using this pipeline.

◆ onComputeShaderUsingPipeline()

void ne::Pipeline::onComputeShaderUsingPipeline ( ComputeShaderInterface pComputeShaderInterface)
private

Called to notify this pipeline that a compute shader interface started storing a shared pointer to this pipeline.

Remarks
When a compute interface is no longer references the pipeline use onComputeShaderNoLongerUsingPipeline.
Parameters
pComputeShaderInterfaceCompute shader interface that started using this pipeline.

◆ onMaterialNoLongerUsingPipeline()

void ne::Pipeline::onMaterialNoLongerUsingPipeline ( Material pMaterial)
private

Called to notify this Pipeline that the shared pointer to this pipeline (that Material stores) is now nullptr.

Warning
Call this function after clearing (setting to nullptr) the shared pointer, not before.
Parameters
pMaterialMaterial that stopped using this pipeline.

◆ onMaterialUsingPipeline()

void ne::Pipeline::onMaterialUsingPipeline ( Material pMaterial)
private

Called to notify this pipeline that a material started storing a shared pointer to this pipeline.

Remarks
When a material is no longer references the Pipeline use onMaterialNoLongerUsingPipeline.
Parameters
pMaterialMaterial that started using this pipeline.

◆ releaseInternalResources()

virtual std::optional< Error > ne::Pipeline::releaseInternalResources ( )
protectedpure virtual

Releases internal resources such as root signature, internal Pipeline, 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 (for ex. shader configuration, texture filtering), so that no Pipeline will reference old resources, to later call restoreInternalResources that will recreate internal resources with new render settings.
Returns
Error if something went wrong.

Implemented in ne::DirectXPso, and ne::VulkanPipeline.

◆ restoreInternalResources()

virtual std::optional< Error > ne::Pipeline::restoreInternalResources ( )
protectedpure virtual

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.

Implemented in ne::DirectXPso, and ne::VulkanPipeline.

◆ saveUsedShaderConfiguration()

void ne::Pipeline::saveUsedShaderConfiguration ( ShaderType  shaderType,
std::set< ShaderMacro > &&  fullConfiguration 
)
protected

Saves shader configuration of the currently used shader.

Remarks
This should be called by derived classes when they start to use some shader.
Parameters
shaderTypeType of the shader being currently used.
fullConfigurationShader's full (might include renderer's configuration) configuration.

◆ setShaderConstants()

void ne::Pipeline::setShaderConstants ( const std::unordered_map< std::string, size_t > &  uintConstantsOffsets)
protected

Sets new push/root constants that will were found in the shaders of the pipeline.

Parameters
uintConstantsOffsetsEmpty if shader constants should not be used, otherwise pairs of: names of fields defined in GLSL as push constants or as root constants in HLSL (all with uint type) and offset of the constant from the beginning of the layout/struct.

Member Data Documentation

◆ additionalPixelShaderMacros

std::set<ShaderMacro> ne::Pipeline::additionalPixelShaderMacros
private

Additional macros that were specified during pipeline creation to be enabled for pixel/fragment shader configuration.

Remarks
Generally used in restoreInternalResources.

◆ additionalVertexShaderMacros

std::set<ShaderMacro> ne::Pipeline::additionalVertexShaderMacros
private

Additional macros that were specified during pipeline creation to be enabled for vertex shader configuration.

Remarks
Generally used in restoreInternalResources.

◆ bEnableDepthBias

bool ne::Pipeline::bEnableDepthBias = false
private

Whether depth bias (offset) should be used or not (generally used for shadow map pipelines).

◆ bIsUsedForPointLightsShadowMapping

bool ne::Pipeline::bIsUsedForPointLightsShadowMapping = false
private

Whether this pipeline is used for shadow mapping of point lights or not.

◆ bIsUsingPixelBlending

bool ne::Pipeline::bIsUsingPixelBlending = false
private

Whether this Pipeline is using pixel blending or not.

◆ mtxComputeShadersThatUseThisPipeline

std::pair<std::mutex, std::unordered_set<ComputeShaderInterface*> > ne::Pipeline::mtxComputeShadersThatUseThisPipeline
private

Array of compute shader interfaces that currently reference this compute pipeline.

Remarks
Must be used with mutex.

◆ mtxMaterialsThatUseThisPipeline

std::pair<std::mutex, std::unordered_set<Material*> > ne::Pipeline::mtxMaterialsThatUseThisPipeline
private

Array of materials that currently reference this graphics pipeline.

Remarks
Must be used with mutex.

◆ mtxShaderConstantsData

std::pair<std::mutex, std::optional<ShaderConstantsData> > ne::Pipeline::mtxShaderConstantsData
private

Not empty if push/root constants are used.

◆ pPipelineManager

PipelineManager* ne::Pipeline::pPipelineManager = nullptr
private

Do not delete (free) this pointer. Pipeline manager that owns this Pipeline.

◆ pRenderer

Renderer* ne::Pipeline::pRenderer = nullptr
private

Do not delete (free) this pointer. Current renderer.

◆ sComputeShaderName

const std::string ne::Pipeline::sComputeShaderName
private

Name of the compiled compute shader that this Pipeline uses (empty if graphics pipeline).

◆ sPixelShaderName

const std::string ne::Pipeline::sPixelShaderName
private

Name of the compiled pixel shader that this Pipeline uses (empty if compute pipeline).

◆ sVertexShaderName

const std::string ne::Pipeline::sVertexShaderName
private

Name of the compiled vertex shader that this Pipeline uses (empty if compute pipeline).

◆ usedShaderConfiguration

std::unordered_map<ShaderType, std::set<ShaderMacro> > ne::Pipeline::usedShaderConfiguration
private

Full shader configuration (might include renderer's configuration) of a currently used shader.


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