From 3db43e8f3e60f8dc746eb4ab2e86f6b1b32d248a Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Mon, 30 Nov 2015 10:31:44 -0800 Subject: [PATCH] vk/0.210.0: Switch to the new-style handle declarations --- include/vulkan/vk_ext_khr_device_swapchain.h | 2 +- include/vulkan/vulkan.h | 87 +++++++------------- src/vulkan/anv_descriptor_set.c | 4 +- src/vulkan/anv_device.c | 2 +- src/vulkan/anv_meta.c | 4 +- src/vulkan/anv_pipeline.c | 2 +- src/vulkan/anv_private.h | 4 +- 7 files changed, 38 insertions(+), 67 deletions(-) diff --git a/include/vulkan/vk_ext_khr_device_swapchain.h b/include/vulkan/vk_ext_khr_device_swapchain.h index 3bf73c84a96..af95ff0cdfb 100644 --- a/include/vulkan/vk_ext_khr_device_swapchain.h +++ b/include/vulkan/vk_ext_khr_device_swapchain.h @@ -41,7 +41,7 @@ extern "C" // ------------------------------------------------------------------------------------------------ // Objects -VK_DEFINE_NONDISP_HANDLE(VkSwapchainKHR); +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSwapchainKHR); // ------------------------------------------------------------------------------------------------ // Enumeration constants diff --git a/include/vulkan/vulkan.h b/include/vulkan/vulkan.h index 03bcefea50a..fd898736fc5 100644 --- a/include/vulkan/vulkan.h +++ b/include/vulkan/vulkan.h @@ -44,46 +44,17 @@ extern "C" { #define VK_API_VERSION VK_MAKE_VERSION(0, 170, 2) -#if defined(__cplusplus) && (_MSC_VER >= 1800 || __cplusplus >= 201103L) - #define VK_NULL_HANDLE nullptr -#else - #define VK_NULL_HANDLE 0 -#endif +#define VK_NULL_HANDLE 0 + + + +#define VK_DEFINE_HANDLE(object) typedef struct object##_T* object; -#define VK_DEFINE_HANDLE(obj) typedef struct obj##_T* obj; - - -#if defined(__cplusplus) - #if ((defined(_MSC_VER) && _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; } - #define VK_NONDISP_HANDLE_CONSTRUCTOR_FROM_UINT64(obj) \ - explicit obj(uint64_t x) : handle(x) { } \ - obj(decltype(nullptr)) : handle(0) { } - #else - #define VK_NONDISP_HANDLE_OPERATOR_BOOL() - #define VK_NONDISP_HANDLE_CONSTRUCTOR_FROM_UINT64(obj) \ - obj(uint64_t x) : handle(x) { } - #endif - #define VK_DEFINE_NONDISP_HANDLE(obj) \ - struct obj { \ - obj() : handle(0) { } \ - VK_NONDISP_HANDLE_CONSTRUCTOR_FROM_UINT64(obj) \ - 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; \ - }; +#if defined(__LP64__) || defined(_WIN64) || defined(__x86_64__) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__) + #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef struct object##_T *object; #else - #define VK_DEFINE_NONDISP_HANDLE(obj) typedef struct obj##_T { uint64_t handle; } obj; + #define VK_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object; #endif @@ -98,27 +69,27 @@ 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(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(VkFramebuffer) -VK_DEFINE_NONDISP_HANDLE(VkCmdPool) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkFence) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDeviceMemory) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkBuffer) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkImage) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSemaphore) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkEvent) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkQueryPool) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkBufferView) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkImageView) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkShaderModule) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkShader) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkPipelineCache) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkPipelineLayout) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkRenderPass) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkPipeline) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDescriptorSetLayout) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkSampler) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDescriptorPool) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkDescriptorSet) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkFramebuffer) +VK_DEFINE_NON_DISPATCHABLE_HANDLE(VkCmdPool) #define VK_LOD_CLAMP_NONE 1000.0f #define VK_REMAINING_MIP_LEVELS (~0U) diff --git a/src/vulkan/anv_descriptor_set.c b/src/vulkan/anv_descriptor_set.c index d518dfa34ba..22041b540d6 100644 --- a/src/vulkan/anv_descriptor_set.c +++ b/src/vulkan/anv_descriptor_set.c @@ -286,7 +286,7 @@ VkResult anv_CreateDescriptorPool( VkDescriptorPool* pDescriptorPool) { anv_finishme("VkDescriptorPool is a stub"); - pDescriptorPool->handle = 1; + *pDescriptorPool = (VkDescriptorPool)1; return VK_SUCCESS; } @@ -466,7 +466,7 @@ void anv_UpdateDescriptorSets( case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: for (uint32_t j = 0; j < write->count; j++) { - assert(write->pDescriptors[j].bufferInfo.buffer.handle); + assert(write->pDescriptors[j].bufferInfo.buffer); ANV_FROM_HANDLE(anv_buffer, buffer, write->pDescriptors[j].bufferInfo.buffer); assert(buffer); diff --git a/src/vulkan/anv_device.c b/src/vulkan/anv_device.c index 94bc4f11f27..aca082ac1b5 100644 --- a/src/vulkan/anv_device.c +++ b/src/vulkan/anv_device.c @@ -1336,7 +1336,7 @@ VkResult anv_CreateSemaphore( const VkSemaphoreCreateInfo* pCreateInfo, VkSemaphore* pSemaphore) { - pSemaphore->handle = 1; + *pSemaphore = (VkSemaphore)1; stub_return(VK_SUCCESS); } diff --git a/src/vulkan/anv_meta.c b/src/vulkan/anv_meta.c index c9e46a9286e..96792e9d6da 100644 --- a/src/vulkan/anv_meta.c +++ b/src/vulkan/anv_meta.c @@ -335,7 +335,7 @@ anv_device_init_meta_blit_state(struct anv_device *device) }, { .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, .stage = VK_SHADER_STAGE_FRAGMENT, - .shader = {0}, /* TEMPLATE VALUE! FILL ME IN! */ + .shader = VK_NULL_HANDLE, /* TEMPLATE VALUE! FILL ME IN! */ .pSpecializationInfo = NULL }, }; @@ -452,7 +452,7 @@ meta_emit_blit(struct anv_cmd_buffer *cmd_buffer, VkTexFilter blit_filter) { struct anv_device *device = cmd_buffer->device; - VkDescriptorPool dummy_desc_pool = { .handle = 1 }; + VkDescriptorPool dummy_desc_pool = (VkDescriptorPool)1; struct blit_vb_data { float pos[2]; diff --git a/src/vulkan/anv_pipeline.c b/src/vulkan/anv_pipeline.c index cf4bf9f87a0..a0606adaea6 100644 --- a/src/vulkan/anv_pipeline.c +++ b/src/vulkan/anv_pipeline.c @@ -189,7 +189,7 @@ VkResult anv_CreatePipelineCache( const VkPipelineCacheCreateInfo* pCreateInfo, VkPipelineCache* pPipelineCache) { - pPipelineCache->handle = 1; + *pPipelineCache = (VkPipelineCache)1; stub_return(VK_SUCCESS); } diff --git a/src/vulkan/anv_private.h b/src/vulkan/anv_private.h index d208b2d74a0..c99d4e0a59e 100644 --- a/src/vulkan/anv_private.h +++ b/src/vulkan/anv_private.h @@ -1537,13 +1537,13 @@ void anv_dump_image_to_ppm(struct anv_device *device, static inline struct __anv_type * \ __anv_type ## _from_handle(__VkType _handle) \ { \ - return (struct __anv_type *) _handle.handle; \ + return (struct __anv_type *)(uintptr_t) _handle; \ } \ \ static inline __VkType \ __anv_type ## _to_handle(struct __anv_type *_obj) \ { \ - return (__VkType) { .handle = (uint64_t) _obj }; \ + return (__VkType)(uintptr_t) _obj; \ } #define ANV_FROM_HANDLE(__anv_type, __name, __handle) \ -- 2.30.2