anv: Deduplicate dispatch calls
[mesa.git] / src / vulkan / anv_wsi.c
index 24379337a5e4ed1f54009620700b4cc7ca84e88f..c5911a3635b111be549f856fc2c08cfb9f683c2f 100644 (file)
 VkResult
 anv_init_wsi(struct anv_instance *instance)
 {
-   memset(instance->wsi_impl, 0, sizeof(instance->wsi_impl));
-   return anv_x11_init_wsi(instance);
+   VkResult result;
+
+   result = anv_x11_init_wsi(instance);
+   if (result != VK_SUCCESS)
+      return result;
+
+#ifdef HAVE_WAYLAND_PLATFORM
+   result = anv_wl_init_wsi(instance);
+   if (result != VK_SUCCESS) {
+      anv_x11_finish_wsi(instance);
+      return result;
+   }
+#endif
+
+   return VK_SUCCESS;
 }
 
 void
 anv_finish_wsi(struct anv_instance *instance)
 {
+#ifdef HAVE_WAYLAND_PLATFORM
+   anv_wl_finish_wsi(instance);
+#endif
    anv_x11_finish_wsi(instance);
 }
 
-VkResult
-anv_GetPhysicalDeviceSurfaceSupportWSI(
-    VkPhysicalDevice                        physicalDevice,
-    uint32_t                                queueFamilyIndex,
-    const VkSurfaceDescriptionWSI*          pSurfaceDescription,
-    VkBool32*                               pSupported)
+void anv_DestroySurfaceKHR(
+    VkInstance                                   _instance,
+    VkSurfaceKHR                                 _surface,
+    const VkAllocationCallbacks*                 pAllocator)
 {
-   ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice);
-
-   assert(pSurfaceDescription->sType ==
-          VK_STRUCTURE_TYPE_SURFACE_DESCRIPTION_WINDOW_WSI);
+   ANV_FROM_HANDLE(anv_instance, instance, _instance);
+   ANV_FROM_HANDLE(_VkIcdSurfaceBase, surface, _surface);
 
-   VkSurfaceDescriptionWindowWSI *window = (void *)pSurfaceDescription;
+   anv_free2(&instance->alloc, pAllocator, surface);
+}
 
-   struct anv_wsi_implementation *impl =
-      physical_device->instance->wsi_impl[window->platform];
+VkResult anv_GetPhysicalDeviceSurfaceSupportKHR(
+    VkPhysicalDevice                            physicalDevice,
+    uint32_t                                    queueFamilyIndex,
+    VkSurfaceKHR                                _surface,
+    VkBool32*                                   pSupported)
+{
+   ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
+   ANV_FROM_HANDLE(_VkIcdSurfaceBase, surface, _surface);
+   struct anv_wsi_interface *iface = device->instance->wsi[surface->platform];
 
-   if (impl) {
-      return impl->get_window_supported(impl, physical_device,
-                                        window, pSupported);
-   } else {
-      *pSupported = false;
-      return VK_SUCCESS;
-   }
+   return iface->get_support(surface, device, queueFamilyIndex, pSupported);
 }
 
-VkResult
-anv_GetSurfaceInfoWSI(
-    VkDevice                                 _device,
-    const VkSurfaceDescriptionWSI*           pSurfaceDescription,
-    VkSurfaceInfoTypeWSI                     infoType,
-    size_t*                                  pDataSize,
-    void*                                    pData)
+VkResult anv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
+    VkPhysicalDevice                            physicalDevice,
+    VkSurfaceKHR                                _surface,
+    VkSurfaceCapabilitiesKHR*                   pSurfaceCapabilities)
 {
-   ANV_FROM_HANDLE(anv_device, device, _device);
-
-   assert(pSurfaceDescription->sType ==
-          VK_STRUCTURE_TYPE_SURFACE_DESCRIPTION_WINDOW_WSI);
-   VkSurfaceDescriptionWindowWSI *window =
-      (VkSurfaceDescriptionWindowWSI *)pSurfaceDescription;
+   ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
+   ANV_FROM_HANDLE(_VkIcdSurfaceBase, surface, _surface);
+   struct anv_wsi_interface *iface = device->instance->wsi[surface->platform];
 
-   struct anv_wsi_implementation *impl =
-      device->instance->wsi_impl[window->platform];
+   return iface->get_capabilities(surface, device, pSurfaceCapabilities);
+}
 
-   assert(impl);
+VkResult anv_GetPhysicalDeviceSurfaceFormatsKHR(
+    VkPhysicalDevice                            physicalDevice,
+    VkSurfaceKHR                                _surface,
+    uint32_t*                                   pSurfaceFormatCount,
+    VkSurfaceFormatKHR*                         pSurfaceFormats)
+{
+   ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
+   ANV_FROM_HANDLE(_VkIcdSurfaceBase, surface, _surface);
+   struct anv_wsi_interface *iface = device->instance->wsi[surface->platform];
 
-   return impl->get_surface_info(impl, device, window, infoType,
-                                 pDataSize, pData);
+   return iface->get_formats(surface, device, pSurfaceFormatCount,
+                             pSurfaceFormats);
 }
 
-VkResult
-anv_CreateSwapChainWSI(
-    VkDevice                                 _device,
-    const VkSwapChainCreateInfoWSI*          pCreateInfo,
-    VkSwapChainWSI*                          pSwapChain)
+VkResult anv_GetPhysicalDeviceSurfacePresentModesKHR(
+    VkPhysicalDevice                            physicalDevice,
+    VkSurfaceKHR                                _surface,
+    uint32_t*                                   pPresentModeCount,
+    VkPresentModeKHR*                           pPresentModes)
 {
-   ANV_FROM_HANDLE(anv_device, device, _device);
-   struct anv_swap_chain *swap_chain;
-   VkResult result;
-
-   assert(pCreateInfo->pSurfaceDescription->sType ==
-          VK_STRUCTURE_TYPE_SURFACE_DESCRIPTION_WINDOW_WSI);
-   VkSurfaceDescriptionWindowWSI *window =
-      (VkSurfaceDescriptionWindowWSI *)pCreateInfo->pSurfaceDescription;
+   ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
+   ANV_FROM_HANDLE(_VkIcdSurfaceBase, surface, _surface);
+   struct anv_wsi_interface *iface = device->instance->wsi[surface->platform];
 
-   struct anv_wsi_implementation *impl =
-      device->instance->wsi_impl[window->platform];
+   return iface->get_present_modes(surface, device, pPresentModeCount,
+                                   pPresentModes);
+}
 
-   assert(impl);
+VkResult anv_CreateSwapchainKHR(
+    VkDevice                                     _device,
+    const VkSwapchainCreateInfoKHR*              pCreateInfo,
+    const VkAllocationCallbacks*                 pAllocator,
+    VkSwapchainKHR*                              pSwapchain)
+{
+   ANV_FROM_HANDLE(anv_device, device, _device);
+   ANV_FROM_HANDLE(_VkIcdSurfaceBase, surface, pCreateInfo->surface);
+   struct anv_wsi_interface *iface = device->instance->wsi[surface->platform];
+   struct anv_swapchain *swapchain;
 
-   result = impl->create_swap_chain(impl, device, pCreateInfo, &swap_chain);
+   VkResult result = iface->create_swapchain(surface, device, pCreateInfo,
+                                             pAllocator, &swapchain);
+   if (result != VK_SUCCESS)
+      return result;
 
-   if (result == VK_SUCCESS)
-      *pSwapChain = anv_swap_chain_to_handle(swap_chain);
+   *pSwapchain = anv_swapchain_to_handle(swapchain);
 
-   return result;
+   return VK_SUCCESS;
 }
 
-VkResult
-anv_DestroySwapChainWSI(
-    VkDevice                                 device,
-    VkSwapChainWSI                           swapChain)
+void anv_DestroySwapchainKHR(
+    VkDevice                                     device,
+    VkSwapchainKHR                               _swapchain,
+    const VkAllocationCallbacks*                 pAllocator)
 {
-   ANV_FROM_HANDLE(anv_swap_chain, swap_chain, swapChain);
-
-   assert(swap_chain->device == anv_device_from_handle(device));
+   ANV_FROM_HANDLE(anv_swapchain, swapchain, _swapchain);
 
-   return swap_chain->destroy(swap_chain);
+   swapchain->destroy(swapchain, pAllocator);
 }
 
-VkResult
-anv_GetSwapChainInfoWSI(
-    VkDevice                                 device,
-    VkSwapChainWSI                           swapChain,
-    VkSwapChainInfoTypeWSI                   infoType,
-    size_t*                                  pDataSize,
-    void*                                    pData)
+VkResult anv_GetSwapchainImagesKHR(
+    VkDevice                                     device,
+    VkSwapchainKHR                               _swapchain,
+    uint32_t*                                    pSwapchainImageCount,
+    VkImage*                                     pSwapchainImages)
 {
-   ANV_FROM_HANDLE(anv_swap_chain, swap_chain, swapChain);
-
-   assert(swap_chain->device == anv_device_from_handle(device));
+   ANV_FROM_HANDLE(anv_swapchain, swapchain, _swapchain);
 
-   return swap_chain->get_swap_chain_info(swap_chain, infoType,
-                                          pDataSize, pData);
+   return swapchain->get_images(swapchain, pSwapchainImageCount,
+                                pSwapchainImages);
 }
 
-VkResult
-anv_AcquireNextImageWSI(
-    VkDevice                                 device,
-    VkSwapChainWSI                           swapChain,
-    uint64_t                                 timeout,
-    VkSemaphore                              semaphore,
-    uint32_t*                                pImageIndex)
+VkResult anv_AcquireNextImageKHR(
+    VkDevice                                     device,
+    VkSwapchainKHR                               _swapchain,
+    uint64_t                                     timeout,
+    VkSemaphore                                  semaphore,
+    VkFence                                      fence,
+    uint32_t*                                    pImageIndex)
 {
-   ANV_FROM_HANDLE(anv_swap_chain, swap_chain, swapChain);
-
-   assert(swap_chain->device == anv_device_from_handle(device));
+   ANV_FROM_HANDLE(anv_swapchain, swapchain, _swapchain);
 
-   return swap_chain->acquire_next_image(swap_chain,
-                                         timeout, semaphore, pImageIndex);
+   return swapchain->acquire_next_image(swapchain, timeout, semaphore,
+                                        pImageIndex);
 }
 
-VkResult
-anv_QueuePresentWSI(
+VkResult anv_QueuePresentKHR(
     VkQueue                                  _queue,
-    VkPresentInfoWSI*                        pPresentInfo)
+    const VkPresentInfoKHR*                  pPresentInfo)
 {
    ANV_FROM_HANDLE(anv_queue, queue, _queue);
    VkResult result;
 
-   for (uint32_t i = 0; i < pPresentInfo->swapChainCount; i++) {
-      ANV_FROM_HANDLE(anv_swap_chain, swap_chain, pPresentInfo->swapChains[i]);
+   for (uint32_t i = 0; i < pPresentInfo->swapchainCount; i++) {
+      ANV_FROM_HANDLE(anv_swapchain, swapchain, pPresentInfo->pSwapchains[i]);
 
-      assert(swap_chain->device == queue->device);
+      assert(swapchain->device == queue->device);
 
-      result = swap_chain->queue_present(swap_chain, queue,
-                                         pPresentInfo->imageIndices[i]);
+      result = swapchain->queue_present(swapchain, queue,
+                                        pPresentInfo->pImageIndices[i]);
       /* TODO: What if one of them returns OUT_OF_DATE? */
       if (result != VK_SUCCESS)
          return result;