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

#include <PipelineManager.h>

Classes

struct  ComputePipelines
 

Public Member Functions

 PipelineManager (Renderer *pRenderer)
 
virtual ~PipelineManager ()
 
 PipelineManager (const PipelineManager &)=delete
 
PipelineManageroperator= (const PipelineManager &)=delete
 
std::optional< ErrorbindBuffersToAllVulkanPipelinesIfUsed (const std::array< GpuResource *, FrameResourceManager::getFrameResourceCount()> &vResources, const std::string &sShaderResourceName, VkDescriptorType descriptorType)
 
std::optional< ErrorbindImageToAllVulkanPipelinesIfUsed (GpuResource *pImageResourceToBind, const std::string &sShaderResourceName, VkDescriptorType descriptorType, VkImageLayout imageLayout, VkSampler pSampler)
 
std::optional< ErrorrecreateGraphicsPipelinesResources ()
 
std::variant< PipelineSharedPtr, ErrorgetGraphicsPipelineForMaterial (std::unique_ptr< PipelineConfiguration > pPipelineConfiguration, 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::variant< PipelineSharedPtr, ErrorcreateGraphicsPipelineForMaterial (std::unordered_map< std::string, ShaderPipelines > &pipelines, const std::string &sShaderNames, const std::set< ShaderMacro > &macrosToUse, std::unique_ptr< PipelineConfiguration > pPipelineConfiguration, 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< PipelineConfiguration > pPipelineConfiguration, Material *pMaterial)
 

Private Attributes

std::pair< std::recursive_mutex, GraphicsPipelineRegistrymtxGraphicsPipelines
 
ComputePipelines computePipelines
 
Renderer *const pRenderer = 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

◆ bindBuffersToAllVulkanPipelinesIfUsed()

std::optional< Error > ne::PipelineManager::bindBuffersToAllVulkanPipelinesIfUsed ( const std::array< GpuResource *, FrameResourceManager::getFrameResourceCount()> &  vResources,
const std::string &  sShaderResourceName,
VkDescriptorType  descriptorType 
)

Binds the specified GPU resources (buffers, not images) to all Vulkan pipelines that use the specified shader resource.

Parameters
vResourcesResources to bind.
sShaderResourceNameName of the shader resource (name from shader code) to bind to.
descriptorTypeType of the descriptor to bind.
Returns
Error if something went wrong.

◆ bindImageToAllVulkanPipelinesIfUsed()

std::optional< Error > ne::PipelineManager::bindImageToAllVulkanPipelinesIfUsed ( GpuResource pImageResourceToBind,
const std::string &  sShaderResourceName,
VkDescriptorType  descriptorType,
VkImageLayout  imageLayout,
VkSampler  pSampler 
)

Binds the specified GPU image (not buffer) to all Vulkan pipelines that use the specified shader resource.

Parameters
pImageResourceToBindImage to bind.
sShaderResourceNameName of the shader resource (name from shader code) to bind to.
descriptorTypeType of the descriptor to bind.
imageLayoutLayout of the image.
pSamplerSampler to use for the image.
Returns
Error if something went wrong.

◆ 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< PipelineConfiguration pPipelineConfiguration,
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).
pPipelineConfigurationSettings 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< PipelineConfiguration pPipelineConfiguration,
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).
pPipelineConfigurationSettings 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< PipelineConfiguration pPipelineConfiguration,
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
pPipelineConfigurationSettings 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.
Remarks
While the mutex is locked no pipeline will re-create its internal resources.
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.

◆ recreateGraphicsPipelinesResources()

std::optional< Error > ne::PipelineManager::recreateGraphicsPipelinesResources ( )

Releases all internal resources from all graphics graphics pipelines and then recreates them to reference new resources/parameters from the renderer.

Warning
Expects that the GPU is not processing any frames and the rendering is paused (new frames are not submitted) while this function is being called.
Remarks
This function is used when all graphics pipelines reference old render resources/parameters to reference the new (changed) render resources/parameters. The typical workflow goes like this: pause the rendering, change renderer's resource/parameter that all graphics pipelines reference (like render target type (MSAA or not) or MSAA sample count), then call this function (all graphics pipelines will now query up-to-date rendering resources/parameters) and then you can continue rendering.
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* const 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: