WIP: Partially upgrade to vulkan v0.221.0
[mesa.git] / src / vulkan / anv_wsi.c
index 5c2dbb5fbca65db858a90ed0e14a4d0f74b5ea0b..c181cd4d729c3037d5929185303ae25a4e80d8c3 100644 (file)
 #include "anv_wsi.h"
 
 VkResult
-anv_GetPhysicalDeviceSurfaceSupportWSI(
-    VkPhysicalDevice                        physicalDevice,
-    uint32_t                                queueFamilyIndex,
-    const VkSurfaceDescriptionWSI*          pSurfaceDescription,
-    VkBool32*                               pSupported)
+anv_init_wsi(struct anv_instance *instance)
 {
-   assert(pSurfaceDescription->sType ==
-          VK_STRUCTURE_TYPE_SURFACE_DESCRIPTION_WINDOW_WSI);
+   VkResult result;
 
-   VkSurfaceDescriptionWindowWSI *window = (void *)pSurfaceDescription;
+   result = anv_x11_init_wsi(instance);
+   if (result != VK_SUCCESS)
+      return result;
 
-   *pSupported = window->platform == VK_PLATFORM_XCB_WSI;
+#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;
 }
 
-VkResult
-anv_GetSurfaceInfoWSI(
-    VkDevice                                 _device,
-    const VkSurfaceDescriptionWSI*           pSurfaceDescription,
-    VkSurfaceInfoTypeWSI                     infoType,
-    size_t*                                  pDataSize,
-    void*                                    pData)
+void
+anv_finish_wsi(struct anv_instance *instance)
 {
-   ANV_FROM_HANDLE(anv_device, device, _device);
+#ifdef HAVE_WAYLAND_PLATFORM
+   anv_wl_finish_wsi(instance);
+#endif
+   anv_x11_finish_wsi(instance);
+}
 
-   assert(pSurfaceDescription->sType ==
-          VK_STRUCTURE_TYPE_SURFACE_DESCRIPTION_WINDOW_WSI);
-   VkSurfaceDescriptionWindowWSI *window =
-      (VkSurfaceDescriptionWindowWSI *)pSurfaceDescription;
-
-   switch (window->platform) {
-   case VK_PLATFORM_XCB_WSI:
-      return anv_x11_get_surface_info(device, window, infoType,
-                                      pDataSize, pData);
-   default:
-      return vk_error(VK_ERROR_INVALID_VALUE);
-   }
+void anv_DestroySurfaceKHR(
+    VkInstance                                   instance,
+    VkSurfaceKHR                                 _surface,
+    const VkAllocationCallbacks*                 pAllocator)
+{
+   ANV_FROM_HANDLE(anv_wsi_surface, surface, _surface);
+
+   surface->destroy(surface, pAllocator);
 }
 
-VkResult
-anv_CreateSwapChainWSI(
-    VkDevice                                 _device,
-    const VkSwapChainCreateInfoWSI*          pCreateInfo,
-    VkSwapChainWSI*                          pSwapChain)
+VkResult anv_GetPhysicalDeviceSurfaceSupportKHR(
+    VkPhysicalDevice                            physicalDevice,
+    uint32_t                                    queueFamilyIndex,
+    VkSurfaceKHR                                _surface,
+    VkBool32*                                   pSupported)
 {
-   ANV_FROM_HANDLE(anv_device, device, _device);
-   struct anv_swap_chain *swap_chain;
-   VkResult result;
+   ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
+   ANV_FROM_HANDLE(anv_wsi_surface, surface, _surface);
 
-   assert(pCreateInfo->pSurfaceDescription->sType ==
-          VK_STRUCTURE_TYPE_SURFACE_DESCRIPTION_WINDOW_WSI);
-   VkSurfaceDescriptionWindowWSI *window =
-      (VkSurfaceDescriptionWindowWSI *)pCreateInfo->pSurfaceDescription;
-
-   switch (window->platform) {
-   case VK_PLATFORM_XCB_WSI:
-      result = anv_x11_create_swap_chain(device, pCreateInfo,
-                                         (void *)&swap_chain);
-      break;
-   default:
-      return vk_error(VK_ERROR_INVALID_VALUE);
-   }
+   return surface->get_support(surface, device, queueFamilyIndex, pSupported);
+}
 
-   if (result == VK_SUCCESS)
-      *pSwapChain = anv_swap_chain_to_handle(swap_chain);
+VkResult anv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
+    VkPhysicalDevice                            physicalDevice,
+    VkSurfaceKHR                                _surface,
+    VkSurfaceCapabilitiesKHR*                   pSurfaceCapabilities)
+{
+   ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
+   ANV_FROM_HANDLE(anv_wsi_surface, surface, _surface);
 
-   return result;
+   return surface->get_capabilities(surface, device, pSurfaceCapabilities);
 }
 
-VkResult
-anv_DestroySwapChainWSI(
-    VkDevice                                 device,
-    VkSwapChainWSI                           swapChain)
+VkResult anv_GetPhysicalDeviceSurfaceFormatsKHR(
+    VkPhysicalDevice                            physicalDevice,
+    VkSurfaceKHR                                _surface,
+    uint32_t*                                   pSurfaceFormatCount,
+    VkSurfaceFormatKHR*                         pSurfaceFormats)
 {
-   ANV_FROM_HANDLE(anv_swap_chain, swap_chain, swapChain);
+   ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
+   ANV_FROM_HANDLE(anv_wsi_surface, surface, _surface);
 
-   assert(swap_chain->device == anv_device_from_handle(device));
+   return surface->get_formats(surface, device, pSurfaceFormatCount,
+                               pSurfaceFormats);
+}
 
-   switch (swap_chain->type) {
-   case ANV_SWAP_CHAIN_TYPE_X11:
-      return anv_x11_destroy_swap_chain((void *)swap_chain);
-   default:
-      return vk_error(VK_ERROR_INVALID_VALUE);
-   }
+VkResult anv_GetPhysicalDeviceSurfacePresentModesKHR(
+    VkPhysicalDevice                            physicalDevice,
+    VkSurfaceKHR                                _surface,
+    uint32_t*                                   pPresentModeCount,
+    VkPresentModeKHR*                           pPresentModes)
+{
+   ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
+   ANV_FROM_HANDLE(anv_wsi_surface, surface, _surface);
+
+   return surface->get_present_modes(surface, device, pPresentModeCount,
+                                     pPresentModes);
 }
 
-VkResult
-anv_GetSwapChainInfoWSI(
-    VkDevice                                 device,
-    VkSwapChainWSI                           swapChain,
-    VkSwapChainInfoTypeWSI                   infoType,
-    size_t*                                  pDataSize,
-    void*                                    pData)
+VkResult anv_CreateSwapchainKHR(
+    VkDevice                                     _device,
+    const VkSwapchainCreateInfoKHR*              pCreateInfo,
+    const VkAllocationCallbacks*                 pAllocator,
+    VkSwapchainKHR*                              pSwapchain)
 {
-   ANV_FROM_HANDLE(anv_swap_chain, swap_chain, swapChain);
+   ANV_FROM_HANDLE(anv_device, device, _device);
+   ANV_FROM_HANDLE(anv_wsi_surface, surface, pCreateInfo->surface);
+   struct anv_swapchain *swapchain;
 
-   assert(swap_chain->device == anv_device_from_handle(device));
+   VkResult result = surface->create_swapchain(surface, device, pCreateInfo,
+                                               pAllocator, &swapchain);
+   if (result != VK_SUCCESS)
+      return result;
 
-   switch (swap_chain->type) {
-   case ANV_SWAP_CHAIN_TYPE_X11:
-      return anv_x11_get_swap_chain_info((void *)swap_chain,
-                                         infoType, pDataSize, pData);
-   default:
-      return vk_error(VK_ERROR_INVALID_VALUE);
-   }
+   *pSwapchain = anv_swapchain_to_handle(swapchain);
+
+   return VK_SUCCESS;
 }
 
-VkResult
-anv_AcquireNextImageWSI(
-    VkDevice                                 device,
-    VkSwapChainWSI                           swapChain,
-    uint64_t                                 timeout,
-    VkSemaphore                              semaphore,
-    uint32_t*                                pImageIndex)
+void anv_DestroySwapchainKHR(
+    VkDevice                                     device,
+    VkSwapchainKHR                               _swapchain,
+    const VkAllocationCallbacks*                 pAllocator)
 {
-   ANV_FROM_HANDLE(anv_swap_chain, swap_chain, swapChain);
+   ANV_FROM_HANDLE(anv_swapchain, swapchain, _swapchain);
 
-   assert(swap_chain->device == anv_device_from_handle(device));
+   swapchain->destroy(swapchain, pAllocator);
+}
 
-   switch (swap_chain->type) {
-   case ANV_SWAP_CHAIN_TYPE_X11:
-      return anv_x11_acquire_next_image((void *)swap_chain,
-                                        timeout, semaphore, pImageIndex);
-   default:
-      return vk_error(VK_ERROR_INVALID_VALUE);
-   }
+VkResult anv_GetSwapchainImagesKHR(
+    VkDevice                                     device,
+    VkSwapchainKHR                               _swapchain,
+    uint32_t*                                    pSwapchainImageCount,
+    VkImage*                                     pSwapchainImages)
+{
+   ANV_FROM_HANDLE(anv_swapchain, swapchain, _swapchain);
+
+   return swapchain->get_images(swapchain, pSwapchainImageCount,
+                                pSwapchainImages);
 }
 
-VkResult
-anv_QueuePresentWSI(
+VkResult anv_AcquireNextImageKHR(
+    VkDevice                                     device,
+    VkSwapchainKHR                               _swapchain,
+    uint64_t                                     timeout,
+    VkSemaphore                                  semaphore,
+    VkFence                                      fence,
+    uint32_t*                                    pImageIndex)
+{
+   ANV_FROM_HANDLE(anv_swapchain, swapchain, _swapchain);
+
+   return swapchain->acquire_next_image(swapchain, timeout, semaphore,
+                                        pImageIndex);
+}
+
+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]);
-
-      assert(swap_chain->device == queue->device);
+   for (uint32_t i = 0; i < pPresentInfo->swapchainCount; i++) {
+      ANV_FROM_HANDLE(anv_swapchain, swapchain, pPresentInfo->pSwapchains[i]);
 
-      switch (swap_chain->type) {
-      case ANV_SWAP_CHAIN_TYPE_X11:
-         result = anv_x11_queue_present(queue, (void *)swap_chain,
-                                        pPresentInfo->imageIndices[i]);
-         /* TODO: What if one of them returns OUT_OF_DATE? */
-         if (result != VK_SUCCESS)
-            return result;
-         else
-            continue;
+      assert(swapchain->device == queue->device);
 
-      default:
-         return vk_error(VK_ERROR_INVALID_VALUE);
-      }
+      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;
    }
 
    return VK_SUCCESS;