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::pair< std::recursive_mutex, InternalResources > * getInternalResources ()
 
- Public Member Functions inherited from ne::Pipeline
 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::variant< std::shared_ptr< VulkanPipeline >, ErrorcreateGraphicsPipeline (Renderer *pRenderer, PipelineManager *pPipelineManager, std::unique_ptr< PipelineCreationSettings > pPipelineCreationSettings)
 
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 (const std::string &sVertexShaderName, const std::string &sPixelShaderName)
 

Protected Member Functions

virtual std::optional< ErrorreleaseInternalResources () override
 
virtual std::optional< ErrorrestoreInternalResources () override
 
- Protected Member Functions inherited from 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)
 
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

 VulkanPipeline (Renderer *pRenderer, PipelineManager *pPipelineManager, const std::string &sVertexShaderName, const std::set< ShaderMacro > &additionalVertexShaderMacros, const std::string &sFragmentShaderName, const std::set< ShaderMacro > &additionalFragmentShaderMacros={}, const std::string &sComputeShaderName="", bool bEnableDepthBias=false, bool bIsUsedForPointLightsShadowMapping=false, bool bUsePixelBlending=false)
 
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::variant< VkPushConstantRange, ErrordefinePushConstants (const std::unordered_map< std::string, size_t > &pushConstantUintFieldOffsets, const std::unordered_map< std::string, uint32_t > &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,
const std::string &  sVertexShaderName,
const std::set< ShaderMacro > &  additionalVertexShaderMacros,
const std::string &  sFragmentShaderName,
const std::set< ShaderMacro > &  additionalFragmentShaderMacros = {},
const std::string &  sComputeShaderName = "",
bool  bEnableDepthBias = false,
bool  bIsUsedForPointLightsShadowMapping = false,
bool  bUsePixelBlending = false 
)
private

Constructs uninitialized pipeline.

Parameters
pRendererUsed 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.
sFragmentShaderNameName of the compiled pixel shader to use (empty if not used).
additionalFragmentShaderMacrosAdditional macros to enable for fragment 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

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

◆ 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< PipelineCreationSettings pPipelineCreationSettings 
)
static

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

Parameters
pRendererUsed renderer.
pPipelineManagerPipeline manager that owns this pipeline.
pPipelineCreationSettingsSettings that determine pipeline usage and usage details. configuration.
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 > &  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.

◆ releaseInternalResources()

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

Releases internal resources such as pipeline layout, internal pipeline, descriptor layout, etc.

Warning
Expects that the GPU is not referencing this pipeline and that no drawing will occur until restoreInternalResources is called.
Remarks
Typically used before changing something (for ex. shader configuration), so that no pipeline will reference old resources, to later call restoreInternalResources.
Returns
Error if something went wrong.

Implements ne::Pipeline.

◆ restoreInternalResources()

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

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.

Implements ne::Pipeline.

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: