1 template <
size_t maxSets>
6 template <
size_t maxSets>
15 template <
size_t maxSets>
17 if (static_cast<VkDescriptorPool>(
descriptorPool) == VK_NULL_HANDLE) {
21 descriptorPoolBuilder.
setFlags(VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT);
23 descriptorPoolBuilder.setMaxSets(42);
25 std::vector<VkDescriptorPoolSize> poolSizes{
27 VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC,
31 VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
35 descriptorPoolBuilder.setPoolSizes(poolSizes);
37 VkResult result{VK_SUCCESS};
39 LUG_LOG.error(
"DescriptorSetPool: Can't create the descriptor pool: {}", result);
46 template <
size_t maxSets>
48 auto it = _descriptorSetsInUse.find(hash);
49 if (it == _descriptorSetsInUse.end()) {
50 DescriptorSet* descriptorSet = allocateNewDescriptorSet(descriptorSetLayout);
53 return std::make_tuple(
false,
nullptr);
59 _descriptorSetsInUse[hash] = descriptorSet;
61 return std::make_tuple(
true, descriptorSet);
64 it->second->_referenceCount += 1;
65 return std::make_tuple(
false, it->second);
68 template <
size_t maxSets>
74 const_cast<DescriptorSet*
>(descriptorSet)->_referenceCount -= 1;
76 const auto it = _descriptorSetsInUse.find(descriptorSet->
getHash());
78 if (it != _descriptorSetsInUse.end() && it->second == descriptorSet) {
79 _descriptorSetsInUse.erase(descriptorSet->
getHash());
82 _freeDescriptorSets[_freeDescriptorSetsCount] =
const_cast<DescriptorSet*
>(descriptorSet);
83 ++_freeDescriptorSetsCount;
86 VkDescriptorSet vkDescriptorSet =
static_cast<VkDescriptorSet
>(descriptorSet->
getDescriptorSet());
87 vkFreeDescriptorSets(static_cast<VkDevice>(_renderer.getDevice()), static_cast<VkDescriptorPool>(
descriptorPool), 1, &vkDescriptorSet);
91 template <
size_t maxSets>
93 if (_freeDescriptorSetsCount) {
94 --_freeDescriptorSetsCount;
96 DescriptorSet* tmp = _freeDescriptorSets[_freeDescriptorSetsCount];
97 _freeDescriptorSets[_freeDescriptorSetsCount] =
nullptr;
102 VkResult result{VK_SUCCESS};
104 LUG_LOG.error(
"DescriptorSetPool: Can't create descriptor set: {}", result);
111 if (_descriptorSetsCount < maxSets) {
115 VkResult result{VK_SUCCESS};
116 if (!descriptorSetBuilder.build(_descriptorSets[_descriptorSetsCount]._descriptorSet, &result)) {
117 LUG_LOG.error(
"DescriptorSetPool: Can't create descriptor set: {}", result);
121 return &_descriptorSets[_descriptorSetsCount++];
123 LUG_LOG.error(
"DescriptorSetPool: Can't create descriptor set: Maximum number of sets reached");
const API::DescriptorSet & getDescriptorSet() const
void setFlags(VkDescriptorPoolCreateFlags flags)
void setDescriptorSetLayouts(const std::vector< VkDescriptorSetLayout > &descriptorSetLayouts)
API::DescriptorPool descriptorPool
API::DescriptorSet _descriptorSet
void setHash(size_t hash)