anv/wsi: Rework to be compatable with the loader
authorJason Ekstrand <jason.ekstrand@intel.com>
Thu, 28 Jan 2016 23:34:22 +0000 (15:34 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Sat, 30 Jan 2016 04:39:21 +0000 (20:39 -0800)
src/vulkan/anv_device.c
src/vulkan/anv_private.h
src/vulkan/anv_wsi.c
src/vulkan/anv_wsi.h
src/vulkan/anv_wsi_wayland.c
src/vulkan/anv_wsi_x11.c

index fe9808f0bf78513871e40cafa7913bca8419f2c9..1e0bfb080d9490024138c86b387494c37d682d89 100644 (file)
@@ -157,7 +157,7 @@ anv_physical_device_finish(struct anv_physical_device *device)
 static const VkExtensionProperties global_extensions[] = {
    {
       .extensionName = VK_KHR_SURFACE_EXTENSION_NAME,
-      .specVersion = 24,
+      .specVersion = 25,
    },
    {
       .extensionName = VK_KHR_XCB_SURFACE_EXTENSION_NAME,
index 211b83a3bab774649e5c7770008799d501e8befb..f4794d9fb9dbb9ff388f4931f0630840a975eab4 100644 (file)
@@ -541,6 +541,10 @@ struct anv_physical_device {
     struct isl_device                           isl_dev;
 };
 
+struct anv_wsi_interaface;
+
+#define VK_ICD_WSI_PLATFORM_MAX 5
+
 struct anv_instance {
     VK_LOADER_DATA                              _loader_data;
 
@@ -550,7 +554,7 @@ struct anv_instance {
     int                                         physicalDeviceCount;
     struct anv_physical_device                  physicalDevice;
 
-    void *                                      wayland_wsi;
+    struct anv_wsi_interface *                  wsi[VK_ICD_WSI_PLATFORM_MAX];
 };
 
 VkResult anv_init_wsi(struct anv_instance *instance);
index c181cd4d729c3037d5929185303ae25a4e80d8c3..c5911a3635b111be549f856fc2c08cfb9f683c2f 100644 (file)
@@ -53,13 +53,14 @@ anv_finish_wsi(struct anv_instance *instance)
 }
 
 void anv_DestroySurfaceKHR(
-    VkInstance                                   instance,
+    VkInstance                                   _instance,
     VkSurfaceKHR                                 _surface,
     const VkAllocationCallbacks*                 pAllocator)
 {
-   ANV_FROM_HANDLE(anv_wsi_surface, surface, _surface);
+   ANV_FROM_HANDLE(anv_instance, instance, _instance);
+   ANV_FROM_HANDLE(_VkIcdSurfaceBase, surface, _surface);
 
-   surface->destroy(surface, pAllocator);
+   anv_free2(&instance->alloc, pAllocator, surface);
 }
 
 VkResult anv_GetPhysicalDeviceSurfaceSupportKHR(
@@ -69,9 +70,10 @@ VkResult anv_GetPhysicalDeviceSurfaceSupportKHR(
     VkBool32*                                   pSupported)
 {
    ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
-   ANV_FROM_HANDLE(anv_wsi_surface, surface, _surface);
+   ANV_FROM_HANDLE(_VkIcdSurfaceBase, surface, _surface);
+   struct anv_wsi_interface *iface = device->instance->wsi[surface->platform];
 
-   return surface->get_support(surface, device, queueFamilyIndex, pSupported);
+   return iface->get_support(surface, device, queueFamilyIndex, pSupported);
 }
 
 VkResult anv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
@@ -80,9 +82,10 @@ VkResult anv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
     VkSurfaceCapabilitiesKHR*                   pSurfaceCapabilities)
 {
    ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
-   ANV_FROM_HANDLE(anv_wsi_surface, surface, _surface);
+   ANV_FROM_HANDLE(_VkIcdSurfaceBase, surface, _surface);
+   struct anv_wsi_interface *iface = device->instance->wsi[surface->platform];
 
-   return surface->get_capabilities(surface, device, pSurfaceCapabilities);
+   return iface->get_capabilities(surface, device, pSurfaceCapabilities);
 }
 
 VkResult anv_GetPhysicalDeviceSurfaceFormatsKHR(
@@ -92,10 +95,11 @@ VkResult anv_GetPhysicalDeviceSurfaceFormatsKHR(
     VkSurfaceFormatKHR*                         pSurfaceFormats)
 {
    ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
-   ANV_FROM_HANDLE(anv_wsi_surface, surface, _surface);
+   ANV_FROM_HANDLE(_VkIcdSurfaceBase, surface, _surface);
+   struct anv_wsi_interface *iface = device->instance->wsi[surface->platform];
 
-   return surface->get_formats(surface, device, pSurfaceFormatCount,
-                               pSurfaceFormats);
+   return iface->get_formats(surface, device, pSurfaceFormatCount,
+                             pSurfaceFormats);
 }
 
 VkResult anv_GetPhysicalDeviceSurfacePresentModesKHR(
@@ -105,10 +109,11 @@ VkResult anv_GetPhysicalDeviceSurfacePresentModesKHR(
     VkPresentModeKHR*                           pPresentModes)
 {
    ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
-   ANV_FROM_HANDLE(anv_wsi_surface, surface, _surface);
+   ANV_FROM_HANDLE(_VkIcdSurfaceBase, surface, _surface);
+   struct anv_wsi_interface *iface = device->instance->wsi[surface->platform];
 
-   return surface->get_present_modes(surface, device, pPresentModeCount,
-                                     pPresentModes);
+   return iface->get_present_modes(surface, device, pPresentModeCount,
+                                   pPresentModes);
 }
 
 VkResult anv_CreateSwapchainKHR(
@@ -118,11 +123,12 @@ VkResult anv_CreateSwapchainKHR(
     VkSwapchainKHR*                              pSwapchain)
 {
    ANV_FROM_HANDLE(anv_device, device, _device);
-   ANV_FROM_HANDLE(anv_wsi_surface, surface, pCreateInfo->surface);
+   ANV_FROM_HANDLE(_VkIcdSurfaceBase, surface, pCreateInfo->surface);
+   struct anv_wsi_interface *iface = device->instance->wsi[surface->platform];
    struct anv_swapchain *swapchain;
 
-   VkResult result = surface->create_swapchain(surface, device, pCreateInfo,
-                                               pAllocator, &swapchain);
+   VkResult result = iface->create_swapchain(surface, device, pCreateInfo,
+                                             pAllocator, &swapchain);
    if (result != VK_SUCCESS)
       return result;
 
index 15b3f862499c9fb3923ecd7daecc34ed54cb3f46..6e9ff9b8447700cd1a37cba984a0ea17807cee96 100644 (file)
 
 struct anv_swapchain;
 
-struct anv_wsi_surface {
-   struct anv_instance *instance;
-
-   void (*destroy)(struct anv_wsi_surface *surface,
-                   const VkAllocationCallbacks *pAllocator);
-   VkResult (*get_support)(struct anv_wsi_surface *surface,
+struct anv_wsi_interface {
+   VkResult (*get_support)(VkIcdSurfaceBase *surface,
                            struct anv_physical_device *device,
                            uint32_t queueFamilyIndex,
                            VkBool32* pSupported);
-   VkResult (*get_capabilities)(struct anv_wsi_surface *surface,
+   VkResult (*get_capabilities)(VkIcdSurfaceBase *surface,
                                 struct anv_physical_device *device,
                                 VkSurfaceCapabilitiesKHR* pSurfaceCapabilities);
-   VkResult (*get_formats)(struct anv_wsi_surface *surface,
+   VkResult (*get_formats)(VkIcdSurfaceBase *surface,
                            struct anv_physical_device *device,
                            uint32_t* pSurfaceFormatCount,
                            VkSurfaceFormatKHR* pSurfaceFormats);
-   VkResult (*get_present_modes)(struct anv_wsi_surface *surface,
+   VkResult (*get_present_modes)(VkIcdSurfaceBase *surface,
                                  struct anv_physical_device *device,
                                  uint32_t* pPresentModeCount,
                                  VkPresentModeKHR* pPresentModes);
-   VkResult (*create_swapchain)(struct anv_wsi_surface *surface,
+   VkResult (*create_swapchain)(VkIcdSurfaceBase *surface,
                                 struct anv_device *device,
                                 const VkSwapchainCreateInfoKHR* pCreateInfo,
                                 const VkAllocationCallbacks* pAllocator,
@@ -69,7 +65,7 @@ struct anv_swapchain {
                              uint32_t image_index);
 };
 
-ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_wsi_surface, VkSurfaceKHR)
+ANV_DEFINE_NONDISP_HANDLE_CASTS(_VkIcdSurfaceBase, VkSurfaceKHR)
 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_swapchain, VkSwapchainKHR)
 
 VkResult anv_x11_init_wsi(struct anv_instance *instance);
index 5e8a3a56f6826933c5c1b642e1d32586712b6310..fa5d340eee5c03f8d65521fba82be85c74725cff 100644 (file)
 
 #define MIN_NUM_IMAGES 2
 
-struct wsi_wl_surface {
-   struct anv_wsi_surface base;
-
-   struct wl_display *display;
-   struct wl_surface *surface;
-};
-
 struct wsi_wl_display {
    struct wl_display *                          display;
    struct wl_drm *                              drm;
@@ -48,6 +41,8 @@ struct wsi_wl_display {
 };
 
 struct wsi_wayland {
+   struct anv_wsi_interface                     base;
+
    struct anv_instance *                        instance;
 
    pthread_mutex_t                              mutex;
@@ -285,7 +280,8 @@ fail:
 static struct wsi_wl_display *
 wsi_wl_get_display(struct anv_instance *instance, struct wl_display *wl_display)
 {
-   struct wsi_wayland *wsi = instance->wayland_wsi;
+   struct wsi_wayland *wsi =
+      (struct wsi_wayland *)instance->wsi[VK_ICD_WSI_PLATFORM_WAYLAND];
 
    pthread_mutex_lock(&wsi->mutex);
 
@@ -326,7 +322,7 @@ VkBool32 anv_GetPhysicalDeviceWaylandPresentationSupportKHR(
 }
 
 static VkResult
-wsi_wl_surface_get_support(struct anv_wsi_surface *surface,
+wsi_wl_surface_get_support(VkIcdSurfaceBase *surface,
                            struct anv_physical_device *device,
                            uint32_t queueFamilyIndex,
                            VkBool32* pSupported)
@@ -342,7 +338,7 @@ static const VkPresentModeKHR present_modes[] = {
 };
 
 static VkResult
-wsi_wl_surface_get_capabilities(struct anv_wsi_surface *surface,
+wsi_wl_surface_get_capabilities(VkIcdSurfaceBase *surface,
                                 struct anv_physical_device *device,
                                 VkSurfaceCapabilitiesKHR* caps)
 {
@@ -367,12 +363,12 @@ wsi_wl_surface_get_capabilities(struct anv_wsi_surface *surface,
 }
 
 static VkResult
-wsi_wl_surface_get_formats(struct anv_wsi_surface *wsi_surface,
+wsi_wl_surface_get_formats(VkIcdSurfaceBase *icd_surface,
                            struct anv_physical_device *device,
                            uint32_t* pSurfaceFormatCount,
                            VkSurfaceFormatKHR* pSurfaceFormats)
 {
-   struct wsi_wl_surface *surface = (struct wsi_wl_surface *)wsi_surface;
+   VkIcdSurfaceWayland *surface = (VkIcdSurfaceWayland *)icd_surface;
    struct wsi_wl_display *display =
       wsi_wl_get_display(device->instance, surface->display);
 
@@ -399,7 +395,7 @@ wsi_wl_surface_get_formats(struct anv_wsi_surface *wsi_surface,
 }
 
 static VkResult
-wsi_wl_surface_get_present_modes(struct anv_wsi_surface *surface,
+wsi_wl_surface_get_present_modes(VkIcdSurfaceBase *surface,
                                  struct anv_physical_device *device,
                                  uint32_t* pPresentModeCount,
                                  VkPresentModeKHR* pPresentModes)
@@ -416,15 +412,8 @@ wsi_wl_surface_get_present_modes(struct anv_wsi_surface *surface,
    return VK_SUCCESS;
 }
 
-static void
-wsi_wl_surface_destroy(struct anv_wsi_surface *surface,
-                       const VkAllocationCallbacks *pAllocator)
-{
-   anv_free2(&surface->instance->alloc, pAllocator, surface);
-}
-
 static VkResult
-wsi_wl_surface_create_swapchain(struct anv_wsi_surface *surface,
+wsi_wl_surface_create_swapchain(VkIcdSurfaceBase *surface,
                                 struct anv_device *device,
                                 const VkSwapchainCreateInfoKHR* pCreateInfo,
                                 const VkAllocationCallbacks* pAllocator,
@@ -436,10 +425,11 @@ VkResult anv_CreateWaylandSurfaceKHR(
     const VkAllocationCallbacks*                pAllocator,
     VkSurfaceKHR*                               pSurface)
 {
+   ANV_FROM_HANDLE(anv_instance, instance, _instance);
+
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR);
 
-   ANV_FROM_HANDLE(anv_instance, instance, _instance);
-   struct wsi_wl_surface *surface;
+   VkIcdSurfaceWayland *surface;
 
    surface = anv_alloc2(&instance->alloc, pAllocator, sizeof *surface, 8,
                         VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
@@ -449,15 +439,7 @@ VkResult anv_CreateWaylandSurfaceKHR(
    surface->display = pCreateInfo->display;
    surface->surface = pCreateInfo->surface;
 
-   surface->base.instance = instance;
-   surface->base.destroy = wsi_wl_surface_destroy;
-   surface->base.get_support = wsi_wl_surface_get_support;
-   surface->base.get_capabilities = wsi_wl_surface_get_capabilities;
-   surface->base.get_formats = wsi_wl_surface_get_formats;
-   surface->base.get_present_modes = wsi_wl_surface_get_present_modes;
-   surface->base.create_swapchain = wsi_wl_surface_create_swapchain;
-
-   *pSurface = anv_wsi_surface_to_handle(&surface->base);
+   *pSurface = _VkIcdSurfaceBase_to_handle(&surface->base);
 
    return VK_SUCCESS;
 }
@@ -734,13 +716,13 @@ wsi_wl_swapchain_destroy(struct anv_swapchain *anv_chain,
 }
 
 static VkResult
-wsi_wl_surface_create_swapchain(struct anv_wsi_surface *wsi_surface,
+wsi_wl_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
                                 struct anv_device *device,
                                 const VkSwapchainCreateInfoKHR* pCreateInfo,
                                 const VkAllocationCallbacks* pAllocator,
                                 struct anv_swapchain **swapchain_out)
 {
-   struct wsi_wl_surface *surface = (struct wsi_wl_surface *)wsi_surface;
+   VkIcdSurfaceWayland *surface = (VkIcdSurfaceWayland *)icd_surface;
    struct wsi_wl_swapchain *chain;
    VkResult result;
 
@@ -847,7 +829,13 @@ anv_wl_init_wsi(struct anv_instance *instance)
       goto fail_mutex;
    }
 
-   instance->wayland_wsi = wsi;
+   wsi->base.get_support = wsi_wl_surface_get_support;
+   wsi->base.get_capabilities = wsi_wl_surface_get_capabilities;
+   wsi->base.get_formats = wsi_wl_surface_get_formats;
+   wsi->base.get_present_modes = wsi_wl_surface_get_present_modes;
+   wsi->base.create_swapchain = wsi_wl_surface_create_swapchain;
+
+   instance->wsi[VK_ICD_WSI_PLATFORM_WAYLAND] = &wsi->base;
 
    return VK_SUCCESS;
 
@@ -857,7 +845,7 @@ fail_mutex:
 fail_alloc:
    anv_free(&instance->alloc, wsi);
 fail:
-   instance->wayland_wsi = NULL;
+   instance->wsi[VK_ICD_WSI_PLATFORM_WAYLAND] = NULL;
 
    return result;
 }
@@ -865,7 +853,8 @@ fail:
 void
 anv_wl_finish_wsi(struct anv_instance *instance)
 {
-   struct wsi_wayland *wsi = instance->wayland_wsi;
+   struct wsi_wayland *wsi =
+      (struct wsi_wayland *)instance->wsi[VK_ICD_WSI_PLATFORM_WAYLAND];
 
    if (wsi) {
       _mesa_hash_table_destroy(wsi->displays, NULL);
index 8e35191576aa707d775b8c2510761303690af784..8d0d1580d3e4be6b903ba75c454bc404c5408d4f 100644 (file)
 
 #include "anv_wsi.h"
 
-struct x11_surface {
-   struct anv_wsi_surface base;
-
-   xcb_connection_t *connection;
-   xcb_window_t window;
-};
-
 static const VkSurfaceFormatKHR formats[] = {
    { .format = VK_FORMAT_B8G8R8A8_UNORM, },
 };
@@ -53,11 +46,23 @@ VkBool32 anv_GetPhysicalDeviceXcbPresentationSupportKHR(
 }
 
 static VkResult
-x11_surface_get_capabilities(struct anv_wsi_surface *wsi_surface,
+x11_surface_get_support(VkIcdSurfaceBase *surface,
+                        struct anv_physical_device *device,
+                        uint32_t queueFamilyIndex,
+                        VkBool32* pSupported)
+{
+   anv_finishme("Check that we actually have DRI3");
+   *pSupported = true;
+
+   return VK_SUCCESS;
+}
+
+static VkResult
+x11_surface_get_capabilities(VkIcdSurfaceBase *icd_surface,
                              struct anv_physical_device *device,
                              VkSurfaceCapabilitiesKHR *caps)
 {
-   struct x11_surface *surface = (struct x11_surface *)wsi_surface;
+   VkIcdSurfaceXcb *surface = (VkIcdSurfaceXcb *)icd_surface;
 
    xcb_get_geometry_cookie_t cookie = xcb_get_geometry(surface->connection,
                                                        surface->window);
@@ -95,7 +100,7 @@ x11_surface_get_capabilities(struct anv_wsi_surface *wsi_surface,
 }
 
 static VkResult
-x11_surface_get_formats(struct anv_wsi_surface *surface,
+x11_surface_get_formats(VkIcdSurfaceBase *surface,
                         struct anv_physical_device *device,
                         uint32_t *pSurfaceFormatCount,
                         VkSurfaceFormatKHR *pSurfaceFormats)
@@ -113,7 +118,7 @@ x11_surface_get_formats(struct anv_wsi_surface *surface,
 }
 
 static VkResult
-x11_surface_get_present_modes(struct anv_wsi_surface *surface,
+x11_surface_get_present_modes(VkIcdSurfaceBase *surface,
                               struct anv_physical_device *device,
                               uint32_t *pPresentModeCount,
                               VkPresentModeKHR *pPresentModes)
@@ -130,30 +135,32 @@ x11_surface_get_present_modes(struct anv_wsi_surface *surface,
    return VK_SUCCESS;
 }
 
-static void
-x11_surface_destroy(struct anv_wsi_surface *surface,
-                    const VkAllocationCallbacks *pAllocator)
-{
-   anv_free2(&surface->instance->alloc, pAllocator, surface);
-}
-
 static VkResult
-x11_surface_create_swapchain(struct anv_wsi_surface *surface,
+x11_surface_create_swapchain(VkIcdSurfaceBase *surface,
                              struct anv_device *device,
                              const VkSwapchainCreateInfoKHR* pCreateInfo,
                              const VkAllocationCallbacks* pAllocator,
                              struct anv_swapchain **swapchain);
 
+static struct anv_wsi_interface x11_interface = {
+   .get_support = x11_surface_get_support,
+   .get_capabilities = x11_surface_get_capabilities,
+   .get_formats = x11_surface_get_formats,
+   .get_present_modes = x11_surface_get_present_modes,
+   .create_swapchain = x11_surface_create_swapchain,
+};
+
 VkResult anv_CreateXcbSurfaceKHR(
     VkInstance                                  _instance,
     const VkXcbSurfaceCreateInfoKHR*            pCreateInfo,
     const VkAllocationCallbacks*                pAllocator,
     VkSurfaceKHR*                               pSurface)
 {
+   ANV_FROM_HANDLE(anv_instance, instance, _instance);
+
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR);
 
-   ANV_FROM_HANDLE(anv_instance, instance, _instance);
-   struct x11_surface *surface;
+   VkIcdSurfaceXcb *surface;
 
    surface = anv_alloc2(&instance->alloc, pAllocator, sizeof *surface, 8,
                         VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
@@ -163,14 +170,7 @@ VkResult anv_CreateXcbSurfaceKHR(
    surface->connection = pCreateInfo->connection;
    surface->window = pCreateInfo->window;
 
-   surface->base.instance = instance;
-   surface->base.destroy = x11_surface_destroy;
-   surface->base.get_capabilities = x11_surface_get_capabilities;
-   surface->base.get_formats = x11_surface_get_formats;
-   surface->base.get_present_modes = x11_surface_get_present_modes;
-   surface->base.create_swapchain = x11_surface_create_swapchain;
-
-   *pSurface = anv_wsi_surface_to_handle(&surface->base);
+   *pSurface = _VkIcdSurfaceBase_to_handle(&surface->base);
 
    return VK_SUCCESS;
 }
@@ -303,13 +303,13 @@ x11_swapchain_destroy(struct anv_swapchain *anv_chain,
 }
 
 static VkResult
-x11_surface_create_swapchain(struct anv_wsi_surface *wsi_surface,
+x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
                              struct anv_device *device,
                              const VkSwapchainCreateInfoKHR *pCreateInfo,
                              const VkAllocationCallbacks* pAllocator,
                              struct anv_swapchain **swapchain_out)
 {
-   struct x11_surface *surface = (struct x11_surface *)wsi_surface;
+   VkIcdSurfaceXcb *surface = (VkIcdSurfaceXcb *)icd_surface;
    struct x11_swapchain *chain;
    xcb_void_cookie_t cookie;
    VkResult result;
@@ -451,6 +451,8 @@ x11_surface_create_swapchain(struct anv_wsi_surface *wsi_surface,
 VkResult
 anv_x11_init_wsi(struct anv_instance *instance)
 {
+   instance->wsi[VK_ICD_WSI_PLATFORM_XCB] = &x11_interface;
+
    return VK_SUCCESS;
 }