[Mesa-dev] [PATCH v2] vulkan: simplify VK_USE_PLATFORM_*_KHR handling
Emil Velikov
emil.l.velikov at gmail.com
Tue Aug 7 17:17:09 UTC 2018
From: Emil Velikov <emil.velikov at collabora.com>
Instead of having multiple guards littered through the code, simply
introduce static inline no-op functions when the respective macros are
not set.
Inspired by the same convention from the kernel.
v2: Also handle PLATFORM_DISPLAY
Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
Reviewed-by: Eric Engestrom <eric.engestrom at imgtec.com> (v1)
---
src/vulkan/wsi/wsi_common.c | 12 --------
src/vulkan/wsi/wsi_common_private.h | 47 +++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 12 deletions(-)
diff --git a/src/vulkan/wsi/wsi_common.c b/src/vulkan/wsi/wsi_common.c
index f2d90a6bba2..d2ba7871a1d 100644
--- a/src/vulkan/wsi/wsi_common.c
+++ b/src/vulkan/wsi/wsi_common.c
@@ -80,23 +80,17 @@ wsi_device_init(struct wsi_device *wsi,
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)
goto fail;
-#endif
-#ifdef VK_USE_PLATFORM_WAYLAND_KHR
result = wsi_wl_init_wsi(wsi, alloc, pdevice);
if (result != VK_SUCCESS)
goto fail;
-#endif
-#ifdef VK_USE_PLATFORM_DISPLAY_KHR
result = wsi_display_init_wsi(wsi, alloc, display_fd);
if (result != VK_SUCCESS)
goto fail;
-#endif
return VK_SUCCESS;
@@ -109,15 +103,9 @@ void
wsi_device_finish(struct wsi_device *wsi,
const VkAllocationCallbacks *alloc)
{
-#ifdef VK_USE_PLATFORM_DISPLAY_KHR
wsi_display_finish_wsi(wsi, alloc);
-#endif
-#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_private.h b/src/vulkan/wsi/wsi_common_private.h
index 9f2aacd6560..7dc1554e38d 100644
--- a/src/vulkan/wsi/wsi_common_private.h
+++ b/src/vulkan/wsi/wsi_common_private.h
@@ -128,17 +128,49 @@ struct wsi_interface {
struct wsi_swapchain **swapchain);
};
+#ifdef VK_USE_PLATFORM_XCB_KHR
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);
+#else
+static inline
+VkResult wsi_x11_init_wsi(struct wsi_device *wsi_device,
+ const VkAllocationCallbacks *alloc)
+{
+ return VK_SUCCESS;
+}
+
+static inline
+void wsi_x11_finish_wsi(struct wsi_device *wsi_device,
+ const VkAllocationCallbacks *alloc)
+{
+}
+#endif
+
+#ifdef VK_USE_PLATFORM_WAYLAND_KHR
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);
+#else
+static inline
+VkResult wsi_wl_init_wsi(struct wsi_device *wsi_device,
+ const VkAllocationCallbacks *alloc,
+ VkPhysicalDevice physical_device)
+{
+ return VK_SUCCESS;
+}
+static inline
+void wsi_wl_finish_wsi(struct wsi_device *wsi_device,
+ const VkAllocationCallbacks *alloc)
+{
+}
+#endif
+#ifdef VK_USE_PLATFORM_DISPLAY_KHR
VkResult
wsi_display_init_wsi(struct wsi_device *wsi_device,
const VkAllocationCallbacks *alloc,
@@ -147,6 +179,21 @@ wsi_display_init_wsi(struct wsi_device *wsi_device,
void
wsi_display_finish_wsi(struct wsi_device *wsi_device,
const VkAllocationCallbacks *alloc);
+#else
+static inline VkResult
+wsi_display_init_wsi(struct wsi_device *wsi_device,
+ const VkAllocationCallbacks *alloc,
+ int display_fd)
+{
+ return VK_SUCCESS;
+}
+
+static inline void
+wsi_display_finish_wsi(struct wsi_device *wsi_device,
+ const VkAllocationCallbacks *alloc)
+{
+}
+#endif
#define WSI_DEFINE_NONDISP_HANDLE_CASTS(__wsi_type, __VkType) \
\
--
2.18.0
More information about the mesa-dev
mailing list