vengine  0.0.1
3D graphics engine
Loading...
Searching...
No Matches
Pool.hpp
Go to the documentation of this file.
1///
2/// @file Pool.hpp
3/// @brief This file contains the DescriptorPool class
4/// @namespace ven
5///
6
7#pragma once
8
9#include <memory>
10
12
13namespace ven {
14
15 static constexpr uint32_t DEFAULT_MAX_SETS = 1000;
16
17 ///
18 /// @class DescriptorPool
19 /// @brief Class for descriptor pool
20 /// @namespace ven
21 ///
23
24 public:
25
26 class Builder {
27
28 public:
29
30 explicit Builder(Device &device) : m_device{device} {}
31
32 [[nodiscard]] std::unique_ptr<DescriptorPool> build() const { return std::make_unique<DescriptorPool>(m_device, m_maxSets, m_poolFlags, m_poolSizes); }
33
34 Builder &addPoolSize(const VkDescriptorType descriptorType, const uint32_t count) { m_poolSizes.push_back({descriptorType, count}); return *this; }
35 Builder &setPoolFlags(const VkDescriptorPoolCreateFlags flags) { m_poolFlags = flags; return *this; }
36 Builder &setMaxSets(const uint32_t count) { m_maxSets = count; return *this; }
37
38 private:
39
41 std::vector<VkDescriptorPoolSize> m_poolSizes;
43 VkDescriptorPoolCreateFlags m_poolFlags{0};
44
45 }; // class Builder
46
47 DescriptorPool(Device &device, uint32_t maxSets, VkDescriptorPoolCreateFlags poolFlags, const std::vector<VkDescriptorPoolSize> &poolSizes);
48 ~DescriptorPool() { vkDestroyDescriptorPool(m_device.device(), m_descriptorPool, nullptr); }
49
50 DescriptorPool(const DescriptorPool &) = delete;
54
55 bool allocateDescriptor(VkDescriptorSetLayout descriptorSetLayout, VkDescriptorSet &descriptor) const;
56 void freeDescriptors(const std::vector<VkDescriptorSet> &descriptors) const { vkFreeDescriptorSets(m_device.device(), m_descriptorPool, static_cast<uint32_t>(descriptors.size()), descriptors.data()); }
57 void resetPool() const { vkResetDescriptorPool(m_device.device(), m_descriptorPool, 0); }
58
59 [[nodiscard]] VkDescriptorPool getDescriptorPool() const { return m_descriptorPool; }
60
61 private:
62
64 VkDescriptorPool m_descriptorPool;
65 friend class DescriptorWriter;
66
67 }; // class DescriptorPool
68
69} // namespace ven
This file contains the Device class.
std::vector< VkDescriptorPoolSize > m_poolSizes
Definition Pool.hpp:41
std::unique_ptr< DescriptorPool > build() const
Definition Pool.hpp:32
Builder & setPoolFlags(const VkDescriptorPoolCreateFlags flags)
Definition Pool.hpp:35
Builder(Device &device)
Definition Pool.hpp:30
Builder & setMaxSets(const uint32_t count)
Definition Pool.hpp:36
Builder & addPoolSize(const VkDescriptorType descriptorType, const uint32_t count)
Definition Pool.hpp:34
VkDescriptorPoolCreateFlags m_poolFlags
Definition Pool.hpp:43
Class for descriptor pool.
Definition Pool.hpp:22
DescriptorPool(DescriptorPool &&)=delete
void resetPool() const
Definition Pool.hpp:57
VkDescriptorPool m_descriptorPool
Definition Pool.hpp:64
VkDescriptorPool getDescriptorPool() const
Definition Pool.hpp:59
DescriptorPool(Device &device, uint32_t maxSets, VkDescriptorPoolCreateFlags poolFlags, const std::vector< VkDescriptorPoolSize > &poolSizes)
Definition pool.cpp:5
Device & m_device
Definition Pool.hpp:63
bool allocateDescriptor(VkDescriptorSetLayout descriptorSetLayout, VkDescriptorSet &descriptor) const
Definition pool.cpp:20
DescriptorPool & operator=(DescriptorPool &&)=delete
DescriptorPool(const DescriptorPool &)=delete
DescriptorPool & operator=(const DescriptorPool &)=delete
void freeDescriptors(const std::vector< VkDescriptorSet > &descriptors) const
Definition Pool.hpp:56
Class for descriptor writer.
Definition Writer.hpp:19
Class for device.
Definition Device.hpp:35
VkDevice device() const
Definition Device.hpp:54
static constexpr uint32_t DEFAULT_MAX_SETS
Definition Pool.hpp:15