-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Here's my understanding of VULKAN_HPP_TYPESAFE_CONVERSION:
- When targeting 64-bit, implicit conversion of vulkan handles is typesafe. As a result,
VULKAN_HPP_TYPESAFE_CONVERSIONis enabled by default.VULKAN_HPP_TYPESAFE_CONVERSIONis automatically enabled whenVK_USE_64_BIT_PTR_DEFINESis set. The latter is only set when defines like__x86_64__are set by the compiler.
- When targeting 32-bit,
VULKAN_HPP_TYPESAFE_CONVERSIONis not set. - When targeting 32-bit, turning on
VULKAN_HPP_TYPESAFE_CONVERSIONis not typesafe. But it can be turned on anyway. VULKAN_HPP_TYPESAFE_CONVERSIONtriggers the generation of some code.- When targeting 32-bit, this code causes a "conditional expression is ambiguous" when a vulkan handle and a
VK_NULL_HANDLEis used in a ternary expression. Before Disambiguate conditional expressions engine#51285, this can be reproduced by settingVULKAN_HPP_TYPESAFE_CONVERSIONto the:vulkan_headers_confighere - Disambiguate conditional expressions engine#51285 allows the GN build to compile successfully both with and without
VULKAN_HPP_TYPESAFE_CONVERSION
- When targeting 32-bit, this code causes a "conditional expression is ambiguous" when a vulkan handle and a
- Internally,
VULKAN_HPP_TYPESAFE_CONVERSIONis set unconditionally whether we're targeting 32-bit or 64-bit platforms (see details in b/328355475).
Here is what the vulkan docs say:
On 64-bit platforms Vulkan-Hpp supports implicit conversions between C++ Vulkan handles and C Vulkan handles. On 32-bit platforms all non-dispatchable handles are defined as
uint64_t, thus preventing type-conversion checks at compile time which would catch assignments between incompatible handle types. Due to that Vulkan-Hpp does not enable implicit conversion for 32-bit platforms by default and it is recommended to use astatic_castfor the conversion like this:VkImage = static_cast<VkImage>(cppImage)to prevent converting some arbitrary int to a handle or vice versa by accident. If you're developing your code on a 64-bit platform, but want compile your code for a 32-bit platform without adding the explicit casts you can defineVULKAN_HPP_TYPESAFE_CONVERSIONto 1 in your build system or before includingvulkan.hpp. On 64-bit platforms this define is set to 1 by default and can be set to 0 to disable implicit conversions.
The goal for this issue would be to better align the internal build with the GN build here so that errors can be surfaced before they roll in. We could either:
- Set
VULKAN_HPP_TYPESAFE_CONVERSIONfor the GN build - Make the
VULKAN_HPP_TYPESAFE_CONVERSIONsetting internally conditional on whether the build is targeting 32-bit or 64-bit
All this is quite new to me, but it seems like the latter would be better for better type safety. This might take more effort to push through depending on whether there are other vulkan clients that are depending on the current behavior though.