Add support for VK_KHR_incremental_present
authorXuelian Bai <xuelian.bai@samsung.com>
Mon, 26 Jul 2021 07:31:39 +0000 (15:31 +0800)
committerJoonbum Ko <joonbum.ko@samsung.com>
Wed, 24 Nov 2021 05:23:44 +0000 (14:23 +0900)
Read region information from VkPresentRegionsKHR.

Change-Id: I60668599de5331108066a5ba8630867684cea92e
Signed-Off-by: Xuelian Bai <xuelian.bai@samsung.com>
layer/VkLayer_window_system_integration.json
layer/swapchain_api.cpp
wsi/swapchain_base_tizen.cpp
wsi/swapchain_base_tizen.hpp
wsi/tizen/swapchain.cpp
wsi/tizen/swapchain.hpp

index 71bfac0..2d03e61 100644 (file)
@@ -30,7 +30,8 @@
                     "vkGetDeviceGroupSurfacePresentModesKHR",
                     "vkGetPhysicalDevicePresentRectanglesKHR"
                 ]
-            }
+            },
+            {"name" : "VK_KHR_incremental_present", "spec_version" : "1"}
         ],
         "enable_environment": {
             "ENABLE_WSI_LAYER": "1"
index b7c495f..d913e05 100644 (file)
@@ -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<wsi::swapchain_base *>(swapc);
       assert(sc != nullptr);
 
-      res = sc->queue_present(queue, present_info, pPresentInfo->pImageIndices[i]);
+      if (regions && regions->pRegions)
+         region = &regions->pRegions[i];
+
+      VkResult res = sc->queue_present(queue, pPresentInfo, pPresentInfo->pImageIndices[i], region);
 
       if (pPresentInfo->pResults != nullptr)
       {
index 76ece53..d74b7e9 100644 (file)
@@ -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;
 }
index 9c6ff27..9e62bf4 100644 (file)
@@ -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.
index e21efa7..3785caf 100644 (file)
@@ -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<tizen_image_data *>(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)
index 3a6e41a..d2c277c 100644 (file)
@@ -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