From 0771d2657c039f50b4b5c57dcf21facd1ef75b32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20S=C3=BC=C3=9Fenbach?= Date: Mon, 14 Jul 2025 17:56:07 +0200 Subject: [PATCH] Extend support of api "vulkanbase" (#2215) --- VulkanHppGenerator.cpp | 79 ++++++++++++++++++++++++++++-------------- XMLHelper.hpp | 2 +- 2 files changed, 54 insertions(+), 27 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 0c44621..8b4c6ae 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -13766,7 +13766,7 @@ void VulkanHppGenerator::readCommand( tinyxml2::XMLElement const * element ) attributes, {}, { { "allownoqueues", { "true" } }, - { "api", { "vulkan", "vulkansc" } }, + { "api", { "vulkan", "vulkanbase", "vulkansc" } }, { "cmdbufferlevel", { "primary", "secondary" } }, { "comment", {} }, { "errorcodes", {} }, @@ -13782,12 +13782,12 @@ void VulkanHppGenerator::readCommand( tinyxml2::XMLElement const * element ) CommandData commandData; commandData.xmlLine = line; - std::string api; + std::vector api; for ( auto const & attribute : attributes ) { if ( attribute.first == "api" ) { - api = attribute.second; + api = tokenize( attribute.second, "," ); } else if ( attribute.first == "errorcodes" ) { @@ -13827,7 +13827,8 @@ void VulkanHppGenerator::readCommand( tinyxml2::XMLElement const * element ) } } - checkForError( api.empty() || commandData.exports.empty() || ( ( commandData.exports.size() == 1 ) && ( api == commandData.exports.front() ) ), + checkForError( api.empty() || commandData.exports.empty() || + ( ( commandData.exports.size() == 1 ) && ( std::ranges::find( api, commandData.exports.front() ) != api.end() ) ), line, "command <" + name + "> has non-empty but different attributes and " ); @@ -13859,7 +13860,7 @@ void VulkanHppGenerator::readCommand( tinyxml2::XMLElement const * element ) line, "command <" + name + "> does not return a VkResult but specifies successcodes" ); - if ( api.empty() || ( api == m_api ) ) + if ( api.empty() || ( std::ranges::find( api, m_api ) != api.end() ) ) { checkForError( !m_commands.contains( name ), line, "command <" + name + "> already specified" ); addCommand( name, commandData ); @@ -14681,7 +14682,8 @@ void VulkanHppGenerator::readFeature( tinyxml2::XMLElement const * element ) { const int line = element->GetLineNum(); std::map attributes = getAttributes( element ); - checkAttributes( line, attributes, { { "api", { "vulkan", "vulkansc" } }, { "comment", {} }, { "name", {} }, { "number", {} } }, { { "depends", {} } } ); + checkAttributes( + line, attributes, { { "api", { "vulkan", "vulkanbase", "vulkansc" } }, { "comment", {} }, { "name", {} }, { "number", {} } }, { { "depends", {} } } ); std::vector children = getChildElements( element ); checkElements( line, children, { { "require", false } }, { "deprecate", "remove" } ); @@ -14724,11 +14726,28 @@ void VulkanHppGenerator::readFeature( tinyxml2::XMLElement const * element ) } } - checkForError( featureData.name == - ( std::ranges::any_of( featureData.api, []( std::string const & a ) { return a == "vulkan"; } ) ? "VK_VERSION_" : "VKSC_VERSION_" ) + - modifiedNumber, - line, - "unexpected formatting of name <" + featureData.name + ">" ); + if ( std::ranges::find( featureData.api, "vulkan" ) != featureData.api.end() ) + { + checkForError( featureData.name == "VK_VERSION_" + modifiedNumber, + line, + "unexpected formatting of name <" + featureData.name + ">, expected " ); + } + else if ( std::ranges::find( featureData.api, "vulkanbase" ) != featureData.api.end() ) + { + checkForError( featureData.api.size() == 1, line, "feature <" + featureData.name + "> with api must not be combined with other apis" ); + std::string const & name = featureData.name; + checkForError( ( name == "VK_BASE_VERSION_" + modifiedNumber ) || ( name == "VK_COMPUTE_VERSION_" + modifiedNumber ) || + ( name == "VK_GRAPHICS_VERSION_" + modifiedNumber ), + line, + "unexpected formatting of name <" + featureData.name + ">" ); + } + else + { + checkForError( featureData.name == "VKSC_VERSION_" + modifiedNumber, + line, + "unexpected formatting of name <" + featureData.name + ">, expected " ); + } + checkForError( !isFeature( featureData.name ), line, "feature <" + featureData.name + "> already specified" ); if ( featureSupported ) { @@ -15299,9 +15318,14 @@ void VulkanHppGenerator::readRequireEnum( } else { - checkForError( ( eedIt->alias == alias ) && ( eedIt->api == api ) && ( eedIt->protect == protect ) && ( eedIt->supported == supported ), + checkForError( ( eedIt->alias == alias ) && ( eedIt->api == api ) && ( eedIt->protect == protect ), line, "extending enum <" + extends + "> with already listed value <" + name + "> but different properties" ); + // if a previous version was not supported, make it supported now + if ( !eedIt->supported && supported ) + { + eedIt->supported = supported; + } eedIt->requiredBy.insert( requiredBy ); } } @@ -15684,7 +15708,7 @@ void VulkanHppGenerator::readStructMember( tinyxml2::XMLElement const * element, attributes, {}, { { "altlen", {} }, - { "api", { "vulkan", "vulkansc" } }, + { "api", { "vulkan", "vulkanbase", "vulkansc" } }, { "deprecated", { "ignored" } }, { "externsync", { "maybe", "true" } }, { "featurelink", {} }, @@ -15702,12 +15726,12 @@ void VulkanHppGenerator::readStructMember( tinyxml2::XMLElement const * element, MemberData memberData; memberData.xmlLine = line; - std::string api; + std::vector api; for ( auto const & attribute : attributes ) { if ( attribute.first == "api" ) { - api = attribute.second; + api = tokenize( attribute.second, "," ); } else if ( attribute.first == "altlen" ) { @@ -15807,7 +15831,7 @@ void VulkanHppGenerator::readStructMember( tinyxml2::XMLElement const * element, checkForError( ( memberData.type.postfix.length() < 3 ) || !memberData.type.postfix.starts_with( "[" ) || !memberData.type.postfix.ends_with( "]" ), line, "struct member <" + name + "> has its array size <" + memberData.type.postfix + "> at the wrong position" ); - if ( api.empty() || ( api == m_api ) ) + if ( api.empty() || ( std::ranges::find( api, m_api ) != api.end() ) ) { checkForError( std::ranges::none_of( members, [&name]( MemberData const & md ) { return md.name == name; } ), line, "struct member name <" + name + "> already used" ); @@ -16090,14 +16114,16 @@ void VulkanHppGenerator::readTypeBitmask( tinyxml2::XMLElement const * element, } else { - checkAttributes( line, attributes, { { "category", { "bitmask" } } }, { { "api", { "vulkan", "vulkansc" } }, { "bitvalues", {} }, { "requires", {} } } ); + checkAttributes( + line, attributes, { { "category", { "bitmask" } } }, { { "api", { "vulkan", "vulkanbase", "vulkansc" } }, { "bitvalues", {} }, { "requires", {} } } ); - std::string api, bitvalues, require; + std::vector api; + std::string bitvalues, require; for ( auto const & attribute : attributes ) { if ( attribute.first == "api" ) { - api = attribute.second; + api = tokenize( attribute.second, "," ); } else if ( attribute.first == "bitvalues" ) { @@ -16126,7 +16152,7 @@ void VulkanHppGenerator::readTypeBitmask( tinyxml2::XMLElement const * element, require = bitvalues; } - if ( api.empty() || ( api == m_api ) ) + if ( api.empty() || ( std::ranges::find( api, m_api ) != api.end() ) ) { checkForError( m_types.insert( { nameData.name, TypeData{ TypeCategory::Bitmask, {}, line } } ).second, line, "bitmask <" + nameData.name + "> already specified" ); @@ -16182,15 +16208,16 @@ void VulkanHppGenerator::readTypeDefine( tinyxml2::XMLElement const * element, s checkAttributes( line, attributes, { { "category", { "define" } } }, - { { "api", { "vulkan", "vulkansc" } }, { "comment", {} }, { "deprecated", { "true" } }, { "name", {} }, { "requires", {} } } ); + { { "api", { "vulkan", "vulkanbase", "vulkansc" } }, { "comment", {} }, { "deprecated", { "true" } }, { "name", {} }, { "requires", {} } } ); - std::string api, name, require; - bool deprecated = false; + std::vector api; + std::string name, require; + bool deprecated = false; for ( auto const & attribute : attributes ) { if ( attribute.first == "api" ) { - api = attribute.second; + api = tokenize( attribute.second, "," ); } else if ( attribute.first == "deprecated" ) { @@ -16232,7 +16259,7 @@ void VulkanHppGenerator::readTypeDefine( tinyxml2::XMLElement const * element, s line, "unknown formatting of type category define" ); name = trim( child->GetText() ); - if ( ( name == "VK_HEADER_VERSION" ) && ( api.empty() || ( api == m_api ) ) ) + if ( ( name == "VK_HEADER_VERSION" ) && ( api.empty() || ( std::ranges::find( api, m_api ) != api.end() ) ) ) { m_version = trimEnd( element->LastChild()->ToText()->Value() ); } @@ -16246,7 +16273,7 @@ void VulkanHppGenerator::readTypeDefine( tinyxml2::XMLElement const * element, s } assert( !name.empty() ); - if ( api.empty() || ( api == m_api ) ) + if ( api.empty() || ( std::ranges::find( api, m_api ) != api.end() ) ) { MacroVisitor definesVisitor{}; element->Accept( &definesVisitor ); diff --git a/XMLHelper.hpp b/XMLHelper.hpp index 1f06d5a..4d3f356 100644 --- a/XMLHelper.hpp +++ b/XMLHelper.hpp @@ -208,7 +208,7 @@ inline void checkAttributes( std::string const & std::vector values = tokenize( a.second, "," ); for ( auto const & v : values ) { - checkForWarning( + checkForError( intro, optionalIt->second.find( v ) != optionalIt->second.end(), line, "unexpected attribute value <" + v + "> in attribute <" + a.first + ">" ); } }