vulkan/wsi: Move get_images into common code
authorJason Ekstrand <jason.ekstrand@intel.com>
Thu, 16 Nov 2017 17:56:37 +0000 (09:56 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Mon, 4 Dec 2017 18:04:19 +0000 (10:04 -0800)
This moves bits out of all four corners (anv, radv, x11, wayland) and
into the wsi common code.  We also switch to using an outarray to ensure
we get our return code right.

Reviewed-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Chad Versace <chadversary@chromium.org>
src/amd/vulkan/radv_wsi.c
src/intel/vulkan/anv_wsi.c
src/vulkan/wsi/wsi_common.c
src/vulkan/wsi/wsi_common.h
src/vulkan/wsi/wsi_common_wayland.c
src/vulkan/wsi/wsi_common_x11.c

index 054b97bb011e07be38d290382f28ad228d099726..e159b6436e0e1e39a20cd6b13804d7abe1878ca7 100644 (file)
@@ -222,13 +222,12 @@ void radv_DestroySwapchainKHR(
 
 VkResult radv_GetSwapchainImagesKHR(
        VkDevice                                     device,
-       VkSwapchainKHR                               _swapchain,
+       VkSwapchainKHR                               swapchain,
        uint32_t*                                    pSwapchainImageCount,
        VkImage*                                     pSwapchainImages)
 {
-       RADV_FROM_HANDLE(wsi_swapchain, swapchain, _swapchain);
-
-       return swapchain->get_images(swapchain, pSwapchainImageCount,
+       return wsi_common_get_images(swapchain,
+                                    pSwapchainImageCount,
                                     pSwapchainImages);
 }
 
index 975ad18146cf699462cd088d5c14e53503792e2f..eed378cc74f96c552cc26a3119ad92b27f67acd5 100644 (file)
@@ -248,13 +248,12 @@ void anv_DestroySwapchainKHR(
 
 VkResult anv_GetSwapchainImagesKHR(
     VkDevice                                     device,
-    VkSwapchainKHR                               _swapchain,
+    VkSwapchainKHR                               swapchain,
     uint32_t*                                    pSwapchainImageCount,
     VkImage*                                     pSwapchainImages)
 {
-   ANV_FROM_HANDLE(wsi_swapchain, swapchain, _swapchain);
-
-   return swapchain->get_images(swapchain, pSwapchainImageCount,
+   return wsi_common_get_images(swapchain,
+                                pSwapchainImageCount,
                                 pSwapchainImages);
 }
 
index e5a9a28d34732eaa2c5b507b9856c8c3e99e336e..ea4920c6fe3d88bdaafd73712fde225609bd931f 100644 (file)
@@ -507,6 +507,23 @@ wsi_prime_image_blit_to_linear(const struct wsi_swapchain *chain,
    return chain->wsi->QueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);
 }
 
+VkResult
+wsi_common_get_images(VkSwapchainKHR _swapchain,
+                      uint32_t *pSwapchainImageCount,
+                      VkImage *pSwapchainImages)
+{
+   WSI_FROM_HANDLE(wsi_swapchain, swapchain, _swapchain);
+   VK_OUTARRAY_MAKE(images, pSwapchainImages, pSwapchainImageCount);
+
+   for (uint32_t i = 0; i < swapchain->image_count; i++) {
+      vk_outarray_append(&images, image) {
+         *image = swapchain->get_wsi_image(swapchain, i)->image;
+      }
+   }
+
+   return vk_outarray_status(&images);
+}
+
 VkResult
 wsi_common_queue_present(const struct wsi_device *wsi,
                          VkDevice device,
index b47da43e085a32bf4ad7c49dc5c5b9718db1a6f2..892e708671bad3a905e91e2bf0e30baaf9a58f1c 100644 (file)
@@ -64,8 +64,8 @@ struct wsi_swapchain {
 
    VkResult (*destroy)(struct wsi_swapchain *swapchain,
                        const VkAllocationCallbacks *pAllocator);
-   VkResult (*get_images)(struct wsi_swapchain *swapchain,
-                          uint32_t *pCount, VkImage *pSwapchainImages);
+   struct wsi_image *(*get_wsi_image)(struct wsi_swapchain *swapchain,
+                                      uint32_t image_index);
    VkResult (*acquire_next_image)(struct wsi_swapchain *swap_chain,
                                   uint64_t timeout, VkSemaphore semaphore,
                                   uint32_t *image_index);
@@ -216,6 +216,11 @@ VkResult wsi_wl_init_wsi(struct wsi_device *wsi_device,
 void wsi_wl_finish_wsi(struct wsi_device *wsi_device,
                        const VkAllocationCallbacks *alloc);
 
+VkResult
+wsi_common_get_images(VkSwapchainKHR _swapchain,
+                      uint32_t *pSwapchainImageCount,
+                      VkImage *pSwapchainImages);
+
 VkResult
 wsi_common_queue_present(const struct wsi_device *wsi,
                          VkDevice device_h,
index 22c01b2963ab2fe70833ea267dfcc4fc1925e9e8..bf60a9be8264c87a9e151d9d9f063d81d39b6a78 100644 (file)
@@ -582,30 +582,12 @@ struct wsi_wl_swapchain {
    struct wsi_wl_image                          images[0];
 };
 
-static VkResult
-wsi_wl_swapchain_get_images(struct wsi_swapchain *wsi_chain,
-                            uint32_t *pCount, VkImage *pSwapchainImages)
+static struct wsi_image *
+wsi_wl_swapchain_get_wsi_image(struct wsi_swapchain *wsi_chain,
+                               uint32_t image_index)
 {
    struct wsi_wl_swapchain *chain = (struct wsi_wl_swapchain *)wsi_chain;
-   uint32_t ret_count;
-   VkResult result;
-
-   if (pSwapchainImages == NULL) {
-      *pCount = chain->base.image_count;
-      return VK_SUCCESS;
-   }
-
-   result = VK_SUCCESS;
-   ret_count = chain->base.image_count;
-   if (chain->base.image_count > *pCount) {
-     ret_count = *pCount;
-     result = VK_INCOMPLETE;
-   }
-
-   for (uint32_t i = 0; i < ret_count; i++)
-      pSwapchainImages[i] = chain->images[i].base.image;
-
-   return result;
+   return &chain->images[image_index].base;
 }
 
 static VkResult
@@ -832,7 +814,7 @@ wsi_wl_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
                       VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR;
 
    chain->base.destroy = wsi_wl_swapchain_destroy;
-   chain->base.get_images = wsi_wl_swapchain_get_images;
+   chain->base.get_wsi_image = wsi_wl_swapchain_get_wsi_image;
    chain->base.acquire_next_image = wsi_wl_swapchain_acquire_next_image;
    chain->base.queue_present = wsi_wl_swapchain_queue_present;
    chain->base.present_mode = pCreateInfo->presentMode;
index 68cb0355612da9a9b9b2647998e6dfc146075fed..8860d8edb6e883266ec8dd8a6b352f85ffd08acf 100644 (file)
@@ -648,30 +648,11 @@ struct x11_swapchain {
    struct x11_image                             images[0];
 };
 
-static VkResult
-x11_get_images(struct wsi_swapchain *anv_chain,
-               uint32_t* pCount, VkImage *pSwapchainImages)
+static struct wsi_image *
+x11_get_wsi_image(struct wsi_swapchain *wsi_chain, uint32_t image_index)
 {
-   struct x11_swapchain *chain = (struct x11_swapchain *)anv_chain;
-   uint32_t ret_count;
-   VkResult result;
-
-   if (pSwapchainImages == NULL) {
-      *pCount = chain->base.image_count;
-      return VK_SUCCESS;
-   }
-
-   result = VK_SUCCESS;
-   ret_count = chain->base.image_count;
-   if (chain->base.image_count > *pCount) {
-     ret_count = *pCount;
-     result = VK_INCOMPLETE;
-   }
-
-   for (uint32_t i = 0; i < ret_count; i++)
-      pSwapchainImages[i] = chain->images[i].base.image;
-
-   return result;
+   struct x11_swapchain *chain = (struct x11_swapchain *)wsi_chain;
+   return &chain->images[image_index].base;
 }
 
 static VkResult
@@ -1109,7 +1090,7 @@ x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
       goto fail_alloc;
 
    chain->base.destroy = x11_swapchain_destroy;
-   chain->base.get_images = x11_get_images;
+   chain->base.get_wsi_image = x11_get_wsi_image;
    chain->base.acquire_next_image = x11_acquire_next_image;
    chain->base.queue_present = x11_queue_present;
    chain->base.present_mode = pCreateInfo->presentMode;