Introduce support of "encode" and "decode" for attribute <queues> of a command

+ improved formatting of bitmasks and enums
This commit is contained in:
asuessenbach 2021-03-02 11:42:40 +01:00
parent 7b0d0865b7
commit 6121475ba1
2 changed files with 737 additions and 863 deletions

View File

@ -958,28 +958,33 @@ void VulkanHppGenerator::appendBitmask( std::string & str,
} }
} }
std::string name = ( enumName.empty() ? emptyEnumName : enumName ); std::string name = ( enumName.empty() ? emptyEnumName : enumName );
str += str += "\n using " + bitmaskName + " = Flags<" + name + ">;\n";
"\n"
" using " +
bitmaskName + " = Flags<" + name + ">;\n";
if ( !enumValues.empty() ) if ( !enumValues.empty() )
{ {
std::string allFlags; std::string allFlags;
if ( !enumValues.empty() ) bool encounteredFlag = false;
std::string previousEnter, previousLeave;
for ( auto const & value : enumValues )
{ {
for ( auto const & value : enumValues ) std::string enter, leave;
if ( !value.extension.empty() )
{ {
std::string enter, leave; std::tie( enter, leave ) = generateProtection( "", { value.extension } );
if ( !value.extension.empty() ) if ( !leave.empty() )
{ {
std::tie( enter, leave ) = generateProtection( "", { value.extension } ); assert( leave.back() );
leave.pop_back();
leave = "\n" + leave;
} }
allFlags += enter + bitmaskType + "(" + enumName + "::" + value.vkValue + ") |\n" + leave;
} }
assert( endsWith( allFlags, " |\n" ) ); allFlags += ( ( previousEnter != enter ) ? ( previousLeave + "\n" + enter ) : "\n" ) + " " +
allFlags = stripPostfix( allFlags, " |\n" ); ( encounteredFlag ? "| " : " " ) + bitmaskType + "( " + enumName + "::" + value.vkValue + " )";
encounteredFlag = true;
previousEnter = enter;
previousLeave = leave;
} }
allFlags += previousLeave;
static const std::string bitmaskOperatorsTemplate = R"( static const std::string bitmaskOperatorsTemplate = R"(
template <> struct FlagTraits<${enumName}> template <> struct FlagTraits<${enumName}>
@ -2387,43 +2392,64 @@ void VulkanHppGenerator::appendEnum( std::string & str, std::pair<std::string, E
assert( bitmaskIt != m_bitmasks.end() ); assert( bitmaskIt != m_bitmasks.end() );
str += " : " + bitmaskIt->first; str += " : " + bitmaskIt->first;
} }
str +=
"\n"
" {";
if ( !enumData.second.values.empty() || !enumData.second.aliases.empty() ) bool encounteredValue = false, containsProtection = false;
std::string enumList, previousEnter, previousLeave;
for ( auto const & value : enumData.second.values )
{ {
for ( auto const & value : enumData.second.values ) std::string enter, leave;
if ( !value.extension.empty() )
{ {
std::string enter, leave; std::tie( enter, leave ) = generateProtection( "", { value.extension } );
if ( !value.extension.empty() )
{
std::tie( enter, leave ) = generateProtection( "", { value.extension } );
}
if ( !leave.empty() )
{
assert( leave.back() == '\n' );
leave.pop_back();
leave = "\n" + leave;
}
str += "\n" + enter + " " + value.vkValue + " = " + value.vulkanValue + "," + leave;
} }
for ( auto const & alias : enumData.second.aliases ) if ( !leave.empty() )
{ {
// make sure to only list alias values that differ from all non-alias values assert( leave.back() == '\n' );
if ( std::find_if( leave.pop_back();
enumData.second.values.begin(), enumData.second.values.end(), [&alias]( EnumValueData const & evd ) { leave = "\n" + leave;
return alias.second.second == evd.vkValue; containsProtection = true;
} ) == enumData.second.values.end() ) }
{ enumList += ( ( previousEnter != enter ) ? ( previousLeave + "\n" + enter ) : "\n" ) + " " +
str += "\n " + alias.second.second + " = " + alias.first + ","; ( encounteredValue ? ", " : " " ) + value.vkValue + " = " + value.vulkanValue;
}
encounteredValue = true;
previousEnter = enter;
previousLeave = leave;
}
enumList += previousLeave;
for ( auto const & alias : enumData.second.aliases )
{
assert( encounteredValue );
// make sure to only list alias values that differ from all non-alias values
if ( std::find_if(
enumData.second.values.begin(), enumData.second.values.end(), [&alias]( EnumValueData const & evd ) {
return alias.second.second == evd.vkValue;
} ) == enumData.second.values.end() )
{
#if !defined( NDEBUG )
auto enumIt =
std::find_if( enumData.second.values.begin(),
enumData.second.values.end(),
[&alias]( EnumValueData const & evd ) { return alias.second.first == evd.vulkanValue; } );
if ( enumIt == enumData.second.values.end() )
{
auto aliasIt = enumData.second.aliases.find( alias.second.first );
assert( aliasIt != enumData.second.aliases.end() );
enumIt =
std::find_if( enumData.second.values.begin(),
enumData.second.values.end(),
[&aliasIt]( EnumValueData const & evd ) { return aliasIt->second.first == evd.vulkanValue; } );
}
assert( enumIt != enumData.second.values.end() );
assert( enumIt->extension.empty() || generateProtection( "", { enumIt->extension } ).first.empty() );
#endif
enumList += "\n , " + alias.second.second + " = " + alias.first;
} }
assert( str.back() == ',' );
str.pop_back();
} }
str += "};\n"; str += "\n {" +
( containsProtection ? ( "\n // clang-format off" + enumList + "\n // clang-format on" ) : enumList ) +
"\n };\n";
if ( !enumData.second.alias.empty() ) if ( !enumData.second.alias.empty() )
{ {
@ -2514,6 +2540,7 @@ void VulkanHppGenerator::appendEnumToString( std::string &
"\n" "\n"
" switch ( value )\n" " switch ( value )\n"
" {\n"; " {\n";
std::string previousEnter, previousLeave;
for ( auto const & value : enumData.second.values ) for ( auto const & value : enumData.second.values )
{ {
std::string enter, leave; std::string enter, leave;
@ -2521,10 +2548,13 @@ void VulkanHppGenerator::appendEnumToString( std::string &
{ {
std::tie( enter, leave ) = generateProtection( "", { value.extension } ); std::tie( enter, leave ) = generateProtection( "", { value.extension } );
} }
str += enter + " case " + enumName + "::" + value.vkValue + " : return \"" + value.vkValue.substr( 1 ) + str += ( ( previousEnter != enter ) ? ( previousLeave + enter ) : "" ) + " case " + enumName +
"\";\n" + leave; "::" + value.vkValue + " : return \"" + value.vkValue.substr( 1 ) + "\";\n";
previousEnter = enter;
previousLeave = leave;
} }
str += str +=
previousLeave +
" default: return \"invalid ( \" + VULKAN_HPP_NAMESPACE::toHexString( static_cast<uint32_t>( value ) ) + \" )\";\n" " default: return \"invalid ( \" + VULKAN_HPP_NAMESPACE::toHexString( static_cast<uint32_t>( value ) ) + \" )\";\n"
" }\n"; " }\n";
} }
@ -11324,7 +11354,7 @@ void VulkanHppGenerator::readCommand( tinyxml2::XMLElement const *
{ "comment", {} }, { "comment", {} },
{ "errorcodes", {} }, { "errorcodes", {} },
{ "pipeline", { "compute", "graphics", "transfer" } }, { "pipeline", { "compute", "graphics", "transfer" } },
{ "queues", { "compute", "graphics", "sparse_binding", "transfer" } }, { "queues", { "compute", "decode", "encode", "graphics", "sparse_binding", "transfer" } },
{ "renderpass", { "both", "inside", "outside" } }, { "renderpass", { "both", "inside", "outside" } },
{ "successcodes", {} } } ); { "successcodes", {} } } );

File diff suppressed because it is too large Load Diff