vulkan/wsi: move swapchain create/destroy to common code
[mesa.git] / src / amd / vulkan / radv_wsi.c
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(