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

#include <VulkanPipeline.h>

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

Classes

struct  InternalResources
 

Public Member Functions

 VulkanPipeline (const VulkanPipeline &)=delete
 
VulkanPipelineoperator= (const VulkanPipeline &)=delete
 
std::optional< ErrorbindBuffersIfUsed (const std::array< GpuResource *, FrameResourceManager::getFrameResourceCount()> &vResources, const std::string &sShaderResourceName, VkDescriptorType descriptorType)
 
std::optional< ErrorbindImageIfUsed (GpuResource *pImageResourceToBind, std::string_view sShaderResourceName, VkDescriptorType descriptorType, VkImageLayout imageLayout, VkSampler pSampler)
 
std::pair< std::recursive_mutex, InternalResources > * getInternalResources ()
 
- Public Member Functions inherited from ne::Pipeline
 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::variant< std::shared_ptr< VulkanPipeline >, ErrorcreateGraphicsPipeline (Renderer *pRenderer, PipelineManager *pPipelineManager, std::unique_ptr< PipelineConfiguration > pPipelineConfiguration)
 
static std::variant< std::shared_ptr< VulkanPipeline >, ErrorcreateComputePipeline (Renderer *pRenderer, PipelineManager *pPipelineManager, const std::string &sComputeShaderName)
 
- Static Public Member Functions inherited from ne::Pipeline
static std::string combineShaderNames (std::string_view sVertexShaderName, std::string_view sPixelShaderName, std::string_view sComputeShaderName="")
 

Protected Member Functions

virtual std::optional< ErrorrecreateInternalResources () override
 
- Protected Member Functions inherited from ne::Pipeline
 Pipeline (Renderer *pRenderer, PipelineManager *pPipelineManager, std::unique_ptr< PipelineConfiguration > pPipelineConfiguration)
 
virtual std::optional< ErrorrecreateInternalResources ()=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

 VulkanPipeline (Renderer *pRenderer, PipelineManager *pPipelineManager, std::unique_ptr< PipelineConfiguration > pPipelineConfiguration)
 
std::optional< ErrorgenerateGraphicsPipeline ()
 
std::optional< ErrorgenerateComputePipelineForShader (const std::string &sComputeShaderName)
 
std::optional< ErrorcreateGraphicsPipeline (VulkanRenderer *pVulkanRenderer, GlslShader *pVertexShader, GlslShader *pFragmentShader, bool bUsePixelBlending)
 
std::optional< ErrorcreateComputePipeline (VulkanRenderer *pVulkanRenderer, GlslShader *pComputeShader)
 
std::optional< ErrorbindFrameDataDescriptors ()
 
std::optional< ErrorreleaseInternalResources ()
 
std::variant< VkPushConstantRange, ErrordefinePushConstants (const std::unordered_map< std::string, size_t > &pushConstantUintFieldOffsets, const std::unordered_map< std::string, uint32_t, StdStringHash, std::equal_to<> > &resourceBindings)
 

Private Attributes

std::pair< std::recursive_mutex, InternalResourcesmtxInternalResources
 

Detailed Description

VkPipeline object wrapper.

Constructor & Destructor Documentation

◆ VulkanPipeline()

ne::VulkanPipeline::VulkanPipeline ( Renderer pRenderer,
PipelineManager pPipelineManager,
std::unique_ptr< PipelineConfiguration pPipelineConfiguration 
)
private

Constructs uninitialized pipeline.

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

Member Function Documentation

◆ bindBuffersIfUsed()

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

Binds the specified GPU resources (buffers, not images) to this pipeline if it uses 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.

◆ bindFrameDataDescriptors()

std::optional< Error > ne::VulkanPipeline::bindFrameDataDescriptors ( )
private

Binds descriptors that reference "frameData" shader resource to frame resources' uniform buffers.

Remarks
Expects that descriptor sets in mtxInternalResources are initialized.
Returns
Error if something went wrong.

◆ bindImageIfUsed()

std::optional< Error > ne::VulkanPipeline::bindImageIfUsed ( GpuResource pImageResourceToBind,
std::string_view  sShaderResourceName,
VkDescriptorType  descriptorType,
VkImageLayout  imageLayout,
VkSampler  pSampler 
)

Binds the specified GPU resource (image, not buffer) to this pipeline if it uses 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.

◆ createComputePipeline() [1/2]

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

Assigns compute shader to create a compute pipeline.

Parameters
pRendererUsed renderer.
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.

◆ createComputePipeline() [2/2]

std::optional< Error > ne::VulkanPipeline::createComputePipeline ( VulkanRenderer pVulkanRenderer,
GlslShader pComputeShader 
)
private

Fully initializes mtxInternalResources by creating a compute pipeline for the specified shader.

Parameters
pVulkanRendererVulkan renderer.
pComputeShaderCompute shader to use in the pipeline.
Returns
Error if something went wrong.

◆ createGraphicsPipeline() [1/2]

std::variant< std::shared_ptr< VulkanPipeline >, Error > ne::VulkanPipeline::createGraphicsPipeline ( Renderer pRenderer,
PipelineManager pPipelineManager,
std::unique_ptr< PipelineConfiguration pPipelineConfiguration 
)
static

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

Parameters
pRendererUsed renderer.
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.

◆ createGraphicsPipeline() [2/2]

std::optional< Error > ne::VulkanPipeline::createGraphicsPipeline ( VulkanRenderer pVulkanRenderer,
GlslShader pVertexShader,
GlslShader pFragmentShader,
bool  bUsePixelBlending 
)
private

Fully initializes mtxInternalResources by creating a graphics pipeline for the specified shaders.

Parameters
pVulkanRendererVulkan renderer.
pVertexShaderVertex shader to use in the pipeline.
pFragmentShaderFragment shader to use in the pipeline. Specify nullptr if you want to create depth only pipeline (used for z-prepass).
bUsePixelBlendingWhether the pipeline should use blending or not (for transparency).
Returns
Error if something went wrong.

◆ definePushConstants()

std::variant< VkPushConstantRange, Error > ne::VulkanPipeline::definePushConstants ( const std::unordered_map< std::string, size_t > &  pushConstantUintFieldOffsets,
const std::unordered_map< std::string, uint32_t, StdStringHash, std::equal_to<> > &  resourceBindings 
)
private

Initializes internal push constants manager and returns push constants description.

Parameters
pushConstantUintFieldOffsetsStores pairs of "name of field defined in GLSL push constants" (all with uint type) and "offset from the beginning of the push constants struct (in `uint`s not bytes)".
resourceBindingsMap of pairs "resource name" (from GLSL code) - "layout binding index".
Returns
Error if something went wrong, otherwise push constants range.

◆ generateComputePipelineForShader()

std::optional< Error > ne::VulkanPipeline::generateComputePipelineForShader ( const std::string &  sComputeShaderName)
private

(Re)generates Vulkan compute pipeline and pipeline layout for the specified shader.

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 pipeline is immediately generated. Make sure the GPU is not using old shader/pipeline.
Parameters
sComputeShaderNameName of the compiled compute shader (see ShaderManager::compileShaders).
Returns
Error if failed to generate pipeline.

◆ generateGraphicsPipeline()

std::optional< Error > ne::VulkanPipeline::generateGraphicsPipeline ( )
private

(Re)generates Vulkan pipeline and pipeline layout.

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 pipeline is immediately generated. Make sure the GPU is not using old shader/pipeline.
Returns
Error if failed to generate pipeline.

◆ getInternalResources()

std::pair< std::recursive_mutex, InternalResources > * ne::VulkanPipeline::getInternalResources ( )
inline

Returns internal resources that this pipeline uses.

Returns
Internal resources.

◆ recreateInternalResources()

std::optional< Error > ne::VulkanPipeline::recreateInternalResources ( )
overrideprotectedvirtual

Releases all internal resources from this graphics pipeline 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.

Implements ne::Pipeline.

◆ releaseInternalResources()

std::optional< Error > ne::VulkanPipeline::releaseInternalResources ( )
private

Releases all internal resources from this graphics pipeline.

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 in recreateInternalResources and in the destructor to delete/free used resources.
Returns
Error if something went wrong.

Member Data Documentation

◆ mtxInternalResources

std::pair<std::recursive_mutex, InternalResources> ne::VulkanPipeline::mtxInternalResources
private

Internal resources. Must be used with mutex when changing.


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