vulkan/wsi: Store the instance allocator in wsi_device
authorJason Ekstrand <jason.ekstrand@intel.com>
Wed, 17 Oct 2018 19:35:16 +0000 (14:35 -0500)
committerJason Ekstrand <jason.ekstrand@intel.com>
Thu, 18 Oct 2018 14:17:39 +0000 (09:17 -0500)
We already have wsi_device and we know the instance allocator at
wsi_device_init time so there's no need to pass it into the physical
device queries.  This also fixes a memory allocation domain bug that can
occur if CreateSwapchain gets called prior to any queries (not likely)
in which case the cached connection gets allocated off the device
instead of the instance.

Reviewed-by: Eric Engestrom <eric.engestrom@intel.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
src/amd/vulkan/radv_wsi.c
src/amd/vulkan/radv_wsi_x11.c
src/intel/vulkan/anv_wsi.c
src/intel/vulkan/anv_wsi_x11.c
src/vulkan/wsi/wsi_common.c
src/vulkan/wsi/wsi_common.h
src/vulkan/wsi/wsi_common_display.c
src/vulkan/wsi/wsi_common_private.h
src/vulkan/wsi/wsi_common_wayland.c
src/vulkan/wsi/wsi_common_x11.c
src/vulkan/wsi/wsi_common_x11.h

index 6479bea070b096a9510073044eec69263af14d61..8b165ea3916bc79b0b4c18df788f4942b6771049 100644 (file)
@@ -75,7 +75,6 @@ VkResult radv_GetPhysicalDeviceSurfaceSupportKHR(
                                              device->local_fd,
                                              queueFamilyIndex,
                                              surface,
-                                             &device->instance->alloc,
                                              pSupported);
 }
 
index c65ac938772d2a2d878d49058aef3e2dc07f8b0c..9ef02ccc43591cd8eef349f7f49f95d12026ca44 100644 (file)
@@ -44,7 +44,6 @@ VkBool32 radv_GetPhysicalDeviceXcbPresentationSupportKHR(
 
    return wsi_get_physical_device_xcb_presentation_support(
       &device->wsi_device,
-      &device->instance->alloc,
       queueFamilyIndex,
       device->local_fd, true,
       connection, visual_id);
@@ -60,7 +59,6 @@ VkBool32 radv_GetPhysicalDeviceXlibPresentationSupportKHR(
 
    return wsi_get_physical_device_xcb_presentation_support(
       &device->wsi_device,
-      &device->instance->alloc,
       queueFamilyIndex,
       device->local_fd, true,
       XGetXCBConnection(dpy), visualID);
index 5ed1d711689b4e152738492b4017e8c0b5ff018a..1c9a54804e8ac675ca0c6398a9a4734f27921061 100644 (file)
@@ -92,7 +92,6 @@ VkResult anv_GetPhysicalDeviceSurfaceSupportKHR(
                                          device->local_fd,
                                          queueFamilyIndex,
                                          surface,
-                                         &device->instance->alloc,
                                          pSupported);
 }
 
index 2feb5f1337637e0f6129f1934b6e76f46db65aa4..45c43f6f17fbbcb490dc014976f440758c9574f3 100644 (file)
@@ -40,7 +40,6 @@ VkBool32 anv_GetPhysicalDeviceXcbPresentationSupportKHR(
 
    return wsi_get_physical_device_xcb_presentation_support(
       &device->wsi_device,
-      &device->instance->alloc,
       queueFamilyIndex,
       device->local_fd, false,
       connection, visual_id);
@@ -56,7 +55,6 @@ VkBool32 anv_GetPhysicalDeviceXlibPresentationSupportKHR(
 
    return wsi_get_physical_device_xcb_presentation_support(
       &device->wsi_device,
-      &device->instance->alloc,
       queueFamilyIndex,
       device->local_fd, false,
       XGetXCBConnection(dpy), visualID);
index 3416fef3076abae93692172886c36f2b9e9276d7..1e3c4e0028b2f3b640f3489a4f01efc4b8262c18 100644 (file)
@@ -39,6 +39,7 @@ wsi_device_init(struct wsi_device *wsi,
 
    memset(wsi, 0, sizeof(*wsi));
 
+   wsi->instance_alloc = *alloc;
    wsi->pdevice = pdevice;
 
 #define WSI_GET_CB(func) \
@@ -677,13 +678,12 @@ wsi_common_get_surface_support(struct wsi_device *wsi_device,
                                int local_fd,
                                uint32_t queueFamilyIndex,
                                VkSurfaceKHR _surface,
-                               const VkAllocationCallbacks *alloc,
                                VkBool32* pSupported)
 {
    ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface);
    struct wsi_interface *iface = wsi_device->wsi[surface->platform];
 
-   return iface->get_support(surface, wsi_device, alloc,
+   return iface->get_support(surface, wsi_device,
                              queueFamilyIndex, local_fd, pSupported);
 }
 
index 14f65097bb38087897c6a095d98418a037b77963..424330de5663c5b049909f3aa3015acc56bb5661 100644 (file)
@@ -90,6 +90,9 @@ struct wsi_interface;
 #define VK_ICD_WSI_PLATFORM_MAX (VK_ICD_WSI_PLATFORM_DISPLAY + 1)
 
 struct wsi_device {
+   /* Allocator for the instance */
+   VkAllocationCallbacks instance_alloc;
+
    VkPhysicalDevice pdevice;
    VkPhysicalDeviceMemoryProperties memory_props;
    uint32_t queue_family_count;
@@ -166,7 +169,6 @@ wsi_common_get_surface_support(struct wsi_device *wsi_device,
                                int local_fd,
                                uint32_t queueFamilyIndex,
                                VkSurfaceKHR surface,
-                               const VkAllocationCallbacks *alloc,
                                VkBool32* pSupported);
 
 VkResult
index 5cebde5b9bc1d28a961117bddcfb047c3ea0134f..c004060a20533423f39aa9d4147f2f8831c78062 100644 (file)
@@ -802,7 +802,6 @@ wsi_create_display_surface(VkInstance instance,
 static VkResult
 wsi_display_surface_get_support(VkIcdSurfaceBase *surface,
                                 struct wsi_device *wsi_device,
-                                const VkAllocationCallbacks *allocator,
                                 uint32_t queueFamilyIndex,
                                 int local_fd,
                                 VkBool32* pSupported)
index ee7ae75b8f7a645c28fc397980bac112839bf86a..accc11701633334efe7c6c6c20dab888e8aac6e1 100644 (file)
@@ -100,7 +100,6 @@ wsi_destroy_image(const struct wsi_swapchain *chain,
 struct wsi_interface {
    VkResult (*get_support)(VkIcdSurfaceBase *surface,
                            struct wsi_device *wsi_device,
-                           const VkAllocationCallbacks *alloc,
                            uint32_t queueFamilyIndex,
                            int local_fd,
                            VkBool32* pSupported);
index 6b34e21bd982b5b81c7668f61bafbf7c719de826..67d5f8d4c806ad90a8c9f87bb192da94e1bfb0cb 100644 (file)
@@ -464,7 +464,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,
                            int local_fd,
                            VkBool32* pSupported)
index 5f99b2ee473028c799782fc80933a174e7d7e406..75aa83bb7b4415c6a9a948a17ef993fbcfd8ccf8 100644 (file)
@@ -125,7 +125,7 @@ wsi_x11_check_dri3_compatible(xcb_connection_t *conn, int local_fd)
 }
 
 static struct wsi_x11_connection *
-wsi_x11_connection_create(const VkAllocationCallbacks *alloc,
+wsi_x11_connection_create(struct wsi_device *wsi_dev,
                           xcb_connection_t *conn)
 {
    xcb_query_extension_cookie_t dri3_cookie, pres_cookie, amd_cookie, nv_cookie;
@@ -134,7 +134,7 @@ wsi_x11_connection_create(const VkAllocationCallbacks *alloc,
    bool has_present_v1_2 = false;
 
    struct wsi_x11_connection *wsi_conn =
-      vk_alloc(alloc, sizeof(*wsi_conn), 8,
+      vk_alloc(&wsi_dev->instance_alloc, sizeof(*wsi_conn), 8,
                 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE);
    if (!wsi_conn)
       return NULL;
@@ -163,7 +163,7 @@ wsi_x11_connection_create(const VkAllocationCallbacks *alloc,
       free(pres_reply);
       free(amd_reply);
       free(nv_reply);
-      vk_free(alloc, wsi_conn);
+      vk_free(&wsi_dev->instance_alloc, wsi_conn);
       return NULL;
    }
 
@@ -211,10 +211,10 @@ wsi_x11_connection_create(const VkAllocationCallbacks *alloc,
 }
 
 static void
-wsi_x11_connection_destroy(const VkAllocationCallbacks *alloc,
+wsi_x11_connection_destroy(struct wsi_device *wsi_dev,
                            struct wsi_x11_connection *conn)
 {
-   vk_free(alloc, conn);
+   vk_free(&wsi_dev->instance_alloc, conn);
 }
 
 static bool
@@ -231,7 +231,6 @@ wsi_x11_check_for_dri3(struct wsi_x11_connection *wsi_conn)
 
 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 =
@@ -247,7 +246,7 @@ 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, conn);
       if (!wsi_conn)
          return NULL;
 
@@ -256,7 +255,7 @@ wsi_x11_get_connection(struct wsi_device *wsi_dev,
       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, wsi_conn);
       } else {
          entry = _mesa_hash_table_insert(wsi->connections, conn, wsi_conn);
       }
@@ -382,7 +381,6 @@ 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,
     int fd,
     bool can_handle_different_gpu,
@@ -390,7 +388,7 @@ VkBool32 wsi_get_physical_device_xcb_presentation_support(
     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)
       return false;
@@ -433,7 +431,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,
                         int local_fd,
                         VkBool32* pSupported)
@@ -442,7 +439,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;
 
@@ -1279,7 +1276,7 @@ x11_surface_create_swapchain(VkIcdSurfaceBase *icd_surface,
 
    xcb_connection_t *conn = x11_surface_get_connection(icd_surface);
    struct wsi_x11_connection *wsi_conn =
-      wsi_x11_get_connection(wsi_device, pAllocator, conn);
+      wsi_x11_get_connection(wsi_device, conn);
    if (!wsi_conn)
       return VK_ERROR_OUT_OF_HOST_MEMORY;
 
@@ -1501,7 +1498,7 @@ wsi_x11_finish_wsi(struct wsi_device *wsi_device,
    if (wsi) {
       struct hash_entry *entry;
       hash_table_foreach(wsi->connections, entry)
-         wsi_x11_connection_destroy(alloc, entry->data);
+         wsi_x11_connection_destroy(wsi_device, entry->data);
 
       _mesa_hash_table_destroy(wsi->connections, NULL);
 
index b33540856cb5e6c60e41c8a21eef0dc1718602fa..e9b3ecfb2e0834b56e06c20bce21a47085d2653b 100644 (file)
@@ -27,7 +27,6 @@
 
 VkBool32 wsi_get_physical_device_xcb_presentation_support(
     struct wsi_device *wsi_device,
-    VkAllocationCallbacks *alloc,
     uint32_t                                    queueFamilyIndex,
     int local_fd,
     bool can_handle_different_gpu,