Merge pull request #1132 from Saalvage/more-constexpr

More support for constexpr
This commit is contained in:
Andreas Süßenbach 2021-11-15 17:59:19 +01:00 committed by GitHub
commit 323c921a19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 4522 additions and 3831 deletions

View File

@ -29,13 +29,12 @@ To build the local samples and tests you'll have to clone this repository and ru
1. Open a shell which provides git and clone the repository with: 1. Open a shell which provides git and clone the repository with:
```git clone --recurse-submodules https://github.com/KhronosGroup/Vulkan-Hpp.git``` ```git clone --recurse-submodules https://github.com/KhronosGroup/Vulkan-Hpp.git```
2. Change the current directory to the newly created Vulkan-Hpp directory. 2. Change the current directory to the newly created Vulkan-Hpp directory.
3. Create a new folder named ```build``` and change the current directory to the newly created folder. 3. Create a build environment with CMake
4. Create a build environment with CMake ```cmake -D DSAMPLES_BUILD_WITH_LOCAL_VULKAN_HPP=ON -DSAMPLES_BUILD=ON -DTESTS_BUILD_WITH_LOCAL_VULKAN_HPP=ON -DTESTS_BUILD=ON -B build```
```cmake -D DSAMPLES_BUILD_WITH_LOCAL_VULKAN_HPP=ON -DSAMPLES_BUILD=ON -DTESTS_BUILD_WITH_LOCAL_VULKAN_HPP=ON -DTESTS_BUILD=ON -G "<generator>" ..``` You might have to specify a generator via `-G`, for a full list of generators execute ```cmake -G```.
For a full list of generators execute ```cmake -G```.
* To rebuild `vulkan.hpp` from the `vk.xml` XML registry file, add the * To rebuild `vulkan.hpp` from the `vk.xml` XML registry file, add the
`-DVULKAN_HPP_RUN_GENERATOR=ON` option to the CMake command line. `-DVULKAN_HPP_RUN_GENERATOR=ON` option to the CMake command line.
5. Either open the generated project with an IDE, e.g. Visual Studio or launch the build process with ```cmake --build .```. 4. Either open the generated project with an IDE, e.g. Visual Studio or launch the build process with ```cmake --build .```.
Optional: To update the Vulkan-Hpp and its submodules execute ```git pull --recurse-submodules```. Optional: To update the Vulkan-Hpp and its submodules execute ```git pull --recurse-submodules```.

View File

@ -6027,14 +6027,12 @@ std::string VulkanHppGenerator::generateCommandVoidGetValue( std::string const &
} }
} }
std::string VulkanHppGenerator::generateConstexprString( std::pair<std::string, StructureData> const & structData, std::string VulkanHppGenerator::generateConstexprString( std::string const & structName ) const
bool assignmentOperator ) const
{ {
// structs with a union (and VkBaseInStructure and VkBaseOutStructure) can't be a constexpr! // structs with a VkBaseInStructure and VkBaseOutStructure can't be a constexpr!
bool isConstExpression = !containsUnion( structData.first ) && ( structData.first != "VkBaseInStructure" ) && bool isConstExpression = ( structName != "VkBaseInStructure" ) && ( structName != "VkBaseOutStructure" );
( structData.first != "VkBaseOutStructure" );
return isConstExpression ? ( std::string( "VULKAN_HPP_CONSTEXPR" ) + return isConstExpression ? ( std::string( "VULKAN_HPP_CONSTEXPR" ) +
( ( containsArray( structData.first ) || assignmentOperator ) ? "_14 " : " " ) ) ( ( containsUnion( structName ) || containsArray( structName ) ) ? "_14 " : " " ) )
: ""; : "";
} }
@ -11545,7 +11543,7 @@ std::string
std::string str = replaceWithMap( constructors, std::string str = replaceWithMap( constructors,
{ { "arguments", arguments }, { { "arguments", arguments },
{ "constexpr", generateConstexprString( structData, false ) }, { "constexpr", generateConstexprString( structData.first ) },
{ "initializers", initializers }, { "initializers", initializers },
{ "structName", stripPrefix( structData.first, "Vk" ) } } ); { "structName", stripPrefix( structData.first, "Vk" ) } } );
@ -11971,7 +11969,7 @@ std::string VulkanHppGenerator::generateStructSetter( std::string const &
if ( member.type.type != "VkStructureType" ) // filter out StructureType, which is supposed to be immutable ! if ( member.type.type != "VkStructureType" ) // filter out StructureType, which is supposed to be immutable !
{ {
static const std::string templateString = R"( static const std::string templateString = R"(
${structureName} & set${MemberName}( ${memberType} ${reference}${memberName}_ ) VULKAN_HPP_NOEXCEPT ${constexpr}${structureName} & set${MemberName}( ${memberType} ${reference}${memberName}_ ) VULKAN_HPP_NOEXCEPT
{ {
${assignment}; ${assignment};
return *this; return *this;
@ -11982,8 +11980,9 @@ std::string VulkanHppGenerator::generateStructSetter( std::string const &
member.arraySizes.empty() member.arraySizes.empty()
? member.type.compose( "VULKAN_HPP_NAMESPACE" ) ? member.type.compose( "VULKAN_HPP_NAMESPACE" )
: generateStandardArray( member.type.compose( "VULKAN_HPP_NAMESPACE" ), member.arraySizes ); : generateStandardArray( member.type.compose( "VULKAN_HPP_NAMESPACE" ), member.arraySizes );
bool isReinterpretation = !member.bitCount.empty() && beginsWith( member.type.type, "Vk" );
std::string assignment; std::string assignment;
if ( !member.bitCount.empty() && beginsWith( member.type.type, "Vk" ) ) if ( isReinterpretation )
{ {
assignment = member.name + " = " + "*reinterpret_cast<" + member.type.type + "*>(&" + member.name + "_)"; assignment = member.name + " = " + "*reinterpret_cast<" + member.type.type + "*>(&" + member.name + "_)";
} }
@ -11995,6 +11994,7 @@ std::string VulkanHppGenerator::generateStructSetter( std::string const &
str += replaceWithMap( str += replaceWithMap(
templateString, templateString,
{ { "assignment", assignment }, { { "assignment", assignment },
{ "constexpr", isReinterpretation ? "" : "VULKAN_HPP_CONSTEXPR_14 " },
{ "memberName", member.name }, { "memberName", member.name },
{ "MemberName", startUpperCase( member.name ) }, { "MemberName", startUpperCase( member.name ) },
{ "memberType", memberType }, { "memberType", memberType },
@ -12196,8 +12196,10 @@ std::string VulkanHppGenerator::generateUnion( std::pair<std::string, StructureD
: ( "const " + : ( "const " +
generateStandardArray( memberIt->type.compose( "VULKAN_HPP_NAMESPACE" ), memberIt->arraySizes ) + "&" ); generateStandardArray( memberIt->type.compose( "VULKAN_HPP_NAMESPACE" ), memberIt->arraySizes ) + "&" );
// In a majority of cases this can be constexpr in C++11 as well, however, determining when exactly
// that is the case is a lot more involved and probably not worth it.
static const std::string constructorTemplate = R"( static const std::string constructorTemplate = R"(
${unionName}( ${memberType} ${argumentName}_${defaultAssignment} ) VULKAN_HPP_CONSTEXPR_14 ${unionName}( ${memberType} ${argumentName}_${defaultAssignment} )
: ${memberName}( ${argumentName}_ ) : ${memberName}( ${argumentName}_ )
{})"; {})";
@ -12266,10 +12268,6 @@ ${enter} union ${unionName}
{ {
using NativeType = Vk${unionName}; using NativeType = Vk${unionName};
#if !defined( VULKAN_HPP_NO_UNION_CONSTRUCTORS ) #if !defined( VULKAN_HPP_NO_UNION_CONSTRUCTORS )
${unionName}( VULKAN_HPP_NAMESPACE::${unionName} const & rhs ) VULKAN_HPP_NOEXCEPT
{
memcpy( static_cast<void *>( this ), &rhs, sizeof( VULKAN_HPP_NAMESPACE::${unionName} ) );
}
${constructors} ${constructors}
#endif /*VULKAN_HPP_NO_UNION_CONSTRUCTORS*/ #endif /*VULKAN_HPP_NO_UNION_CONSTRUCTORS*/
@ -12277,12 +12275,6 @@ ${constructors}
${setters} ${setters}
#endif /*VULKAN_HPP_NO_UNION_SETTERS*/ #endif /*VULKAN_HPP_NO_UNION_SETTERS*/
VULKAN_HPP_NAMESPACE::${unionName} & operator=( VULKAN_HPP_NAMESPACE::${unionName} const & rhs ) VULKAN_HPP_NOEXCEPT
{
memcpy( static_cast<void*>( this ), &rhs, sizeof( VULKAN_HPP_NAMESPACE::${unionName} ) );
return *this;
}
operator Vk${unionName} const &() const operator Vk${unionName} const &() const
{ {
return *reinterpret_cast<const Vk${unionName}*>( this ); return *reinterpret_cast<const Vk${unionName}*>( this );

View File

@ -775,8 +775,7 @@ private:
bool definition, bool definition,
std::map<size_t, size_t> const & vectorParamIndices, std::map<size_t, size_t> const & vectorParamIndices,
size_t returnParamIndex ) const; size_t returnParamIndex ) const;
std::string generateConstexprString( std::pair<std::string, StructureData> const & structData, std::string generateConstexprString( std::string const & structName ) const;
bool assignmentOperator ) const;
std::string generateDestroyCommand( std::string const & name, CommandData const & commandData ) const; std::string generateDestroyCommand( std::string const & name, CommandData const & commandData ) const;
std::string generateDispatchLoaderDynamicCommandAssignment( std::string const & commandName, std::string generateDispatchLoaderDynamicCommandAssignment( std::string const & commandName,
CommandData const & commandData, CommandData const & commandData,

File diff suppressed because it is too large Load Diff