Add C++20 module interface file and tests (#1582)

* feat: exported vk::raii types in vulkan.ixx, with a small test

* feat: *almost* complete vulkan.ixx; missing functions in vulkan_funcs.hpp and constexpr auto defines

* Exported free functions in `vulkan_funcs.hpp` in `vulkan.ixx`

* Completed vulkan.ixx

Exported all types, structs, functions; need to handle anonymous namespace and getDispatchLoaderStatic()

* Moved `vk::anon-namespace::throwResultException` to `vk::detail::throwResultException` to solve linking errors

* Made `vk::getDispatchLoaderStatic` not `static`

`static`in namespace/global scope has to do with internal/external linkage, and not lifetime

* Fixed debug assert fail in `generateCppModuleStructUsings`

* Removed references to `.cppm`

* Formatting and versioning changes

- CMake version handling simplified
- vulkan.ixx includes new structs from new versions
- vulkan.hpp and vulkan_raii.hpp reformatted with clang-format 14

* Removed extraneous includes

- std::optional -> std::string::empty
- std::filesystem was unused

* Fixed constexpr function and value generation
- 'c' prefix removed
- Constants casing fixed
- Types for constants fixed
- Constants assigned to macros
- Ordering of constants and consteval functions fixed

* Moved constexprs to `vulkan.hpp`

- Added corresponding `using` statements to `vulkan.ixx`
- Changed `consteval auto(auto)` functions into templated SFINAE `constexpr` functions

* Formatting, signposting, misc fixes

- 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

* Changed module file extension to `.cppm`

- It follows the rest of the project convention; `ixx` looks really weird next to `.hpp` and `.cpp`
- CMake transparently handles any extension anyway

* Added `VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE` to `vulkan.cppm`

* Added format traits and extension inspections

- Straightforward, since everything is hard-coded

* Added documentation about Vulkan-Hpp C++ module

- Compiler requirements
- CMake compilation
- Command-line examples

* Added vulkan_hash.hpp

- No need for `using`, since all declarations are template specialisations of existing `std` objects

* Documentation and comment fixes

- Removed extraneous CMake version comments
- Documentation about default dynamic dispatcher with the module
- Comment updates in the source code

* Moved constexpr defines and using statements 

- Moved to after resultUsings in both vulkan.hpp and vulkan.cppm
- Also split up constexprDefinesAndUsings
- Used const_cast for constexprDefines()

* Used std::string instead of std::stringstream

- Some changes also in previous commit
- Also removed overly-clever ranges algorithms

* Simplified protection generation

- Removed `generateNotProtection`
- Added optional `bool` parameter to `generateProtection` for `#if !defined( ... )`

* Simplified Cpp20Modules CMakeLists

- Made C++ standard and libraries into parameters
- Removed FindVulkan call; already done

* `constexpr` generation fixed

- Made all generating functions `const`
- Removed typos and extra comments
- Extracted out filtering functionality into separate functions

* Simplified defines partition generation

- 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

* Added `generateUsingsAndProtection` lambda to RAII name generation

* Moved around `partitionDefines` to make more sense

- called once at the end of the constructor
- edited comments

* Updated headers to 1.3.255

* Removed std::ranges and ranges view adaptors

- CI isn't passing with them

* Fixed constexpr functions for C++11 and C++14

- Removed `enable_if_t` and `is_integral_v` 
- Changed `auto` return type into `uint32_t`

---------

Co-authored-by: Sharadh Rajaraman <r.sharadh@yahoo.com.sg>
This commit is contained in:
Sharadh Rajaraman
2023-06-28 20:10:51 +08:00
committed by GitHub
parent 5d8c550b0d
commit 6c1996f068
12 changed files with 4208 additions and 153 deletions

View File

@@ -6027,7 +6027,7 @@ namespace VULKAN_HPP_NAMESPACE
}
extern VULKAN_HPP_STORAGE_API DispatchLoaderDynamic defaultDispatchLoaderDynamic;
# else
static inline ::VULKAN_HPP_NAMESPACE::DispatchLoaderStatic & getDispatchLoaderStatic()
inline ::VULKAN_HPP_NAMESPACE::DispatchLoaderStatic & getDispatchLoaderStatic()
{
static ::VULKAN_HPP_NAMESPACE::DispatchLoaderStatic dls;
return dls;
@@ -6688,9 +6688,9 @@ namespace VULKAN_HPP_NAMESPACE
IncompatibleShaderBinaryEXTError( char const * message ) : SystemError( make_error_code( Result::eErrorIncompatibleShaderBinaryEXT ), message ) {}
};
namespace
namespace detail
{
[[noreturn]] void throwResultException( Result result, char const * message )
[[noreturn]] VULKAN_HPP_INLINE void throwResultException( Result result, char const * message )
{
switch ( result )
{
@@ -6736,7 +6736,7 @@ namespace VULKAN_HPP_NAMESPACE
default: throw SystemError( make_error_code( result ), message );
}
}
} // namespace
} // namespace detail
#endif
template <typename T>
@@ -6896,7 +6896,7 @@ namespace VULKAN_HPP_NAMESPACE
#else
if ( result != Result::eSuccess )
{
throwResultException( result, message );
detail::throwResultException( result, message );
}
#endif
}
@@ -6911,10 +6911,106 @@ namespace VULKAN_HPP_NAMESPACE
#else
if ( std::find( successCodes.begin(), successCodes.end(), result ) == successCodes.end() )
{
throwResultException( result, message );
detail::throwResultException( result, message );
}
#endif
}
//=========================================
//=== CONSTEXPR CONSTANTs AND FUNCTIONs ===
//=========================================
VULKAN_HPP_CONSTEXPR uint32_t AttachmentUnused = VK_ATTACHMENT_UNUSED;
VULKAN_HPP_CONSTEXPR uint32_t False = VK_FALSE;
VULKAN_HPP_CONSTEXPR float LodClampNone = VK_LOD_CLAMP_NONE;
VULKAN_HPP_CONSTEXPR uint32_t LuidSize = VK_LUID_SIZE;
VULKAN_HPP_CONSTEXPR uint32_t MaxDescriptionSize = VK_MAX_DESCRIPTION_SIZE;
VULKAN_HPP_CONSTEXPR uint32_t MaxDeviceGroupSize = VK_MAX_DEVICE_GROUP_SIZE;
VULKAN_HPP_CONSTEXPR uint32_t MaxDriverInfoSize = VK_MAX_DRIVER_INFO_SIZE;
VULKAN_HPP_CONSTEXPR uint32_t MaxDriverNameSize = VK_MAX_DRIVER_NAME_SIZE;
VULKAN_HPP_CONSTEXPR uint32_t MaxExtensionNameSize = VK_MAX_EXTENSION_NAME_SIZE;
VULKAN_HPP_CONSTEXPR uint32_t MaxGlobalPrioritySizeKhr = VK_MAX_GLOBAL_PRIORITY_SIZE_KHR;
VULKAN_HPP_CONSTEXPR uint32_t MaxMemoryHeaps = VK_MAX_MEMORY_HEAPS;
VULKAN_HPP_CONSTEXPR uint32_t MaxMemoryTypes = VK_MAX_MEMORY_TYPES;
VULKAN_HPP_CONSTEXPR uint32_t MaxPhysicalDeviceNameSize = VK_MAX_PHYSICAL_DEVICE_NAME_SIZE;
VULKAN_HPP_CONSTEXPR uint32_t MaxShaderModuleIdentifierSizeExt = VK_MAX_SHADER_MODULE_IDENTIFIER_SIZE_EXT;
VULKAN_HPP_CONSTEXPR uint32_t QueueFamilyExternal = VK_QUEUE_FAMILY_EXTERNAL;
VULKAN_HPP_CONSTEXPR uint32_t QueueFamilyForeignExt = VK_QUEUE_FAMILY_FOREIGN_EXT;
VULKAN_HPP_CONSTEXPR uint32_t QueueFamilyIgnored = VK_QUEUE_FAMILY_IGNORED;
VULKAN_HPP_CONSTEXPR uint32_t Remaining3DSlicesExt = VK_REMAINING_3D_SLICES_EXT;
VULKAN_HPP_CONSTEXPR uint32_t RemainingArrayLayers = VK_REMAINING_ARRAY_LAYERS;
VULKAN_HPP_CONSTEXPR uint32_t RemainingMipLevels = VK_REMAINING_MIP_LEVELS;
VULKAN_HPP_CONSTEXPR uint32_t ShaderUnusedKhr = VK_SHADER_UNUSED_KHR;
VULKAN_HPP_CONSTEXPR uint32_t SubpassExternal = VK_SUBPASS_EXTERNAL;
VULKAN_HPP_CONSTEXPR uint32_t True = VK_TRUE;
VULKAN_HPP_CONSTEXPR uint32_t UuidSize = VK_UUID_SIZE;
VULKAN_HPP_CONSTEXPR uint64_t WholeSize = VK_WHOLE_SIZE;
VULKAN_HPP_CONSTEXPR uint32_t HeaderVersion = VK_HEADER_VERSION;
template <typename T, typename = typename std::enable_if<std::is_integral<T>::value>::type>
VULKAN_HPP_CONSTEXPR uint32_t apiVersionMajor( T const version )
{
return ( ( (uint32_t)( version ) >> 22U ) & 0x7FU );
}
template <typename T, typename = typename std::enable_if<std::is_integral<T>::value>::type>
VULKAN_HPP_CONSTEXPR uint32_t apiVersionMinor( T const version )
{
return ( ( (uint32_t)( version ) >> 12U ) & 0x3FFU );
}
template <typename T, typename = typename std::enable_if<std::is_integral<T>::value>::type>
VULKAN_HPP_CONSTEXPR uint32_t apiVersionPatch( T const version )
{
return ( (uint32_t)(version)&0xFFFU );
}
template <typename T, typename = typename std::enable_if<std::is_integral<T>::value>::type>
VULKAN_HPP_CONSTEXPR uint32_t apiVersionVariant( T const version )
{
return ( (uint32_t)( version ) >> 29U );
}
template <typename T, typename = typename std::enable_if<std::is_integral<T>::value>::type>
VULKAN_HPP_CONSTEXPR uint32_t makeApiVersion( T const variant, T const major, T const minor, T const patch )
{
return ( ( ( (uint32_t)( variant ) ) << 29U ) | ( ( (uint32_t)( major ) ) << 22U ) | ( ( (uint32_t)( minor ) ) << 12U ) | ( (uint32_t)( patch ) ) );
}
template <typename T, typename = typename std::enable_if<std::is_integral<T>::value>::type>
VULKAN_HPP_DEPRECATED( "This define is deprecated. VK_MAKE_API_VERSION should be used instead." )
VULKAN_HPP_CONSTEXPR uint32_t makeVersion( T const major, T const minor, T const patch )
{
return ( ( ( (uint32_t)( major ) ) << 22U ) | ( ( (uint32_t)( minor ) ) << 12U ) | ( (uint32_t)( patch ) ) );
}
template <typename T, typename = typename std::enable_if<std::is_integral<T>::value>::type>
VULKAN_HPP_DEPRECATED( "This define is deprecated. VK_API_VERSION_MAJOR should be used instead." )
VULKAN_HPP_CONSTEXPR uint32_t versionMajor( T const version )
{
return ( (uint32_t)( version ) >> 22U );
}
template <typename T, typename = typename std::enable_if<std::is_integral<T>::value>::type>
VULKAN_HPP_DEPRECATED( "This define is deprecated. VK_API_VERSION_MINOR should be used instead." )
VULKAN_HPP_CONSTEXPR uint32_t versionMinor( T const version )
{
return ( ( (uint32_t)( version ) >> 12U ) & 0x3FFU );
}
template <typename T, typename = typename std::enable_if<std::is_integral<T>::value>::type>
VULKAN_HPP_DEPRECATED( "This define is deprecated. VK_API_VERSION_PATCH should be used instead." )
VULKAN_HPP_CONSTEXPR uint32_t versionPatch( T const version )
{
return ( (uint32_t)(version)&0xFFFU );
}
VULKAN_HPP_CONSTEXPR auto ApiVersion = makeApiVersion( 0, 1, 0, 0 );
VULKAN_HPP_CONSTEXPR auto ApiVersion10 = makeApiVersion( 0, 1, 0, 0 );
VULKAN_HPP_CONSTEXPR auto ApiVersion11 = makeApiVersion( 0, 1, 1, 0 );
VULKAN_HPP_CONSTEXPR auto ApiVersion12 = makeApiVersion( 0, 1, 2, 0 );
VULKAN_HPP_CONSTEXPR auto ApiVersion13 = makeApiVersion( 0, 1, 3, 0 );
VULKAN_HPP_CONSTEXPR auto HeaderVersionComplete = makeApiVersion( 0, 1, 3, VK_HEADER_VERSION );
} // namespace VULKAN_HPP_NAMESPACE
// clang-format off