From 969001a1e3c331ca0a7c17b0a3866a963227ea3e Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 13 Oct 2024 19:24:26 -0400 Subject: [PATCH] vulkan: Release swapchain images With the swapchain maintenance extension, we have a way to release the acquired swapchain image before recreating the swapchain, in the VK_SUBOPTIMAL_KHR case. Use it. Tested by toggling fullscreen in the bloatpad example, which causes mesa to return VK_SUBOPTIMAL_KHR (since dmabuf modifiers change). --- gdk/gdkvulkancontext.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/gdk/gdkvulkancontext.c b/gdk/gdkvulkancontext.c index 919f01dfc3..14700a90bc 100644 --- a/gdk/gdkvulkancontext.c +++ b/gdk/gdkvulkancontext.c @@ -566,12 +566,20 @@ physical_device_supports_extension (VkPhysicalDevice device, { VkExtensionProperties *extensions; uint32_t n_device_extensions; + static gboolean first = TRUE; GDK_VK_CHECK (vkEnumerateDeviceExtensionProperties, device, NULL, &n_device_extensions, NULL); extensions = g_newa (VkExtensionProperties, n_device_extensions); GDK_VK_CHECK (vkEnumerateDeviceExtensionProperties, device, NULL, &n_device_extensions, extensions); + if (first) + { + first = FALSE; + for (uint32_t i = 0; i < n_device_extensions; i++) + g_print ("%s\n", extensions[i].extensionName); + } + for (uint32_t i = 0; i < n_device_extensions; i++) { if (g_str_equal (extensions[i].extensionName, extension_name)) @@ -712,6 +720,22 @@ gdk_vulkan_context_begin_frame (GdkDrawContext *draw_context, }, VK_NULL_HANDLE); vkQueueWaitIdle (gdk_vulkan_context_get_queue (context)); + + if (gdk_vulkan_context_has_feature (context, GDK_VULKAN_FEATURE_SWAPCHAIN_MAINTENANCE)) + { + PFN_vkReleaseSwapchainImagesEXT vkReleaseSwapchainImagesEXT; + + vkReleaseSwapchainImagesEXT = (PFN_vkReleaseSwapchainImagesEXT) vkGetDeviceProcAddr (gdk_vulkan_context_get_device (context), "vkReleaseSwapchainImagesEXT"); + + vkReleaseSwapchainImagesEXT (gdk_vulkan_context_get_device (context), + &(VkReleaseSwapchainImagesInfoEXT) { + .sType = VK_STRUCTURE_TYPE_RELEASE_SWAPCHAIN_IMAGES_INFO_EXT, + .pNext = NULL, + .swapchain = priv->swapchain, + .imageIndexCount = 1, + .pImageIndices = &priv->draw_index, + }); + } } if (gdk_vulkan_context_check_swapchain (context, &error))