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::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::string combineShaderNames (std::string_view sVertexShaderName, std::string_view sPixelShaderName, std::string_view sComputeShaderName="")
 

Protected Member Functions

 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

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< PipelineConfiguration > pPipelineConfiguration)
 
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
 
const std::unique_ptr< PipelineConfigurationpPipelineConfiguration
 
PipelineManager *const pPipelineManager = nullptr
 
Renderer *const pRenderer = nullptr
 

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,
std::unique_ptr< PipelineConfiguration pPipelineConfiguration 
)
explicitprotected

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

Parameters
pRendererCurrent renderer.
pPipelineManagerPipeline manager that owns this pipeline.
pPipelineConfigurationSettings and usage details.

Member Function Documentation

◆ combineShaderNames()

std::string ne::Pipeline::combineShaderNames ( std::string_view  sVertexShaderName,
std::string_view  sPixelShaderName,
std::string_view  sComputeShaderName = "" 
)
static

Combines shader names into a 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.
sComputeShaderNameName of the compute shader that pipeline is using. Can be empty.
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< PipelineConfiguration pPipelineConfiguration 
)
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.
pPipelineConfigurationSettings 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.

◆ getConfiguration()

const PipelineConfiguration * ne::Pipeline::getConfiguration ( ) const

Returns pipeline's settings and usage details.

Warning
Do not delete (free) returned pointer. It's guaranteed to live while the object is alive.
Returns
Settings.

◆ 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.

◆ 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.

◆ getUintConstantOffset()

std::variant< size_t, Error > ne::Pipeline::getUintConstantOffset ( const std::string &  sConstantName)

Looks for an offset of a uint field in root/push constants of the specified name.

Parameters
sConstantNameName of the push/root constant.
Returns
Error if something went wrong, otherwise offset (in uints) of the field from the start of the root/push constants struct.

◆ 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 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.

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.

◆ 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

◆ 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.

◆ pPipelineConfiguration

const std::unique_ptr<PipelineConfiguration> ne::Pipeline::pPipelineConfiguration
private

Usage details of this pipeline.

◆ pPipelineManager

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

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

◆ pRenderer

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

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


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