vulkan/wsi: move swapchain create/destroy to common code
authorDave Airlie <airlied@redhat.com>
Thu, 16 Nov 2017 02:02:04 +0000 (12:02 +1000)
committerJason Ekstrand <jason.ekstrand@intel.com>
Mon, 4 Dec 2017 18:04:19 +0000 (10:04 -0800)
v2 (Jason Ekstrand):
 - Rebase
 - Alter the names of the helpers to better match the vulkan entrypoints
 - Use the helpers in anv

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

index e159b6436e0e1e39a20cd6b13804d7abe1878ca7..d00e0281689df55091bba1009aadc94d2598c3a7 100644 (file)
@@ -164,60 +164,34 @@ VkResult radv_CreateSwapchainKHR(
        VkSwapchainKHR*                              pSwapchain)
 {
        RADV_FROM_HANDLE(radv_device, device, _device);
-       ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, pCreateInfo->surface);
-       struct wsi_interface *iface =
-               device->physical_device->wsi_device.wsi[surface->platform];
-       struct wsi_swapchain *swapchain;
        const VkAllocationCallbacks *alloc;
        if (pAllocator)
                alloc = pAllocator;
        else
                alloc = &device->alloc;
-       VkResult result = iface->create_swapchain(surface, _device,
-                                                 &device->physical_device->wsi_device,
-                                                 device->physical_device->local_fd,
-                                                 pCreateInfo,
-                                                 alloc,
-                                                 &swapchain);
-       if (result != VK_SUCCESS)
-               return result;
-
-       if (pAllocator)
-               swapchain->alloc = *pAllocator;
-       else
-               swapchain->alloc = device->alloc;
-
-       for (unsigned i = 0; i < ARRAY_SIZE(swapchain->fences); i++)
-               swapchain->fences[i] = VK_NULL_HANDLE;
-
-       *pSwapchain = wsi_swapchain_to_handle(swapchain);
 
-       return VK_SUCCESS;
+       return wsi_common_create_swapchain(&device->physical_device->wsi_device,
+                                          radv_device_to_handle(device),
+                                          device->physical_device->local_fd,
+                                          pCreateInfo,
+                                          alloc,
+                                          pSwapchain);
 }
 
 void radv_DestroySwapchainKHR(
        VkDevice                                     _device,
-       VkSwapchainKHR                               _swapchain,
+       VkSwapchainKHR                               swapchain,
        const VkAllocationCallbacks*                 pAllocator)
 {
        RADV_FROM_HANDLE(radv_device, device, _device);
-       RADV_FROM_HANDLE(wsi_swapchain, swapchain, _swapchain);
        const VkAllocationCallbacks *alloc;
 
-       if (!_swapchain)
-               return;
-
        if (pAllocator)
                alloc = pAllocator;
        else
                alloc = &device->alloc;
 
-       for (unsigned i = 0; i < ARRAY_SIZE(swapchain->fences); i++) {
-               if (swapchain->fences[i] != VK_NULL_HANDLE)
-                       radv_DestroyFence(_device, swapchain->fences[i], pAllocator);
-       }
-
-       swapchain->destroy(swapchain, alloc);
+       wsi_common_destroy_swapchain(_device, swapchain, alloc);
 }
 
 VkResult radv_GetSwapchainImagesKHR(
index eed378cc74f96c552cc26a3119ad92b27f67acd5..62368a10a066ce693fdf6da231282749098ac613 100644 (file)
@@ -193,57 +193,32 @@ VkResult anv_CreateSwapchainKHR(
     VkSwapchainKHR*                              pSwapchain)
 {
    ANV_FROM_HANDLE(anv_device, device, _device);
-   ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, pCreateInfo->surface);
-   struct wsi_interface *iface =
-      device->instance->physicalDevice.wsi_device.wsi[surface->platform];
-   struct wsi_swapchain *swapchain;
+   struct wsi_device *wsi_device = &device->instance->physicalDevice.wsi_device;
    const VkAllocationCallbacks *alloc;
 
    if (pAllocator)
      alloc = pAllocator;
    else
      alloc = &device->alloc;
-   VkResult result = iface->create_swapchain(surface, _device,
-                                             &device->instance->physicalDevice.wsi_device,
-                                             device->instance->physicalDevice.local_fd,
-                                             pCreateInfo,
-                                             alloc,
-                                             &swapchain);
-   if (result != VK_SUCCESS)
-      return result;
-
-   swapchain->alloc = *alloc;
 
-   for (unsigned i = 0; i < ARRAY_SIZE(swapchain->fences); i++)
-      swapchain->fences[i] = VK_NULL_HANDLE;
-
-   *pSwapchain = wsi_swapchain_to_handle(swapchain);
-
-   return VK_SUCCESS;
+   return wsi_common_create_swapchain(wsi_device, _device, device->fd,
+                                      pCreateInfo, alloc, pSwapchain);
 }
 
 void anv_DestroySwapchainKHR(
     VkDevice                                     _device,
-    VkSwapchainKHR                               _swapchain,
+    VkSwapchainKHR                               swapchain,
     const VkAllocationCallbacks*                 pAllocator)
 {
    ANV_FROM_HANDLE(anv_device, device, _device);
-   ANV_FROM_HANDLE(wsi_swapchain, swapchain, _swapchain);
    const VkAllocationCallbacks *alloc;
 
-   if (!swapchain)
-      return;
-
    if (pAllocator)
      alloc = pAllocator;
    else
      alloc = &device->alloc;
-   for (unsigned i = 0; i < ARRAY_SIZE(swapchain->fences); i++) {
-      if (swapchain->fences[i] != VK_NULL_HANDLE)
-         anv_DestroyFence(_device, swapchain->fences[i], pAllocator);
-   }
 
-   swapchain->destroy(swapchain, alloc);
+   wsi_common_destroy_swapchain(_device, swapchain, alloc);
 }
 
 VkResult anv_GetSwapchainImagesKHR(
index d420e48a00798a6007c646df3e1699544c758c5d..69cb71dfdbc5e3e4688f2a41cc818c9cc3bbca46 100644 (file)
@@ -115,6 +115,9 @@ fail:
 void
 wsi_swapchain_finish(struct wsi_swapchain *chain)
 {
+   for (unsigned i = 0; i < ARRAY_SIZE(chain->fences); i++)
+      chain->wsi->DestroyFence(chain->device, chain->fences[i], &chain->alloc);
+
    for (uint32_t i = 0; i < chain->wsi->queue_family_count; i++) {
       chain->wsi->DestroyCommandPool(chain->device, chain->cmd_pools[i],
                                      &chain->alloc);
@@ -484,6 +487,41 @@ wsi_destroy_image(const struct wsi_swapchain *chain,
    wsi->DestroyBuffer(chain->device, image->prime.buffer, &chain->alloc);
 }
 
+VkResult
+wsi_common_create_swapchain(struct wsi_device *wsi,
+                            VkDevice device,
+                            int fd,
+                            const VkSwapchainCreateInfoKHR *pCreateInfo,
+                            const VkAllocationCallbacks *pAllocator,
+                            VkSwapchainKHR *pSwapchain)
+{
+   ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, pCreateInfo->surface);
+   struct wsi_interface *iface = wsi->wsi[surface->platform];
+   struct wsi_swapchain *swapchain;
+
+   VkResult result = iface->create_swapchain(surface, device, wsi, fd,
+                                             pCreateInfo, pAllocator,
+                                             &swapchain);
+   if (result != VK_SUCCESS)
+      return result;
+
+   *pSwapchain = wsi_swapchain_to_handle(swapchain);
+
+   return VK_SUCCESS;
+}
+
+void
+wsi_common_destroy_swapchain(VkDevice device,
+                             VkSwapchainKHR _swapchain,
+                             const VkAllocationCallbacks *pAllocator)
+{
+   WSI_FROM_HANDLE(wsi_swapchain, swapchain, _swapchain);
+   if (!swapchain)
+      return;
+
+   swapchain->destroy(swapchain, pAllocator);
+}
+
 VkResult
 wsi_common_get_images(VkSwapchainKHR _swapchain,
                       uint32_t *pSwapchainImageCount,
index 9ff28e76f3383937b25353cc9b44b85b0feabfc6..6ed10b85921d1bb2f898bd2352b9380076a2351f 100644 (file)
@@ -220,6 +220,18 @@ wsi_common_get_images(VkSwapchainKHR _swapchain,
                       uint32_t *pSwapchainImageCount,
                       VkImage *pSwapchainImages);
 
+VkResult
+wsi_common_create_swapchain(struct wsi_device *wsi,
+                            VkDevice device,
+                            int fd,
+                            const VkSwapchainCreateInfoKHR *pCreateInfo,
+                            const VkAllocationCallbacks *pAllocator,
+                            VkSwapchainKHR *pSwapchain);
+void
+wsi_common_destroy_swapchain(VkDevice device,
+                             VkSwapchainKHR swapchain,
+                             const VkAllocationCallbacks *pAllocator);
+
 VkResult
 wsi_common_queue_present(const struct wsi_device *wsi,
                          VkDevice device_h,