[Mesa-dev] [PATCH 01/23] anv/wsi: Make WSI per-physical-device rather than per-instance

Jason Ekstrand jason at jlekstrand.net
Mon May 16 19:08:06 UTC 2016


This better maps to the Vulkan object model and also allows WSI to at least
know the hardware generation which is useful for format checks.
---
 src/intel/vulkan/anv_device.c      |  9 +++------
 src/intel/vulkan/anv_private.h     | 16 +++++++--------
 src/intel/vulkan/anv_wsi.c         | 27 +++++++++++++------------
 src/intel/vulkan/anv_wsi.h         |  8 ++++----
 src/intel/vulkan/anv_wsi_wayland.c | 36 ++++++++++++++++++----------------
 src/intel/vulkan/anv_wsi_x11.c     | 40 ++++++++++++++++++++------------------
 6 files changed, 70 insertions(+), 66 deletions(-)

diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index c81498d..54810d9 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -149,6 +149,8 @@ anv_physical_device_init(struct anv_physical_device *device,
    device->compiler->shader_debug_log = compiler_debug_log;
    device->compiler->shader_perf_log = compiler_perf_log;
 
+   anv_init_wsi(device);
+
    /* XXX: Actually detect bit6 swizzling */
    isl_device_init(&device->isl_dev, device->info, swizzled);
 
@@ -162,6 +164,7 @@ fail:
 static void
 anv_physical_device_finish(struct anv_physical_device *device)
 {
+   anv_finish_wsi(device);
    ralloc_free(device->compiler);
 }
 
@@ -272,14 +275,10 @@ VkResult anv_CreateInstance(
    instance->apiVersion = client_version;
    instance->physicalDeviceCount = -1;
 
-   memset(instance->wsi, 0, sizeof(instance->wsi));
-
    _mesa_locale_init();
 
    VG(VALGRIND_CREATE_MEMPOOL(instance, 0, false));
 
-   anv_init_wsi(instance);
-
    *pInstance = anv_instance_to_handle(instance);
 
    return VK_SUCCESS;
@@ -297,8 +296,6 @@ void anv_DestroyInstance(
       anv_physical_device_finish(&instance->physicalDevice);
    }
 
-   anv_finish_wsi(instance);
-
    VG(VALGRIND_DESTROY_MEMPOOL(instance));
 
    _mesa_locale_fini();
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index c55f1db..e4b92d3 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -532,6 +532,10 @@ anv_free2(const VkAllocationCallbacks *parent_alloc,
       anv_free(parent_alloc, data);
 }
 
+struct anv_wsi_interaface;
+
+#define VK_ICD_WSI_PLATFORM_MAX 5
+
 struct anv_physical_device {
     VK_LOADER_DATA                              _loader_data;
 
@@ -544,11 +548,9 @@ struct anv_physical_device {
     struct brw_compiler *                       compiler;
     struct isl_device                           isl_dev;
     int                                         cmd_parser_version;
-};
-
-struct anv_wsi_interaface;
 
-#define VK_ICD_WSI_PLATFORM_MAX 5
+    struct anv_wsi_interface *                  wsi[VK_ICD_WSI_PLATFORM_MAX];
+};
 
 struct anv_instance {
     VK_LOADER_DATA                              _loader_data;
@@ -558,12 +560,10 @@ struct anv_instance {
     uint32_t                                    apiVersion;
     int                                         physicalDeviceCount;
     struct anv_physical_device                  physicalDevice;
-
-    struct anv_wsi_interface *                  wsi[VK_ICD_WSI_PLATFORM_MAX];
 };
 
-VkResult anv_init_wsi(struct anv_instance *instance);
-void anv_finish_wsi(struct anv_instance *instance);
+VkResult anv_init_wsi(struct anv_physical_device *physical_device);
+void anv_finish_wsi(struct anv_physical_device *physical_device);
 
 struct anv_meta_state {
    VkAllocationCallbacks alloc;
diff --git a/src/intel/vulkan/anv_wsi.c b/src/intel/vulkan/anv_wsi.c
index 49edbdc..ce9ec32 100644
--- a/src/intel/vulkan/anv_wsi.c
+++ b/src/intel/vulkan/anv_wsi.c
@@ -24,20 +24,22 @@
 #include "anv_wsi.h"
 
 VkResult
-anv_init_wsi(struct anv_instance *instance)
+anv_init_wsi(struct anv_physical_device *physical_device)
 {
    VkResult result;
 
+   memset(physical_device->wsi, 0, sizeof(physical_device->wsi));
+
 #ifdef VK_USE_PLATFORM_XCB_KHR
-   result = anv_x11_init_wsi(instance);
+   result = anv_x11_init_wsi(physical_device);
    if (result != VK_SUCCESS)
       return result;
 #endif
 
 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
-   result = anv_wl_init_wsi(instance);
+   result = anv_wl_init_wsi(physical_device);
    if (result != VK_SUCCESS) {
-      anv_x11_finish_wsi(instance);
+      anv_x11_finish_wsi(physical_device);
       return result;
    }
 #endif
@@ -46,13 +48,13 @@ anv_init_wsi(struct anv_instance *instance)
 }
 
 void
-anv_finish_wsi(struct anv_instance *instance)
+anv_finish_wsi(struct anv_physical_device *physical_device)
 {
 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
-   anv_wl_finish_wsi(instance);
+   anv_wl_finish_wsi(physical_device);
 #endif
 #ifdef VK_USE_PLATFORM_XCB_KHR
-   anv_x11_finish_wsi(instance);
+   anv_x11_finish_wsi(physical_device);
 #endif
 }
 
@@ -75,7 +77,7 @@ VkResult anv_GetPhysicalDeviceSurfaceSupportKHR(
 {
    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_interface *iface = device->wsi[surface->platform];
 
    return iface->get_support(surface, device, queueFamilyIndex, pSupported);
 }
@@ -87,7 +89,7 @@ VkResult anv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
 {
    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_interface *iface = device->wsi[surface->platform];
 
    return iface->get_capabilities(surface, device, pSurfaceCapabilities);
 }
@@ -100,7 +102,7 @@ VkResult anv_GetPhysicalDeviceSurfaceFormatsKHR(
 {
    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_interface *iface = device->wsi[surface->platform];
 
    return iface->get_formats(surface, device, pSurfaceFormatCount,
                              pSurfaceFormats);
@@ -114,7 +116,7 @@ VkResult anv_GetPhysicalDeviceSurfacePresentModesKHR(
 {
    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_interface *iface = device->wsi[surface->platform];
 
    return iface->get_present_modes(surface, device, pPresentModeCount,
                                    pPresentModes);
@@ -128,7 +130,8 @@ VkResult anv_CreateSwapchainKHR(
 {
    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_wsi_interface *iface =
+      device->instance->physicalDevice.wsi[surface->platform];
    struct anv_swapchain *swapchain;
 
    VkResult result = iface->create_swapchain(surface, device, pCreateInfo,
diff --git a/src/intel/vulkan/anv_wsi.h b/src/intel/vulkan/anv_wsi.h
index bf17f03..67cb690 100644
--- a/src/intel/vulkan/anv_wsi.h
+++ b/src/intel/vulkan/anv_wsi.h
@@ -72,7 +72,7 @@ struct anv_swapchain {
 ANV_DEFINE_NONDISP_HANDLE_CASTS(_VkIcdSurfaceBase, VkSurfaceKHR)
 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_swapchain, VkSwapchainKHR)
 
-VkResult anv_x11_init_wsi(struct anv_instance *instance);
-void anv_x11_finish_wsi(struct anv_instance *instance);
-VkResult anv_wl_init_wsi(struct anv_instance *instance);
-void anv_wl_finish_wsi(struct anv_instance *instance);
+VkResult anv_x11_init_wsi(struct anv_physical_device *physical_device);
+void anv_x11_finish_wsi(struct anv_physical_device *physical_device);
+VkResult anv_wl_init_wsi(struct anv_physical_device *physical_device);
+void anv_wl_finish_wsi(struct anv_physical_device *physical_device);
diff --git a/src/intel/vulkan/anv_wsi_wayland.c b/src/intel/vulkan/anv_wsi_wayland.c
index 6f25eaf..0c21029 100644
--- a/src/intel/vulkan/anv_wsi_wayland.c
+++ b/src/intel/vulkan/anv_wsi_wayland.c
@@ -43,7 +43,7 @@ struct wsi_wl_display {
 struct wsi_wayland {
    struct anv_wsi_interface                     base;
 
-   struct anv_instance *                        instance;
+   struct anv_physical_device *                 physical_device;
 
    pthread_mutex_t                              mutex;
    /* Hash table of wl_display -> wsi_wl_display mappings */
@@ -226,14 +226,14 @@ wsi_wl_display_destroy(struct wsi_wayland *wsi, struct wsi_wl_display *display)
    anv_vector_finish(&display->formats);
    if (display->drm)
       wl_drm_destroy(display->drm);
-   anv_free(&wsi->instance->alloc, display);
+   anv_free(&wsi->physical_device->instance->alloc, display);
 }
 
 static struct wsi_wl_display *
 wsi_wl_display_create(struct wsi_wayland *wsi, struct wl_display *wl_display)
 {
    struct wsi_wl_display *display =
-      anv_alloc(&wsi->instance->alloc, sizeof(*display), 8,
+      anv_alloc(&wsi->physical_device->instance->alloc, sizeof(*display), 8,
                 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
    if (!display)
       return NULL;
@@ -278,10 +278,11 @@ fail:
 }
 
 static struct wsi_wl_display *
-wsi_wl_get_display(struct anv_instance *instance, struct wl_display *wl_display)
+wsi_wl_get_display(struct anv_physical_device *device,
+                   struct wl_display *wl_display)
 {
    struct wsi_wayland *wsi =
-      (struct wsi_wayland *)instance->wsi[VK_ICD_WSI_PLATFORM_WAYLAND];
+      (struct wsi_wayland *)device->wsi[VK_ICD_WSI_PLATFORM_WAYLAND];
 
    pthread_mutex_lock(&wsi->mutex);
 
@@ -318,7 +319,7 @@ VkBool32 anv_GetPhysicalDeviceWaylandPresentationSupportKHR(
 {
    ANV_FROM_HANDLE(anv_physical_device, physical_device, physicalDevice);
 
-   return wsi_wl_get_display(physical_device->instance, display) != NULL;
+   return wsi_wl_get_display(physical_device, display) != NULL;
 }
 
 static VkResult
@@ -372,7 +373,7 @@ wsi_wl_surface_get_formats(VkIcdSurfaceBase *icd_surface,
 {
    VkIcdSurfaceWayland *surface = (VkIcdSurfaceWayland *)icd_surface;
    struct wsi_wl_display *display =
-      wsi_wl_get_display(device->instance, surface->display);
+      wsi_wl_get_display(device, surface->display);
 
    uint32_t count = anv_vector_length(&display->formats);
 
@@ -775,7 +776,8 @@ wsi_wl_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
       chain->images[i].buffer = NULL;
    chain->queue = NULL;
 
-   chain->display = wsi_wl_get_display(device->instance, surface->display);
+   chain->display = wsi_wl_get_display(&device->instance->physicalDevice,
+                                       surface->display);
    if (!chain->display)
       goto fail;
 
@@ -801,19 +803,19 @@ fail:
 }
 
 VkResult
-anv_wl_init_wsi(struct anv_instance *instance)
+anv_wl_init_wsi(struct anv_physical_device *device)
 {
    struct wsi_wayland *wsi;
    VkResult result;
 
-   wsi = anv_alloc(&instance->alloc, sizeof(*wsi), 8,
+   wsi = anv_alloc(&device->instance->alloc, sizeof(*wsi), 8,
                    VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
    if (!wsi) {
       result = vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
       goto fail;
    }
 
-   wsi->instance = instance;
+   wsi->physical_device = device;
 
    int ret = pthread_mutex_init(&wsi->mutex, NULL);
    if (ret != 0) {
@@ -840,7 +842,7 @@ anv_wl_init_wsi(struct anv_instance *instance)
    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;
+   device->wsi[VK_ICD_WSI_PLATFORM_WAYLAND] = &wsi->base;
 
    return VK_SUCCESS;
 
@@ -848,24 +850,24 @@ fail_mutex:
    pthread_mutex_destroy(&wsi->mutex);
 
 fail_alloc:
-   anv_free(&instance->alloc, wsi);
+   anv_free(&device->instance->alloc, wsi);
 fail:
-   instance->wsi[VK_ICD_WSI_PLATFORM_WAYLAND] = NULL;
+   device->wsi[VK_ICD_WSI_PLATFORM_WAYLAND] = NULL;
 
    return result;
 }
 
 void
-anv_wl_finish_wsi(struct anv_instance *instance)
+anv_wl_finish_wsi(struct anv_physical_device *device)
 {
    struct wsi_wayland *wsi =
-      (struct wsi_wayland *)instance->wsi[VK_ICD_WSI_PLATFORM_WAYLAND];
+      (struct wsi_wayland *)device->wsi[VK_ICD_WSI_PLATFORM_WAYLAND];
 
    if (wsi) {
       _mesa_hash_table_destroy(wsi->displays, NULL);
 
       pthread_mutex_destroy(&wsi->mutex);
 
-      anv_free(&instance->alloc, wsi);
+      anv_free(&device->instance->alloc, wsi);
    }
 }
diff --git a/src/intel/vulkan/anv_wsi_x11.c b/src/intel/vulkan/anv_wsi_x11.c
index 9ef0296..de56ca7 100644
--- a/src/intel/vulkan/anv_wsi_x11.c
+++ b/src/intel/vulkan/anv_wsi_x11.c
@@ -44,13 +44,14 @@ struct wsi_x11 {
 };
 
 static struct wsi_x11_connection *
-wsi_x11_connection_create(struct anv_instance *instance, xcb_connection_t *conn)
+wsi_x11_connection_create(struct anv_physical_device *device,
+                          xcb_connection_t *conn)
 {
    xcb_query_extension_cookie_t dri3_cookie, pres_cookie;
    xcb_query_extension_reply_t *dri3_reply, *pres_reply;
 
    struct wsi_x11_connection *wsi_conn =
-      anv_alloc(&instance->alloc, sizeof(*wsi_conn), 8,
+      anv_alloc(&device->instance->alloc, sizeof(*wsi_conn), 8,
                 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
    if (!wsi_conn)
       return NULL;
@@ -63,7 +64,7 @@ wsi_x11_connection_create(struct anv_instance *instance, xcb_connection_t *conn)
    if (dri3_reply == NULL || pres_reply == NULL) {
       free(dri3_reply);
       free(pres_reply);
-      anv_free(&instance->alloc, wsi_conn);
+      anv_free(&device->instance->alloc, wsi_conn);
       return NULL;
    }
 
@@ -77,17 +78,18 @@ wsi_x11_connection_create(struct anv_instance *instance, xcb_connection_t *conn)
 }
 
 static void
-wsi_x11_connection_destroy(struct anv_instance *instance,
+wsi_x11_connection_destroy(struct anv_physical_device *device,
                            struct wsi_x11_connection *conn)
 {
-   anv_free(&instance->alloc, conn);
+   anv_free(&device->instance->alloc, conn);
 }
 
 static struct wsi_x11_connection *
-wsi_x11_get_connection(struct anv_instance *instance, xcb_connection_t *conn)
+wsi_x11_get_connection(struct anv_physical_device *device,
+                       xcb_connection_t *conn)
 {
    struct wsi_x11 *wsi =
-      (struct wsi_x11 *)instance->wsi[VK_ICD_WSI_PLATFORM_XCB];
+      (struct wsi_x11 *)device->wsi[VK_ICD_WSI_PLATFORM_XCB];
 
    pthread_mutex_lock(&wsi->mutex);
 
@@ -99,14 +101,14 @@ wsi_x11_get_connection(struct anv_instance *instance, xcb_connection_t *conn)
       pthread_mutex_unlock(&wsi->mutex);
 
       struct wsi_x11_connection *wsi_conn =
-         wsi_x11_connection_create(instance, conn);
+         wsi_x11_connection_create(device, conn);
 
       pthread_mutex_lock(&wsi->mutex);
 
       entry = _mesa_hash_table_search(wsi->connections, conn);
       if (entry) {
          /* Oops, someone raced us to it */
-         wsi_x11_connection_destroy(instance, wsi_conn);
+         wsi_x11_connection_destroy(device, wsi_conn);
       } else {
          entry = _mesa_hash_table_insert(wsi->connections, conn, wsi_conn);
       }
@@ -236,7 +238,7 @@ VkBool32 anv_GetPhysicalDeviceXcbPresentationSupportKHR(
    ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
 
    struct wsi_x11_connection *wsi_conn =
-      wsi_x11_get_connection(device->instance, connection);
+      wsi_x11_get_connection(device, connection);
 
    if (!wsi_conn->has_dri3) {
       fprintf(stderr, "vulkan: No DRI3 support\n");
@@ -262,7 +264,7 @@ x11_surface_get_support(VkIcdSurfaceBase *icd_surface,
    VkIcdSurfaceXcb *surface = (VkIcdSurfaceXcb *)icd_surface;
 
    struct wsi_x11_connection *wsi_conn =
-      wsi_x11_get_connection(device->instance, surface->connection);
+      wsi_x11_get_connection(device, surface->connection);
    if (!wsi_conn)
       return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
 
@@ -835,12 +837,12 @@ fail_register:
 }
 
 VkResult
-anv_x11_init_wsi(struct anv_instance *instance)
+anv_x11_init_wsi(struct anv_physical_device *device)
 {
    struct wsi_x11 *wsi;
    VkResult result;
 
-   wsi = anv_alloc(&instance->alloc, sizeof(*wsi), 8,
+   wsi = anv_alloc(&device->instance->alloc, sizeof(*wsi), 8,
                    VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
    if (!wsi) {
       result = vk_error(VK_ERROR_OUT_OF_HOST_MEMORY);
@@ -872,31 +874,31 @@ anv_x11_init_wsi(struct anv_instance *instance)
    wsi->base.get_present_modes = x11_surface_get_present_modes;
    wsi->base.create_swapchain = x11_surface_create_swapchain;
 
-   instance->wsi[VK_ICD_WSI_PLATFORM_XCB] = &wsi->base;
+   device->wsi[VK_ICD_WSI_PLATFORM_XCB] = &wsi->base;
 
    return VK_SUCCESS;
 
 fail_mutex:
    pthread_mutex_destroy(&wsi->mutex);
 fail_alloc:
-   anv_free(&instance->alloc, wsi);
+   anv_free(&device->instance->alloc, wsi);
 fail:
-   instance->wsi[VK_ICD_WSI_PLATFORM_XCB] = NULL;
+   device->wsi[VK_ICD_WSI_PLATFORM_XCB] = NULL;
 
    return result;
 }
 
 void
-anv_x11_finish_wsi(struct anv_instance *instance)
+anv_x11_finish_wsi(struct anv_physical_device *device)
 {
    struct wsi_x11 *wsi =
-      (struct wsi_x11 *)instance->wsi[VK_ICD_WSI_PLATFORM_XCB];
+      (struct wsi_x11 *)device->wsi[VK_ICD_WSI_PLATFORM_XCB];
 
    if (wsi) {
       _mesa_hash_table_destroy(wsi->connections, NULL);
 
       pthread_mutex_destroy(&wsi->mutex);
 
-      anv_free(&instance->alloc, wsi);
+      anv_free(&device->instance->alloc, wsi);
    }
 }
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list