From a0b6497838d028003781af93ccc56e5d85b640b3 Mon Sep 17 00:00:00 2001 From: Ginu Jacob Date: Tue, 27 Jan 2026 11:25:45 +0000 Subject: [PATCH] Shared present mode, free image on release and limit image count to 1 In this change, the shared present mode is fixed to keep the min/max image count to 1. Additionally the image status is set to free when the image is released. Signed-off-by: Ginu Jacob ginu.jacob@arm.com Change-Id: Ibb779911a222b7917190e35fbf8711b292a6d1c3 --- wsi/display/surface_properties.cpp | 10 ++++------ wsi/headless/surface_properties.cpp | 13 +++++++++++-- wsi/surface_properties.cpp | 17 +++++++++++++++-- wsi/surface_properties.hpp | 13 +++++++++---- wsi/swapchain_base.cpp | 13 +++++++------ wsi/swapchain_base.hpp | 5 +++-- wsi/wayland/surface_properties.cpp | 6 +++--- 7 files changed, 52 insertions(+), 25 deletions(-) diff --git a/wsi/display/surface_properties.cpp b/wsi/display/surface_properties.cpp index 27248ac..332d72e 100644 --- a/wsi/display/surface_properties.cpp +++ b/wsi/display/surface_properties.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024-2025 Arm Limited. + * Copyright (c) 2024-2026 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -59,7 +59,9 @@ surface_properties::surface_properties() VkResult surface_properties::get_surface_capabilities(VkPhysicalDevice physical_device, VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) { - get_surface_capabilities_common(physical_device, pSurfaceCapabilities); + /* Image count limits */ + surface_properties_override_params override_params = { 2, 3 }; + get_surface_capabilities_common(physical_device, pSurfaceCapabilities, &override_params); if (m_specific_surface != nullptr) { @@ -68,10 +70,6 @@ VkResult surface_properties::get_surface_capabilities(VkPhysicalDevice physical_ pSurfaceCapabilities->maxImageExtent = m_specific_surface->get_extent(); } - /* Image count limits */ - pSurfaceCapabilities->minImageCount = 2; - pSurfaceCapabilities->maxImageCount = 3; - /* Composite alpha */ pSurfaceCapabilities->supportedCompositeAlpha = static_cast(VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR | VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR); diff --git a/wsi/headless/surface_properties.cpp b/wsi/headless/surface_properties.cpp index 0bcb226..2c39518 100644 --- a/wsi/headless/surface_properties.cpp +++ b/wsi/headless/surface_properties.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019, 2021-2025 Arm Limited. + * Copyright (c) 2017-2019, 2021-2026 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -93,7 +93,16 @@ VkResult surface_properties::get_surface_capabilities(VkPhysicalDevice physical_ VkSurfaceCapabilities2KHR *surface_capabilities) { TRY(check_surface_present_mode_query_is_supported(surface_info, m_supported_modes)); - get_surface_capabilities_common(physical_device, &surface_capabilities->surfaceCapabilities); + surface_properties_override_params override_params = {}; + auto surface_present_mode = + util::find_extension(VK_STRUCTURE_TYPE_SURFACE_PRESENT_MODE_EXT, surface_info); + if ((surface_present_mode != nullptr) && + ((surface_present_mode->presentMode == VK_PRESENT_MODE_SHARED_DEMAND_REFRESH_KHR) || + (surface_present_mode->presentMode == VK_PRESENT_MODE_SHARED_CONTINUOUS_REFRESH_KHR))) + { + override_params = { 1, 1 }; + } + get_surface_capabilities_common(physical_device, &surface_capabilities->surfaceCapabilities, &override_params); m_compatible_present_modes.get_surface_present_mode_compatibility_common(surface_info, surface_capabilities); auto surface_scaling_capabilities = util::find_extension( diff --git a/wsi/surface_properties.cpp b/wsi/surface_properties.cpp index b8c919a..0299c9e 100644 --- a/wsi/surface_properties.cpp +++ b/wsi/surface_properties.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, 2024-2025 Arm Limited. + * Copyright (c) 2022, 2024-2026 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -95,12 +95,25 @@ void surface_format_properties::fill_format_properties(VkSurfaceFormat2KHR &surf } } -void get_surface_capabilities_common(VkPhysicalDevice physical_device, VkSurfaceCapabilitiesKHR *surface_capabilities) +void get_surface_capabilities_common(VkPhysicalDevice physical_device, VkSurfaceCapabilitiesKHR *surface_capabilities, + const surface_properties_override_params *override_params) { /* Image count limits */ surface_capabilities->minImageCount = 1; surface_capabilities->maxImageCount = surface_properties::MAX_SWAPCHAIN_IMAGE_COUNT; + if (override_params != nullptr) + { + if (override_params->min_swapchain_image_count != 0) + { + surface_capabilities->minImageCount = override_params->min_swapchain_image_count; + } + if (override_params->max_swapchain_image_count != 0) + { + surface_capabilities->maxImageCount = override_params->max_swapchain_image_count; + } + } + /* Surface extents */ surface_capabilities->currentExtent = { 0xffffffff, 0xffffffff }; surface_capabilities->minImageExtent = { 1, 1 }; diff --git a/wsi/surface_properties.hpp b/wsi/surface_properties.hpp index 1cffb4f..ce996a9 100644 --- a/wsi/surface_properties.hpp +++ b/wsi/surface_properties.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019, 2021-2025 Arm Limited. + * Copyright (c) 2017-2019, 2021-2026 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -42,7 +42,11 @@ namespace wsi { - +struct surface_properties_override_params +{ + uint32_t min_swapchain_image_count = 0; + uint32_t max_swapchain_image_count = 0; +}; /** * @brief The base surface property query interface. */ @@ -285,9 +289,10 @@ VkResult check_surface_present_mode_query_is_supported(const VkPhysicalDeviceSur * * @param physical_device Vulkan physical_device. * @param surface_capabilities address of Vulkan surface capabilities struct. - * + * @param override_params Backend specfic parameters to override. */ -void get_surface_capabilities_common(VkPhysicalDevice physical_device, VkSurfaceCapabilitiesKHR *surface_capabilities); +void get_surface_capabilities_common(VkPhysicalDevice physical_device, VkSurfaceCapabilitiesKHR *surface_capabilities, + const surface_properties_override_params *override_params = nullptr); /** * @brief Common function for the get_surface_present_modes. diff --git a/wsi/swapchain_base.cpp b/wsi/swapchain_base.cpp index 2fd4805..37551c6 100644 --- a/wsi/swapchain_base.cpp +++ b/wsi/swapchain_base.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2025 Arm Limited. + * Copyright (c) 2017-2026 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -176,7 +176,7 @@ VkResult swapchain_base::init_page_flip_thread() return VK_SUCCESS; } -void swapchain_base::unpresent_image(uint32_t presented_index) +void swapchain_base::unpresent_image(uint32_t presented_index, bool release_image) { util::unique_lock image_status_lock(m_image_status_mutex); if (!image_status_lock) @@ -186,11 +186,12 @@ void swapchain_base::unpresent_image(uint32_t presented_index) } const bool is_shared_present = is_using_shared_present_mode(); - m_swapchain_images[presented_index].set_status(is_shared_present ? swapchain_image::ACQUIRED : - swapchain_image::FREE); + const bool should_keep_acquired = is_shared_present && !release_image; + m_swapchain_images[presented_index].set_status(should_keep_acquired ? swapchain_image::ACQUIRED : + swapchain_image::FREE); image_status_lock.unlock(); - if (!is_shared_present) + if (!should_keep_acquired) { m_free_image_semaphore.post(); } @@ -781,7 +782,7 @@ void swapchain_base::release_images(uint32_t image_count, const uint32_t *indice assert(index < m_swapchain_images.size()); /* Applications can only pass acquired images that the device doesn't own */ assert(m_swapchain_images[index].get_status() == swapchain_image::ACQUIRED); - unpresent_image(index); + unpresent_image(index, true); } } diff --git a/wsi/swapchain_base.hpp b/wsi/swapchain_base.hpp index 31cee5d..f23669f 100644 --- a/wsi/swapchain_base.hpp +++ b/wsi/swapchain_base.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2025 Arm Limited. + * Copyright (c) 2017-2026 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -538,8 +538,9 @@ protected: * Called by swapchain implementation when a new image has been presented. * * @param presented_index Index of the image to be marked as free. + * @param release_image The image is released. */ - void unpresent_image(uint32_t presented_index); + void unpresent_image(uint32_t presented_index, bool release_image = false); /** * @brief Hook for any actions to free up a buffer for acquire diff --git a/wsi/wayland/surface_properties.cpp b/wsi/wayland/surface_properties.cpp index ac0ce07..1dcbf07 100644 --- a/wsi/wayland/surface_properties.cpp +++ b/wsi/wayland/surface_properties.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019, 2021-2025 Arm Limited. + * Copyright (c) 2017-2019, 2021-2026 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -90,8 +90,8 @@ VkResult surface_properties::get_surface_capabilities(VkPhysicalDevice physical_ { /* Image count limits */ - get_surface_capabilities_common(physical_device, pSurfaceCapabilities); - pSurfaceCapabilities->minImageCount = 2; + surface_properties_override_params override_params = { 2, 0 }; + get_surface_capabilities_common(physical_device, pSurfaceCapabilities, &override_params); /* Composite alpha */ pSurfaceCapabilities->supportedCompositeAlpha = static_cast(