[Mesa-dev] [PATCH] vulkan: simplify VK_USE_PLATFORM_*_KHR handling

Eric Engestrom eric.engestrom at imgtec.com
Fri Mar 9 16:53:45 UTC 2018


On Friday, 2018-03-09 15:24:18 +0000, Emil Velikov wrote:
> 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.

Oh right, I didn't get what you meant at first, but this makes sense. As
the number of supported platform increases, this will be much cleaner.

> 
> Cc: Eric Engestrom <eric.engestrom at imgtec.com>
> Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
> ---
> Here is an example of my earlier suggestion.
> NOTE: not even compile tested!
> ---
>  src/vulkan/wsi/wsi_common.c         |  8 --------
>  src/vulkan/wsi/wsi_common_private.h | 27 +++++++++++++++++++++++++++
>  2 files changed, 27 insertions(+), 8 deletions(-)
> 
> diff --git a/src/vulkan/wsi/wsi_common.c b/src/vulkan/wsi/wsi_common.c
> index fe262b4968d..c91075325b9 100644
> --- a/src/vulkan/wsi/wsi_common.c
> +++ b/src/vulkan/wsi/wsi_common.c
> @@ -79,17 +79,13 @@ 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
>  
>     return VK_SUCCESS;
>  
> @@ -102,12 +98,8 @@ 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_private.h b/src/vulkan/wsi/wsi_common_private.h
> index b608119b969..501bbf0498e 100644
> --- a/src/vulkan/wsi/wsi_common_private.h
> +++ b/src/vulkan/wsi/wsi_common_private.h
> @@ -129,16 +129,43 @@ 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) { }

Nit: can we have all the `{` and `}` on their own lines, just like the
`init` stub above?

Provided you compile-test :P
Reviewed-by: Eric Engestrom <eric.engestrom at imgtec.com>

> +#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
>  
>  #define WSI_DEFINE_NONDISP_HANDLE_CASTS(__wsi_type, __VkType)              \
>                                                                             \
> -- 
> 2.16.0
> 


More information about the mesa-dev mailing list