descriptor

This commit is contained in:
Jorijn van der Graaf 2026-01-28 23:45:33 +01:00
commit 962cc4b8cb
2 changed files with 13 additions and 8 deletions

View file

@ -15,7 +15,10 @@ int main() {
*/ */
VulkanDevice::CreateDevice(); VulkanDevice::CreateDevice();
Raygenspv::CreateShader(); Raygenspv::CreateShader();
DescriptorPool<1, Raygenspv> pool;
pool.setsCount = 1;
pool.BuildPool(0);
WindowVulkan window(1280, 720, "HelloVulkan"); WindowVulkan window(1280, 720, "HelloVulkan");
/* /*

View file

@ -40,6 +40,7 @@ export namespace Crafter {
public: public:
inline static Event<void> onDescriptorRefresh; inline static Event<void> onDescriptorRefresh;
inline static std::uint32_t setIndex = 0; inline static std::uint32_t setIndex = 0;
inline static std::uint32_t setsCount = 0;
inline static std::vector<VkDescriptorSet> sets; inline static std::vector<VkDescriptorSet> sets;
inline static VkDescriptorPool descriptorPool[PoolCount] = { VK_NULL_HANDLE }; inline static VkDescriptorPool descriptorPool[PoolCount] = { VK_NULL_HANDLE };
@ -116,19 +117,19 @@ export namespace Crafter {
public: public:
static void BuildPool(std::uint32_t poolIndex) { static void BuildPool(std::uint32_t poolIndex) {
if(descriptorPool[poolIndex] != VK_NULL_HANDLE) { if(descriptorPool[poolIndex] != VK_NULL_HANDLE) {
vkDestroyDescriptorPool(VulkanDevice::device, descriptorPool, nullptr); vkDestroyDescriptorPool(VulkanDevice::device, descriptorPool[poolIndex], nullptr);
} }
std::array<VkDescriptorPoolSize, uniqueDescriptorCount> poolSizes = GetPoolSizes(); std::array<VkDescriptorPoolSize, uniqueDescriptorCount> poolSizes = GetPoolSizes();
for(VkDescriptorPoolSize& size : poolSizes) { for(VkDescriptorPoolSize& size : poolSizes) {
size.descriptorCount *= sets.size(); size.descriptorCount *= setsCount;
} }
VkDescriptorPoolCreateInfo descriptorPoolInfo { VkDescriptorPoolCreateInfo descriptorPoolInfo {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
.maxSets = static_cast<std::uint32_t>(setsCount),
.poolSizeCount = uniqueDescriptorCount, .poolSizeCount = uniqueDescriptorCount,
.pPoolSizes = poolSizes.data(), .pPoolSizes = poolSizes.data()
.maxSets = sets.size()
}; };
VulkanDevice::CheckVkResult(vkCreateDescriptorPool(VulkanDevice::device, &descriptorPoolInfo, nullptr, &descriptorPool[poolIndex])); VulkanDevice::CheckVkResult(vkCreateDescriptorPool(VulkanDevice::device, &descriptorPoolInfo, nullptr, &descriptorPool[poolIndex]));
@ -141,8 +142,8 @@ export namespace Crafter {
constexpr std::array<VkDescriptorSetLayoutBinding, Shaders::descriptorCount> setLayoutBindingsMesh = GetDescriptorSet<Shaders>(); constexpr std::array<VkDescriptorSetLayoutBinding, Shaders::descriptorCount> setLayoutBindingsMesh = GetDescriptorSet<Shaders>();
VkDescriptorSetLayoutCreateInfo descriptorLayoutInfoMesh = { VkDescriptorSetLayoutCreateInfo descriptorLayoutInfoMesh = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
.pBindings = setLayoutBindingsMesh.data(), .bindingCount = Shaders::descriptorCount,
.bindingCount = Shaders::descriptorCount .pBindings = setLayoutBindingsMesh.data()
}; };
VulkanDevice::CheckVkResult(vkCreateDescriptorSetLayout(VulkanDevice::device, &descriptorLayoutInfoMesh, nullptr, &descriptorSetLayout[shaderIndex++])); VulkanDevice::CheckVkResult(vkCreateDescriptorSetLayout(VulkanDevice::device, &descriptorLayoutInfoMesh, nullptr, &descriptorSetLayout[shaderIndex++]));
}(), }(),
@ -151,10 +152,11 @@ export namespace Crafter {
VkDescriptorSetAllocateInfo allocInfo { VkDescriptorSetAllocateInfo allocInfo {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO, .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
.descriptorPool = descriptorPool[poolIndex], .descriptorPool = descriptorPool[poolIndex],
.descriptorSetCount = setsCount,
.pSetLayouts = descriptorSetLayout, .pSetLayouts = descriptorSetLayout,
.descriptorSetCount = sets.size()
}; };
sets.resize(setsCount);
VulkanDevice::CheckVkResult(vkAllocateDescriptorSets(VulkanDevice::device, &allocInfo, sets.data())); VulkanDevice::CheckVkResult(vkAllocateDescriptorSets(VulkanDevice::device, &allocInfo, sets.data()));
setIndex = 0; setIndex = 0;