From 73f210a604686234852d68613241949b8970754b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20S=C3=BC=C3=9Fenbach?= Date: Wed, 28 Feb 2024 13:04:56 +0100 Subject: [PATCH] Three fixes: (#1816) - do not create enhanced struct constructors, if the length of an array is determined by a member of that struct that is a pointer; - check for error if a command parameter has a len attribute, but is not a pointer - accept sync access and sync stage to be multiply aliased. --- VulkanHppGenerator.cpp | 27 ++++++++++++++++++++------- VulkanHppGenerator.hpp | 2 +- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 030c629..cb48f1a 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -10634,13 +10634,15 @@ std::string VulkanHppGenerator::generateStructConstructors( std::pair const & structData ) const { - if ( std::any_of( structData.second.members.begin(), structData.second.members.end(), [this]( MemberData const & md ) { return hasLen( md ); } ) ) + if ( std::any_of( structData.second.members.begin(), + structData.second.members.end(), + [this, &members = structData.second.members]( MemberData const & md ) { return hasLen( md, members ); } ) ) { // map from len-members to all the array members using that len std::map::const_iterator, std::vector::const_iterator>> lenIts; for ( auto mit = structData.second.members.begin(); mit != structData.second.members.end(); ++mit ) { - if ( hasLen( *mit ) ) + if ( hasLen( *mit, structData.second.members ) ) { std::string lenName = ( mit->lenExpressions.front() == "codeSize / 4" ) ? "codeSize" : mit->lenExpressions.front(); auto lenIt = findStructMemberIt( lenName, structData.second.members ); @@ -10670,7 +10672,7 @@ std::string VulkanHppGenerator::generateStructConstructorsEnhanced( std::pairname + "( " + generateLenInitializer( mit, litit, structData.second.mutualExclusiveLens ) + " )" ); sizeChecks += generateSizeCheck( litit->second, stripPrefix( structData.first, "Vk" ), structData.second.mutualExclusiveLens ); } - else if ( hasLen( *mit ) ) + else if ( hasLen( *mit, structData.second.members ) ) { assert( mit->type.isPointer() || !mit->arraySizes.empty() ); std::string argumentName = ( mit->type.isPointer() ? startLowerCase( stripPrefix( mit->name, "p" ) ) : mit->name ) + "_"; @@ -11452,7 +11454,7 @@ std::string VulkanHppGenerator::generateStructSetter( std::string const & struct { "reference", ( member.type.postfix.empty() && m_structs.contains( member.type.type ) ) ? "const & " : "" }, { "structureName", structureName } } ); - if ( hasLen( member ) ) + if ( hasLen( member, memberData ) ) { assert( member.type.isPointer() || !member.arraySizes.empty() ); assert( !member.type.isPointer() || member.name.starts_with( "p" ) ); @@ -12540,11 +12542,12 @@ bool VulkanHppGenerator::handleRemovalType( std::string const & type, std::vecto return removed; } -bool VulkanHppGenerator::hasLen( MemberData const & memberData ) const +bool VulkanHppGenerator::hasLen( MemberData const & memberData, std::vector const & members ) const { assert( memberData.lenMembers.size() <= memberData.lenExpressions.size() ); - return ( !memberData.lenMembers.empty() && ( ( memberData.lenExpressions[0] == memberData.lenMembers[0].first ) || - ( memberData.lenExpressions[0] == ( memberData.lenMembers[0].first + " / 4" ) ) ) ) || + return ( !memberData.lenMembers.empty() && + ( ( ( memberData.lenExpressions[0] == memberData.lenMembers[0].first ) && members[memberData.lenMembers[0].second].type.isValue() ) || + ( memberData.lenExpressions[0] == ( memberData.lenMembers[0].first + " / 4" ) ) ) ) || ( !memberData.lenExpressions.empty() && ( memberData.lenExpressions[0] == "null-terminated" ) && !memberData.arraySizes.empty() ); } @@ -12995,6 +12998,8 @@ std::pair VulkanHppGenerator::readCommandPa ( paramData.type.postfix == "* const *" ), line, "unexpected type postfix <" + paramData.type.postfix + ">" ); + checkForError( + paramData.lenParams.empty() || paramData.type.isPointer(), line, "parameter <" + nameData.name + "> has an attribute but is not a pointer" ); paramData.name = nameData.name; paramData.arraySizes = nameData.arraySizes; @@ -14524,6 +14529,10 @@ void VulkanHppGenerator::readSyncAccess( tinyxml2::XMLElement const * { assert( attribute.first == "name" ); auto namePtr = findEnumValueData( accessFlagBits2It, attribute.second ); + while ( namePtr && !namePtr->alias.empty() ) + { + namePtr = findEnumValueData( accessFlagBits2It, namePtr->alias ); + } checkForError( namePtr != nullptr, line, "syncaccess name <" + attribute.second + "> not specified as a VkAccessFlagBits value!" ); if ( aliasPtr != nullptr ) { @@ -14632,6 +14641,10 @@ void VulkanHppGenerator::readSyncStage( tinyxml2::XMLElement const * { assert( attribute.first == "name" ); auto namePtr = findEnumValueData( stageFlagBits2It, attribute.second ); + while ( namePtr && !namePtr->alias.empty() ) + { + namePtr = findEnumValueData( stageFlagBits2It, namePtr->alias ); + } checkForError( namePtr != nullptr, line, "syncstage name <" + attribute.second + "> not specified as a VkPipelineStageFlagBits2 value!" ); if ( aliasPtr != nullptr ) { diff --git a/VulkanHppGenerator.hpp b/VulkanHppGenerator.hpp index 9c95540..ddd4327 100644 --- a/VulkanHppGenerator.hpp +++ b/VulkanHppGenerator.hpp @@ -918,7 +918,7 @@ private: bool handleRemovalCommand( std::string const & command, std::vector & requireData ); void handleRemovals(); bool handleRemovalType( std::string const & type, std::vector & requireData ); - bool hasLen( MemberData const & md ) const; + bool hasLen( MemberData const & md, std::vector const & members ) const; bool hasParentHandle( std::string const & handle, std::string const & parent ) const; bool isDeviceCommand( CommandData const & commandData ) const; bool isExtension( std::string const & name ) const;