diff --git a/framework/encode/vulkan_handle_wrapper_util.h b/framework/encode/vulkan_handle_wrapper_util.h index 1d66daf783..bd329a6df7 100644 --- a/framework/encode/vulkan_handle_wrapper_util.h +++ b/framework/encode/vulkan_handle_wrapper_util.h @@ -423,6 +423,7 @@ CreateWrappedHandle(VkDevice, CreateWrappedNonDispatchHandle(handle, get_id); wrapper = GetWrapper(*handle); wrapper->is_swapchain_image = true; + wrapper->parent_swapchains.insert(co_parent); parent_wrapper->child_images.push_back(wrapper); } } @@ -613,8 +614,12 @@ inline void DestroyWrappedHandle(VkSwapchainKHR handle) for (auto image_wrapper : wrapper->child_images) { - RemoveWrapper(image_wrapper); - delete image_wrapper; + image_wrapper->parent_swapchains.erase(handle); + if (image_wrapper->parent_swapchains.empty()) + { + RemoveWrapper(image_wrapper); + delete image_wrapper; + } } RemoveWrapper(wrapper); diff --git a/framework/encode/vulkan_handle_wrappers.h b/framework/encode/vulkan_handle_wrappers.h index ad2d433d96..fadbf949f1 100644 --- a/framework/encode/vulkan_handle_wrappers.h +++ b/framework/encode/vulkan_handle_wrappers.h @@ -201,18 +201,19 @@ struct ImageWrapper : public HandleWrapper const void* bind_pnext{ nullptr }; HandleUnwrapMemory bind_pnext_memory; // Global HandleUnwrapMemory could be reset anytime, so it should have its own // HandleUnwrapMemory. - format::HandleId bind_memory_id{ format::kNullHandleId }; - VkDeviceSize bind_offset{ 0 }; - uint32_t queue_family_index{ 0 }; - VkImageType image_type{ VK_IMAGE_TYPE_2D }; - VkFormat format{ VK_FORMAT_UNDEFINED }; - VkExtent3D extent{ 0, 0, 0 }; - uint32_t mip_levels{ 0 }; - uint32_t array_layers{ 0 }; - VkSampleCountFlagBits samples{}; - VkImageTiling tiling{}; - VkImageLayout current_layout{ VK_IMAGE_LAYOUT_UNDEFINED }; - bool is_swapchain_image{ false }; + format::HandleId bind_memory_id{ format::kNullHandleId }; + VkDeviceSize bind_offset{ 0 }; + uint32_t queue_family_index{ 0 }; + VkImageType image_type{ VK_IMAGE_TYPE_2D }; + VkFormat format{ VK_FORMAT_UNDEFINED }; + VkExtent3D extent{ 0, 0, 0 }; + uint32_t mip_levels{ 0 }; + uint32_t array_layers{ 0 }; + VkSampleCountFlagBits samples{}; + VkImageTiling tiling{}; + VkImageLayout current_layout{ VK_IMAGE_LAYOUT_UNDEFINED }; + bool is_swapchain_image{ false }; + std::set parent_swapchains; }; struct BufferViewWrapper : public HandleWrapper