From 32c5ad9d1b66b588e7cf612af96b7cf1914ff087 Mon Sep 17 00:00:00 2001 From: Iason Paraskevopoulos Date: Mon, 27 Jun 2022 15:00:14 +0100 Subject: [PATCH] Remove swapchain from device_data after destruction Fixes an issue, where the swapchain addresses weren't removed from the device_private_data::swapchains member after swapchain destruction. This could cause clashes with swapchains handled by different components (e.g. ICD). Signed-off-by: Iason Paraskevopoulos Change-Id: I0e05734368ef6100b67ded973283f99ef248e540 --- layer/private_data.cpp | 10 ++++++++++ layer/private_data.hpp | 8 ++++++++ layer/swapchain_api.cpp | 2 ++ 3 files changed, 20 insertions(+) diff --git a/layer/private_data.cpp b/layer/private_data.cpp index e2befab..e360094 100644 --- a/layer/private_data.cpp +++ b/layer/private_data.cpp @@ -392,6 +392,16 @@ VkResult device_private_data::add_layer_swapchain(VkSwapchainKHR swapchain) return result.has_value() ? VK_SUCCESS : VK_ERROR_OUT_OF_HOST_MEMORY; } +void device_private_data::remove_layer_swapchain(VkSwapchainKHR swapchain) +{ + scoped_mutex lock(swapchains_lock); + auto it = swapchains.find(swapchain); + if (it != swapchains.end()) + { + swapchains.erase(swapchain); + } +} + bool device_private_data::layer_owns_all_swapchains(const VkSwapchainKHR *swapchain, uint32_t swapchain_count) const { scoped_mutex lock(swapchains_lock); diff --git a/layer/private_data.hpp b/layer/private_data.hpp index 048aee4..02e40a0 100644 --- a/layer/private_data.hpp +++ b/layer/private_data.hpp @@ -429,8 +429,16 @@ public: */ static device_private_data &get(VkQueue queue); + /** + * @brief Add a swapchain to the swapchains member variable. + */ VkResult add_layer_swapchain(VkSwapchainKHR swapchain); + /** + * @brief Remove a swapchain from the swapchains member variable. + */ + void remove_layer_swapchain(VkSwapchainKHR swapchain); + /** * @brief Return whether all the provided swapchains are owned by us (the WSI Layer). */ diff --git a/layer/swapchain_api.cpp b/layer/swapchain_api.cpp index 80fd051..dc48e34 100644 --- a/layer/swapchain_api.cpp +++ b/layer/swapchain_api.cpp @@ -91,6 +91,8 @@ wsi_layer_vkDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapc, assert(swapc != VK_NULL_HANDLE); auto *sc = reinterpret_cast(swapc); wsi::destroy_surface_swapchain(sc, device_data, pAllocator); + + device_data.remove_layer_swapchain(swapc); } VWL_VKAPI_CALL(VkResult)