[Mesa-dev] [PATCH 28/28] vulkan/wsi: Initialize individual WSI interfaces in wsi_device_init

Jason Ekstrand jason at jlekstrand.net
Thu Nov 16 21:29:16 UTC 2017


Now that we have anv_device_init/finish functions, there's no reason to
have the individual driver do any more work than that.
---
 src/amd/vulkan/radv_wsi.c           | 36 ++++++------------------------------
 src/intel/vulkan/anv_wsi.c          | 36 ++++++------------------------------
 src/vulkan/wsi/wsi_common.c         | 37 +++++++++++++++++++++++++++++++++++--
 src/vulkan/wsi/wsi_common.h         | 19 +++++++------------
 src/vulkan/wsi/wsi_common_private.h | 10 ++++++++++
 5 files changed, 64 insertions(+), 74 deletions(-)

diff --git a/src/amd/vulkan/radv_wsi.c b/src/amd/vulkan/radv_wsi.c
index aa06944..cb61eb6 100644
--- a/src/amd/vulkan/radv_wsi.c
+++ b/src/amd/vulkan/radv_wsi.c
@@ -38,41 +38,17 @@ radv_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName)
 VkResult
 radv_init_wsi(struct radv_physical_device *physical_device)
 {
-	VkResult result;
-
-	wsi_device_init(&physical_device->wsi_device,
-			radv_physical_device_to_handle(physical_device),
-			radv_wsi_proc_addr);
-
-#ifdef VK_USE_PLATFORM_XCB_KHR
-	result = wsi_x11_init_wsi(&physical_device->wsi_device, &physical_device->instance->alloc);
-	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));
-	if (result != VK_SUCCESS) {
-#ifdef VK_USE_PLATFORM_XCB_KHR
-		wsi_x11_finish_wsi(&physical_device->wsi_device, &physical_device->instance->alloc);
-#endif
-		return result;
-	}
-#endif
-
-	return VK_SUCCESS;
+	return wsi_device_init(&physical_device->wsi_device,
+			       radv_physical_device_to_handle(physical_device),
+			       radv_wsi_proc_addr,
+			       &physical_device->instance->alloc);
 }
 
 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);
-#endif
-#ifdef VK_USE_PLATFORM_XCB_KHR
-	wsi_x11_finish_wsi(&physical_device->wsi_device, &physical_device->instance->alloc);
-#endif
+	wsi_device_finish(&physical_device->wsi_device,
+			  &physical_device->instance->alloc);
 }
 
 void radv_DestroySurfaceKHR(
diff --git a/src/intel/vulkan/anv_wsi.c b/src/intel/vulkan/anv_wsi.c
index add983f..6082c3d 100644
--- a/src/intel/vulkan/anv_wsi.c
+++ b/src/intel/vulkan/anv_wsi.c
@@ -36,41 +36,17 @@ anv_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName)
 VkResult
 anv_init_wsi(struct anv_physical_device *physical_device)
 {
-   VkResult result;
-
-   wsi_device_init(&physical_device->wsi_device,
-                   anv_physical_device_to_handle(physical_device),
-                   anv_wsi_proc_addr);
-
-#ifdef VK_USE_PLATFORM_XCB_KHR
-   result = wsi_x11_init_wsi(&physical_device->wsi_device, &physical_device->instance->alloc);
-   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));
-   if (result != VK_SUCCESS) {
-#ifdef VK_USE_PLATFORM_XCB_KHR
-      wsi_x11_finish_wsi(&physical_device->wsi_device, &physical_device->instance->alloc);
-#endif
-      return result;
-   }
-#endif
-
-   return VK_SUCCESS;
+   return wsi_device_init(&physical_device->wsi_device,
+                          anv_physical_device_to_handle(physical_device),
+                          anv_wsi_proc_addr,
+                          &physical_device->instance->alloc);
 }
 
 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);
-#endif
-#ifdef VK_USE_PLATFORM_XCB_KHR
-   wsi_x11_finish_wsi(&physical_device->wsi_device, &physical_device->instance->alloc);
-#endif
+   wsi_device_finish(&physical_device->wsi_device,
+                     &physical_device->instance->alloc);
 }
 
 void anv_DestroySurfaceKHR(
diff --git a/src/vulkan/wsi/wsi_common.c b/src/vulkan/wsi/wsi_common.c
index cd98e95..595d76e 100644
--- a/src/vulkan/wsi/wsi_common.c
+++ b/src/vulkan/wsi/wsi_common.c
@@ -25,11 +25,14 @@
 #include "util/macros.h"
 #include "vk_util.h"
 
-void
+VkResult
 wsi_device_init(struct wsi_device *wsi,
                 VkPhysicalDevice pdevice,
-                WSI_FN_GetPhysicalDeviceProcAddr proc_addr)
+                WSI_FN_GetPhysicalDeviceProcAddr proc_addr,
+                const VkAllocationCallbacks *alloc)
 {
+   VkResult result;
+
    memset(wsi, 0, sizeof(*wsi));
 
 #define WSI_GET_CB(func) \
@@ -69,6 +72,36 @@ wsi_device_init(struct wsi_device *wsi,
    WSI_GET_CB(QueueSubmit);
    WSI_GET_CB(WaitForFences);
 #undef WSI_GET_CB
+
+#ifdef VK_USE_PLATFORM_XCB_KHR
+   result = wsi_x11_init_wsi(wsi, alloc);
+   if (result != VK_SUCCESS)
+      return result;
+#endif
+
+#ifdef VK_USE_PLATFORM_WAYLAND_KHR
+   result = wsi_wl_init_wsi(wsi, alloc, pdevice);
+   if (result != VK_SUCCESS) {
+#ifdef VK_USE_PLATFORM_XCB_KHR
+      wsi_x11_finish_wsi(wsi, alloc);
+#endif
+      return result;
+   }
+#endif
+
+   return VK_SUCCESS;
+}
+
+void
+wsi_device_finish(struct wsi_device *wsi,
+                  const VkAllocationCallbacks *alloc)
+{
+#ifdef VK_USE_PLATFORM_WAYLAND_KHR
+   wsi_wl_finish_wsi(wsi, alloc);
+#endif
+#ifdef VK_USE_PLATFORM_XCB_KHR
+   wsi_x11_finish_wsi(wsi, alloc);
+#endif
 }
 
 VkResult
diff --git a/src/vulkan/wsi/wsi_common.h b/src/vulkan/wsi/wsi_common.h
index 2225fe0..0d35e89 100644
--- a/src/vulkan/wsi/wsi_common.h
+++ b/src/vulkan/wsi/wsi_common.h
@@ -81,10 +81,15 @@ struct wsi_device {
 
 typedef PFN_vkVoidFunction (VKAPI_PTR *WSI_FN_GetPhysicalDeviceProcAddr)(VkPhysicalDevice physicalDevice, const char* pName);
 
-void
+VkResult
 wsi_device_init(struct wsi_device *wsi,
                 VkPhysicalDevice pdevice,
-                WSI_FN_GetPhysicalDeviceProcAddr proc_addr);
+                WSI_FN_GetPhysicalDeviceProcAddr proc_addr,
+                const VkAllocationCallbacks *alloc);
+
+void
+wsi_device_finish(struct wsi_device *wsi,
+                  const VkAllocationCallbacks *alloc);
 
 #define ICD_DEFINE_NONDISP_HANDLE_CASTS(__VkIcdType, __VkType)             \
                                                                            \
@@ -105,16 +110,6 @@ wsi_device_init(struct wsi_device *wsi,
 
 ICD_DEFINE_NONDISP_HANDLE_CASTS(VkIcdSurfaceBase, VkSurfaceKHR)
 
-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);
-void wsi_wl_finish_wsi(struct wsi_device *wsi_device,
-                       const VkAllocationCallbacks *alloc);
-
 VkResult
 wsi_common_get_surface_support(struct wsi_device *wsi_device,
                                int local_fd,
diff --git a/src/vulkan/wsi/wsi_common_private.h b/src/vulkan/wsi/wsi_common_private.h
index e29a239..503b2a0 100644
--- a/src/vulkan/wsi/wsi_common_private.h
+++ b/src/vulkan/wsi/wsi_common_private.h
@@ -124,6 +124,16 @@ struct wsi_interface {
                                 struct wsi_swapchain **swapchain);
 };
 
+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);
+void wsi_wl_finish_wsi(struct wsi_device *wsi_device,
+                       const VkAllocationCallbacks *alloc);
+
 
 #define WSI_DEFINE_NONDISP_HANDLE_CASTS(__wsi_type, __VkType)              \
                                                                            \
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list