c - 为什么不可分派(dispatch)句柄在 64 位平台上使用 ptr?

标签 c vulkan

为什么不可分派(dispatch)的句柄不总是 uint64_t?为什么在 64 位平台上必须将它们表示为 ptr

#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

规范说

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.

最佳答案

它们不一定使用指针,只是它们是 64 位的。

尽可能使用指针的原因是因为 C 和 C++ 没有强类型定义,所以使用指针可以提供一点额外的类型安全性,因为您不能将 VkImageView_T* 分配给 >VkImage_T*.

关于c - 为什么不可分派(dispatch)句柄在 64 位平台上使用 ptr?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51743500/

相关文章:

textures - 在 Vulkan 中从数组创建纹理的步骤是什么?

python - 对于多平台 GPGPU 计算,是否有 OpenCL+PyOpenCL 的替代方案?

c - 为什么,当我将 char[] 转换为 int 时,是否会得到按字节反转

c - 防止内核处理绑定(bind)到原始套接字的 TCP 段

c++ - 将 `VkImage` 清除为单一颜色的最佳方法是什么?

c++ - vk::DeviceQueueCreateFlags() 实际上做了什么?

gpu - Vulkan 管道 + 颜色附件

c - pthread_create 是否从指针复制参数值?

c - 编译C代码后出错

c - 在 debugfs 中实现读取操作列表