Skip to content

Modularize samples - #2667

Open
sharadhr wants to merge 37 commits into
KhronosGroup:mainfrom
sharadhr:feature/modularize-samples
Open

sharadhr wants to merge 37 commits into
KhronosGroup:mainfrom
sharadhr:feature/modularize-samples

Conversation

@sharadhr

Copy link
Copy Markdown
Contributor

An experiment to modularise the samples. utils and RAII_utils are provided as named modules, and all the samples consume them as executables in normal translation units.

This is largely AI-generated (not this commit message), and linker errors are still seen in my local experiments. Do not merge yet.

@sharadhr
sharadhr force-pushed the feature/modularize-samples branch from d24f9db to 6607f92 Compare August 23, 2026 20:48
@sharadhr
sharadhr marked this pull request as ready for review August 24, 2026 16:43
@sharadhr

Copy link
Copy Markdown
Contributor Author

I think this is mostly ready, but this branch also includes changes to make Vulkan-Hpp ready for proposed changes in CMake 4.5 that aren't in the public releases yet. These include temporary changes in CI to pull and build with CMake's nightly builds.

Additionally, the MSVC build appears to fail regularly with the following error:

FAILED: [code=2] RAII_Samples/utils/CMakeFiles/RAII_utils_module@synth_0.dir/e9d132dddfaf.bmi 
"C:\Program Files\Microsoft Visual Studio\18\Enterprise\VC\Tools\MSVC\14.51.36231\bin\Hostx64\x64\cl.exe"  /nologo /TP -DVK_NO_PROTOTYPES -DVK_USE_PLATFORM_WIN32_KHR -DVULKAN_HPP_DISPATCH_LOADER_DYNAMIC -ID:\a\Vulkan-Hpp\Vulkan-Hpp\glfw\include -ID:\a\Vulkan-Hpp\Vulkan-Hpp\glm -ID:\a\Vulkan-Hpp\Vulkan-Hpp\glslang\glslang\.. -ID:\a\Vulkan-Hpp\Vulkan-Hpp\build\include -ID:\a\Vulkan-Hpp\Vulkan-Hpp\glslang\SPIRV\.. -ID:\a\Vulkan-Hpp\Vulkan-Hpp -ID:\a\Vulkan-Hpp\Vulkan-Hpp\Vulkan-Headers\include /EHsc /Zi /Ob0 /Od /RTC1 -std:c++latest -MDd -ifcOnly -ifcOutput RAII_Samples\utils\CMakeFiles\RAII_utils_module@synth_0.dir\e9d132dddfaf.bmi /showIncludes @RAII_Samples\utils\CMakeFiles\RAII_utils_module@synth_0.dir\e9d132dddfaf.bmi.modmap /FoRAII_Samples\utils\CMakeFiles\RAII_utils_module@synth_0.dir\e9d132dddfaf.bmi /Fd"" /FS -c D:\a\Vulkan-Hpp\Vulkan-Hpp\RAII_Samples\utils\RAII_utils.cppm
RAII_utils.cppm
D:\a\Vulkan-Hpp\Vulkan-Hpp\RAII_Samples\utils\RAII_utils.cppm: fatal error C1041: cannot open program database 'D:\a\Vulkan-Hpp\Vulkan-Hpp\build\vc140.pdb'; if multiple CL.EXE write to the same .PDB file, please use /FS

The invocation does contain /FS, but it still shows up. I think I may set CMAKE_MSVC_DEBUG_INFORMATION_FORMAT to Embedded as a fix. @asuessenbach do you have any possible thoughts on fixing this?

Additionally as a stretch goal I want to provide benchmarks, as I think this build of the samples is a reasonably complex attempt at a (mostly) modularised project. To give some preliminary data, I am seeing something like a 2× speedup over a pure header build, and it is slightly slower than the PCH build, but changing a header (and therefore changing the PCH interface and module interface) is much faster. I suspect there is plenty of low-hanging fruit to resolve to speed up the module build.

@M2-TE

M2-TE commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Do you encounter the MSVC build errors only on CI, or also on local runs?
There was an MSVC issue with FS access during async operations when we generated headers in parallel.
Tried to fix it a bunch of times but never managed, here was the first time I tried: #2084
Figured they may be related.

I suspect there is plenty of low-hanging fruit to resolve to speed up the module build.

Indeed. Something that may be even more important than full compilation benchmarks would be iterative builds. Leave the PCH/module as is and just change code that includes/imports those. PCHs are quite large so perhaps there's a measurable difference there. Binary size may also be of note.

@asuessenbach

Copy link
Copy Markdown
Contributor

There's one thing that makes me wonder: where does that Vulkan-Hpp\build\vc140.pdb come from?
I think, every sample uses a separate directory to store its pdb file?

@M2-TE

M2-TE commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

The utils module is shared between the samples; thats where the concurrent access should be coming from

@sharadhr

Copy link
Copy Markdown
Contributor Author

Do you encounter the MSVC build errors only on CI, or also on local runs?

I saw it locally in a previous commit, but it seems to have gone away.

@sharadhr

sharadhr commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Ah. The macOS build fails because that workflow uses CMake 4.1.2, whereas I have modified the CMakeLists to expect 4.5 behaviour (removed CXX_IMPORT_STD etc).

@sharadhr
sharadhr force-pushed the feature/modularize-samples branch 3 times, most recently from 5e28bdf to 0c481b9 Compare September 4, 2026 17:45
@sharadhr
sharadhr marked this pull request as draft September 15, 2026 13:24
@sharadhr
sharadhr force-pushed the feature/modularize-samples branch 6 times, most recently from 6e27097 to 2e3252d Compare September 27, 2026 14:28
@sharadhr
sharadhr force-pushed the feature/modularize-samples branch 5 times, most recently from 8eb807c to 88d4e79 Compare October 18, 2026 22:36
@sharadhr
sharadhr force-pushed the feature/modularize-samples branch from 88d4e79 to a57a2d0 Compare October 27, 2026 22:23
CMake 4.5.0 has been released, so install it with lukka/get-cmake
(`latest`) rather than downloading a pinned nightly.
Extract common target setup and Vulkan include-dir logic into shared helpers, and collapse the repetitive option -> compile-definition checks into a loop. Prepares for modularizing sample target setup.
Replace vulkan_hpp__setup_sample_static/_dynamic with a single parametrized vulkan_hpp__setup_sample_variant, removing duplicate wrapper functions and their ~50 call sites.
Needed to reuse it for glm's and (later) utils'/RAII_utils' own modules,
not just Vulkan's.
Optionally skip the plain variant (VULKAN_HPP_SAMPLES_BUILD_MODULES_ONLY)
for faster module-only iteration.
Platform-conditional constants are baked in at build time; without this
they're missing depending on which platform macro was set.
Reordering GLFW after Vulkan needs windows.h's APIENTRY/NOMINMAX
defined first, so use vulkan/vulkan.h (not vulkan_core.h) and define
NOMINMAX up front.
Modules do not expose macros or incidental declarations from textual headers. Import standard and GLM facilities explicitly, prefer Vulkan-Hpp constants, and isolate required C API headers before module imports.
Import dependencies explicitly, qualify standard-library calls in exported templates, and avoid relying on macros or declarations leaked by textual includes.
Import std directly and neutralize Windows macro collisions so isolated module builds do not depend on textual-header side effects.
Use CMake 4.5's automatic import std support, make module mode select MODULE_* samples without PCHs, and inherit Vulkan-Hpp configuration through module utility targets. Anchor module file sets for isolated test builds.
@sharadhr
sharadhr force-pushed the feature/modularize-samples branch from a57a2d0 to 9826aa6 Compare November 13, 2026 20:59
@sharadhr
sharadhr marked this pull request as ready for review November 13, 2026 21:26
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 this pull request may close these issues.

3 participants