Skip to content

Consider using VULKAN_HPP_TYPESAFE_CONVERSION #144916

@jiahaog

Description

@jiahaog

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_CONVERSION is enabled by default.
    • VULKAN_HPP_TYPESAFE_CONVERSION is automatically enabled when VK_USE_64_BIT_PTR_DEFINES is set. The latter is only set when defines like __x86_64__ are set by the compiler.
  • When targeting 32-bit, VULKAN_HPP_TYPESAFE_CONVERSION is not set.
  • When targeting 32-bit, turning on VULKAN_HPP_TYPESAFE_CONVERSION is not typesafe. But it can be turned on anyway.
  • VULKAN_HPP_TYPESAFE_CONVERSION triggers the generation of some code.
  • Internally, VULKAN_HPP_TYPESAFE_CONVERSION is 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 a static_cast for 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 define VULKAN_HPP_TYPESAFE_CONVERSION to 1 in your build system or before including vulkan.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_CONVERSION for the GN build
  • Make the VULKAN_HPP_TYPESAFE_CONVERSION setting 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.

cc @chinmaygarde

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: proposalA detailed proposal for a change to Flutterengineflutter/engine related. See also e: labels.team-engineOwned by Engine teamtriaged-engineTriaged by Engine team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions