Nameless Engine
Loading...
Searching...
No Matches
VulkanPipeline.h
1#pragma once
2
3// Standard.
4#include <memory>
5#include <unordered_set>
6
7// Custom.
8#include "render/general/pipeline/Pipeline.h"
9#include "render/general/resource/frame/FrameResourceManager.h"
10#include "shader/general/resource/ShaderArrayIndexManager.h"
11#include "misc/StdHashes.hpp"
12
13// External.
14#include "vulkan/vulkan.h"
15
16namespace ne {
17 class VulkanRenderer;
18 class GlslShader;
19
21 class VulkanPipeline : public Pipeline {
22 public:
25 InternalResources() = default;
26
28 VkPipelineLayout pPipelineLayout = nullptr;
29
31 VkPipeline pPipeline = nullptr;
32
34 VkDescriptorSetLayout pDescriptorSetLayout = nullptr;
35
37 VkDescriptorPool pDescriptorPool = nullptr;
38
56
65 std::unordered_map<std::string, uint32_t, StdStringHash, std::equal_to<>> resourceBindings;
66
85 std::unordered_map<std::string, std::unique_ptr<ShaderArrayIndexManager>>
87
89 bool bIsReadyForUsage = false;
90 };
91
92 VulkanPipeline() = delete;
93 VulkanPipeline(const VulkanPipeline&) = delete;
94 VulkanPipeline& operator=(const VulkanPipeline&) = delete;
95
96 virtual ~VulkanPipeline() override;
97
108 static std::variant<std::shared_ptr<VulkanPipeline>, Error> createGraphicsPipeline(
111 std::unique_ptr<PipelineConfiguration> pPipelineConfiguration);
112
123 static std::variant<std::shared_ptr<VulkanPipeline>, Error> createComputePipeline(
124 Renderer* pRenderer, PipelineManager* pPipelineManager, const std::string& sComputeShaderName);
125
136 [[nodiscard]] std::optional<Error> bindBuffersIfUsed(
137 const std::array<GpuResource*, FrameResourceManager::getFrameResourceCount()>& vResources,
138 const std::string& sShaderResourceName,
139 VkDescriptorType descriptorType);
140
153 [[nodiscard]] std::optional<Error> bindImageIfUsed(
154 GpuResource* pImageResourceToBind,
155 std::string_view sShaderResourceName,
156 VkDescriptorType descriptorType,
157 VkImageLayout imageLayout,
158 VkSampler pSampler);
159
165 inline std::pair<std::recursive_mutex, InternalResources>* getInternalResources() {
166 return &mtxInternalResources;
167 }
168
169 protected:
186 [[nodiscard]] virtual std::optional<Error> recreateInternalResources() override;
187
188 private:
199 std::unique_ptr<PipelineConfiguration> pPipelineConfiguration);
200
210 [[nodiscard]] std::optional<Error> generateGraphicsPipeline();
211
223 [[nodiscard]] std::optional<Error>
224 generateComputePipelineForShader(const std::string& sComputeShaderName);
225
238 [[nodiscard]] std::optional<Error> createGraphicsPipeline(
239 VulkanRenderer* pVulkanRenderer,
240 GlslShader* pVertexShader,
241 GlslShader* pFragmentShader,
242 bool bUsePixelBlending);
243
253 [[nodiscard]] std::optional<Error>
254 createComputePipeline(VulkanRenderer* pVulkanRenderer, GlslShader* pComputeShader);
255
263 [[nodiscard]] std::optional<Error> bindFrameDataDescriptors();
264
276 [[nodiscard]] std::optional<Error> releaseInternalResources();
277
289 std::variant<VkPushConstantRange, Error> definePushConstants(
290 const std::unordered_map<std::string, size_t>& pushConstantUintFieldOffsets,
291 const std::unordered_map<std::string, uint32_t, StdStringHash, std::equal_to<>>&
292 resourceBindings);
293
298 std::pair<std::recursive_mutex, InternalResources> mtxInternalResources;
299 };
300} // namespace ne
Definition: Error.h:27
static constexpr unsigned int getFrameResourceCount()
Definition: FrameResourceManager.h:74
Definition: GlslShader.h:20
Definition: GpuResource.h:16
Definition: PipelineManager.h:54
Definition: Pipeline.h:20
const std::unique_ptr< PipelineConfiguration > pPipelineConfiguration
Definition: Pipeline.h:266
Renderer *const pRenderer
Definition: Pipeline.h:272
PipelineManager *const pPipelineManager
Definition: Pipeline.h:269
Definition: Renderer.h:43
Definition: VulkanPipeline.h:21
std::pair< std::recursive_mutex, InternalResources > mtxInternalResources
Definition: VulkanPipeline.h:298
static std::variant< std::shared_ptr< VulkanPipeline >, Error > createGraphicsPipeline(Renderer *pRenderer, PipelineManager *pPipelineManager, std::unique_ptr< PipelineConfiguration > pPipelineConfiguration)
Definition: VulkanPipeline.cpp:64
std::optional< Error > generateGraphicsPipeline()
Definition: VulkanPipeline.cpp:335
std::pair< std::recursive_mutex, InternalResources > * getInternalResources()
Definition: VulkanPipeline.h:165
virtual std::optional< Error > recreateInternalResources() override
Definition: VulkanPipeline.cpp:282
std::optional< Error > bindImageIfUsed(GpuResource *pImageResourceToBind, std::string_view sShaderResourceName, VkDescriptorType descriptorType, VkImageLayout imageLayout, VkSampler pSampler)
Definition: VulkanPipeline.cpp:163
std::variant< VkPushConstantRange, Error > definePushConstants(const std::unordered_map< std::string, size_t > &pushConstantUintFieldOffsets, const std::unordered_map< std::string, uint32_t, StdStringHash, std::equal_to<> > &resourceBindings)
Definition: VulkanPipeline.cpp:304
std::optional< Error > bindFrameDataDescriptors()
Definition: VulkanPipeline.cpp:1045
std::optional< Error > generateComputePipelineForShader(const std::string &sComputeShaderName)
Definition: VulkanPipeline.cpp:412
std::optional< Error > bindBuffersIfUsed(const std::array< GpuResource *, FrameResourceManager::getFrameResourceCount()> &vResources, const std::string &sShaderResourceName, VkDescriptorType descriptorType)
Definition: VulkanPipeline.cpp:98
static std::variant< std::shared_ptr< VulkanPipeline >, Error > createComputePipeline(Renderer *pRenderer, PipelineManager *pPipelineManager, const std::string &sComputeShaderName)
Definition: VulkanPipeline.cpp:82
std::optional< Error > releaseInternalResources()
Definition: VulkanPipeline.cpp:223
Definition: VulkanRenderer.h:26
Definition: StdHashes.hpp:10
Definition: VulkanPipeline.h:24
std::array< VkDescriptorSet, FrameResourceManager::getFrameResourceCount()> vDescriptorSets
Definition: VulkanPipeline.h:55
bool bIsReadyForUsage
Definition: VulkanPipeline.h:89
VkPipelineLayout pPipelineLayout
Definition: VulkanPipeline.h:28
VkDescriptorPool pDescriptorPool
Definition: VulkanPipeline.h:37
VkDescriptorSetLayout pDescriptorSetLayout
Definition: VulkanPipeline.h:34
std::unordered_map< std::string, uint32_t, StdStringHash, std::equal_to<> > resourceBindings
Definition: VulkanPipeline.h:65
std::unordered_map< std::string, std::unique_ptr< ShaderArrayIndexManager > > shaderArrayIndexManagers
Definition: VulkanPipeline.h:86
VkPipeline pPipeline
Definition: VulkanPipeline.h:31