WIP Fix descriptor teardown order

jackun 1 year ago
parent dadcf041a6
commit 4fcedf4a20
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

@ -70,6 +70,7 @@ struct vk_image {
VkImage image; VkImage image;
VkImageView view; VkImageView view;
VkDeviceMemory mem; VkDeviceMemory mem;
VkDescriptorSet descset;
uint32_t width, height; uint32_t width, height;
size_t size; size_t size;
bool uploaded; bool uploaded;
@ -77,7 +78,6 @@ struct vk_image {
struct texture_info { struct texture_info {
vk_image image; vk_image image;
VkDescriptorSet descset;
std::string filename; std::string filename;
int maxwidth; int maxwidth;
}; };
@ -852,14 +852,14 @@ ImTextureID add_texture(swapchain_stats* stats, const std::string& filename, int
*width = original_width * ratio; *width = original_width * ratio;
*height = original_height * ratio; *height = original_height * ratio;
ti.descset = create_image_with_desc(data, *width, *height, VK_FORMAT_R8G8B8A8_UNORM, ti.image); ti.image.descset = create_image_with_desc(data, *width, *height, VK_FORMAT_R8G8B8A8_UNORM, ti.image);
update_image_descriptor(data, ti.image.view, ti.descset); update_image_descriptor(data, ti.image.view, ti.image.descset);
ti.filename = filename; ti.filename = filename;
ti.maxwidth = maxwidth; ti.maxwidth = maxwidth;
data->textures.push_back(ti); data->textures.push_back(ti);
return (ImTextureID) ti.descset; return (ImTextureID) ti.image.descset;
} }
static void CreateOrResizeBuffer(struct device_data *data, static void CreateOrResizeBuffer(struct device_data *data,
@ -931,7 +931,7 @@ static struct overlay_draw *render_swapchain_display(struct swapchain_data *data
/* ensure_textures */ /* ensure_textures */
for (auto& tex : data->textures) { for (auto& tex : data->textures) {
if (!tex.descset || tex.image.uploaded) if (!tex.image.descset || tex.image.uploaded)
continue; continue;
// load // load
@ -1239,6 +1239,7 @@ static void setup_swapchain_data_pipeline(struct swapchain_data *data)
desc_pool_info.maxSets = 3; desc_pool_info.maxSets = 3;
desc_pool_info.poolSizeCount = 1; desc_pool_info.poolSizeCount = 1;
desc_pool_info.pPoolSizes = &sampler_pool_size; desc_pool_info.pPoolSizes = &sampler_pool_size;
desc_pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
VK_CHECK(device_data->vtable.CreateDescriptorPool(device_data->device, VK_CHECK(device_data->vtable.CreateDescriptorPool(device_data->device,
&desc_pool_info, &desc_pool_info,
NULL, &data->descriptor_pool)); NULL, &data->descriptor_pool));
@ -1573,6 +1574,9 @@ static void shutdown_swapchain_font(struct swapchain_data *data)
{ {
struct device_data *device_data = data->device; struct device_data *device_data = data->device;
destroy_vk_image(device_data, data->font_image); destroy_vk_image(device_data, data->font_image);
device_data->vtable.FreeDescriptorSets(device_data->device, data->descriptor_pool, 1, &data->font_image.descset);
device_data->vtable.DestroyBuffer(device_data->device, data->upload_font_buffer, NULL);
device_data->vtable.FreeMemory(device_data->device, data->upload_font_buffer_mem, NULL);
} }
static void shutdown_textures(struct swapchain_data *data) static void shutdown_textures(struct swapchain_data *data)
@ -1580,7 +1584,7 @@ static void shutdown_textures(struct swapchain_data *data)
struct device_data *device_data = data->device; struct device_data *device_data = data->device;
for (auto& tex : data->textures) for (auto& tex : data->textures)
{ {
device_data->vtable.FreeDescriptorSets(device_data->device, data->descriptor_pool, 1, &tex.descset); device_data->vtable.FreeDescriptorSets(device_data->device, data->descriptor_pool, 1, &tex.image.descset);
destroy_vk_image(device_data, tex.image); destroy_vk_image(device_data, tex.image);
} }
@ -1609,6 +1613,9 @@ static void shutdown_swapchain_data(struct swapchain_data *data)
device_data->vtable.DestroyFramebuffer(device_data->device, data->framebuffers[i], NULL); device_data->vtable.DestroyFramebuffer(device_data->device, data->framebuffers[i], NULL);
} }
shutdown_swapchain_font(data);
shutdown_textures(data);
device_data->vtable.DestroyRenderPass(device_data->device, data->render_pass, NULL); device_data->vtable.DestroyRenderPass(device_data->device, data->render_pass, NULL);
device_data->vtable.DestroyCommandPool(device_data->device, data->command_pool, NULL); device_data->vtable.DestroyCommandPool(device_data->device, data->command_pool, NULL);
@ -1622,8 +1629,6 @@ static void shutdown_swapchain_data(struct swapchain_data *data)
data->descriptor_layout, NULL); data->descriptor_layout, NULL);
device_data->vtable.DestroySampler(device_data->device, data->font_sampler, NULL); device_data->vtable.DestroySampler(device_data->device, data->font_sampler, NULL);
shutdown_swapchain_font(data);
shutdown_textures(data);
IM_FREE(data->font_atlas); IM_FREE(data->font_atlas);
ImGui::DestroyContext(data->imgui_context); ImGui::DestroyContext(data->imgui_context);

Loading…
Cancel
Save