Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defining VULKAN_HPP_NO_EXCEPTIONS when using C++ modules results in missing vk::raii members #1648

Closed
Zingam opened this issue Aug 27, 2023 · 8 comments · Fixed by #1650
Closed

Comments

@Zingam
Copy link

Zingam commented Aug 27, 2023

I'm experimenting with the C++ module and I have created the following working setup (the example one in the README.md doesn't work):

# RToolBox\cmake\VulkanHPP.cmake
include_guard()

# find Vulkan SDK
find_package("Vulkan" REQUIRED)

# set up Vulkan C++ module
add_library("VulkanCppModule")
add_library("vulkan::cppm" ALIAS "VulkanCppModule")

target_compile_definitions("VulkanCppModule"
  PUBLIC
    # Disable exceptions
    "VULKAN_HPP_NO_EXCEPTIONS"
    # Enable designated initializers
    "VULKAN_HPP_NO_STRUCT_CONSTRUCTORS"

)
target_compile_features("VulkanCppModule"
  PUBLIC
    cxx_std_23
)
target_include_directories("VulkanCppModule"
  PRIVATE
    "${Vulkan_INCLUDE_DIR}"
)
target_link_libraries("VulkanCppModule"
  PUBLIC
    "Vulkan::Vulkan"
)

target_sources("VulkanCppModule"
  PUBLIC
    FILE_SET cxx_modules TYPE CXX_MODULES
    BASE_DIRS
      "${Vulkan_INCLUDE_DIR}"
    FILES
      "${Vulkan_INCLUDE_DIR}/vulkan/vulkan.cppm"
)

Build errors:

[build] vulkan.cppm
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2915): error C2039: 'Context': is not a member of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2909): note: see declaration of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2915): error C2873: 'Context': symbol cannot be used in a using-declaration
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2916): error C2039: 'ContextDispatcher': is not a member of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2909): note: see declaration of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2916): error C2873: 'ContextDispatcher': symbol cannot be used in a using-declaration
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2917): error C2039: 'DeviceDispatcher': is not a member of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2909): note: see declaration of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2917): error C2873: 'DeviceDispatcher': symbol cannot be used in a using-declaration
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2918): error C2039: 'exchange': is not a member of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2909): note: see declaration of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2918): error C2873: 'exchange': symbol cannot be used in a using-declaration
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2919): error C2039: 'InstanceDispatcher': is not a member of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2909): note: see declaration of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2919): error C2873: 'InstanceDispatcher': symbol cannot be used in a using-declaration
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2926): error C2039: 'Buffer': is not a member of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2909): note: see declaration of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2926): error C2873: 'Buffer': symbol cannot be used in a using-declaration
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2927): error C2039: 'BufferView': is not a member of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2909): note: see declaration of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2927): error C2873: 'BufferView': symbol cannot be used in a using-declaration
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2928): error C2039: 'CommandBuffer': is not a member of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2909): note: see declaration of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2928): error C2873: 'CommandBuffer': symbol cannot be used in a using-declaration
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2929): error C2039: 'CommandBuffers': is not a member of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2909): note: see declaration of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2929): error C2873: 'CommandBuffers': symbol cannot be used in a using-declaration
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2930): error C2039: 'CommandPool': is not a member of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2909): note: see declaration of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2930): error C2873: 'CommandPool': symbol cannot be used in a using-declaration
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2931): error C2039: 'DescriptorPool': is not a member of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2909): note: see declaration of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2931): error C2873: 'DescriptorPool': symbol cannot be used in a using-declaration
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2932): error C2039: 'DescriptorSet': is not a member of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2909): note: see declaration of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2932): error C2873: 'DescriptorSet': symbol cannot be used in a using-declaration
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2933): error C2039: 'DescriptorSetLayout': is not a member of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2909): note: see declaration of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2933): error C2873: 'DescriptorSetLayout': symbol cannot be used in a using-declaration
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2934): error C2039: 'DescriptorSets': is not a member of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2909): note: see declaration of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2934): error C2873: 'DescriptorSets': symbol cannot be used in a using-declaration
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2935): error C2039: 'Device': is not a member of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2909): note: see declaration of 'vk::raii'
[build] C:\SDKs\VulkanSDK\1.3.261.0\Include\vulkan\vulkan.cppm(2935): error C2873: 'Device': symbol cannot be used in a using-declaration

... etc...
@theHamsta
Copy link
Contributor

It seems that the VULKAN_HPP_NO_EXCEPTIONS disables all RAII definitions https://github.com/KhronosGroup/Vulkan-Hpp/blob/17fa2b92f7f63c6922efbcd2a9b48e321a7b9b2a/vulkan/vulkan_raii.hpp#L19. I'm wondering whether this should disable the exports, too, or whether there should be a VULKAN_HPP_NO_EXCEPTIONS version of the RAII header

@Zingam
Copy link
Author

Zingam commented Aug 28, 2023

This may or may not be related: #1498

@asuessenbach
Copy link
Contributor

You're absolutely right, this is related to #1498.
But as long as that's not implemented, the using vk::raii-names in vulkan.cppm need to be guarded by #if !defined( VULKAN_HPP_DISABLE_ENHANCED_MODE ) && !defined( VULKAN_HPP_NO_EXCEPTIONS ), just as in vulkan_raii.hpp.
Thanks a lot for reporting that issue! Will be fixed asap.

@asuessenbach
Copy link
Contributor

the example one in the README.md doesn't work

What problems do you have with the example from the README.md?

@Zingam
Copy link
Author

Zingam commented Aug 28, 2023

the example one in the README.md doesn't work

What problems do you have with the example from the README.md?

From the tip of my head I had to add all these lines:

# find Vulkan SDK
find_package( Vulkan REQUIRED )

+target_compile_features("VulkanCppModule"
+  PUBLIC
+    cxx_std_23
+)
+target_include_directories("VulkanCppModule"
+  PRIVATE
+    "${Vulkan_INCLUDE_DIR}"
+)
+target_link_libraries("VulkanCppModule"
+  PUBLIC
+    "Vulkan::Vulkan"
+)

# set up Vulkan C++ module
add_library(VulkanCppModule)
-target_sources(VulkanCppModule PRIVATE
+  target_sources(VulkanCppModule PUBLIC
-   FILE_SET CXX_MODULES
+  FILE_SET cxx_modules TYPE CXX_MODULES
+  BASE_DIRS "${Vulkan_INCLUDE_DIR}"
  FILES ${Vulkan_INCLUDE_DIR}/vulkan.cppm
)

target_compile_features is probably not needed but the rest IMO are required at least in my setup to get the module build and be imported correctly, especially BASE_DIR. I also think linking against Vulkan::Vulkan is should be done in this "module".

@Zingam
Copy link
Author

Zingam commented Aug 28, 2023

@asuessenbach Thank you for the quick reaction!

@Zingam
Copy link
Author

Zingam commented Aug 29, 2023

the example one in the README.md doesn't work

What problems do you have with the example from the README.md?

I finally found the C++20 module sample and it add almost the same additional settings as mine setup above:

target_sources( VulkanHppModule

Maybe the instructions on the README page need to be updated.

@H-G-Hristov
Copy link

Also the README recommends using vulkan-hpp with vcpkg but the ports itself instructs to use another port: vulkan-headers

https://github.com/microsoft/vcpkg/blob/master/ports/vulkan-hpp/usage

Screenshot 2023-08-29 at 18 22 14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants