From 8256b027d7c45a8ae1dcdd3e34243a5ae7530b38 Mon Sep 17 00:00:00 2001 From: Nir Ekhauz Date: Mon, 18 Aug 2025 09:23:02 +0000 Subject: [PATCH] Add initial support for VK_KHR_present_id2 in the layer Add support for present id2 ext. for physical, surface and sc. Signed-off-by: Nir Ekhauz Change-Id: I934d5d8ef7e0fde2de8682bb54696a4044edb047 --- layer/swapchain_api.cpp | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/layer/swapchain_api.cpp b/layer/swapchain_api.cpp index f548a09..492ceb9 100644 --- a/layer/swapchain_api.cpp +++ b/layer/swapchain_api.cpp @@ -191,7 +191,43 @@ wsi_layer_vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) VkResult ret = VK_SUCCESS; +#if VULKAN_WSI_LAYER_EXPERIMENTAL + struct present_ids + { + uint32_t ids_num{ 0 }; + const uint64_t *p_present_ids{ nullptr }; + + bool has_ids() + { + return ids_num > 0; + } + }; + + present_ids present_ids{}; + + if (device_data.is_present_id2_enabled()) + { + auto *ext2 = util::find_extension(VK_STRUCTURE_TYPE_PRESENT_ID_2_KHR, pPresentInfo->pNext); + if (ext2 != nullptr) + { + present_ids.ids_num = ext2->swapchainCount; + present_ids.p_present_ids = ext2->pPresentIds; + } + } + + if (!present_ids.has_ids()) + { + auto *ext = util::find_extension(VK_STRUCTURE_TYPE_PRESENT_ID_KHR, pPresentInfo->pNext); + if (ext != nullptr) + { + present_ids.ids_num = ext->swapchainCount; + present_ids.p_present_ids = ext->pPresentIds; + } + } +#else auto *present_ids = util::find_extension(VK_STRUCTURE_TYPE_PRESENT_ID_KHR, pPresentInfo->pNext); +#endif + const auto present_fence_info = util::find_extension( VK_STRUCTURE_TYPE_SWAPCHAIN_PRESENT_FENCE_INFO_EXT, present_info->pNext); const auto swapchain_present_mode_info = util::find_extension( @@ -211,10 +247,18 @@ wsi_layer_vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) assert(sc != nullptr); uint64_t present_id = 0; /* No present ID by default */ + +#if VULKAN_WSI_LAYER_EXPERIMENTAL + if (present_ids.p_present_ids && present_ids.ids_num == pPresentInfo->swapchainCount) + { + present_id = present_ids.p_present_ids[i]; + } +#else if (present_ids && present_ids->pPresentIds && present_ids->swapchainCount == pPresentInfo->swapchainCount) { present_id = present_ids->pPresentIds[i]; } +#endif wsi::swapchain_presentation_parameters present_params{}; present_params.present_fence = (present_fence_info == nullptr) ? VK_NULL_HANDLE : present_fence_info->pFences[i];