-
Notifications
You must be signed in to change notification settings - Fork 304
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
Add C++20 module interface file and tests #1582
Conversation
With respect to c416dc2, the tests that make reference to it, specifically I am using MSVC 19.35, Visual Studio 2022, CMake 3.26, Ninja 1.11.0. Not sure if they are broken tests or I'm doing something wrong. |
I was also thinking if we should add signpost comments to
so that users know where each type is defined. Of course, IDEs come with a go-to-definition/declaration feature, but maybe this is useful. Any thoughts? |
Experimenting with exporting vulkan module I came to a point, where compiler started to complain about std::weak_ordering and other structs, I had to resort to VULKAN_HPP_NO_SPACESHIP_OPERATOR definition. Is that solved somehow? |
@Agrael1, I have written a simple test, where I simply re-defined the While Visual Studio's IntelliSense doesn't detect the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, what a big PR!
And an important one as well. I'm pretty sure, having vulkan.hpp as a module will be very much appreciated by everyone who suffers from the long compile times when including it.
So, thanks a lot for your contribution here!
Besides all my comments below: maybe you could switch to a different clang-format version, to prevent all the formatting differences in vulkan.hpp and vulkan_raii.hpp. I think, 14.x is a good choice.
f50b70e
to
2514ab0
Compare
9e456b9
to
378087f
Compare
Okay; at this juncture, I think the PR is ready for complete review; I will move it from draft mode. Everything in the bag is included in When this is merged, I will post in CMake's forum about this, and hopefully the As for the CI, I have used some C++20 functionality (ranges and I look forward to hearing what you guys have to say. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For all those simple " using VULKAN_HPP_NAMESPACE::${name}" replacements, it's probably easier to just use that text and concatenate the name instead of calling replaceWithMap.
clang++-12 on Ubuntu seems to have issues with ranges... any idea what that is and how to resolve that? |
I think clang++12 is a bit too old for ranges, but I'm not sure. The library certainly appears to be recent enough, it's libstdc++ 12... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't const_cast
.
If you think the logic is too complex to be repeated, once for the constants and functions and once for the usings, you could introduce some preparing non-const function called in the VulkanHppGenerator constructor.
- std::optional -> std::string::empty - std::filesystem was unused
- 'c' prefix removed - Constants casing fixed - Types for constants fixed - Constants assigned to macros - Ordering of constants and consteval functions fixed
- Added corresponding `using` statements to `vulkan.ixx` - Changed `consteval auto(auto)` functions into templated SFINAE `constexpr` functions
- Added newlines around macro guards - Added signposting comments for relevant groups of `using`-statements in `vulkan.ixx` - Guarded createInstanceUnique with macro guard - Use m_handles.at("").commands for Funcs
- It follows the rest of the project convention; `ixx` looks really weird next to `.hpp` and `.cpp` - CMake transparently handles any extension anyway
- Straightforward, since everything is hard-coded
- Compiler requirements - CMake compilation - Command-line examples
- No need for `using`, since all declarations are template specialisations of existing `std` objects
- Removed extraneous CMake version comments - Documentation about default dynamic dispatcher with the module - Comment updates in the source code
- Moved to after resultUsings in both vulkan.hpp and vulkan.cppm - Also split up constexprDefinesAndUsings - Used const_cast for constexprDefines()
- Some changes also in previous commit - Also removed overly-clever ranges algorithms
- Removed `generateNotProtection` - Added optional `bool` parameter to `generateProtection` for `#if !defined( ... )`
- Made C++ standard and libraries into parameters - Removed FindVulkan call; already done
- Made all generating functions `const` - Removed typos and extra comments - Extracted out filtering functionality into separate functions
- Added `DefinesPartition` struct as a member variable - Added non-const function to write to the above in `readTypeDefines` - Removed previous implementation that made many copies
- called once at the end of the constructor - edited comments
- CI isn't passing with them
Okay; looks like the way I have implemented the macro functions needs to change if we are to make them work for C++11. I need to remove the I was thinking about requiring |
I think, staying with |
- Removed `enable_if_t` and `is_integral_v` - Changed `auto` return type into `uint32_t`
Your PR looks great now and passes all CI steps! |
I think I have nothing left to add! Thanks for assisting me with all the reviews; I think it is also ready to merge. |
It was a pleasure to review your PR. |
Resolves #1580.
VulkanHppGenerator
andCMakeLists.txt
have been modified to produce a C++20vulkan.cppm
module file that exports all types, structs, functions, names, handles, etc. used by Vulkan in the module,vulkan
. C++20 users can now consume all ofVulkan-Hpp
with a single line:import vulkan;
.Additional new features include
consteval auto
functions for macros that take numeric parameters, andconstexpr auto
variables for macros, both prefaced withc
. So,VK_MAKE_API_VERSION
is nowvk::makeApiVersion
, and isconsteval
-callable. A notable exclusion isVK_DEFINE_HANDLE
, which performs macro magic, and cannot really beconsteval
-ed, trivially.This is still a draft, as MSVC emits errors and warnings pertaining toResolved with 32d5a69 and c416dc2.vk::getDispatchLoaderStatic()
being declared but not defined, andvk::anonymous-namespace::throwResultException()
being, well, in an anonymous namespace.This is an RFC and I'm looking for feedback on my code. There are still a few things to be done, besides correcting the above-mentioned warnings and errors:
using vulkan;
;As mentioned in theResolved with 7b4969b.TODO
, some of the free functions invulkan_funcs.hpp
were eye-balled and hard-coded into the generator. It is very difficult to follow the recursivegenerateCommand...
functions, and I'm hoping the maintainers have some input for this...vulkan.hpp
andvulkan_raii.hpp
indeed were exported, and they are correctly guarded by macros;Export types fromResolved with 09a1177.vulkan_format_traits.hpp
,vulkan_extension_inspection.hpp
andvulkan_hash.hpp
.Thanks, and all feedback is welcome.