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

#include <PipelineManager.h>

Classes

struct  ComputePipelines
 
struct  GraphicsPipelineRegistry
 
struct  ShaderPipelines
 

Public Member Functions

 PipelineManager (Renderer *pRenderer)
 
virtual ~PipelineManager ()
 
 PipelineManager (const PipelineManager &)=delete
 
PipelineManageroperator= (const PipelineManager &)=delete
 
DelayedPipelineResourcesCreation clearGraphicsPipelinesInternalResourcesAndDelayRestoring ()
 
std::variant< PipelineSharedPtr, ErrorgetGraphicsPipelineForMaterial (std::unique_ptr< PipelineCreationSettings > pPipelineCreationSettings, Material *pMaterial)
 
std::pair< std::recursive_mutex *, QueuedForExecutionComputeShaders * > getComputeShadersForGraphicsQueueExecution ()
 
std::pair< std::recursive_mutex, GraphicsPipelineRegistry > * getGraphicsPipelines ()
 
size_t getCurrentGraphicsPipelineCount ()
 
size_t getCurrentComputePipelineCount ()
 
RenderergetRenderer () const
 

Private Member Functions

std::optional< ErrorreleaseInternalGraphicsPipelinesResources ()
 
std::optional< ErrorrestoreInternalGraphicsPipelinesResources ()
 
std::variant< PipelineSharedPtr, ErrorcreateGraphicsPipelineForMaterial (std::unordered_map< std::string, ShaderPipelines > &pipelines, const std::string &sShaderNames, const std::set< ShaderMacro > &macrosToUse, std::unique_ptr< PipelineCreationSettings > pPipelineCreationSettings, Material *pMaterial)
 
void onPipelineNoLongerUsedByMaterial (const std::string &sPipelineIdentifier)
 
void onPipelineNoLongerUsedByComputeShaderInterface (const std::string &sComputeShaderName, ComputeShaderInterface *pComputeShaderInterface)
 
std::variant< PipelineSharedPtr, ErrorfindOrCreatePipeline (std::unordered_map< std::string, ShaderPipelines > &pipelines, const std::string &sKeyToLookFor, const std::set< ShaderMacro > &macrosToLookFor, std::unique_ptr< PipelineCreationSettings > pPipelineCreationSettings, Material *pMaterial)
 

Private Attributes

std::pair< std::recursive_mutex, GraphicsPipelineRegistrymtxGraphicsPipelines
 
ComputePipelines computePipelines
 
RendererpRenderer = nullptr
 

Friends

class Pipeline
 
class DelayedPipelineResourcesCreation
 
class ComputeShaderInterface
 

Detailed Description

Base class for managing render specific pipelines.

Constructor & Destructor Documentation

◆ PipelineManager()

ne::PipelineManager::PipelineManager ( Renderer pRenderer)

Creates a new pipeline manager.

Parameters
pRendererRenderer that owns this pipeline manager.

◆ ~PipelineManager()

ne::PipelineManager::~PipelineManager ( )
virtual

Checks that there are no existing pipelines left.

Member Function Documentation

◆ clearGraphicsPipelinesInternalResourcesAndDelayRestoring()

DelayedPipelineResourcesCreation ne::PipelineManager::clearGraphicsPipelinesInternalResourcesAndDelayRestoring ( )

Returns a RAII object that once acquired waits for the GPU to finish work up to this point, pauses the rendering, releases all internal resources from all graphics pipelines, then in destructor restores them.

Returns
RAII object.

◆ createGraphicsPipelineForMaterial()

std::variant< PipelineSharedPtr, Error > ne::PipelineManager::createGraphicsPipelineForMaterial ( std::unordered_map< std::string, ShaderPipelines > &  pipelines,
const std::string &  sShaderNames,
const std::set< ShaderMacro > &  macrosToUse,
std::unique_ptr< PipelineCreationSettings pPipelineCreationSettings,
Material pMaterial 
)
private

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

Parameters
pipelinesPipelines of specific type to look in.
sShaderNamesShader or shaders (map key value) for target pipeline.
macrosToUseMacros that are set (can be only vertex or combined).
pPipelineCreationSettingsSettings that determine pipeline usage and usage details.
pMaterialMaterial that requests the pipeline.
Returns
Error if one or both were not found in ShaderManager or if failed to generate pipeline, otherwise created pipeline.

◆ findOrCreatePipeline()

std::variant< PipelineSharedPtr, Error > ne::PipelineManager::findOrCreatePipeline ( std::unordered_map< std::string, ShaderPipelines > &  pipelines,
const std::string &  sKeyToLookFor,
const std::set< ShaderMacro > &  macrosToLookFor,
std::unique_ptr< PipelineCreationSettings pPipelineCreationSettings,
Material pMaterial 
)
private

Looks for a pipeline and returns it if found, otherwise creates and return it.

Parameters
pipelinesPipelines of specific type to look in.
sKeyToLookForShader or shaders (map key value) for target pipeline.
macrosToLookForMacros that are set (can be only vertex or combined).
pPipelineCreationSettingsSettings that determine pipeline usage and usage details.
pMaterialMaterial that requests the pipeline.
Returns
Error if something went wrong, otherwise valid pipeline pointer.

◆ getComputeShadersForGraphicsQueueExecution()

std::pair< std::recursive_mutex *, QueuedForExecutionComputeShaders * > ne::PipelineManager::getComputeShadersForGraphicsQueueExecution ( )
inline

Returns all compute shaders and their pipelines to be executed on the graphics queue.

Warning
Do not delete (free) returned pointers.
Returns
Shaders and pipelines.

◆ getCurrentComputePipelineCount()

size_t ne::PipelineManager::getCurrentComputePipelineCount ( )

Returns the total number of currently existing compute pipelines.

Returns
The total number of currently existing compute pipelines.

◆ getCurrentGraphicsPipelineCount()

size_t ne::PipelineManager::getCurrentGraphicsPipelineCount ( )

Returns the total number of currently existing graphics pipelines.

Returns
The total number of currently existing graphics pipelines.

◆ getGraphicsPipelineForMaterial()

std::variant< PipelineSharedPtr, Error > ne::PipelineManager::getGraphicsPipelineForMaterial ( std::unique_ptr< PipelineCreationSettings pPipelineCreationSettings,
Material pMaterial 
)

Look for already created pipeline that uses the specified shaders and settings and returns it, otherwise creates a new pipeline.

Remarks
If creating a new pipeline, loads the specified shaders from disk into the memory, they will be released from the memory once the pipeline object is destroyed (not the shared pointer) and no other object is using them.
Parameters
pPipelineCreationSettingsSettings that determine pipeline usage and usage details.
pMaterialMaterial that requests the pipeline.
Returns
Error if one or both shaders were not found in ShaderManager or if failed to generate pipeline, otherwise created pipeline.

◆ getGraphicsPipelines()

std::pair< std::recursive_mutex, GraphicsPipelineRegistry > * ne::PipelineManager::getGraphicsPipelines ( )
inline

Returns all vertex/pixel shaders and their graphics pipelines.

Warning
Do not delete (free) returned pointers.
Returns
Shaders and pipelines.

◆ getRenderer()

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

Returns renderer that owns this pipeline manager.

Returns
Renderer.

◆ onPipelineNoLongerUsedByComputeShaderInterface()

void ne::PipelineManager::onPipelineNoLongerUsedByComputeShaderInterface ( const std::string &  sComputeShaderName,
ComputeShaderInterface pComputeShaderInterface 
)
private

Called from a pipeline when a compute shader interface is no longer using a pipeline.

Parameters
sComputeShaderNameName of the compute shader that the pipeline uses.
pComputeShaderInterfaceCompute shader interface that stopped using the pipeline.

◆ onPipelineNoLongerUsedByMaterial()

void ne::PipelineManager::onPipelineNoLongerUsedByMaterial ( const std::string &  sPipelineIdentifier)
private

Called from a pipeline when a material is no longer using a pipeline (for ex. because changing shaders).

Parameters
sPipelineIdentifierPipeline identifier.

◆ releaseInternalGraphicsPipelinesResources()

std::optional< Error > ne::PipelineManager::releaseInternalGraphicsPipelinesResources ( )
private

Releases internal resources (such as root signature, internal pipeline, etc.) from all created graphics pipelines.

Warning
Expects that the GPU is not referencing graphics pipelines and that no drawing will occur until restoreInternalGraphicsPipelinesResources is called.
Remarks
Causes the mutex that guards graphics pipelines to be locked until restoreInternalGraphicsPipelinesResources is not called and finished.
Typically used before changing something (for ex. shader configuration), so that no pipeline will reference old resources, to later call restoreInternalGraphicsPipelinesResources.
Returns
Error if something went wrong.

◆ restoreInternalGraphicsPipelinesResources()

std::optional< Error > ne::PipelineManager::restoreInternalGraphicsPipelinesResources ( )
private

Creates internal resources for all created graphics pipelines using their current configuration.

Remarks
Called after releaseInternalGraphicsPipelinesResources to create resources that will now reference changed (new) resources.
Returns
Error if something went wrong.

Member Data Documentation

◆ computePipelines

ComputePipelines ne::PipelineManager::computePipelines
private

Stores all compute pipelines.

◆ mtxGraphicsPipelines

std::pair<std::recursive_mutex, GraphicsPipelineRegistry> ne::PipelineManager::mtxGraphicsPipelines
private

Groups all graphics pipelines.

◆ pRenderer

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

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


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