Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do non dispatchable handles use a ptr on 64bit platofrms?

Tags:

c

vulkan

Why are non dispatchable handles not always a uint64_t? Why is it neccessary that they are represented as a ptr on 64bit platforms?

#if !defined(VK_DEFINE_NON_DISPATCHABLE_HANDLE)
#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__) ) || 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_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t object;
#endif
#endif

The spec says

Non-dispatchable handle types are a 64-bit integer type whose meaning is implementation-dependent, and may encode object information directly in the handle rather than acting as a reference to an underlying object. Objects of a non-dispatchable type may not have unique handle values within a type or across types. If handle values are not unique, then destroying one such handle must not cause identical handles of other types to become invalid, and must not cause identical handles of the same type to become invalid if that handle value has been created more times than it has been destroyed.

like image 528
Maik Klein Avatar asked Feb 03 '26 16:02

Maik Klein


1 Answers

It isn't necessary that they use pointers, only that they are 64 bit.

The reason pointers are used when possible is because C and C++ don't have strong typedefs so using pointers give a little bit of extra type safety because you cannot assign a VkImageView_T* to a VkImage_T*.

like image 192
ratchet freak Avatar answered Feb 06 '26 11:02

ratchet freak