From ef9b6eed8cb5a726fb3c44812e0ae78ecac0388f Mon Sep 17 00:00:00 2001 From: Ginu Jacob Date: Fri, 6 Jun 2025 09:56:17 +0000 Subject: [PATCH] Improvement for present timing stages In this change, handling for the present timings stages are improved. Signed-off-by: Ginu Jacob Change-Id: I68e9ae67fa94d39e23504890d922a85bdce938cd --- wsi/extensions/present_timing.cpp | 39 ++++++++++++++++++------------- wsi/swapchain_base.cpp | 8 +++---- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/wsi/extensions/present_timing.cpp b/wsi/extensions/present_timing.cpp index b05889b..e4e3f13 100644 --- a/wsi/extensions/present_timing.cpp +++ b/wsi/extensions/present_timing.cpp @@ -79,7 +79,7 @@ wsi_ext_present_timing::~wsi_ext_present_timing() m_query_pool = VK_NULL_HANDLE; } - for (auto semaphore : m_present_semaphore) + for (const auto &semaphore : m_present_semaphore) { if (semaphore != VK_NULL_HANDLE) { @@ -179,21 +179,28 @@ VkResult wsi_ext_present_timing::present_timing_queue_set_size(size_t queue_size { return VK_NOT_READY; } - + /* A vector is reserved with the updated size and the outstanding entries + * are copied over. A vector resize is not used since the outstanding entries + * are not sequential. + */ util::vector presentation_timing( - util::allocator(m_allocator, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE)); + util::allocator(m_allocator, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT)); if (!presentation_timing.try_reserve(queue_size)) { return VK_ERROR_OUT_OF_HOST_MEMORY; } - for (auto &iter : m_queue) + for (auto &slot : m_queue) { - if (iter.has_outstanding_stages()) + if (slot.has_outstanding_stages()) { - if (!presentation_timing.try_push_back(std::move(iter))) - { - return VK_ERROR_OUT_OF_HOST_MEMORY; - } + /* The memory is already reserved for the new vector + * and there are no possibilities for an exception + * at this point. An exception at this point will + * cause bad state as the vector has partially copied. + */ + bool res = presentation_timing.try_push_back(std::move(slot)); + assert(res); + UNUSED(res); } } m_queue.swap(presentation_timing); @@ -204,9 +211,9 @@ size_t wsi_ext_present_timing::present_timing_get_num_outstanding_results() { size_t num_outstanding = 0; - for (auto &iter : m_queue) + for (auto &slot : m_queue) { - if (iter.has_outstanding_stages()) + if (slot.has_outstanding_stages()) { num_outstanding++; } @@ -321,16 +328,16 @@ VkResult wsi_ext_present_timing::get_past_presentation_results( VkPastPresentationTimingEXT &timing = past_present_timing_properties->pPresentationTimings[i]; for (auto slot = m_queue.begin(); slot != m_queue.end();) { - if ((!(*slot).copied) && (*slot).has_completed_stages()) + if (!slot->copied && slot->has_completed_stages()) { /* There will be only one slot in the queue per presentId. */ - if ((timing.presentId == 0) || (timing.presentId == (*slot).m_present_id)) + if ((timing.presentId == 0) || (timing.presentId == slot->m_present_id)) { - assert(timing.presentStageCount >= (*slot).m_num_present_stages); - if (((*slot).populate(timing))) + assert(timing.presentStageCount >= slot->m_num_present_stages); + if (slot->populate(timing)) { count_results++; - (*slot).copied = true; + slot->copied = true; timings_found = true; if (timing.reportComplete) { diff --git a/wsi/swapchain_base.cpp b/wsi/swapchain_base.cpp index 718a1bf..ae58be8 100644 --- a/wsi/swapchain_base.cpp +++ b/wsi/swapchain_base.cpp @@ -634,13 +634,13 @@ VkResult swapchain_base::queue_present(VkQueue queue, const VkPresentInfoKHR *pr m_swapchain_images[submit_info.pending_present.image_index].present_fence_wait; } #if VULKAN_WSI_LAYER_EXPERIMENTAL - const VkPresentTimingInfoEXT *present_timing_info = VK_NULL_HANDLE; + const VkPresentTimingInfoEXT *present_timing_info = nullptr; const auto *present_timings_info = util::find_extension(VK_STRUCTURE_TYPE_PRESENT_TIMINGS_INFO_EXT, present_info->pNext); - if (present_timings_info != VK_NULL_HANDLE) + if (present_timings_info != nullptr) { present_timing_info = present_timings_info->pTimingInfos; - assert(present_timing_info != VK_NULL_HANDLE); + assert(present_timing_info != nullptr); if (present_timing_info->presentStageQueries & VK_PRESENT_STAGE_QUEUE_OPERATIONS_END_BIT_EXT) { auto *ext_present_timing = get_swapchain_extension(true); @@ -672,7 +672,7 @@ VkResult swapchain_base::queue_present(VkQueue queue, const VkPresentInfoKHR *pr TRY(notify_presentation_engine(submit_info.pending_present)); #if VULKAN_WSI_LAYER_EXPERIMENTAL - if (present_timing_info != VK_NULL_HANDLE) + if (present_timing_info != nullptr) { auto *ext_present_timing = get_swapchain_extension(true); TRY_LOG_CALL(ext_present_timing->add_presentation_entry(