vk: Remove more raw casts
authorChad Versace <chad.versace@intel.com>
Fri, 17 Jul 2015 20:59:48 +0000 (13:59 -0700)
committerChad Versace <chad.versace@intel.com>
Fri, 17 Jul 2015 21:32:22 +0000 (14:32 -0700)
This removes nearly all the remaining raw Anvil<->Vulkan casts from the
C source files.  (File compiler.cpp still contains many raw casts, and
I plan on ignoring that).

As far as I can tell, the only remaining raw casts are:
    anv_attachment_view -> anv_depth_stencil_view
    anv_attachment_view -> anv_color_attachment_view

src/vulkan/anv_cmd_emit.c
src/vulkan/device.c
src/vulkan/intel.c
src/vulkan/private.h
src/vulkan/x11.c

index 4c9f29ffaabb5d43e5612ddaf32ee3db4cb81154..6f8788c348131a9a7874eefd0bb193acac23115a 100644 (file)
@@ -1002,19 +1002,19 @@ void anv_CmdPipelineBarrier(
       const struct anv_common *common = ppMemBarriers[i];
       switch (common->sType) {
       case VK_STRUCTURE_TYPE_MEMORY_BARRIER: {
-         const VkMemoryBarrier *barrier = (VkMemoryBarrier *)common;
+         ANV_COMMON_TO_STRUCT(VkMemoryBarrier, barrier, common);
          out_flags |= barrier->outputMask;
          in_flags |= barrier->inputMask;
          break;
       }
       case VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER: {
-         const VkBufferMemoryBarrier *barrier = (VkBufferMemoryBarrier *)common;
+         ANV_COMMON_TO_STRUCT(VkBufferMemoryBarrier, barrier, common);
          out_flags |= barrier->outputMask;
          in_flags |= barrier->inputMask;
          break;
       }
       case VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER: {
-         const VkImageMemoryBarrier *barrier = (VkImageMemoryBarrier *)common;
+         ANV_COMMON_TO_STRUCT(VkImageMemoryBarrier, barrier, common);
          out_flags |= barrier->outputMask;
          in_flags |= barrier->inputMask;
          break;
index 0691c61c03894d41b4e1c22adbeca92485f3aca6..1073ab00ad44f30917f8ce23b90d31d97d3e5cf8 100644 (file)
@@ -1189,10 +1189,10 @@ VkResult anv_ResetFences(
     uint32_t                                    fenceCount,
     const VkFence*                              pFences)
 {
-   struct anv_fence **fences = (struct anv_fence **) pFences;
-
-   for (uint32_t i = 0; i < fenceCount; i++)
-      fences[i]->ready = false;
+   for (uint32_t i = 0; i < fenceCount; i++) {
+      ANV_FROM_HANDLE(anv_fence, fence, pFences[i]);
+      fence->ready = false;
+   }
 
    return VK_SUCCESS;
 }
index 6457b211f73777f300ca8e8ececb0921aaa11119..e314ba605860598c9874636c5bf6c1a2d047e9a8 100644 (file)
@@ -35,7 +35,7 @@ VkResult anv_CreateDmaBufImageINTEL(
     VkDeviceMemory*                             pMem,
     VkImage*                                    pImage)
 {
-   struct anv_device *device = (struct anv_device *) _device;
+   ANV_FROM_HANDLE(anv_device, device, _device);
    struct anv_device_memory *mem;
    struct anv_image *image;
    VkResult result;
index cf8a869cdfd14ba05c5d3b575accf475205ef4ff..a1fe5304572eb1370ccf7cb7b1495669b191a891 100644 (file)
@@ -1038,6 +1038,7 @@ ANV_DEFINE_HANDLE_CASTS(anv_device, VkDevice)
 ANV_DEFINE_HANDLE_CASTS(anv_instance, VkInstance)
 ANV_DEFINE_HANDLE_CASTS(anv_physical_device, VkPhysicalDevice)
 ANV_DEFINE_HANDLE_CASTS(anv_queue, VkQueue)
+ANV_DEFINE_HANDLE_CASTS(anv_swap_chain, VkSwapChainWSI);
 
 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_attachment_view, VkAttachmentView)
 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer, VkBuffer)
@@ -1061,6 +1062,21 @@ ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_sampler, VkSampler)
 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_shader, VkShader)
 ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_shader_module, VkShaderModule)
 
+#define ANV_DEFINE_STRUCT_CASTS(__anv_type, __VkType) \
+   \
+   static inline const __VkType * \
+   __anv_type ## _to_ ## __VkType(const struct __anv_type *__anv_obj) \
+   { \
+      return (const __VkType *) __anv_obj; \
+   }
+
+#define ANV_COMMON_TO_STRUCT(__VkType, __vk_name, __common_name) \
+   const __VkType *__vk_name = anv_common_to_ ## __VkType(__common_name)
+
+ANV_DEFINE_STRUCT_CASTS(anv_common, VkMemoryBarrier)
+ANV_DEFINE_STRUCT_CASTS(anv_common, VkBufferMemoryBarrier)
+ANV_DEFINE_STRUCT_CASTS(anv_common, VkImageMemoryBarrier)
+
 #ifdef __cplusplus
 }
 #endif
index 73a7e2fc8ac5bc60c16e901e0f8b821fe944b0c3..1e0bdb12bd04eb1fdaf40ffac43d031d0f609c0f 100644 (file)
@@ -205,7 +205,7 @@ VkResult anv_CreateSwapChainWSI(
                           (uint32_t []) { 0 });
    xcb_discard_reply(chain->conn, cookie.sequence);
 
-   *pSwapChain = (VkSwapChainWSI) chain;
+   *pSwapChain = anv_swap_chain_to_handle(chain);
 
    return VK_SUCCESS;
 
@@ -214,23 +214,23 @@ VkResult anv_CreateSwapChainWSI(
 }
 
 VkResult anv_DestroySwapChainWSI(
-    VkSwapChainWSI                          swapChain)
+    VkSwapChainWSI                          _chain)
 {
-   struct anv_swap_chain *chain = (struct anv_swap_chain *) swapChain;
-   struct anv_device *device = chain->device;
+   ANV_FROM_HANDLE(anv_swap_chain, chain, _chain);
 
-   anv_device_free(device, chain);
+   anv_device_free(chain->device, chain);
 
    return VK_SUCCESS;
 }
 
 VkResult anv_GetSwapChainInfoWSI(
-    VkSwapChainWSI                          swapChain,
+    VkSwapChainWSI                          _chain,
     VkSwapChainInfoTypeWSI                  infoType,
     size_t*                                 pDataSize,
     void*                                   pData)
 {
-   struct anv_swap_chain *chain = (struct anv_swap_chain *) swapChain;
+   ANV_FROM_HANDLE(anv_swap_chain, chain, _chain);
+
    VkSwapChainImageInfoWSI *images;
    size_t size;