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:
184 [[nodiscard]] virtual std::optional<Error> releaseInternalResources() override;
185
194 [[nodiscard]] virtual std::optional<Error> restoreInternalResources() override;
195
196 private:
207 std::unique_ptr<PipelineConfiguration> pPipelineConfiguration);
208
218 [[nodiscard]] std::optional<Error> generateGraphicsPipeline();
219
231 [[nodiscard]] std::optional<Error>
232 generateComputePipelineForShader(const std::string& sComputeShaderName);
233
246 [[nodiscard]] std::optional<Error> createGraphicsPipeline(
247 VulkanRenderer* pVulkanRenderer,
248 GlslShader* pVertexShader,
249 GlslShader* pFragmentShader,
250 bool bUsePixelBlending);
251
261 [[nodiscard]] std::optional<Error>
262 createComputePipeline(VulkanRenderer* pVulkanRenderer, GlslShader* pComputeShader);
263
271 [[nodiscard]] std::optional<Error> bindFrameDataDescriptors();
272
284 std::variant<VkPushConstantRange, Error> definePushConstants(
285 const std::unordered_map<std::string, size_t>& pushConstantUintFieldOffsets,
286 const std::unordered_map<std::string, uint32_t, StdStringHash, std::equal_to<>>&
287 resourceBindings);
288
293 std::pair<std::recursive_mutex, InternalResources> mtxInternalResources;
294 };
295} // 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:98
Definition: Pipeline.h:20
const std::unique_ptr< PipelineConfiguration > pPipelineConfiguration
Definition: Pipeline.h:274
Renderer *const pRenderer
Definition: Pipeline.h:280
PipelineManager *const pPipelineManager
Definition: Pipeline.h:277
Definition: Renderer.h:43
Definition: VulkanPipeline.h:21
std::pair< std::recursive_mutex, InternalResources > mtxInternalResources
Definition: VulkanPipeline.h:293
static std::variant< std::shared_ptr< VulkanPipeline >, Error > createGraphicsPipeline(Renderer *pRenderer, PipelineManager *pPipelineManager, std::unique_ptr< PipelineConfiguration > pPipelineConfiguration)
Definition: VulkanPipeline.cpp:65
virtual std::optional< Error > releaseInternalResources() override
Definition: VulkanPipeline.cpp:224
std::optional< Error > generateGraphicsPipeline()
Definition: VulkanPipeline.cpp:328
std::pair< std::recursive_mutex, InternalResources > * getInternalResources()
Definition: VulkanPipeline.h:165
std::optional< Error > bindImageIfUsed(GpuResource *pImageResourceToBind, std::string_view sShaderResourceName, VkDescriptorType descriptorType, VkImageLayout imageLayout, VkSampler pSampler)
Definition: VulkanPipeline.cpp:164
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:297
std::optional< Error > bindFrameDataDescriptors()
Definition: VulkanPipeline.cpp:1038
std::optional< Error > generateComputePipelineForShader(const std::string &sComputeShaderName)
Definition: VulkanPipeline.cpp:405
std::optional< Error > bindBuffersIfUsed(const std::array< GpuResource *, FrameResourceManager::getFrameResourceCount()> &vResources, const std::string &sShaderResourceName, VkDescriptorType descriptorType)
Definition: VulkanPipeline.cpp:99
static std::variant< std::shared_ptr< VulkanPipeline >, Error > createComputePipeline(Renderer *pRenderer, PipelineManager *pPipelineManager, const std::string &sComputeShaderName)
Definition: VulkanPipeline.cpp:83
virtual std::optional< Error > restoreInternalResources() override
Definition: VulkanPipeline.cpp:283
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