summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2025-02-24 23:46:55 -0500
committerJonathan Bradley <jcb@pikum.xyz>2025-02-24 23:46:55 -0500
commit7b266e9763280dcfd07045868fc08238a8e117ba (patch)
tree24362b236628d2fa024ef43dd31d145f23095cb2
parent4f36a5fb7d0dcb3942d6f8e985361dd8a056cc50 (diff)
pke: font cleanup
-rw-r--r--src/font.cpp64
-rw-r--r--src/font.hpp2
-rw-r--r--src/window.cpp2
3 files changed, 21 insertions, 47 deletions
diff --git a/src/font.cpp b/src/font.cpp
index 30877f2..ba3008a 100644
--- a/src/font.cpp
+++ b/src/font.cpp
@@ -939,13 +939,13 @@ FontTypeIndex FontType_RegisterFont(pk_cstr title, AssetHandle fontTextureHandle
*/
VkDescriptorPoolSize descriptorPoolSizes[1];
descriptorPoolSizes[0].type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
- descriptorPoolSizes[0].descriptorCount = swapchainLength;
+ descriptorPoolSizes[0].descriptorCount = (uint32_t)1;
VkDescriptorPoolCreateInfo vkDescriptorPoolCreateInfo;
vkDescriptorPoolCreateInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
vkDescriptorPoolCreateInfo.pNext = nullptr;
vkDescriptorPoolCreateInfo.flags = 0;
- vkDescriptorPoolCreateInfo.maxSets = swapchainLength;
+ vkDescriptorPoolCreateInfo.maxSets = (uint32_t)1;
vkDescriptorPoolCreateInfo.poolSizeCount = (uint32_t)1;
vkDescriptorPoolCreateInfo.pPoolSizes = descriptorPoolSizes;
@@ -953,58 +953,34 @@ FontTypeIndex FontType_RegisterFont(pk_cstr title, AssetHandle fontTextureHandle
vkResult = vkCreateDescriptorPool(vkDevice, &vkDescriptorPoolCreateInfo, vkAllocator, &ft->gr.vkDescriptorPool);
assert(vkResult == VK_SUCCESS);
- VkDescriptorSetLayout *descriptorSets = pk_new<VkDescriptorSetLayout>(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->gr.vkDescriptorPool;
- vkDescriptorSetAllocateInfo.descriptorSetCount = swapchainLength;
- vkDescriptorSetAllocateInfo.pSetLayouts = descriptorSets;
+ vkDescriptorSetAllocateInfo.descriptorSetCount = (uint32_t)1;
+ vkDescriptorSetAllocateInfo.pSetLayouts = &pkePipelines.descr_layouts.named.glyph;
- ft->gr.vkDescriptorSets = pk_new<VkDescriptorSet>(swapchainLength);
- for (long i = 0; i < swapchainLength; ++i) {
- ft->gr.vkDescriptorSets[i] = VkDescriptorSet{};
- }
- vkResult = vkAllocateDescriptorSets(vkDevice, &vkDescriptorSetAllocateInfo, ft->gr.vkDescriptorSets);
- pk_delete<VkDescriptorSetLayout>(descriptorSets, swapchainLength);
+ vkResult = vkAllocateDescriptorSets(vkDevice, &vkDescriptorSetAllocateInfo, &ft->gr.vkDescriptorSet);
assert(vkResult == VK_SUCCESS);
- VkWriteDescriptorSet *writeDescriptorSets = pk_new<VkWriteDescriptorSet>(swapchainLength);
- for (long i = 0; i < swapchainLength; ++i) {
- writeDescriptorSets[i].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
- writeDescriptorSets[i].pNext = nullptr;
- writeDescriptorSets[i].dstSet = nullptr;
- writeDescriptorSets[i].dstBinding = 0;
- writeDescriptorSets[i].dstArrayElement = 0;
- writeDescriptorSets[i].descriptorCount = 1;
- writeDescriptorSets[i].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
- writeDescriptorSets[i].pImageInfo = nullptr;
- writeDescriptorSets[i].pBufferInfo = nullptr;
- writeDescriptorSets[i].pTexelBufferView = nullptr;
- }
-
VkDescriptorImageInfo textureDescriptorInfo;
textureDescriptorInfo.sampler = global_sampler;
textureDescriptorInfo.imageView = ft->gr.textureImageView;
textureDescriptorInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
- VkDescriptorBufferInfo *vkDescriptorBufferInfo = pk_new<VkDescriptorBufferInfo>(swapchainLength);
-
- for (long i = 0; i < swapchainLength; ++i) {
- vkDescriptorBufferInfo[i].buffer = UniformBuffers[i];
- vkDescriptorBufferInfo[i].offset = 0;
- vkDescriptorBufferInfo[i].range = sizeof(UniformBufferObject);
-
- writeDescriptorSets[i].pImageInfo = &textureDescriptorInfo;
- writeDescriptorSets[i].dstSet = ft->gr.vkDescriptorSets[i];
- }
+ VkWriteDescriptorSet writeDescriptorSet;
+ writeDescriptorSet.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
+ writeDescriptorSet.pNext = nullptr;
+ writeDescriptorSet.dstSet = ft->gr.vkDescriptorSet;
+ writeDescriptorSet.dstBinding = (uint32_t)0;
+ writeDescriptorSet.dstArrayElement = (uint32_t)0;
+ writeDescriptorSet.descriptorCount = (uint32_t)1;
+ writeDescriptorSet.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
+ writeDescriptorSet.pImageInfo = &textureDescriptorInfo;
+ writeDescriptorSet.pBufferInfo = nullptr;
+ writeDescriptorSet.pTexelBufferView = nullptr;
- vkUpdateDescriptorSets(vkDevice, swapchainLength, writeDescriptorSets, 0, nullptr);
- pk_delete<VkDescriptorBufferInfo>(vkDescriptorBufferInfo, swapchainLength);
- pk_delete<VkWriteDescriptorSet>(writeDescriptorSets, swapchainLength);
+ vkUpdateDescriptorSets(vkDevice, (uint32_t)1, &writeDescriptorSet, 0, nullptr);
AM_Release(fontTextureHandle);
AM_Release(glyphsHandle);
@@ -1025,15 +1001,14 @@ void FontType_Unload(FontTypeIndex idx) {
pk_delete<FontRender>(ft->renders, (FontTypeIndex_T)ft->n_render);
}
- if (ft->gr.vkDescriptorSets != VK_NULL_HANDLE && ft->gr.vkDescriptorPool != VK_NULL_HANDLE) {
+ if (ft->gr.vkDescriptorSet != VK_NULL_HANDLE && ft->gr.vkDescriptorPool != VK_NULL_HANDLE) {
// 2023-09-27 - JCB (copied from entities.cpp)
// We are not setting the pool flag for allowing freeing descriptor sets
// so all we need to do is destroy the pool
// If we switch to a global pool, we will need to free here, and
// destroy the pool outside of this loop
vkDestroyDescriptorPool(vkDevice, ft->gr.vkDescriptorPool, vkAllocator);
- pk_delete<VkDescriptorSet>(ft->gr.vkDescriptorSets, swapchainLength);
- ft->gr.vkDescriptorSets = CAFE_BABE(VkDescriptorSet);
+ ft->gr.vkDescriptorSet = VK_NULL_HANDLE;
ft->gr.vkDescriptorPool = VK_NULL_HANDLE;
}
@@ -1318,7 +1293,6 @@ FontRenderHandle FontType_AddStringRender(FontTypeIndex idx_ft, const pk_str str
void FontType_RemoveStringRender(FontRenderHandle handle) {
FontRender *fr;
uint32_t buffer_start_index;
- // TODO
FontType *ft = &ftd.arr_ft[(FontTypeIndex_T)handle.index_ft];
// hack, but works
assert(ft->last_graphics_resize_index > 0);
diff --git a/src/font.hpp b/src/font.hpp
index 09ed87a..86d53cc 100644
--- a/src/font.hpp
+++ b/src/font.hpp
@@ -89,7 +89,7 @@ struct FontType : public Entity_Base {
VkImage textureImage = VK_NULL_HANDLE;
VkImageView textureImageView = VK_NULL_HANDLE;
VkDescriptorPool vkDescriptorPool = VK_NULL_HANDLE;
- VkDescriptorSet *vkDescriptorSets = nullptr;
+ VkDescriptorSet vkDescriptorSet = VK_NULL_HANDLE;
} gr;
struct FontTypeBindings {
BufferBindingDetails vertexBD;
diff --git a/src/window.cpp b/src/window.cpp
index b42a1b3..989c3cb 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -2754,7 +2754,7 @@ void RecordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) {
continue;
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pkePipelines.pipelines.named.glyph);
- vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pkePipelines.pipe_layouts.named.glyph, 0, 1, &ft->gr.vkDescriptorSets[imageIndex], 0, {});
+ vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pkePipelines.pipe_layouts.named.glyph, 0, 1, &ft->gr.vkDescriptorSet, 0, {});
vkCmdBindIndexBuffer(commandBuffer, ft->bindings.indexBD.buffer, ft->bindings.indexBD.offsets[0], VK_INDEX_TYPE_UINT16);
vkCmdBindVertexBuffers(commandBuffer, ft->bindings.vertexBD.firstBinding, ft->bindings.vertexBD.bindingCount, &ft->bindings.vertexBD.buffer, ft->bindings.vertexBD.offsets);