vOOlkan
An object oriented approach to Vulkan
Set.h
Go to the documentation of this file.
1#ifndef VULKAN_SET
2#define VULKAN_SET
3
4#include <glm/glm.hpp>
5#include <tuple>
6#include <concepts>
7#include <type_traits>
8
9#include "UniformBuffer.h"
10#include "LogicalDevice.h"
11#include "PhysicalDevice.h"
13
14
15namespace Vulkan {
16
21 class Set {
22 public:
23
29 const VkDescriptorSetLayout& operator+() const {
31 }
32
33
37 struct BindingInfo {
38
45 virtual DescriptorSetBindingCreationInfo generateDescriptorSetBindingInfo(const VkDescriptorSet& descriptorSet) const = 0;
46
50 unsigned int binding;
51 };
52
53
59 int getAmountOfBindings() const {
60 return bindingsInfo.size();
61 }
62
63
67 const std::vector<std::unique_ptr<BindingInfo>>& getBindingsInfo() const {
68 return bindingsInfo;
69 }
70
71
75 const BindingInfo& getBindingInfo(int i) const {
76 return *bindingsInfo[i];
77 }
78
79
80 protected:
81
82
84
85 Set(const Set&) = delete;
86 Set& operator=(const Set&) = delete;
87 Set(Set&&) = delete;
88 Set& operator=(Set&&) = delete;
89
90 ~Set() {
91 vkDestroyDescriptorSetLayout(+virtualGpu, descriptorSetLayout, nullptr);
92 }
93
94
95 //Creates the VkDescriptorSetLayout Vulkan object for this set
96 template<std::same_as<std::pair<VkShaderStageFlagBits, VkDescriptorType>>... ShaderStages>
97 void createDescriptorSetLayout(ShaderStages... shaderStages) {
98 //create info structs for each binding
99 std::vector<VkDescriptorSetLayoutBinding> bindings; //vector containing the binding info structures for this set
100 int counter = 0;
101 ([&bindings, &counter](std::pair<VkShaderStageFlagBits, VkDescriptorType> shaderStage) {
102 VkDescriptorSetLayoutBinding binding{};
103 binding.binding = counter;
104 binding.descriptorCount = 1; //no arrays for now
105 binding.descriptorType = shaderStage.second;
106 binding.pImmutableSamplers = nullptr;
107 binding.stageFlags = shaderStage.first;
108 bindings.push_back(binding);
109 counter++;
110 }(shaderStages), ...);
111
112 //put toghether the info structs for each binding and create the final layout object
113 VkDescriptorSetLayoutCreateInfo layoutInfo{};
114 layoutInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
115 layoutInfo.bindingCount = bindings.size();
116 layoutInfo.pBindings = bindings.data();
117
118 if (VkResult result = vkCreateDescriptorSetLayout(+virtualGpu, &layoutInfo, nullptr, &descriptorSetLayout); result != VK_SUCCESS) {
119 throw VulkanException("Failed to create descriptor set layout!", result);
120 }
121 }
122
123
124
125 VkDescriptorSetLayout descriptorSetLayout;
126 std::vector<std::unique_ptr<BindingInfo>> bindingsInfo;
128
129 };
130
131}
132
133
134
135#endif
Definition: DescriptorSetBindingCreationInfo.h:10
A logical device is an abstraction of the physical GPU which we can mainly use to send commands.
Definition: LogicalDevice.h:15
A Set is a set of bindings which can be read by the shader.
Definition: Set.h:21
const BindingInfo & getBindingInfo(int i) const
Returns the size, offset and buffer of the binding number i of this set.
Definition: Set.h:75
void createDescriptorSetLayout(ShaderStages... shaderStages)
Definition: Set.h:97
const std::vector< std::unique_ptr< BindingInfo > > & getBindingsInfo() const
Returns the size, offset and buffer of each binding in this set.
Definition: Set.h:67
Set & operator=(Set &&)=delete
Set & operator=(const Set &)=delete
VkDescriptorSetLayout descriptorSetLayout
Definition: Set.h:125
Set(const Set &)=delete
int getAmountOfBindings() const
Returns the number of bindings in this set.
Definition: Set.h:59
const LogicalDevice & virtualGpu
Definition: Set.h:127
Set(const LogicalDevice &virtualGpu)
Definition: Set.h:83
Set(Set &&)=delete
std::vector< std::unique_ptr< BindingInfo > > bindingsInfo
Definition: Set.h:126
const VkDescriptorSetLayout & operator+() const
Returns the underlying VkDescriptorSetLayout object.
Definition: Set.h:29
~Set()
Definition: Set.h:90
Generic runtime exception thrown by Vulkan-related functions.
Definition: VulkanException.h:13
Types of queue families.
Definition: Animations.h:17
A struct containing all of the information of a specific binding. This class must be the base of othe...
Definition: Set.h:37
unsigned int binding
The binding index.
Definition: Set.h:50
virtual DescriptorSetBindingCreationInfo generateDescriptorSetBindingInfo(const VkDescriptorSet &descriptorSet) const =0
Creates the struct for this binding used to create the descriptor set.