Combine two types of commands into one generation function

This commit is contained in:
asuessenbach
2022-06-28 13:33:36 +02:00
parent fae2b5ce6f
commit 39be44dc65
3 changed files with 27 additions and 130 deletions

View File

@@ -2638,7 +2638,7 @@ std::string VulkanHppGenerator::generateArgumentTemplates( std::vector<ParamData
std::map<size_t, size_t> const & vectorParams,
std::set<size_t> const & templatedParams,
bool chained,
bool complete ) const
bool raii ) const
{
std::string argumentTemplates;
if ( !templatedParams.empty() )
@@ -2660,7 +2660,7 @@ std::string VulkanHppGenerator::generateArgumentTemplates( std::vector<ParamData
{
argumentTemplates = ( returnParams.size() == 1 ) ? "typename X, typename Y, typename... Z, " : "typename StructureChain, ";
}
if ( !argumentTemplates.empty() && complete )
if ( !argumentTemplates.empty() && raii )
{
argumentTemplates = "template <" + stripPostfix( argumentTemplates, ", " ) + ">";
}
@@ -6671,8 +6671,7 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandResultMultiSuccessWithE
std::string str = generateRAIIHandleCommandEnhanced( commandIt, initialSkipCount, returnParams, vectorParams, definition, false, false );
if ( isStructureChainAnchor( commandIt->second.params[returnParams[1]].type.type ) )
{
str += generateRAIIHandleCommandResultMultiSuccessWithErrors2Return1VectorEnumerateChain(
commandIt, initialSkipCount, vectorParams, returnParams, definition );
str += generateRAIIHandleCommandEnhanced( commandIt, initialSkipCount, returnParams, vectorParams, definition, true, false );
}
return str;
}
@@ -6686,98 +6685,6 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandResultMultiSuccessWithE
return "";
}
std::string VulkanHppGenerator::generateRAIIHandleCommandResultMultiSuccessWithErrors2Return1VectorEnumerateChain(
std::map<std::string, CommandData>::const_iterator commandIt,
size_t initialSkipCount,
std::map<size_t, size_t> const & vectorParams,
std::vector<size_t> const & returnParams,
bool definition ) const
{
std::set<size_t> skippedParams = determineSkippedParams( commandIt->second.params, initialSkipCount, vectorParams, returnParams, false );
std::string argumentList =
generateArgumentListEnhanced( commandIt->second.params, returnParams, vectorParams, skippedParams, {}, {}, definition, false, true, false );
std::string commandName = generateCommandName( commandIt->first, commandIt->second.params, initialSkipCount, m_tags, false, false );
std::string vectorElementType = commandIt->second.params[vectorParams.begin()->first].type.type;
if ( !isHandleType( vectorElementType ) )
{
assert( commandIt->second.params[vectorParams.begin()->first].type.isNonConstPointer() );
vectorElementType = ( vectorElementType == "void" )
? "uint8_t"
: stripPostfix( commandIt->second.params[vectorParams.begin()->first].type.compose( "VULKAN_HPP_NAMESPACE" ), "*" );
}
if ( definition )
{
const std::string definitionTemplate =
R"(
template <typename X, typename Y, typename... Z>
VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE std::vector<StructureChain<X, Y, Z...>> ${className}::${commandName}( ${argumentList} ) const
{${functionPointerCheck}
std::vector<StructureChain<X, Y, Z...>> returnVector;
std::vector<${vectorElementType}> ${vectorName};
${counterType} ${counterName};
VULKAN_HPP_NAMESPACE::Result result;
do
{
result = static_cast<VULKAN_HPP_NAMESPACE::Result>( getDispatcher()->${vkCommand}( ${firstCallArguments} ) );
if ( ( result == VULKAN_HPP_NAMESPACE::Result::eSuccess ) && ${counterName} )
{
returnVector.resize( ${counterName} );
${vectorName}.resize( ${counterName} );
for ( ${counterType} i = 0; i < ${counterName}; i++ )
{
${vectorName}[i].pNext = returnVector[i].template get<${vectorElementType}>().pNext;
}
result = static_cast<VULKAN_HPP_NAMESPACE::Result>( getDispatcher()->${vkCommand}( ${secondCallArguments} ) );
}
} while ( result == VULKAN_HPP_NAMESPACE::Result::eIncomplete );
if ( result != VULKAN_HPP_NAMESPACE::Result::eSuccess )
{
throwResultException( result, VULKAN_HPP_NAMESPACE_STRING"::${className}::${commandName}" );
}
VULKAN_HPP_ASSERT( ${counterName} <= ${vectorName}.size() );
if ( ${counterName} < ${vectorName}.size() )
{
returnVector.resize( ${counterName} );
}
for ( ${counterType} i = 0; i < ${counterName}; i++ )
{
returnVector[i].template get<${vectorElementType}>() = ${vectorName}[i];
}
return ${vectorName};
}
)";
std::string counterName = startLowerCase( stripPrefix( commandIt->second.params[vectorParams.begin()->second].name, "p" ) );
std::string firstCallArguments = generateCallArgumentsEnhanced( commandIt->second, initialSkipCount, true, {}, {}, true );
std::string secondCallArguments = generateCallArgumentsEnhanced( commandIt->second, initialSkipCount, false, {}, {}, true );
std::string vectorName = startLowerCase( stripPrefix( commandIt->second.params[vectorParams.begin()->first].name, "p" ) );
return replaceWithMap( definitionTemplate,
{ { "argumentList", argumentList },
{ "className", initialSkipCount ? stripPrefix( commandIt->second.params[initialSkipCount - 1].type.type, "Vk" ) : "Context" },
{ "commandName", commandName },
{ "counterName", counterName },
{ "counterType", commandIt->second.params[vectorParams.begin()->second].type.type },
{ "firstCallArguments", firstCallArguments },
{ "functionPointerCheck", generateFunctionPointerCheck( commandIt->first, commandIt->second.referencedIn ) },
{ "secondCallArguments", secondCallArguments },
{ "vectorElementType", vectorElementType },
{ "vectorName", vectorName },
{ "vkCommand", commandIt->first } } );
}
else
{
std::string const declarationTemplate =
R"(
template <typename X, typename Y, typename... Z>
VULKAN_HPP_NODISCARD std::vector<StructureChain<X, Y, Z...>> ${commandName}( ${argumentList} ) const;
)";
return replaceWithMap( declarationTemplate, { { "argumentList", argumentList }, { "commandName", commandName } } );
}
}
std::string
VulkanHppGenerator::generateRAIIHandleCommandResultMultiSuccessWithErrors2ReturnValues( std::map<std::string, CommandData>::const_iterator commandIt,
size_t initialSkipCount,