/* 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 #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 class DescriptorPool { public: inline static Event onDescriptorRefresh; inline static std::uint32_t setIndex = 0; inline static std::uint32_t setsCount = 0; inline static std::vector 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::uniqueDescriptorCount> poolSizes = DescriptorLayoutVulkan::GetPoolSizes(); for(VkDescriptorPoolSize& size : poolSizes) { size.descriptorCount *= setsCount; } VkDescriptorPoolCreateInfo descriptorPoolInfo { .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, .maxSets = static_cast(setsCount), .poolSizeCount = DescriptorLayoutVulkan::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::descriptorSetLayout, }; sets.resize(setsCount); VulkanDevice::CheckVkResult(vkAllocateDescriptorSets(VulkanDevice::device, &allocInfo, sets.data())); setIndex = 0; onDescriptorRefresh.Invoke(); } }; } #endif