From 4c241454f5698de3e6a5be07feb22ce930d63002 Mon Sep 17 00:00:00 2001 From: Jonathan Bradley Date: Tue, 28 Jan 2025 10:52:30 -0500 Subject: pke: remove MAX_FRAMES_IN_FLIGHT --- src/font.cpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'src/font.cpp') diff --git a/src/font.cpp b/src/font.cpp index d218430..59fb2af 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -192,7 +192,7 @@ FontTypeIndex FontType_RegisterFont(pk_cstr title, AssetHandle fontTextureHandle VkMemoryAllocateInfo vkMemoryAllocateInfo{}; vkMemoryAllocateInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO; vkMemoryAllocateInfo.pNext = nullptr; - vkMemoryAllocateInfo.allocationSize = paddedImageSize * MAX_FRAMES_IN_FLIGHT; + vkMemoryAllocateInfo.allocationSize = paddedImageSize * swapchainLength; vkMemoryAllocateInfo.memoryTypeIndex = FindMemoryTypeIndex(imageMemoryRequirements.memoryTypeBits, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); @@ -498,13 +498,13 @@ FontTypeIndex FontType_RegisterFont(pk_cstr title, AssetHandle fontTextureHandle */ VkDescriptorPoolSize descriptorPoolSizes[1]; descriptorPoolSizes[0].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; - descriptorPoolSizes[0].descriptorCount = MAX_FRAMES_IN_FLIGHT; + descriptorPoolSizes[0].descriptorCount = swapchainLength; VkDescriptorPoolCreateInfo vkDescriptorPoolCreateInfo; vkDescriptorPoolCreateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; vkDescriptorPoolCreateInfo.pNext = nullptr; vkDescriptorPoolCreateInfo.flags = 0; - vkDescriptorPoolCreateInfo.maxSets = MAX_FRAMES_IN_FLIGHT; + vkDescriptorPoolCreateInfo.maxSets = swapchainLength; vkDescriptorPoolCreateInfo.poolSizeCount = (uint32_t)1; vkDescriptorPoolCreateInfo.pPoolSizes = descriptorPoolSizes; @@ -512,26 +512,27 @@ FontTypeIndex FontType_RegisterFont(pk_cstr title, AssetHandle fontTextureHandle vkResult = vkCreateDescriptorPool(vkDevice, &vkDescriptorPoolCreateInfo, vkAllocator, &ft->vkDescriptorPool); assert(vkResult == VK_SUCCESS); - VkDescriptorSetLayout descriptorSets[MAX_FRAMES_IN_FLIGHT]; - for (long i = 0; i < MAX_FRAMES_IN_FLIGHT; ++i) { + VkDescriptorSetLayout *descriptorSets = pk_new(swapchainLength); + for (long i = 0; i < swapchainLength; ++i) { descriptorSets[i] = pkePipelines.descr_layouts.named.glyph; } VkDescriptorSetAllocateInfo vkDescriptorSetAllocateInfo; vkDescriptorSetAllocateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; vkDescriptorSetAllocateInfo.pNext = nullptr; vkDescriptorSetAllocateInfo.descriptorPool = ft->vkDescriptorPool; - vkDescriptorSetAllocateInfo.descriptorSetCount = MAX_FRAMES_IN_FLIGHT; + vkDescriptorSetAllocateInfo.descriptorSetCount = swapchainLength; vkDescriptorSetAllocateInfo.pSetLayouts = descriptorSets; - ft->vkDescriptorSets = pk_new(MAX_FRAMES_IN_FLIGHT); - for (long i = 0; i < MAX_FRAMES_IN_FLIGHT; ++i) { + ft->vkDescriptorSets = pk_new(swapchainLength); + for (long i = 0; i < swapchainLength; ++i) { ft->vkDescriptorSets[i] = VkDescriptorSet{}; } vkResult = vkAllocateDescriptorSets(vkDevice, &vkDescriptorSetAllocateInfo, ft->vkDescriptorSets); + pk_delete(descriptorSets, swapchainLength); assert(vkResult == VK_SUCCESS); - VkWriteDescriptorSet writeDescriptorSets[1 * MAX_FRAMES_IN_FLIGHT]; - for (long i = 0; i < 1 * MAX_FRAMES_IN_FLIGHT; ++i) { + VkWriteDescriptorSet *writeDescriptorSets = pk_new(swapchainLength); + for (long i = 0; i < 1 * swapchainLength; ++i) { writeDescriptorSets[i].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; writeDescriptorSets[i].pNext = nullptr; writeDescriptorSets[i].dstSet = nullptr; @@ -549,9 +550,9 @@ FontTypeIndex FontType_RegisterFont(pk_cstr title, AssetHandle fontTextureHandle textureDescriptorInfo.imageView = ft->textureImageView; textureDescriptorInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; - VkDescriptorBufferInfo vkDescriptorBufferInfo[MAX_FRAMES_IN_FLIGHT]; + VkDescriptorBufferInfo *vkDescriptorBufferInfo = pk_new(swapchainLength); - for (long i = 0; i < MAX_FRAMES_IN_FLIGHT; ++i) { + for (long i = 0; i < swapchainLength; ++i) { vkDescriptorBufferInfo[i].buffer = UniformBuffers[i]; vkDescriptorBufferInfo[i].offset = 0; vkDescriptorBufferInfo[i].range = sizeof(UniformBufferObject); @@ -566,7 +567,9 @@ FontTypeIndex FontType_RegisterFont(pk_cstr title, AssetHandle fontTextureHandle writeDescriptorSets[samplerIndex].dstSet = ft->vkDescriptorSets[i]; } - vkUpdateDescriptorSets(vkDevice, 2 * MAX_FRAMES_IN_FLIGHT, writeDescriptorSets, 0, nullptr); + vkUpdateDescriptorSets(vkDevice, 2 * swapchainLength, writeDescriptorSets, 0, nullptr); + pk_delete(vkDescriptorBufferInfo, swapchainLength); + pk_delete(writeDescriptorSets, swapchainLength); return idx; } @@ -582,6 +585,7 @@ void FontType_Unload(FontTypeIndex idx) // If we switch to a global pool, we will need to free here, and // destroy the pool outside of this loop vkDestroyDescriptorPool(vkDevice, ft->vkDescriptorPool, vkAllocator); + pk_delete(ft->vkDescriptorSets, swapchainLength); ft->vkDescriptorSets = CAFE_BABE(VkDescriptorSet); ft->vkDescriptorPool = VK_NULL_HANDLE; } -- cgit v1.2.3