aboutsummaryrefslogtreecommitdiffstats
path: root/src/vulkan
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2020-04-21 15:03:58 -0500
committerMarge Bot <[email protected]>2020-05-04 14:06:27 +0000
commit73fb7cdbe1c8ce476f21cb6d39944a96151ec4b5 (patch)
tree32610a036afe7b16be791e2c4c97eded5699a182 /src/vulkan
parent682c81bdfb7ea28efccea1e8cbfeb7cfc67d02b8 (diff)
vulkan,anv: Move the DEFINE_HANDLE_CASTS macros to vk_object.h
We've already got these duplicated a bunch of places. They should really probably live in common code. The new versions take two more arguments: 1. The struct member which gets you from __driver_type to the vk_object_base. This requires drivers which use this to also use vk_object_base. 2. The VkObjectType enum which represents that object type. Reviewed-by: Lionel Landwerlin <[email protected]> Acked-by: Kristian H. Kristensen <[email protected]> Acked-by: Bas Nieuwenhuizen <[email protected]> Reviewed-by: Samuel Pitoiset <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4690>
Diffstat (limited to 'src/vulkan')
-rw-r--r--src/vulkan/util/vk_object.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/vulkan/util/vk_object.h b/src/vulkan/util/vk_object.h
index c2b3926133e..f91cc1640a0 100644
--- a/src/vulkan/util/vk_object.h
+++ b/src/vulkan/util/vk_object.h
@@ -55,6 +55,37 @@ void vk_device_init(struct vk_device *device,
const VkAllocationCallbacks *device_alloc);
void vk_device_finish(struct vk_device *device);
+#define VK_DEFINE_HANDLE_CASTS(__driver_type, __base, __VkType, __VK_TYPE) \
+ static inline struct __driver_type * \
+ __driver_type ## _from_handle(__VkType _handle) \
+ { \
+ STATIC_ASSERT(offsetof(struct __driver_type, __base) == 0); \
+ return (struct __driver_type *) _handle; \
+ } \
+ \
+ static inline __VkType \
+ __driver_type ## _to_handle(struct __driver_type *_obj) \
+ { \
+ return (__VkType) _obj; \
+ }
+
+#define VK_DEFINE_NONDISP_HANDLE_CASTS(__driver_type, __base, __VkType, __VK_TYPE) \
+ static inline struct __driver_type * \
+ __driver_type ## _from_handle(__VkType _handle) \
+ { \
+ STATIC_ASSERT(offsetof(struct __driver_type, __base) == 0); \
+ return (struct __driver_type *)(uintptr_t) _handle; \
+ } \
+ \
+ static inline __VkType \
+ __driver_type ## _to_handle(struct __driver_type *_obj) \
+ { \
+ return (__VkType)(uintptr_t) _obj; \
+ }
+
+#define VK_FROM_HANDLE(__driver_type, __name, __handle) \
+ struct __driver_type *__name = __driver_type ## _from_handle(__handle)
+
#ifdef __cplusplus
}
#endif