While the Vulkan-Hpp C++20 module can make Vulkan quite nice for beginners in the (hopefully near) future, it is currently still in a very experimental state and introduces breaking changes every now and then. This might frustrate newcomers who follow the tutorial.
Sections such as the one under 02_Development_environment are already outdated:
|
Vulkan has support for C{pp} modules which became available with c{pp}20. A |
|
large advantage of C{pp} modules is they give all the benefits of C{pp} without |
|
the overhead of long compile times. To do this, the .cppm file must be compiled |
|
for your target device. This tutorial demonstrates how to take advantage of C{pp} |
|
modules. However, to maximize compatibility across compilers and IDEs, the |
|
attachments template has C{pp}20 module support disabled by default, but it is |
|
recommended to enable it if your toolchain supports it. |
|
|
|
To enable the Vulkan C{pp}20 module in the attachments template, configure CMake with: |
|
|
|
[,bash] |
|
---- |
|
cmake -DENABLE_CPP20_MODULE=ON .. |
|
---- |
|
|
|
When enabled, the CMakeLists.txt contains all the instructions needed for building the |
|
module automatically. The relevant snippet looks like this: |
|
|
|
[,cmake] |
|
---- |
|
find_package (Vulkan REQUIRED) |
|
|
|
# set up Vulkan C++ module (enabled when ENABLE_CPP20_MODULE=ON) |
|
add_library(VulkanCppModule) |
|
add_library(Vulkan::cppm ALIAS VulkanCppModule) |
|
|
|
target_compile_definitions(VulkanCppModule PUBLIC |
|
VULKAN_HPP_DISPATCH_LOADER_DYNAMIC=1 |
|
VULKAN_HPP_NO_STRUCT_CONSTRUCTORS=1 |
|
) |
|
|
|
target_include_directories(VulkanCppModule PRIVATE "${Vulkan_INCLUDE_DIR}") |
|
|
|
target_link_libraries(VulkanCppModule PUBLIC Vulkan::Vulkan) |
|
|
|
set_target_properties(VulkanCppModule PROPERTIES CXX_STANDARD 20) |
|
|
|
target_sources(VulkanCppModule |
|
PUBLIC |
|
FILE_SET cxx_modules TYPE CXX_MODULES |
|
BASE_DIRS "${Vulkan_INCLUDE_DIR}" |
|
FILES "${Vulkan_INCLUDE_DIR}/vulkan/vulkan.cppm" |
|
) |
|
---- |
|
|
|
The VulkanCppModule target only needs to be defined once, then add it to the |
|
dependencies of your consuming project, and it will be built automatically. You |
|
won't need to also add Vulkan::Vulkan to your project. |
|
|
|
[,cmake] |
|
---- |
|
target_link_libraries (${PROJECT_NAME} Vulkan::cppm) |
|
---- |
|
|
|
If you choose to keep modules disabled (the default), you can continue to use the |
|
traditional header-based includes (e.g., `#include <vulkan/vulkan_raii.hpp>`). The |
|
sample code in the attachments is written to compile either way and will import the |
|
module only when `ENABLE_CPP20_MODULE=ON` (which defines `USE_CPP20_MODULES`). |
Once the module changes in KhronosGroup/Vulkan-Hpp#2443 are complete, I can update the tutorial sections regarding modules here, similar to the updates to our own README and tutorial we are working on in KhronosGroup/Vulkan-Hpp#2358.
Until then, it would probably be a good idea to very explictly mark that section as experimental, or at least write the matching SDK version for the shown sample.
While the Vulkan-Hpp C++20 module can make Vulkan quite nice for beginners in the (hopefully near) future, it is currently still in a very experimental state and introduces breaking changes every now and then. This might frustrate newcomers who follow the tutorial.
Sections such as the one under
02_Development_environmentare already outdated:Vulkan-Tutorial/en/02_Development_environment.adoc
Lines 127 to 184 in 0aad08a
Once the module changes in KhronosGroup/Vulkan-Hpp#2443 are complete, I can update the tutorial sections regarding modules here, similar to the updates to our own README and tutorial we are working on in KhronosGroup/Vulkan-Hpp#2358.
Until then, it would probably be a good idea to very explictly mark that section as experimental, or at least write the matching SDK version for the shown sample.