vOOlkan
An object oriented approach to Vulkan
DescriptorSet.h
Go to the documentation of this file.
1#ifndef VULKAN_DESCRIPTORSET
2#define VULKAN_DESCRIPTORSET
3
4#include <vulkan/vulkan.h>
5#include <concepts>
6
7#include "DescriptorSetPool.h"
8#include "Set.h"
9#include "DynamicSet.h"
10#include "StaticSet.h"
11#include "LogicalDevice.h"
12#include "PhysicalDevice.h"
13#include "UniformBuffer.h"
14#include "TextureImage.h"
15#include "VulkanException.h"
16
17
18namespace Vulkan {
19
20
25 template<std::derived_from<Vulkan::Set> S>
27 public:
28
37 DescriptorSet(const LogicalDevice& virtualGpu, const DescriptorSetPool& descriptorPool, const S& set) : set{ set } {
38 //create the descriptor set
39 VkDescriptorSetAllocateInfo allocInfo{};
40 allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
41 allocInfo.descriptorPool = +descriptorPool;
42 allocInfo.descriptorSetCount = 1;
43 allocInfo.pSetLayouts = &+set;
44
45 if (VkResult result = vkAllocateDescriptorSets(+virtualGpu, &allocInfo, &descriptorSet); result != VK_SUCCESS) {
46 throw VulkanException("Failed to allocate descriptor sets!", result);
47 }
48
49
50 //fill the descriptor set's bindings
51 std::vector<DescriptorSetBindingCreationInfo> descriptorsInfo;
52 for (int i = 0; i < set.getAmountOfBindings(); ++i) {
53 descriptorsInfo.push_back(set.getBindingInfo(i).generateDescriptorSetBindingInfo(descriptorSet));
54 }
55
56 std::vector<VkWriteDescriptorSet> rawDescriptorsInfo;
57 for (const auto& descriptorInfo : descriptorsInfo) {
58 rawDescriptorsInfo.push_back(+descriptorInfo);
59 }
60
61 vkUpdateDescriptorSets(+virtualGpu, rawDescriptorsInfo.size(), rawDescriptorsInfo.data(), 0, nullptr);
62 }
63
64
65 const VkDescriptorSet& operator+() const {
66 return descriptorSet;
67 }
68
69
73 const S& getSet() const {
74 return set;
75 }
76
77
78 private:
79 VkDescriptorSet descriptorSet;
80 const S& set;
81 };
82}
83
84#endif
A DescriptorSet is an object which holds the handles (pointers) to the bindings (variables) in a spec...
Definition: DescriptorSet.h:26
const VkDescriptorSet & operator+() const
Definition: DescriptorSet.h:65
DescriptorSet(const LogicalDevice &virtualGpu, const DescriptorSetPool &descriptorPool, const S &set)
Builds a DescriptorSet by following the information of the passed-in set.
Definition: DescriptorSet.h:37
const S & getSet() const
Returns the underlying set of this descriptor set.
Definition: DescriptorSet.h:73
Class used to allocate DescriptorSet(s).
Definition: DescriptorSetPool.h:16
A logical device is an abstraction of the physical GPU which we can mainly use to send commands.
Definition: LogicalDevice.h:15
Generic runtime exception thrown by Vulkan-related functions.
Definition: VulkanException.h:13
Types of queue families.
Definition: Animations.h:17