Nameless Engine
Loading...
Searching...
No Matches
DescriptorSetLayoutGenerator.h
1#pragma once
2
3// Standard.
4#include <variant>
5#include <vector>
6#include <unordered_map>
7#include <array>
8#include <unordered_set>
9
10// Custom.
11#include "misc/Error.h"
12#include "render/general/resource/frame/FrameResourceManager.h"
13#include "shader/VulkanAlignmentConstants.hpp"
14#include "misc/StdHashes.hpp"
15
16// External.
17#include "vulkan/vulkan.h"
18
19namespace ne {
20 class GlslShader;
21 class VulkanRenderer;
22
24 enum class GlslResourceType {
25 UNIFORM_BUFFER,
26 STORAGE_BUFFER,
27 COMBINED_SAMPLER,
28 STORAGE_IMAGE,
29 // ... add new resource types here ...
30 };
31
34 public:
36 struct Collected {
40 GlslResourceType resourceType;
41
43 std::string sResourceName;
44 };
45
50 std::unordered_map<uint32_t, DescriptorSetLayoutBindingInfo> bindingInfo;
51
60 std::unordered_map<std::string, size_t> pushConstantUintFieldOffsets;
61 };
62
64 struct Generated {
66 VkDescriptorSetLayout pDescriptorSetLayout = nullptr;
67
69 VkDescriptorPool pDescriptorPool = nullptr;
70
73
82 std::unordered_map<std::string, uint32_t, StdStringHash, std::equal_to<>> resourceBindings;
83
92 std::unordered_map<std::string, size_t> pushConstantUintFieldOffsets;
93 };
94
98
108 static std::variant<Collected, Error>
109 collectInfoFromBytecode(void* pSpirvBytecode, size_t iSizeInBytes);
110
125 static std::variant<Generated, Error>
126 generateGraphics(VulkanRenderer* pRenderer, GlslShader* pVertexShader, GlslShader* pFragmentShader);
127
139 static std::variant<Generated, Error>
140 generateCompute(VulkanRenderer* pRenderer, GlslShader* pComputeShader);
141
142 private:
153 static std::variant<std::pair<VkDescriptorSetLayoutBinding, VkDescriptorBindingFlags>, Error>
155 uint32_t iBindingIndex,
157 bool bIsComputeShader);
158 };
159} // namespace ne
Definition: DescriptorSetLayoutGenerator.h:33
static std::variant< std::pair< VkDescriptorSetLayoutBinding, VkDescriptorBindingFlags >, Error > generateLayoutBinding(uint32_t iBindingIndex, const Collected::DescriptorSetLayoutBindingInfo &bindingInfo, bool bIsComputeShader)
Definition: DescriptorSetLayoutGenerator.cpp:793
static std::variant< Collected, Error > collectInfoFromBytecode(void *pSpirvBytecode, size_t iSizeInBytes)
Definition: DescriptorSetLayoutGenerator.cpp:19
static std::variant< Generated, Error > generateCompute(VulkanRenderer *pRenderer, GlslShader *pComputeShader)
Definition: DescriptorSetLayoutGenerator.cpp:570
static std::variant< Generated, Error > generateGraphics(VulkanRenderer *pRenderer, GlslShader *pVertexShader, GlslShader *pFragmentShader)
Definition: DescriptorSetLayoutGenerator.cpp:179
Definition: Error.h:27
static constexpr unsigned int getFrameResourceCount()
Definition: FrameResourceManager.h:74
Definition: GlslShader.h:20
Definition: VulkanRenderer.h:26
std::string sResourceName
Definition: DescriptorSetLayoutGenerator.h:43
GlslResourceType resourceType
Definition: DescriptorSetLayoutGenerator.h:40
Definition: DescriptorSetLayoutGenerator.h:36
std::unordered_map< uint32_t, DescriptorSetLayoutBindingInfo > bindingInfo
Definition: DescriptorSetLayoutGenerator.h:50
std::unordered_map< std::string, size_t > pushConstantUintFieldOffsets
Definition: DescriptorSetLayoutGenerator.h:60
Definition: DescriptorSetLayoutGenerator.h:64
VkDescriptorSetLayout pDescriptorSetLayout
Definition: DescriptorSetLayoutGenerator.h:66
std::unordered_map< std::string, uint32_t, StdStringHash, std::equal_to<> > resourceBindings
Definition: DescriptorSetLayoutGenerator.h:82
std::array< VkDescriptorSet, FrameResourceManager::getFrameResourceCount()> vDescriptorSets
Definition: DescriptorSetLayoutGenerator.h:72
std::unordered_map< std::string, size_t > pushConstantUintFieldOffsets
Definition: DescriptorSetLayoutGenerator.h:92
VkDescriptorPool pDescriptorPool
Definition: DescriptorSetLayoutGenerator.h:69