From 2da499bb77b032668ca134ce07fb75dca060f755 Mon Sep 17 00:00:00 2001 From: Xuelian Bai Date: Mon, 26 Jul 2021 15:31:39 +0800 Subject: [PATCH] Add support for VK_KHR_incremental_present Read region information from VkPresentRegionsKHR. Change-Id: I60668599de5331108066a5ba8630867684cea92e Signed-Off-by: Xuelian Bai --- layer/VkLayer_window_system_integration.json | 3 ++- layer/swapchain_api.cpp | 16 +++++++++++++++- wsi/swapchain_base_tizen.cpp | 4 ++-- wsi/swapchain_base_tizen.hpp | 4 ++-- wsi/tizen/swapchain.cpp | 22 ++++++++++++++++++++-- wsi/tizen/swapchain.hpp | 2 +- 6 files changed, 42 insertions(+), 9 deletions(-) diff --git a/layer/VkLayer_window_system_integration.json b/layer/VkLayer_window_system_integration.json index 71bfac0..2d03e61 100644 --- a/layer/VkLayer_window_system_integration.json +++ b/layer/VkLayer_window_system_integration.json @@ -30,7 +30,8 @@ "vkGetDeviceGroupSurfacePresentModesKHR", "vkGetPhysicalDevicePresentRectanglesKHR" ] - } + }, + {"name" : "VK_KHR_incremental_present", "spec_version" : "1"} ], "enable_environment": { "ENABLE_WSI_LAYER": "1" diff --git a/layer/swapchain_api.cpp b/layer/swapchain_api.cpp index b7c495f..d913e05 100644 --- a/layer/swapchain_api.cpp +++ b/layer/swapchain_api.cpp @@ -205,14 +205,28 @@ wsi_layer_vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) } VkResult ret = VK_SUCCESS; + const VkPresentRegionsKHR *regions = NULL; + VkBaseOutStructure *s; + for (s = (struct VkBaseOutStructure *)((void *)(pPresentInfo->pNext));s; s = s->pNext) + { + if (s->sType == VK_STRUCTURE_TYPE_PRESENT_REGIONS_KHR) + { + regions = (const VkPresentRegionsKHR *)s; + break; + } + } for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i) { VkSwapchainKHR swapc = pPresentInfo->pSwapchains[i]; + const VkPresentRegionKHR *region = NULL; auto *sc = reinterpret_cast(swapc); assert(sc != nullptr); - res = sc->queue_present(queue, present_info, pPresentInfo->pImageIndices[i]); + if (regions && regions->pRegions) + region = ®ions->pRegions[i]; + + VkResult res = sc->queue_present(queue, pPresentInfo, pPresentInfo->pImageIndices[i], region); if (pPresentInfo->pResults != nullptr) { diff --git a/wsi/swapchain_base_tizen.cpp b/wsi/swapchain_base_tizen.cpp index 76ece53..d74b7e9 100644 --- a/wsi/swapchain_base_tizen.cpp +++ b/wsi/swapchain_base_tizen.cpp @@ -164,7 +164,7 @@ VkResult swapchain_base::get_swapchain_images(uint32_t *swapchain_image_count, V } } -VkResult swapchain_base::queue_present(VkQueue queue, const VkPresentInfoKHR *present_info, const uint32_t image_index) +VkResult swapchain_base::queue_present(VkQueue queue, const VkPresentInfoKHR *present_info, const uint32_t image_index, const VkPresentRegionKHR *region) { VkResult result; @@ -196,7 +196,7 @@ VkResult swapchain_base::queue_present(VkQueue queue, const VkPresentInfoKHR *pr return result; } - present_image(image_index); + present_image(image_index, region); return VK_SUCCESS; } diff --git a/wsi/swapchain_base_tizen.hpp b/wsi/swapchain_base_tizen.hpp index 9c6ff27..9e62bf4 100644 --- a/wsi/swapchain_base_tizen.hpp +++ b/wsi/swapchain_base_tizen.hpp @@ -87,7 +87,7 @@ public: * swapchain has a descendant who started presenting returns VK_ERROR_OUT_OF_DATE_KHR, * otherwise returns VK_SUCCESS. */ - VkResult queue_present(VkQueue queue, const VkPresentInfoKHR *present_info, const uint32_t image_index); + VkResult queue_present(VkQueue queue, const VkPresentInfoKHR *present_info, const uint32_t image_index, const VkPresentRegionKHR *region); protected: @@ -212,7 +212,7 @@ protected: * @param pending_index Index of the pending image to be presented. * */ - virtual void present_image(uint32_t pending_index) = 0; + virtual void present_image(uint32_t pending_index, const VkPresentRegionKHR *region) = 0; /** * @brief Transition a presented image to free. diff --git a/wsi/tizen/swapchain.cpp b/wsi/tizen/swapchain.cpp index e21efa7..3785caf 100644 --- a/wsi/tizen/swapchain.cpp +++ b/wsi/tizen/swapchain.cpp @@ -356,10 +356,28 @@ VkResult swapchain::acquire_image(uint32_t *image_index) return VK_ERROR_SURFACE_LOST_KHR; } -void swapchain::present_image(uint32_t pendingIndex) +void swapchain::present_image(uint32_t pendingIndex, const VkPresentRegionKHR *region) { tizen_image_data *image_data = reinterpret_cast(m_swapchain_images[pendingIndex].data); - tpl_surface_enqueue_buffer_with_damage_and_sync(m_tpl_surface, image_data->tbm_buffer, 0, NULL, -1); + int *rects = NULL; + int rect_count = 0; + + if (region) + { + rect_count = region->rectangleCount; + rects = new int[rect_count*4]; + for (int i = 0; i < rect_count*4; i+=4) + { + rects[i] = region->pRectangles->offset.x; + rects[i+1] = region->pRectangles->offset.y; + rects[i+2] = region->pRectangles->extent.width; + rects[i+3] = region->pRectangles->extent.height; + } + } + + tpl_surface_enqueue_buffer_with_damage_and_sync(m_tpl_surface, image_data->tbm_buffer, rect_count, rects, -1); + if (rects) + delete rects; } void swapchain::destroy_image(void) diff --git a/wsi/tizen/swapchain.hpp b/wsi/tizen/swapchain.hpp index 3a6e41a..d2c277c 100644 --- a/wsi/tizen/swapchain.hpp +++ b/wsi/tizen/swapchain.hpp @@ -70,7 +70,7 @@ protected: * * @param pendingIndex Index of the pending image to be presented. */ - void present_image(uint32_t pendingIndex) override; + void present_image(uint32_t pendingIndex, const VkPresentRegionKHR *region) override; /** * @brief Method to release a swapchain image -- 2.7.4