vulkan: Add new cast macros for VkIcd types
authorChad Versace <chadversary@chromium.org>
Tue, 10 Jan 2017 21:23:06 +0000 (13:23 -0800)
committerChad Versace <chadversary@chromium.org>
Thu, 12 Jan 2017 17:42:32 +0000 (09:42 -0800)
We can't import the latest vk_icd.h because the new header breaks the
Mesa build. This patch defines new casting macros,
ICD_DEFINE_NONDISP_HANDLE_CASTS() and ICD_FROM_HANDLE(), which can
handle both the old and new vk_icd.h, and will prevent the build from
breaking when we update the header.

In the old vk_icd.h, types were defined as:

  typedef struct _VkIcdFoo {
    ...
  } VkIcdFoo;

Commit 6ebba1f6 in the Vulkan loader changed the above to

  typedef {
    ...
  } VkIcdFoo;

because the old definitions violated the C and C++ specs. According to
the specs, identifiers that begins with an underscore followed by an
uppercase letter are reserved. (It's pedantic, I know), See the Github
issue referenced below.

References: https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/issues/7
References: https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/commit/6ebba1f630015af7a78767a15c1e74ba9b23601c
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Cc: mesa-stable@lists.freedesktop.org
src/amd/vulkan/radv_wsi.c
src/intel/vulkan/anv_wsi.c
src/vulkan/wsi/wsi_common.h
src/vulkan/wsi/wsi_common_wayland.c
src/vulkan/wsi/wsi_common_x11.c

index 2eb8e458c782b9233cd62fcddbce22a10166e9de..952f2c342a66162efc4c8c232616bc698dba8467 100644 (file)
@@ -75,7 +75,7 @@ void radv_DestroySurfaceKHR(
        const VkAllocationCallbacks*                 pAllocator)
 {
        RADV_FROM_HANDLE(radv_instance, instance, _instance);
-       RADV_FROM_HANDLE(_VkIcdSurfaceBase, surface, _surface);
+       ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface);
 
        vk_free2(&instance->alloc, pAllocator, surface);
 }
@@ -87,7 +87,7 @@ VkResult radv_GetPhysicalDeviceSurfaceSupportKHR(
        VkBool32*                                   pSupported)
 {
        RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
-       RADV_FROM_HANDLE(_VkIcdSurfaceBase, surface, _surface);
+       ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface);
        struct wsi_interface *iface = device->wsi_device.wsi[surface->platform];
 
        return iface->get_support(surface, &device->wsi_device,
@@ -101,7 +101,7 @@ VkResult radv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
        VkSurfaceCapabilitiesKHR*                   pSurfaceCapabilities)
 {
        RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
-       RADV_FROM_HANDLE(_VkIcdSurfaceBase, surface, _surface);
+       ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface);
        struct wsi_interface *iface = device->wsi_device.wsi[surface->platform];
 
        return iface->get_capabilities(surface, pSurfaceCapabilities);
@@ -114,7 +114,7 @@ VkResult radv_GetPhysicalDeviceSurfaceFormatsKHR(
        VkSurfaceFormatKHR*                         pSurfaceFormats)
 {
        RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
-       RADV_FROM_HANDLE(_VkIcdSurfaceBase, surface, _surface);
+       ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface);
        struct wsi_interface *iface = device->wsi_device.wsi[surface->platform];
 
        return iface->get_formats(surface, &device->wsi_device, pSurfaceFormatCount,
@@ -128,7 +128,7 @@ VkResult radv_GetPhysicalDeviceSurfacePresentModesKHR(
        VkPresentModeKHR*                           pPresentModes)
 {
        RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
-       RADV_FROM_HANDLE(_VkIcdSurfaceBase, surface, _surface);
+       ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface);
        struct wsi_interface *iface = device->wsi_device.wsi[surface->platform];
 
        return iface->get_present_modes(surface, pPresentModeCount,
@@ -249,7 +249,7 @@ VkResult radv_CreateSwapchainKHR(
        VkSwapchainKHR*                              pSwapchain)
 {
        RADV_FROM_HANDLE(radv_device, device, _device);
-       RADV_FROM_HANDLE(_VkIcdSurfaceBase, surface, pCreateInfo->surface);
+       ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, pCreateInfo->surface);
        struct wsi_interface *iface =
                device->instance->physicalDevice.wsi_device.wsi[surface->platform];
        struct wsi_swapchain *swapchain;
index 669eacc93cf4d71fe50cadd1c60ee2cbf8bfe27f..a01ef03c11b6520d9f12014b7625dc8f9f6b648a 100644 (file)
@@ -74,7 +74,7 @@ void anv_DestroySurfaceKHR(
     const VkAllocationCallbacks*                 pAllocator)
 {
    ANV_FROM_HANDLE(anv_instance, instance, _instance);
-   ANV_FROM_HANDLE(_VkIcdSurfaceBase, surface, _surface);
+   ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface);
 
    if (!surface)
       return;
@@ -89,7 +89,7 @@ VkResult anv_GetPhysicalDeviceSurfaceSupportKHR(
     VkBool32*                                   pSupported)
 {
    ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
-   ANV_FROM_HANDLE(_VkIcdSurfaceBase, surface, _surface);
+   ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface);
    struct wsi_interface *iface = device->wsi_device.wsi[surface->platform];
 
    return iface->get_support(surface, &device->wsi_device,
@@ -103,7 +103,7 @@ VkResult anv_GetPhysicalDeviceSurfaceCapabilitiesKHR(
     VkSurfaceCapabilitiesKHR*                   pSurfaceCapabilities)
 {
    ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
-   ANV_FROM_HANDLE(_VkIcdSurfaceBase, surface, _surface);
+   ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface);
    struct wsi_interface *iface = device->wsi_device.wsi[surface->platform];
 
    return iface->get_capabilities(surface, pSurfaceCapabilities);
@@ -116,7 +116,7 @@ VkResult anv_GetPhysicalDeviceSurfaceFormatsKHR(
     VkSurfaceFormatKHR*                         pSurfaceFormats)
 {
    ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
-   ANV_FROM_HANDLE(_VkIcdSurfaceBase, surface, _surface);
+   ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface);
    struct wsi_interface *iface = device->wsi_device.wsi[surface->platform];
 
    return iface->get_formats(surface, &device->wsi_device, pSurfaceFormatCount,
@@ -130,7 +130,7 @@ VkResult anv_GetPhysicalDeviceSurfacePresentModesKHR(
     VkPresentModeKHR*                           pPresentModes)
 {
    ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
-   ANV_FROM_HANDLE(_VkIcdSurfaceBase, surface, _surface);
+   ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface);
    struct wsi_interface *iface = device->wsi_device.wsi[surface->platform];
 
    return iface->get_present_modes(surface, pPresentModeCount,
@@ -260,7 +260,7 @@ VkResult anv_CreateSwapchainKHR(
     VkSwapchainKHR*                              pSwapchain)
 {
    ANV_FROM_HANDLE(anv_device, device, _device);
-   ANV_FROM_HANDLE(_VkIcdSurfaceBase, surface, pCreateInfo->surface);
+   ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, pCreateInfo->surface);
    struct wsi_interface *iface =
       device->instance->physicalDevice.wsi_device.wsi[surface->platform];
    struct wsi_swapchain *swapchain;
index a1f5a40186c4b63214d4bfc811245a83656e2650..394b8fa1914dbed153e15b0c478a847d35c23540 100644 (file)
@@ -116,9 +116,27 @@ struct wsi_callbacks {
       return (__VkType)(uintptr_t) _obj;                                   \
    }
 
-WSI_DEFINE_NONDISP_HANDLE_CASTS(_VkIcdSurfaceBase, VkSurfaceKHR)
 WSI_DEFINE_NONDISP_HANDLE_CASTS(wsi_swapchain, VkSwapchainKHR)
 
+#define ICD_DEFINE_NONDISP_HANDLE_CASTS(__VkIcdType, __VkType)             \
+                                                                           \
+   static inline __VkIcdType *                                             \
+   __VkIcdType ## _from_handle(__VkType _handle)                           \
+   {                                                                       \
+      return (__VkIcdType *)(uintptr_t) _handle;                           \
+   }                                                                       \
+                                                                           \
+   static inline __VkType                                                  \
+   __VkIcdType ## _to_handle(__VkIcdType *_obj)                            \
+   {                                                                       \
+      return (__VkType)(uintptr_t) _obj;                                   \
+   }
+
+#define ICD_FROM_HANDLE(__VkIcdType, __name, __handle) \
+   __VkIcdType *__name = __VkIcdType ## _from_handle(__handle)
+
+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,
index 2fe889ecc2a7741fe5fb0dcfb8b171d8ae792d72..687ac9c731bd0887487205f0fabfdecbf8ebaf32 100644 (file)
@@ -463,7 +463,7 @@ VkResult wsi_create_wl_surface(const VkAllocationCallbacks *pAllocator,
    surface->display = pCreateInfo->display;
    surface->surface = pCreateInfo->surface;
 
-   *pSurface = _VkIcdSurfaceBase_to_handle(&surface->base);
+   *pSurface = VkIcdSurfaceBase_to_handle(&surface->base);
 
    return VK_SUCCESS;
 }
index 7126838848489cc6b4381084bc8059c9d6e861fa..158446c2ca7a0ec3d2bf5651d48a617859b01e39 100644 (file)
@@ -453,7 +453,7 @@ VkResult wsi_create_xcb_surface(const VkAllocationCallbacks *pAllocator,
    surface->connection = pCreateInfo->connection;
    surface->window = pCreateInfo->window;
 
-   *pSurface = _VkIcdSurfaceBase_to_handle(&surface->base);
+   *pSurface = VkIcdSurfaceBase_to_handle(&surface->base);
    return VK_SUCCESS;
 }
 
@@ -472,7 +472,7 @@ VkResult wsi_create_xlib_surface(const VkAllocationCallbacks *pAllocator,
    surface->dpy = pCreateInfo->dpy;
    surface->window = pCreateInfo->window;
 
-   *pSurface = _VkIcdSurfaceBase_to_handle(&surface->base);
+   *pSurface = VkIcdSurfaceBase_to_handle(&surface->base);
    return VK_SUCCESS;
 }