[Mesa-dev] [PATCH 2/2] vulkan/wsi: move some things into wsi_device.

Dave Airlie airlied at gmail.com
Wed Oct 19 00:08:18 UTC 2016


From: Dave Airlie <airlied at redhat.com>

This copies the allocator callbacks, along with normal
callbacks and physical device into the wsi device.

I'm a bit 50/50 on whether this makes things cleaner so far
---
 src/amd/vulkan/radv_wsi.c           | 17 +++++++++--------
 src/amd/vulkan/radv_wsi_x11.c       |  2 --
 src/intel/vulkan/anv_wsi.c          | 17 +++++++++--------
 src/intel/vulkan/anv_wsi_x11.c      |  2 --
 src/vulkan/wsi/wsi_common.h         | 28 +++++++++++++---------------
 src/vulkan/wsi/wsi_common_wayland.c | 32 +++++++++++++-------------------
 src/vulkan/wsi/wsi_common_x11.c     | 23 +++++++++--------------
 src/vulkan/wsi/wsi_common_x11.h     |  1 -
 8 files changed, 53 insertions(+), 69 deletions(-)

diff --git a/src/amd/vulkan/radv_wsi.c b/src/amd/vulkan/radv_wsi.c
index 3c3abe9..56eacc5 100644
--- a/src/amd/vulkan/radv_wsi.c
+++ b/src/amd/vulkan/radv_wsi.c
@@ -37,19 +37,21 @@ radv_init_wsi(struct radv_physical_device *physical_device)
 
 	memset(physical_device->wsi_device.wsi, 0, sizeof(physical_device->wsi_device.wsi));
 
+        physical_device->wsi_device.alloc = physical_device->instance->alloc;
+        physical_device->wsi_device.physical_device = anv_physical_device_to_handle(physical_device);
+        physical_device->wsi_device.cbs = &wsi_cbs;
+
 #ifdef VK_USE_PLATFORM_XCB_KHR
-	result = wsi_x11_init_wsi(&physical_device->wsi_device, &physical_device->instance->alloc);
+	result = wsi_x11_init_wsi(&physical_device->wsi_device);
 	if (result != VK_SUCCESS)
 		return result;
 #endif
 
 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
-	result = wsi_wl_init_wsi(&physical_device->wsi_device, &physical_device->instance->alloc,
-				 radv_physical_device_to_handle(physical_device),
-				 &wsi_cbs);
+	result = wsi_wl_init_wsi(&physical_device->wsi_device);
 	if (result != VK_SUCCESS) {
 #ifdef VK_USE_PLATFORM_XCB_KHR
-		wsi_x11_finish_wsi(&physical_device->wsi_device, &physical_device->instance->alloc);
+                wsi_x11_finish_wsi(&physical_device->wsi_device);
 #endif
 		return result;
 	}
@@ -62,10 +64,10 @@ void
 radv_finish_wsi(struct radv_physical_device *physical_device)
 {
 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
-	wsi_wl_finish_wsi(&physical_device->wsi_device, &physical_device->instance->alloc);
+	wsi_wl_finish_wsi(&physical_device->wsi_device);
 #endif
 #ifdef VK_USE_PLATFORM_XCB_KHR
-	wsi_x11_finish_wsi(&physical_device->wsi_device, &physical_device->instance->alloc);
+	wsi_x11_finish_wsi(&physical_device->wsi_device);
 #endif
 }
 
@@ -91,7 +93,6 @@ VkResult radv_GetPhysicalDeviceSurfaceSupportKHR(
 	struct wsi_interface *iface = device->wsi_device.wsi[surface->platform];
 
 	return iface->get_support(surface, &device->wsi_device,
-				  &device->instance->alloc,
 				  queueFamilyIndex, pSupported);
 }
 
diff --git a/src/amd/vulkan/radv_wsi_x11.c b/src/amd/vulkan/radv_wsi_x11.c
index 946b990..66c9bbb 100644
--- a/src/amd/vulkan/radv_wsi_x11.c
+++ b/src/amd/vulkan/radv_wsi_x11.c
@@ -44,7 +44,6 @@ VkBool32 radv_GetPhysicalDeviceXcbPresentationSupportKHR(
 
    return wsi_get_physical_device_xcb_presentation_support(
       &device->wsi_device,
-      &device->instance->alloc,
       queueFamilyIndex, connection, visual_id);
 }
 
@@ -58,7 +57,6 @@ VkBool32 radv_GetPhysicalDeviceXlibPresentationSupportKHR(
 
    return wsi_get_physical_device_xcb_presentation_support(
       &device->wsi_device,
-      &device->instance->alloc,
       queueFamilyIndex, XGetXCBConnection(dpy), visualID);
 }
 
diff --git a/src/intel/vulkan/anv_wsi.c b/src/intel/vulkan/anv_wsi.c
index f816735..3520300 100644
--- a/src/intel/vulkan/anv_wsi.c
+++ b/src/intel/vulkan/anv_wsi.c
@@ -36,19 +36,21 @@ anv_init_wsi(struct anv_physical_device *physical_device)
 
    memset(physical_device->wsi_device.wsi, 0, sizeof(physical_device->wsi_device.wsi));
 
+   physical_device->wsi_device.alloc = physical_device->instance->alloc;
+   physical_device->wsi_device.physical_device = anv_physical_device_to_handle(physical_device);
+   physical_device->wsi_device.cbs = &wsi_cbs;
+
 #ifdef VK_USE_PLATFORM_XCB_KHR
-   result = wsi_x11_init_wsi(&physical_device->wsi_device, &physical_device->instance->alloc);
+   result = wsi_x11_init_wsi(&physical_device->wsi_device);
    if (result != VK_SUCCESS)
       return result;
 #endif
 
 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
-   result = wsi_wl_init_wsi(&physical_device->wsi_device, &physical_device->instance->alloc,
-                            anv_physical_device_to_handle(physical_device),
-                            &wsi_cbs);
+   result = wsi_wl_init_wsi(&physical_device->wsi_device);
    if (result != VK_SUCCESS) {
 #ifdef VK_USE_PLATFORM_XCB_KHR
-      wsi_x11_finish_wsi(&physical_device->wsi_device, &physical_device->instance->alloc);
+      wsi_x11_finish_wsi(&physical_device->wsi_device);
 #endif
       return result;
    }
@@ -61,10 +63,10 @@ void
 anv_finish_wsi(struct anv_physical_device *physical_device)
 {
 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
-   wsi_wl_finish_wsi(&physical_device->wsi_device, &physical_device->instance->alloc);
+   wsi_wl_finish_wsi(&physical_device->wsi_device);
 #endif
 #ifdef VK_USE_PLATFORM_XCB_KHR
-   wsi_x11_finish_wsi(&physical_device->wsi_device, &physical_device->instance->alloc);
+   wsi_x11_finish_wsi(&physical_device->wsi_device);
 #endif
 }
 
@@ -90,7 +92,6 @@ VkResult anv_GetPhysicalDeviceSurfaceSupportKHR(
    struct wsi_interface *iface = device->wsi_device.wsi[surface->platform];
 
    return iface->get_support(surface, &device->wsi_device,
-                             &device->instance->alloc,
                              queueFamilyIndex, pSupported);
 }
 
diff --git a/src/intel/vulkan/anv_wsi_x11.c b/src/intel/vulkan/anv_wsi_x11.c
index 60bc568..e8d70bb 100644
--- a/src/intel/vulkan/anv_wsi_x11.c
+++ b/src/intel/vulkan/anv_wsi_x11.c
@@ -40,7 +40,6 @@ VkBool32 anv_GetPhysicalDeviceXcbPresentationSupportKHR(
 
    return wsi_get_physical_device_xcb_presentation_support(
       &device->wsi_device,
-      &device->instance->alloc,
       queueFamilyIndex, connection, visual_id);
 }
 
@@ -54,7 +53,6 @@ VkBool32 anv_GetPhysicalDeviceXlibPresentationSupportKHR(
 
    return wsi_get_physical_device_xcb_presentation_support(
       &device->wsi_device,
-      &device->instance->alloc,
       queueFamilyIndex, XGetXCBConnection(dpy), visualID);
 }
 
diff --git a/src/vulkan/wsi/wsi_common.h b/src/vulkan/wsi/wsi_common.h
index 1f4e0ae..6d6fc4a 100644
--- a/src/vulkan/wsi/wsi_common.h
+++ b/src/vulkan/wsi/wsi_common.h
@@ -68,7 +68,6 @@ struct wsi_swapchain {
 struct wsi_interface {
    VkResult (*get_support)(VkIcdSurfaceBase *surface,
                            struct wsi_device *wsi_device,
-                           const VkAllocationCallbacks *alloc,
                            uint32_t queueFamilyIndex,
                            VkBool32* pSupported);
    VkResult (*get_capabilities)(VkIcdSurfaceBase *surface,
@@ -91,16 +90,19 @@ struct wsi_interface {
 
 #define VK_ICD_WSI_PLATFORM_MAX 5
 
-struct wsi_device {
-    struct wsi_interface *                  wsi[VK_ICD_WSI_PLATFORM_MAX];
-};
-
 struct wsi_callbacks {
    void (*get_phys_device_format_properties)(VkPhysicalDevice physicalDevice,
                                              VkFormat format,
                                              VkFormatProperties *pFormatProperties);
 };
 
+struct wsi_device {
+    VkAllocationCallbacks alloc;
+    VkPhysicalDevice physical_device;
+    const struct wsi_callbacks *cbs;
+    struct wsi_interface *                  wsi[VK_ICD_WSI_PLATFORM_MAX];
+};
+
 #define WSI_DEFINE_NONDISP_HANDLE_CASTS(__wsi_type, __VkType)              \
                                                                            \
    static inline struct __wsi_type *                                       \
@@ -118,16 +120,12 @@ struct wsi_callbacks {
 WSI_DEFINE_NONDISP_HANDLE_CASTS(_VkIcdSurfaceBase, VkSurfaceKHR)
 WSI_DEFINE_NONDISP_HANDLE_CASTS(wsi_swapchain, VkSwapchainKHR)
 
-VkResult wsi_x11_init_wsi(struct wsi_device *wsi_device,
-                          const VkAllocationCallbacks *alloc);
-void wsi_x11_finish_wsi(struct wsi_device *wsi_device,
-                        const VkAllocationCallbacks *alloc);
-VkResult wsi_wl_init_wsi(struct wsi_device *wsi_device,
-                         const VkAllocationCallbacks *alloc,
-                         VkPhysicalDevice physical_device,
-                         const struct wsi_callbacks *cbs);
-void wsi_wl_finish_wsi(struct wsi_device *wsi_device,
-                       const VkAllocationCallbacks *alloc);
+VkResult wsi_x11_init_wsi(struct wsi_device *wsi_device);
+void wsi_x11_finish_wsi(struct wsi_device *wsi_device);
+
+VkResult wsi_wl_init_wsi(struct wsi_device *wsi_device);
+void wsi_wl_finish_wsi(struct wsi_device *wsi_device);
+
 
 
 #endif
diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c
index ecb1ab5..2f4e11d 100644
--- a/src/vulkan/wsi/wsi_common_wayland.c
+++ b/src/vulkan/wsi/wsi_common_wayland.c
@@ -59,8 +59,7 @@ struct wsi_wl_display {
 struct wsi_wayland {
    struct wsi_interface                     base;
 
-   const VkAllocationCallbacks *alloc;
-   VkPhysicalDevice physical_device;
+   struct wsi_device *wsi_device;
 
    pthread_mutex_t                              mutex;
    /* Hash table of wl_display -> wsi_wl_display mappings */
@@ -81,8 +80,8 @@ wsi_wl_display_add_vk_format(struct wsi_wl_display *display, VkFormat format)
    /* Don't add formats that aren't renderable. */
    VkFormatProperties props;
 
-   display->wsi_wl->cbs->get_phys_device_format_properties(display->wsi_wl->physical_device,
-                                                           format, &props);
+   display->wsi_wl->wsi_device->cbs->get_phys_device_format_properties(display->wsi_wl->wsi_device->physical_device,
+                                                                       format, &props);
    if (!(props.optimalTilingFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT))
       return;
 
@@ -251,14 +250,14 @@ wsi_wl_display_destroy(struct wsi_wayland *wsi, struct wsi_wl_display *display)
    u_vector_finish(&display->formats);
    if (display->drm)
       wl_drm_destroy(display->drm);
-   vk_free(wsi->alloc, display);
+   vk_free(&wsi->wsi_device->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 =
-      vk_alloc(wsi->alloc, sizeof(*display), 8,
+      vk_alloc(&wsi->wsi_device->alloc, sizeof(*display), 8,
                VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
    if (!display)
       return NULL;
@@ -348,7 +347,6 @@ wsi_wl_get_presentation_support(struct wsi_device *wsi_device,
 static VkResult
 wsi_wl_surface_get_support(VkIcdSurfaceBase *surface,
                            struct wsi_device *wsi_device,
-                           const VkAllocationCallbacks *alloc,
                            uint32_t queueFamilyIndex,
                            VkBool32* pSupported)
 {
@@ -753,24 +751,21 @@ fail:
 }
 
 VkResult
-wsi_wl_init_wsi(struct wsi_device *wsi_device,
-                const VkAllocationCallbacks *alloc,
-                VkPhysicalDevice physical_device,
-                const struct wsi_callbacks *cbs)
+wsi_wl_init_wsi(struct wsi_device *wsi_device)
 {
    struct wsi_wayland *wsi;
    VkResult result;
 
-   wsi = vk_alloc(alloc, sizeof(*wsi), 8,
+   wsi = vk_alloc(&wsi_device->alloc, sizeof(*wsi), 8,
                    VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
    if (!wsi) {
       result = VK_ERROR_OUT_OF_HOST_MEMORY;
       goto fail;
    }
 
-   wsi->physical_device = physical_device;
-   wsi->alloc = alloc;
-   wsi->cbs = cbs;
+
+   wsi->wsi_device = wsi_device;
+
    int ret = pthread_mutex_init(&wsi->mutex, NULL);
    if (ret != 0) {
       if (ret == ENOMEM) {
@@ -804,7 +799,7 @@ fail_mutex:
    pthread_mutex_destroy(&wsi->mutex);
 
 fail_alloc:
-   vk_free(alloc, wsi);
+   vk_free(&wsi_device->alloc, wsi);
 fail:
    wsi_device->wsi[VK_ICD_WSI_PLATFORM_WAYLAND] = NULL;
 
@@ -812,8 +807,7 @@ fail:
 }
 
 void
-wsi_wl_finish_wsi(struct wsi_device *wsi_device,
-                  const VkAllocationCallbacks *alloc)
+wsi_wl_finish_wsi(struct wsi_device *wsi_device)
 {
    struct wsi_wayland *wsi =
       (struct wsi_wayland *)wsi_device->wsi[VK_ICD_WSI_PLATFORM_WAYLAND];
@@ -823,6 +817,6 @@ wsi_wl_finish_wsi(struct wsi_device *wsi_device,
 
       pthread_mutex_destroy(&wsi->mutex);
 
-      vk_free(alloc, wsi);
+      vk_free(&wsi_device->alloc, wsi);
    }
 }
diff --git a/src/vulkan/wsi/wsi_common_x11.c b/src/vulkan/wsi/wsi_common_x11.c
index 3bb8f35..090a2f2 100644
--- a/src/vulkan/wsi/wsi_common_x11.c
+++ b/src/vulkan/wsi/wsi_common_x11.c
@@ -100,7 +100,6 @@ wsi_x11_connection_destroy(const VkAllocationCallbacks *alloc,
 
 static struct wsi_x11_connection *
 wsi_x11_get_connection(struct wsi_device *wsi_dev,
-		       const VkAllocationCallbacks *alloc,
                        xcb_connection_t *conn)
 {
    struct wsi_x11 *wsi =
@@ -116,14 +115,14 @@ wsi_x11_get_connection(struct wsi_device *wsi_dev,
       pthread_mutex_unlock(&wsi->mutex);
 
       struct wsi_x11_connection *wsi_conn =
-         wsi_x11_connection_create(alloc, conn);
+         wsi_x11_connection_create(&wsi_dev->alloc, 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(alloc, wsi_conn);
+         wsi_x11_connection_destroy(&wsi_dev->alloc, wsi_conn);
       } else {
          entry = _mesa_hash_table_insert(wsi->connections, conn, wsi_conn);
       }
@@ -247,13 +246,12 @@ visual_has_alpha(xcb_visualtype_t *visual, unsigned depth)
 
 VkBool32 wsi_get_physical_device_xcb_presentation_support(
     struct wsi_device *wsi_device,
-    VkAllocationCallbacks *alloc,
     uint32_t                                    queueFamilyIndex,
     xcb_connection_t*                           connection,
     xcb_visualid_t                              visual_id)
 {
    struct wsi_x11_connection *wsi_conn =
-      wsi_x11_get_connection(wsi_device, alloc, connection);
+      wsi_x11_get_connection(wsi_device, connection);
 
    if (!wsi_conn->has_dri3) {
       fprintf(stderr, "vulkan: No DRI3 support\n");
@@ -291,7 +289,6 @@ x11_surface_get_window(VkIcdSurfaceBase *icd_surface)
 static VkResult
 x11_surface_get_support(VkIcdSurfaceBase *icd_surface,
                         struct wsi_device *wsi_device,
-                        const VkAllocationCallbacks *alloc,
                         uint32_t queueFamilyIndex,
                         VkBool32* pSupported)
 {
@@ -299,7 +296,7 @@ x11_surface_get_support(VkIcdSurfaceBase *icd_surface,
    xcb_window_t window = x11_surface_get_window(icd_surface);
 
    struct wsi_x11_connection *wsi_conn =
-      wsi_x11_get_connection(wsi_device, alloc, conn);
+      wsi_x11_get_connection(wsi_device, conn);
    if (!wsi_conn)
       return VK_ERROR_OUT_OF_HOST_MEMORY;
 
@@ -815,13 +812,12 @@ fail_register:
 }
 
 VkResult
-wsi_x11_init_wsi(struct wsi_device *wsi_device,
-                 const VkAllocationCallbacks *alloc)
+wsi_x11_init_wsi(struct wsi_device *wsi_device)
 {
    struct wsi_x11 *wsi;
    VkResult result;
 
-   wsi = vk_alloc(alloc, sizeof(*wsi), 8,
+   wsi = vk_alloc(&wsi_device->alloc, sizeof(*wsi), 8,
                    VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
    if (!wsi) {
       result = VK_ERROR_OUT_OF_HOST_MEMORY;
@@ -861,7 +857,7 @@ wsi_x11_init_wsi(struct wsi_device *wsi_device,
 fail_mutex:
    pthread_mutex_destroy(&wsi->mutex);
 fail_alloc:
-   vk_free(alloc, wsi);
+   vk_free(&wsi_device->alloc, wsi);
 fail:
    wsi_device->wsi[VK_ICD_WSI_PLATFORM_XCB] = NULL;
    wsi_device->wsi[VK_ICD_WSI_PLATFORM_XLIB] = NULL;
@@ -870,8 +866,7 @@ fail:
 }
 
 void
-wsi_x11_finish_wsi(struct wsi_device *wsi_device,
-                   const VkAllocationCallbacks *alloc)
+wsi_x11_finish_wsi(struct wsi_device *wsi_device)
 {
    struct wsi_x11 *wsi =
       (struct wsi_x11 *)wsi_device->wsi[VK_ICD_WSI_PLATFORM_XCB];
@@ -881,6 +876,6 @@ wsi_x11_finish_wsi(struct wsi_device *wsi_device,
 
       pthread_mutex_destroy(&wsi->mutex);
 
-      vk_free(alloc, wsi);
+      vk_free(&wsi_device->alloc, wsi);
    }
 }
diff --git a/src/vulkan/wsi/wsi_common_x11.h b/src/vulkan/wsi/wsi_common_x11.h
index 7166f09..e4b1e94 100644
--- a/src/vulkan/wsi/wsi_common_x11.h
+++ b/src/vulkan/wsi/wsi_common_x11.h
@@ -27,7 +27,6 @@
 
 VkBool32 wsi_get_physical_device_xcb_presentation_support(
     struct wsi_device *wsi_device,
-    VkAllocationCallbacks *alloc,
     uint32_t                                    queueFamilyIndex,
     xcb_connection_t*                           connection,
     xcb_visualid_t                              visual_id);
-- 
2.5.5



More information about the mesa-dev mailing list