From 169251bff0ec4bdafa84da50b6144e6cf02bf0da Mon Sep 17 00:00:00 2001 From: Chad Versace Date: Fri, 17 Jul 2015 13:59:48 -0700 Subject: [PATCH] vk: Remove more raw casts 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 | 6 +++--- src/vulkan/device.c | 8 ++++---- src/vulkan/intel.c | 2 +- src/vulkan/private.h | 16 ++++++++++++++++ src/vulkan/x11.c | 14 +++++++------- 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/vulkan/anv_cmd_emit.c b/src/vulkan/anv_cmd_emit.c index 4c9f29ffaab..6f8788c3481 100644 --- a/src/vulkan/anv_cmd_emit.c +++ b/src/vulkan/anv_cmd_emit.c @@ -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; diff --git a/src/vulkan/device.c b/src/vulkan/device.c index 0691c61c038..1073ab00ad4 100644 --- a/src/vulkan/device.c +++ b/src/vulkan/device.c @@ -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; } diff --git a/src/vulkan/intel.c b/src/vulkan/intel.c index 6457b211f73..e314ba60586 100644 --- a/src/vulkan/intel.c +++ b/src/vulkan/intel.c @@ -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; diff --git a/src/vulkan/private.h b/src/vulkan/private.h index cf8a869cdfd..a1fe5304572 100644 --- a/src/vulkan/private.h +++ b/src/vulkan/private.h @@ -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 diff --git a/src/vulkan/x11.c b/src/vulkan/x11.c index 73a7e2fc8ac..1e0bdb12bd0 100644 --- a/src/vulkan/x11.c +++ b/src/vulkan/x11.c @@ -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; -- 2.30.2