From 756d8064c103b9abe131ca5f6679d79426557424 Mon Sep 17 00:00:00 2001 From: Chad Versace Date: Wed, 15 Jul 2015 15:48:41 -0700 Subject: [PATCH] vk/0.132: Do type-safety --- include/vulkan/vk_wsi_lunarg.h | 8 +- include/vulkan/vulkan.h | 152 +++++++++++++-------------------- src/vulkan/device.c | 115 +------------------------ src/vulkan/meta.c | 3 +- src/vulkan/pipeline.c | 2 +- src/vulkan/private.h | 92 +++++++++++--------- 6 files changed, 121 insertions(+), 251 deletions(-) diff --git a/include/vulkan/vk_wsi_lunarg.h b/include/vulkan/vk_wsi_lunarg.h index c1af9f50fb0..9587952d067 100644 --- a/include/vulkan/vk_wsi_lunarg.h +++ b/include/vulkan/vk_wsi_lunarg.h @@ -59,8 +59,8 @@ extern "C" // ------------------------------------------------------------------------------------------------ // Objects -VK_DEFINE_DISP_SUBCLASS_HANDLE(VkDisplayWSI, VkObject) -VK_DEFINE_DISP_SUBCLASS_HANDLE(VkSwapChainWSI, VkObject) +VK_DEFINE_HANDLE(VkDisplayWSI) +VK_DEFINE_HANDLE(VkSwapChainWSI) // ------------------------------------------------------------------------------------------------ // Enumeration constants @@ -78,10 +78,6 @@ VK_DEFINE_DISP_SUBCLASS_HANDLE(VkSwapChainWSI, VkObject) // Extend VkImageLayout enum with extension specific constants #define VK_IMAGE_LAYOUT_PRESENT_SOURCE_WSI VK_WSI_LUNARG_ENUM(VkImageLayout, 0) -// Extend VkObjectType enum for new objects -#define VK_OBJECT_TYPE_DISPLAY_WSI VK_WSI_LUNARG_ENUM(VkObjectType, 0) -#define VK_OBJECT_TYPE_SWAP_CHAIN_WSI VK_WSI_LUNARG_ENUM(VkObjectType, 1) - // ------------------------------------------------------------------------------------------------ // Enumerations diff --git a/include/vulkan/vulkan.h b/include/vulkan/vulkan.h index 174ec1b354c..3e4af9d0070 100644 --- a/include/vulkan/vulkan.h +++ b/include/vulkan/vulkan.h @@ -43,22 +43,37 @@ extern "C" { // Vulkan API version supported by this file #define VK_API_VERSION VK_MAKE_VERSION(0, 131, 0) -#if defined (__cplusplus) && (VK_UINTPTRLEAST64_MAX == UINTPTR_MAX) - #define VK_TYPE_SAFE_COMPATIBLE_HANDLES 1 -#endif - -#if defined(VK_TYPE_SAFE_COMPATIBLE_HANDLES) && !defined(VK_DISABLE_TYPE_SAFE_HANDLES) - #define VK_DEFINE_PTR_HANDLE(_obj) struct _obj##_T { char _dummy; }; typedef _obj##_T* _obj; - #define VK_DEFINE_PTR_SUBCLASS_HANDLE(_obj, _base) struct _obj##_T : public _base##_T {}; typedef _obj##_T* _obj; - #define VK_DEFINE_BASE_HANDLE(_obj) VK_DEFINE_PTR_HANDLE(_obj) - #define VK_DEFINE_DISP_SUBCLASS_HANDLE(_obj, _base) VK_DEFINE_PTR_SUBCLASS_HANDLE(_obj, _base) - #define VK_DEFINE_NONDISP_SUBCLASS_HANDLE(_obj, _base) VK_DEFINE_PTR_SUBCLASS_HANDLE(_obj, _base) +#define VK_DEFINE_HANDLE(obj) typedef struct obj##_T* obj; + + +#if defined(__cplusplus) + #if (_MSC_VER >= 1800 || __cplusplus >= 201103L) + // The bool operator only works if there are no implicit conversions from an obj to + // a bool-compatible type, which can then be used to unintentionally violate type safety. + // C++11 and above supports the "explicit" keyword on conversion operators to stop this + // from happening. Otherwise users of C++ below C++11 won't get direct access to evaluating + // the object handle as a bool in expressions like: + // if (obj) vkDestroy(obj); + #define VK_NONDISP_HANDLE_OPERATOR_BOOL() explicit operator bool() const { return handle != 0; } + #else + #define VK_NONDISP_HANDLE_OPERATOR_BOOL() + #endif + #define VK_DEFINE_NONDISP_HANDLE(obj) \ + struct obj { \ + obj() { } \ + obj(uint64_t x) { handle = x; } \ + obj& operator =(uint64_t x) { handle = x; return *this; } \ + bool operator==(const obj& other) const { return handle == other.handle; } \ + bool operator!=(const obj& other) const { return handle != other.handle; } \ + bool operator!() const { return !handle; } \ + VK_NONDISP_HANDLE_OPERATOR_BOOL() \ + uint64_t handle; \ + }; #else - #define VK_DEFINE_BASE_HANDLE(_obj) typedef VkUintPtrLeast64 _obj; - #define VK_DEFINE_DISP_SUBCLASS_HANDLE(_obj, _base) typedef uintptr_t _obj; - #define VK_DEFINE_NONDISP_SUBCLASS_HANDLE(_obj, _base) typedef VkUintPtrLeast64 _obj; + #define VK_DEFINE_NONDISP_HANDLE(obj) typedef struct obj##_T { uint64_t handle; } obj; #endif + #define VK_LOD_CLAMP_NONE MAX_FLOAT @@ -76,40 +91,37 @@ extern "C" { #define VK_MAX_EXTENSION_NAME 256 #define VK_MAX_DESCRIPTION 256 -VK_DEFINE_BASE_HANDLE(VkObject) -VK_DEFINE_DISP_SUBCLASS_HANDLE(VkInstance, VkObject) -VK_DEFINE_DISP_SUBCLASS_HANDLE(VkPhysicalDevice, VkObject) -VK_DEFINE_DISP_SUBCLASS_HANDLE(VkDevice, VkObject) -VK_DEFINE_DISP_SUBCLASS_HANDLE(VkQueue, VkObject) -VK_DEFINE_DISP_SUBCLASS_HANDLE(VkCmdBuffer, VkObject) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkNonDispatchable, VkObject) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkFence, VkNonDispatchable) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkDeviceMemory, VkNonDispatchable) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkBuffer, VkNonDispatchable) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkImage, VkNonDispatchable) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkSemaphore, VkNonDispatchable) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkEvent, VkNonDispatchable) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkQueryPool, VkNonDispatchable) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkBufferView, VkNonDispatchable) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkImageView, VkNonDispatchable) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkAttachmentView, VkNonDispatchable) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkShaderModule, VkNonDispatchable) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkShader, VkNonDispatchable) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkPipelineCache, VkNonDispatchable) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkPipelineLayout, VkNonDispatchable) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkRenderPass, VkNonDispatchable) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkPipeline, VkNonDispatchable) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkDescriptorSetLayout, VkNonDispatchable) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkSampler, VkNonDispatchable) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkDescriptorPool, VkNonDispatchable) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkDescriptorSet, VkNonDispatchable) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkDynamicStateObject, VkNonDispatchable) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkDynamicViewportState, VkDynamicStateObject) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkDynamicRasterState, VkDynamicStateObject) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkDynamicColorBlendState, VkDynamicStateObject) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkDynamicDepthStencilState, VkDynamicStateObject) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkFramebuffer, VkNonDispatchable) -VK_DEFINE_NONDISP_SUBCLASS_HANDLE(VkCmdPool, VkNonDispatchable) +VK_DEFINE_HANDLE(VkInstance) +VK_DEFINE_HANDLE(VkPhysicalDevice) +VK_DEFINE_HANDLE(VkDevice) +VK_DEFINE_HANDLE(VkQueue) +VK_DEFINE_HANDLE(VkCmdBuffer) +VK_DEFINE_NONDISP_HANDLE(VkFence) +VK_DEFINE_NONDISP_HANDLE(VkDeviceMemory) +VK_DEFINE_NONDISP_HANDLE(VkBuffer) +VK_DEFINE_NONDISP_HANDLE(VkImage) +VK_DEFINE_NONDISP_HANDLE(VkSemaphore) +VK_DEFINE_NONDISP_HANDLE(VkEvent) +VK_DEFINE_NONDISP_HANDLE(VkQueryPool) +VK_DEFINE_NONDISP_HANDLE(VkBufferView) +VK_DEFINE_NONDISP_HANDLE(VkImageView) +VK_DEFINE_NONDISP_HANDLE(VkAttachmentView) +VK_DEFINE_NONDISP_HANDLE(VkShaderModule) +VK_DEFINE_NONDISP_HANDLE(VkShader) +VK_DEFINE_NONDISP_HANDLE(VkPipelineCache) +VK_DEFINE_NONDISP_HANDLE(VkPipelineLayout) +VK_DEFINE_NONDISP_HANDLE(VkRenderPass) +VK_DEFINE_NONDISP_HANDLE(VkPipeline) +VK_DEFINE_NONDISP_HANDLE(VkDescriptorSetLayout) +VK_DEFINE_NONDISP_HANDLE(VkSampler) +VK_DEFINE_NONDISP_HANDLE(VkDescriptorPool) +VK_DEFINE_NONDISP_HANDLE(VkDescriptorSet) +VK_DEFINE_NONDISP_HANDLE(VkDynamicViewportState) +VK_DEFINE_NONDISP_HANDLE(VkDynamicRasterState) +VK_DEFINE_NONDISP_HANDLE(VkDynamicColorBlendState) +VK_DEFINE_NONDISP_HANDLE(VkDynamicDepthStencilState) +VK_DEFINE_NONDISP_HANDLE(VkFramebuffer) +VK_DEFINE_NONDISP_HANDLE(VkCmdPool) typedef enum { @@ -139,7 +151,7 @@ typedef enum { VK_ERROR_INVALID_IMAGE = -17, VK_ERROR_INVALID_DESCRIPTOR_SET_DATA = -18, VK_ERROR_INVALID_QUEUE_TYPE = -19, - VK_ERROR_INVALID_OBJECT_TYPE = -20, + VK_ERROR_UNSUPPORTED_SHADER_IL_VERSION = -21, VK_ERROR_BAD_SHADER_CODE = -22, VK_ERROR_BAD_PIPELINE_DATA = -23, @@ -441,44 +453,6 @@ typedef enum { VK_PHYSICAL_DEVICE_TYPE_MAX_ENUM = 0x7FFFFFFF } VkPhysicalDeviceType; -typedef enum { - VK_OBJECT_TYPE_INSTANCE = 0, - VK_OBJECT_TYPE_PHYSICAL_DEVICE = 1, - VK_OBJECT_TYPE_DEVICE = 2, - VK_OBJECT_TYPE_QUEUE = 3, - VK_OBJECT_TYPE_COMMAND_BUFFER = 4, - VK_OBJECT_TYPE_DEVICE_MEMORY = 5, - VK_OBJECT_TYPE_BUFFER = 6, - VK_OBJECT_TYPE_BUFFER_VIEW = 7, - VK_OBJECT_TYPE_IMAGE = 8, - VK_OBJECT_TYPE_IMAGE_VIEW = 9, - VK_OBJECT_TYPE_ATTACHMENT_VIEW = 10, - VK_OBJECT_TYPE_SHADER_MODULE = 11, - VK_OBJECT_TYPE_SHADER = 12, - VK_OBJECT_TYPE_PIPELINE = 13, - VK_OBJECT_TYPE_PIPELINE_LAYOUT = 14, - VK_OBJECT_TYPE_SAMPLER = 15, - VK_OBJECT_TYPE_DESCRIPTOR_SET = 16, - VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT = 17, - VK_OBJECT_TYPE_DESCRIPTOR_POOL = 18, - VK_OBJECT_TYPE_DYNAMIC_VP_STATE = 19, - VK_OBJECT_TYPE_DYNAMIC_RS_STATE = 20, - VK_OBJECT_TYPE_DYNAMIC_CB_STATE = 21, - VK_OBJECT_TYPE_DYNAMIC_DS_STATE = 22, - VK_OBJECT_TYPE_FENCE = 23, - VK_OBJECT_TYPE_SEMAPHORE = 24, - VK_OBJECT_TYPE_EVENT = 25, - VK_OBJECT_TYPE_QUERY_POOL = 26, - VK_OBJECT_TYPE_FRAMEBUFFER = 27, - VK_OBJECT_TYPE_RENDER_PASS = 28, - VK_OBJECT_TYPE_PIPELINE_CACHE = 29, - VK_OBJECT_TYPE_CMD_POOL = 30, - VK_OBJECT_TYPE_BEGIN_RANGE = VK_OBJECT_TYPE_INSTANCE, - VK_OBJECT_TYPE_END_RANGE = VK_OBJECT_TYPE_PIPELINE_CACHE, - VK_OBJECT_TYPE_NUM = (VK_OBJECT_TYPE_PIPELINE_CACHE - VK_OBJECT_TYPE_INSTANCE + 1), - VK_OBJECT_TYPE_MAX_ENUM = 0x7FFFFFFF -} VkObjectType; - typedef enum { VK_IMAGE_ASPECT_COLOR = 0, VK_IMAGE_ASPECT_DEPTH = 1, @@ -2135,7 +2109,6 @@ typedef VkResult (VKAPI *PFN_vkMapMemory)(VkDevice device, VkDeviceMemory mem, V typedef VkResult (VKAPI *PFN_vkUnmapMemory)(VkDevice device, VkDeviceMemory mem); typedef VkResult (VKAPI *PFN_vkFlushMappedMemoryRanges)(VkDevice device, uint32_t memRangeCount, const VkMappedMemoryRange* pMemRanges); typedef VkResult (VKAPI *PFN_vkInvalidateMappedMemoryRanges)(VkDevice device, uint32_t memRangeCount, const VkMappedMemoryRange* pMemRanges); -typedef VkResult (VKAPI *PFN_vkDestroyObject)(VkDevice device, VkObjectType objType, VkObject object); typedef VkResult (VKAPI *PFN_vkGetDeviceMemoryCommitment)(VkDevice device, VkDeviceMemory memory, VkDeviceSize* pCommittedMemoryInBytes); typedef VkResult (VKAPI *PFN_vkBindBufferMemory)(VkDevice device, VkBuffer buffer, VkDeviceMemory mem, VkDeviceSize memOffset); typedef VkResult (VKAPI *PFN_vkBindImageMemory)(VkDevice device, VkImage image, VkDeviceMemory mem, VkDeviceSize memOffset); @@ -2395,11 +2368,6 @@ VkResult VKAPI vkInvalidateMappedMemoryRanges( uint32_t memRangeCount, const VkMappedMemoryRange* pMemRanges); -VkResult VKAPI vkDestroyObject( - VkDevice device, - VkObjectType objType, - VkObject object); - VkResult VKAPI vkGetDeviceMemoryCommitment( VkDevice device, VkDeviceMemory memory, diff --git a/src/vulkan/device.c b/src/vulkan/device.c index 052b725348e..0691c61c038 100644 --- a/src/vulkan/device.c +++ b/src/vulkan/device.c @@ -984,117 +984,6 @@ VkResult anv_InvalidateMappedMemoryRanges( return anv_FlushMappedMemoryRanges(device, memRangeCount, pMemRanges); } -VkResult anv_DestroyObject( - VkDevice _device, - VkObjectType objType, - VkObject _object) -{ - ANV_FROM_HANDLE(anv_device, device, _device); - - switch (objType) { - case VK_OBJECT_TYPE_FENCE: - return anv_DestroyFence(_device, (VkFence) _object); - - case VK_OBJECT_TYPE_INSTANCE: - return anv_DestroyInstance((VkInstance) _object); - - case VK_OBJECT_TYPE_PHYSICAL_DEVICE: - /* We don't want to actually destroy physical devices */ - return VK_SUCCESS; - - case VK_OBJECT_TYPE_DEVICE: - assert(_device == (VkDevice) _object); - return anv_DestroyDevice((VkDevice) _object); - - case VK_OBJECT_TYPE_QUEUE: - /* TODO */ - return VK_SUCCESS; - - case VK_OBJECT_TYPE_DEVICE_MEMORY: - return anv_FreeMemory(_device, (VkDeviceMemory) _object); - - case VK_OBJECT_TYPE_DESCRIPTOR_POOL: - return anv_DestroyDescriptorPool(_device, (VkDescriptorPool) _object); - - case VK_OBJECT_TYPE_PIPELINE_CACHE: - return anv_DestroyPipelineCache(_device, (VkPipelineCache) _object); - - case VK_OBJECT_TYPE_BUFFER_VIEW: - return anv_DestroyBufferView(_device, _object); - - case VK_OBJECT_TYPE_IMAGE_VIEW: - return anv_DestroyImageView(_device, _object); - - case VK_OBJECT_TYPE_ATTACHMENT_VIEW: - return anv_DestroyAttachmentView(_device, _object); - - case VK_OBJECT_TYPE_IMAGE: - return anv_DestroyImage(_device, _object); - - case VK_OBJECT_TYPE_BUFFER: - return anv_DestroyBuffer(_device, (VkBuffer) _object); - - case VK_OBJECT_TYPE_SHADER_MODULE: - return anv_DestroyShaderModule(_device, (VkShaderModule) _object); - - case VK_OBJECT_TYPE_SHADER: - return anv_DestroyShader(_device, (VkShader) _object); - - case VK_OBJECT_TYPE_PIPELINE_LAYOUT: - return anv_DestroyPipelineLayout(_device, (VkPipelineLayout) _object); - - case VK_OBJECT_TYPE_SAMPLER: - return anv_DestroySampler(_device, (VkSampler) _object); - - case VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT: - return anv_DestroyDescriptorSetLayout(_device, (VkDescriptorSetLayout) _object); - - case VK_OBJECT_TYPE_DESCRIPTOR_SET: - anv_descriptor_set_destroy(device, anv_descriptor_set_from_handle(_object)); - return VK_SUCCESS; - - case VK_OBJECT_TYPE_RENDER_PASS: - return anv_DestroyRenderPass(_device, (VkRenderPass) _object); - - case VK_OBJECT_TYPE_DYNAMIC_VP_STATE: - return anv_DestroyDynamicViewportState(_device, (VkDynamicViewportState) _object); - - case VK_OBJECT_TYPE_DYNAMIC_RS_STATE: - return anv_DestroyDynamicRasterState(_device, (VkDynamicRasterState) _object); - - case VK_OBJECT_TYPE_DYNAMIC_CB_STATE: - return anv_DestroyDynamicColorBlendState(_device, (VkDynamicColorBlendState) _object); - - case VK_OBJECT_TYPE_DYNAMIC_DS_STATE: - return anv_DestroyDynamicDepthStencilState(_device, (VkDynamicDepthStencilState) _object); - - case VK_OBJECT_TYPE_FRAMEBUFFER: - return anv_DestroyFramebuffer(_device, (VkFramebuffer) _object); - - case VK_OBJECT_TYPE_COMMAND_BUFFER: - return anv_DestroyCommandBuffer(_device, (VkCmdBuffer) _object); - return VK_SUCCESS; - - case VK_OBJECT_TYPE_PIPELINE: - return anv_DestroyPipeline(_device, (VkPipeline) _object); - - case VK_OBJECT_TYPE_QUERY_POOL: - return anv_DestroyQueryPool(_device, (VkQueryPool) _object); - - case VK_OBJECT_TYPE_SEMAPHORE: - return anv_DestroySemaphore(_device, (VkSemaphore) _object); - - case VK_OBJECT_TYPE_EVENT: - return anv_DestroyEvent(_device, (VkEvent) _object); - - case VK_OBJECT_TYPE_CMD_POOL: - return anv_DestroyCommandPool(_device, (VkCmdPool) _object); - - default: - unreachable("Invalid object type"); - } -} - VkResult anv_GetBufferMemoryRequirements( VkDevice device, VkBuffer _buffer, @@ -1851,7 +1740,7 @@ VkResult anv_CreateDescriptorPool( VkDescriptorPool* pDescriptorPool) { anv_finishme("VkDescriptorPool is a stub"); - *pDescriptorPool = 1; + pDescriptorPool->handle = 1; return VK_SUCCESS; } @@ -2270,7 +2159,7 @@ VkResult anv_CreateCommandPool( const VkCmdPoolCreateInfo* pCreateInfo, VkCmdPool* pCmdPool) { - *pCmdPool = 7; + pCmdPool->handle = 7; stub_return(VK_SUCCESS); } diff --git a/src/vulkan/meta.c b/src/vulkan/meta.c index 49c9aa9c563..8e2556b8218 100644 --- a/src/vulkan/meta.c +++ b/src/vulkan/meta.c @@ -523,6 +523,7 @@ meta_emit_blit(struct anv_cmd_buffer *cmd_buffer, VkExtent3D dest_extent) { struct anv_device *device = cmd_buffer->device; + VkDescriptorPool dummy_desc_pool = { .handle = 1 }; struct blit_vb_data { float pos[2]; @@ -588,7 +589,7 @@ meta_emit_blit(struct anv_cmd_buffer *cmd_buffer, uint32_t count; VkDescriptorSet set; - anv_AllocDescriptorSets(anv_device_to_handle(device), 0 /* pool */, + anv_AllocDescriptorSets(anv_device_to_handle(device), dummy_desc_pool, VK_DESCRIPTOR_SET_USAGE_ONE_SHOT, 1, &device->meta_state.blit.ds_layout, &set, &count); anv_UpdateDescriptorSets(anv_device_to_handle(device), diff --git a/src/vulkan/pipeline.c b/src/vulkan/pipeline.c index 218733aaf30..fdb632cd330 100644 --- a/src/vulkan/pipeline.c +++ b/src/vulkan/pipeline.c @@ -116,7 +116,7 @@ VkResult anv_CreatePipelineCache( const VkPipelineCacheCreateInfo* pCreateInfo, VkPipelineCache* pPipelineCache) { - *pPipelineCache = 1; + pPipelineCache->handle = 1; stub_return(VK_SUCCESS); } diff --git a/src/vulkan/private.h b/src/vulkan/private.h index 9c9190ab62a..cf8a869cdfd 100644 --- a/src/vulkan/private.h +++ b/src/vulkan/private.h @@ -1002,49 +1002,65 @@ void anv_device_finish_meta(struct anv_device *device); void *anv_lookup_entrypoint(const char *name); -#define ANV_DEFINE_CASTS(__anv_type, __VkType) \ -static inline struct __anv_type * \ -__anv_type ## _from_handle(__VkType _handle) \ -{ \ - return (struct __anv_type *) _handle; \ -} \ - \ -static inline __VkType \ -__anv_type ## _to_handle(struct __anv_type *_obj) \ -{ \ - return (__VkType) _obj; \ -} +#define ANV_DEFINE_HANDLE_CASTS(__anv_type, __VkType) \ + \ + static inline struct __anv_type * \ + __anv_type ## _from_handle(__VkType _handle) \ + { \ + return (struct __anv_type *) _handle; \ + } \ + \ + static inline __VkType \ + __anv_type ## _to_handle(struct __anv_type *_obj) \ + { \ + return (__VkType) _obj; \ + } -ANV_DEFINE_CASTS(anv_physical_device, VkPhysicalDevice) -ANV_DEFINE_CASTS(anv_instance, VkInstance) -ANV_DEFINE_CASTS(anv_queue, VkQueue) -ANV_DEFINE_CASTS(anv_device, VkDevice) -ANV_DEFINE_CASTS(anv_device_memory, VkDeviceMemory) -ANV_DEFINE_CASTS(anv_dynamic_vp_state, VkDynamicViewportState) -ANV_DEFINE_CASTS(anv_dynamic_rs_state, VkDynamicRasterState) -ANV_DEFINE_CASTS(anv_dynamic_ds_state, VkDynamicDepthStencilState) -ANV_DEFINE_CASTS(anv_dynamic_cb_state, VkDynamicColorBlendState) -ANV_DEFINE_CASTS(anv_descriptor_set_layout, VkDescriptorSetLayout) -ANV_DEFINE_CASTS(anv_descriptor_set, VkDescriptorSet) -ANV_DEFINE_CASTS(anv_pipeline_layout, VkPipelineLayout) -ANV_DEFINE_CASTS(anv_buffer, VkBuffer) -ANV_DEFINE_CASTS(anv_cmd_buffer, VkCmdBuffer) -ANV_DEFINE_CASTS(anv_fence, VkFence) -ANV_DEFINE_CASTS(anv_shader_module, VkShaderModule) -ANV_DEFINE_CASTS(anv_shader, VkShader) -ANV_DEFINE_CASTS(anv_pipeline, VkPipeline) -ANV_DEFINE_CASTS(anv_image, VkImage) -ANV_DEFINE_CASTS(anv_sampler, VkSampler) -ANV_DEFINE_CASTS(anv_attachment_view, VkAttachmentView) -ANV_DEFINE_CASTS(anv_buffer_view, VkBufferView); -ANV_DEFINE_CASTS(anv_image_view, VkImageView); -ANV_DEFINE_CASTS(anv_framebuffer, VkFramebuffer) -ANV_DEFINE_CASTS(anv_render_pass, VkRenderPass) -ANV_DEFINE_CASTS(anv_query_pool, VkQueryPool) +#define ANV_DEFINE_NONDISP_HANDLE_CASTS(__anv_type, __VkType) \ + \ + static inline struct __anv_type * \ + __anv_type ## _from_handle(__VkType _handle) \ + { \ + return (struct __anv_type *) _handle.handle; \ + } \ + \ + static inline __VkType \ + __anv_type ## _to_handle(struct __anv_type *_obj) \ + { \ + return (__VkType) { .handle = (uint64_t) _obj }; \ + } #define ANV_FROM_HANDLE(__anv_type, __name, __handle) \ struct __anv_type *__name = __anv_type ## _from_handle(__handle) +ANV_DEFINE_HANDLE_CASTS(anv_cmd_buffer, VkCmdBuffer) +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_NONDISP_HANDLE_CASTS(anv_attachment_view, VkAttachmentView) +ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer, VkBuffer) +ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_buffer_view, VkBufferView); +ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set, VkDescriptorSet) +ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_descriptor_set_layout, VkDescriptorSetLayout) +ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_device_memory, VkDeviceMemory) +ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_dynamic_cb_state, VkDynamicColorBlendState) +ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_dynamic_ds_state, VkDynamicDepthStencilState) +ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_dynamic_rs_state, VkDynamicRasterState) +ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_dynamic_vp_state, VkDynamicViewportState) +ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_fence, VkFence) +ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_framebuffer, VkFramebuffer) +ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image, VkImage) +ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_image_view, VkImageView); +ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline, VkPipeline) +ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_pipeline_layout, VkPipelineLayout) +ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_query_pool, VkQueryPool) +ANV_DEFINE_NONDISP_HANDLE_CASTS(anv_render_pass, VkRenderPass) +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) + #ifdef __cplusplus } #endif -- 2.30.2