79 lines
3 KiB
Text
79 lines
3 KiB
Text
|
|
/*
|
||
|
|
Crafter®.Graphics
|
||
|
|
Copyright (C) 2026 Catcrafts®
|
||
|
|
catcrafts.net
|
||
|
|
|
||
|
|
This library is free software; you can redistribute it and/or
|
||
|
|
modify it under the terms of the GNU Lesser General Public
|
||
|
|
License version 3.0 as published by the Free Software Foundation;
|
||
|
|
|
||
|
|
This library is distributed in the hope that it will be useful,
|
||
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
|
Lesser General Public License for more details.
|
||
|
|
|
||
|
|
You should have received a copy of the GNU Lesser General Public
|
||
|
|
License along with this library; if not, write to the Free Software
|
||
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||
|
|
*/
|
||
|
|
|
||
|
|
module;
|
||
|
|
#ifdef CRAFTER_GRAPHICS_VULKAN
|
||
|
|
#include <vulkan/vulkan.h>
|
||
|
|
#endif
|
||
|
|
export module Crafter.Graphics:DescriptorPoolVulkan;
|
||
|
|
#ifdef CRAFTER_GRAPHICS_VULKAN
|
||
|
|
import std;
|
||
|
|
import :VulkanDevice;
|
||
|
|
import :Types;
|
||
|
|
import :DescriptorLayoutVulkan;
|
||
|
|
import Crafter.Event;
|
||
|
|
|
||
|
|
export namespace Crafter {
|
||
|
|
template <std::uint32_t PoolCount, typename... Shaders>
|
||
|
|
class DescriptorPool {
|
||
|
|
public:
|
||
|
|
inline static Event<void> onDescriptorRefresh;
|
||
|
|
inline static std::uint32_t setIndex = 0;
|
||
|
|
inline static std::uint32_t setsCount = 0;
|
||
|
|
inline static std::vector<VkDescriptorSet> sets;
|
||
|
|
inline static VkDescriptorPool descriptorPool[PoolCount] = { VK_NULL_HANDLE };
|
||
|
|
|
||
|
|
public:
|
||
|
|
static void BuildPool(std::uint32_t poolIndex) {
|
||
|
|
if(descriptorPool[poolIndex] != VK_NULL_HANDLE) {
|
||
|
|
vkDestroyDescriptorPool(VulkanDevice::device, descriptorPool[poolIndex], nullptr);
|
||
|
|
}
|
||
|
|
|
||
|
|
std::array<VkDescriptorPoolSize, DescriptorLayoutVulkan<Shaders...>::uniqueDescriptorCount> poolSizes = DescriptorLayoutVulkan<Shaders...>::GetPoolSizes();
|
||
|
|
for(VkDescriptorPoolSize& size : poolSizes) {
|
||
|
|
size.descriptorCount *= setsCount;
|
||
|
|
}
|
||
|
|
|
||
|
|
VkDescriptorPoolCreateInfo descriptorPoolInfo {
|
||
|
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
|
||
|
|
.maxSets = static_cast<std::uint32_t>(setsCount),
|
||
|
|
.poolSizeCount = DescriptorLayoutVulkan<Shaders...>::uniqueDescriptorCount,
|
||
|
|
.pPoolSizes = poolSizes.data()
|
||
|
|
};
|
||
|
|
|
||
|
|
VulkanDevice::CheckVkResult(vkCreateDescriptorPool(VulkanDevice::device, &descriptorPoolInfo, nullptr, &descriptorPool[poolIndex]));
|
||
|
|
|
||
|
|
VkDescriptorSetAllocateInfo allocInfo {
|
||
|
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
|
||
|
|
.descriptorPool = descriptorPool[poolIndex],
|
||
|
|
.descriptorSetCount = setsCount,
|
||
|
|
.pSetLayouts = DescriptorLayoutVulkan<Shaders...>::descriptorSetLayout,
|
||
|
|
};
|
||
|
|
|
||
|
|
sets.resize(setsCount);
|
||
|
|
VulkanDevice::CheckVkResult(vkAllocateDescriptorSets(VulkanDevice::device, &allocInfo, sets.data()));
|
||
|
|
|
||
|
|
setIndex = 0;
|
||
|
|
|
||
|
|
onDescriptorRefresh.Invoke();
|
||
|
|
}
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
#endif
|