(re-)add support of commands enumerating a chained structure type.

This commit is contained in:
asuessenbach 2022-05-04 08:46:45 +02:00
parent d715006717
commit a591ef69e3
3 changed files with 147 additions and 47 deletions

View File

@ -3032,7 +3032,6 @@ std::string VulkanHppGenerator::generateCallSequence( std::string const &
size_t initialSkipCount, size_t initialSkipCount,
std::set<size_t> const & singularParams, std::set<size_t> const & singularParams,
std::set<size_t> const & templatedParams, std::set<size_t> const & templatedParams,
bool withAllocator,
bool chained ) const bool chained ) const
{ {
// if at least one returnParam is a size value of a vector param (and no singular params), we need two calls // if at least one returnParam is a size value of a vector param (and no singular params), we need two calls
@ -3058,27 +3057,55 @@ std::string VulkanHppGenerator::generateCallSequence( std::string const &
// chained data needs some more handling!! // chained data needs some more handling!!
std::string vectorElementType = stripPostfix( commandData.params[vectorParamIt->first].type.compose( "VULKAN_HPP_NAMESPACE" ), " *" ); std::string vectorElementType = stripPostfix( commandData.params[vectorParamIt->first].type.compose( "VULKAN_HPP_NAMESPACE" ), " *" );
const std::string callSequenceTemplate = if ( commandData.returnType == "VkResult" )
R"(d.${vkCommand}( ${firstCallArguments} ); {
std::vector<StructureChain, StructureChainAllocator> structureChains( ${counterName}${structureChainAllocator} ); const std::string callSequenceTemplate = R"(VkResult result;
std::vector<${vectorElementType}> ${vectorName}( ${counterName} ); do
{
result = d.${vkCommand}( ${firstCallArguments} );
if ( ( result == VK_SUCCESS ) && ${counterName} )
{
structureChains.resize( ${counterName} );
${vectorName}.resize( ${counterName} );
for ( ${counterType} i = 0; i < ${counterName}; i++ ) for ( ${counterType} i = 0; i < ${counterName}; i++ )
{ {
${vectorName}[i].pNext = structureChains[i].template get<${vectorElementType}>().pNext; ${vectorName}[i].pNext = structureChains[i].template get<${vectorElementType}>().pNext;
} }
d.${vkCommand}( ${secondCallArguments} ); result = d.${vkCommand}( ${secondCallArguments} );
VULKAN_HPP_ASSERT( ${counterName} <= ${vectorName}.size() );)"; }
} while ( result == VK_INCOMPLETE );)";
return replaceWithMap( callSequenceTemplate, return replaceWithMap( callSequenceTemplate,
{ { "counterName", startLowerCase( stripPrefix( commandData.params[vectorParamIt->second].name, "p" ) ) }, { { "counterName", startLowerCase( stripPrefix( commandData.params[vectorParamIt->second].name, "p" ) ) },
{ "counterType", commandData.params[vectorParamIt->second].type.type }, { "counterType", commandData.params[vectorParamIt->second].type.type },
{ "firstCallArguments", firstCallArguments }, { "firstCallArguments", firstCallArguments },
{ "secondCallArguments", secondCallArguments }, { "secondCallArguments", secondCallArguments },
{ "structureChainAllocator", withAllocator ? ( ", structureChainAllocator" ) : "" },
{ "vectorElementType", vectorElementType }, { "vectorElementType", vectorElementType },
{ "vectorName", vectorName }, { "vectorName", vectorName },
{ "vkCommand", name } } ); { "vkCommand", name } } );
} }
else
{
const std::string callSequenceTemplate =
R"(d.${vkCommand}( ${firstCallArguments} );
structureChains.resize( ${counterName} );
${vectorName}.resize( ${counterName} );
for ( ${counterType} i = 0; i < ${counterName}; i++ )
{
${vectorName}[i].pNext = structureChains[i].template get<${vectorElementType}>().pNext;
}
d.${vkCommand}( ${secondCallArguments} );)";
return replaceWithMap( callSequenceTemplate,
{ { "counterName", startLowerCase( stripPrefix( commandData.params[vectorParamIt->second].name, "p" ) ) },
{ "counterType", commandData.params[vectorParamIt->second].type.type },
{ "firstCallArguments", firstCallArguments },
{ "secondCallArguments", secondCallArguments },
{ "vectorElementType", vectorElementType },
{ "vectorName", vectorName },
{ "vkCommand", name } } );
}
}
else if ( commandData.returnType == "VkResult" ) else if ( commandData.returnType == "VkResult" )
{ {
assert( ( commandData.successCodes.size() == 2 ) && ( commandData.successCodes[0] == "VK_SUCCESS" ) && assert( ( commandData.successCodes.size() == 2 ) && ( commandData.successCodes[0] == "VK_SUCCESS" ) &&
@ -3434,7 +3461,7 @@ std::string VulkanHppGenerator::generateCommandEnhanced( std::string const &
commandData, initialSkipCount, returnParams, vectorParams, templatedParams, singular, withAllocator, unique, chained, enumerating ); commandData, initialSkipCount, returnParams, vectorParams, templatedParams, singular, withAllocator, unique, chained, enumerating );
std::string dataSizeChecks = generateDataSizeChecks( commandData, returnParams, dataTypes, vectorParams, templatedParams, singular ); std::string dataSizeChecks = generateDataSizeChecks( commandData, returnParams, dataTypes, vectorParams, templatedParams, singular );
std::string callSequence = std::string callSequence =
generateCallSequence( name, commandData, returnParams, vectorParams, initialSkipCount, singularParams, templatedParams, withAllocator, chained ); generateCallSequence( name, commandData, returnParams, vectorParams, initialSkipCount, singularParams, templatedParams, chained );
std::string resultCheck = generateResultCheck( commandData, className, classSeparator, commandName, enumerating ); std::string resultCheck = generateResultCheck( commandData, className, classSeparator, commandName, enumerating );
std::string returnStatement = generateReturnStatement( std::string returnStatement = generateReturnStatement(
name, commandData, returnVariable, returnType, dataType, initialSkipCount, returnParams.empty() ? INVALID_INDEX : returnParams[0], unique, enumerating ); name, commandData, returnVariable, returnType, dataType, initialSkipCount, returnParams.empty() ? INVALID_INDEX : returnParams[0], unique, enumerating );
@ -3705,7 +3732,27 @@ std::string VulkanHppGenerator::generateCommandResultMultiSuccessWithErrors2Retu
{ {
if ( ( commandData.params[returnParams[0]].type.type == "size_t" ) || ( commandData.params[returnParams[0]].type.type == "uint32_t" ) ) if ( ( commandData.params[returnParams[0]].type.type == "size_t" ) || ( commandData.params[returnParams[0]].type.type == "uint32_t" ) )
{ {
if ( !isStructureChainAnchor( commandData.params[returnParams[1]].type.type ) ) if ( isStructureChainAnchor( commandData.params[returnParams[1]].type.type ) )
{
std::map<size_t, size_t> vectorParams = determineVectorParams( commandData.params );
if ( vectorParams.size() == 1 )
{
if ( returnParams[0] == vectorParams.begin()->second )
{
if ( returnParams[1] == vectorParams.begin()->first )
{
return generateCommandSetStandardEnhancedWithAllocatorChained(
definition,
generateCommandStandard( name, commandData, initialSkipCount, definition ),
generateCommandEnhanced( name, commandData, initialSkipCount, definition, vectorParams, returnParams, false, false, false, false ),
generateCommandEnhanced( name, commandData, initialSkipCount, definition, vectorParams, returnParams, false, true, false, false ),
generateCommandEnhanced( name, commandData, initialSkipCount, definition, vectorParams, returnParams, false, false, true, false ),
generateCommandEnhanced( name, commandData, initialSkipCount, definition, vectorParams, returnParams, false, true, true, false ) );
}
}
}
}
else
{ {
std::map<size_t, size_t> vectorParams = determineVectorParams( commandData.params ); std::map<size_t, size_t> vectorParams = determineVectorParams( commandData.params );
if ( vectorParams.size() == 1 ) if ( vectorParams.size() == 1 )
@ -4642,11 +4689,18 @@ std::string VulkanHppGenerator::generateDataDeclarations( CommandData const &
assert( vectorParamIt != vectorParams.end() ); assert( vectorParamIt != vectorParams.end() );
assert( vectorParamIt->second == returnParams[0] ); assert( vectorParamIt->second == returnParams[0] );
std::string const dataDeclarationTemplate = R"(${counterType} ${counterName};)"; std::string const dataDeclarationTemplate = R"(std::vector<StructureChain, StructureChainAllocator> structureChains${structureChainAllocator};
std::vector<${vectorElementType}> ${vectorName};
${counterType} ${counterName};)";
dataDeclarations = replaceWithMap( dataDeclarations = replaceWithMap( dataDeclarationTemplate,
dataDeclarationTemplate, {
{ { "counterName", startLowerCase( stripPrefix( commandData.params[returnParams[0]].name, "p" ) ) }, { "counterType", dataTypes[0] } } ); { "counterName", startLowerCase( stripPrefix( commandData.params[returnParams[0]].name, "p" ) ) },
{ "counterType", dataTypes[0] },
{ "structureChainAllocator", withAllocator ? ( "( structureChainAllocator )" ) : "" },
{ "vectorElementType", dataTypes[1] },
{ "vectorName", startLowerCase( stripPrefix( commandData.params[returnParams[1]].name, "p" ) ) },
} );
} }
else else
{ {
@ -4784,6 +4838,27 @@ std::string VulkanHppGenerator::generateDataPreparation( CommandData const &
std::string vectorElementType = stripPostfix( commandData.params[vectorParamIt->first].type.compose( "VULKAN_HPP_NAMESPACE" ), " *" ); std::string vectorElementType = stripPostfix( commandData.params[vectorParamIt->first].type.compose( "VULKAN_HPP_NAMESPACE" ), " *" );
if ( enumerating )
{
std::string const dataPreparationTemplate =
R"(VULKAN_HPP_ASSERT( ${counterName} <= ${vectorName}.size() );
if ( ${counterName} < ${vectorName}.size() )
{
structureChains.resize( ${counterName} );
}
for ( ${counterType} i = 0; i < ${counterName}; i++ )
{
structureChains[i].template get<${vectorElementType}>() = ${vectorName}[i];
})";
return replaceWithMap( dataPreparationTemplate,
{ { "counterName", startLowerCase( stripPrefix( commandData.params[vectorParamIt->second].name, "p" ) ) },
{ "counterType", commandData.params[vectorParamIt->second].type.type },
{ "vectorElementType", vectorElementType },
{ "vectorName", vectorName } } );
}
else
{
std::string const dataPreparationTemplate = std::string const dataPreparationTemplate =
R"(for ( ${counterType} i = 0; i < ${counterName}; i++ ) R"(for ( ${counterType} i = 0; i < ${counterName}; i++ )
{ {
@ -4796,6 +4871,7 @@ std::string VulkanHppGenerator::generateDataPreparation( CommandData const &
{ "vectorElementType", vectorElementType }, { "vectorElementType", vectorElementType },
{ "vectorName", vectorName } } ); { "vectorName", vectorName } } );
} }
}
else if ( enumerating ) else if ( enumerating )
{ {
assert( !singular ); assert( !singular );
@ -9961,7 +10037,8 @@ std::string VulkanHppGenerator::generateReturnType( CommandData const &
else else
{ {
assert( returnParams.size() == 2 ); assert( returnParams.size() == 2 );
assert( commandData.returnType == "void" ); assert( ( commandData.returnType == "void" ) ||
( ( commandData.returnType == "VkResult" ) && ( commandData.successCodes.size() == 2 ) && ( commandData.successCodes[1] == "VK_INCOMPLETE" ) ) );
auto vectorIt = vectorParams.find( returnParams[1] ); auto vectorIt = vectorParams.find( returnParams[1] );
assert( ( vectorIt != vectorParams.end() ) && ( vectorIt->second == returnParams[0] ) ); assert( ( vectorIt != vectorParams.end() ) && ( vectorIt->second == returnParams[0] ) );
returnType = "std::vector<StructureChain, StructureChainAllocator>"; returnType = "std::vector<StructureChain, StructureChainAllocator>";

View File

@ -474,7 +474,6 @@ private:
size_t initialSkipCount, size_t initialSkipCount,
std::set<size_t> const & singularParams, std::set<size_t> const & singularParams,
std::set<size_t> const & templatedParams, std::set<size_t> const & templatedParams,
bool withAllocator,
bool chained ) const; bool chained ) const;
std::string generateChainTemplates( std::vector<size_t> const & returnParams, bool chained ) const; std::string generateChainTemplates( std::vector<size_t> const & returnParams, bool chained ) const;
std::string generateCommand( std::string const & name, CommandData const & commandData, size_t initialSkipCount, bool definition ) const; std::string generateCommand( std::string const & name, CommandData const & commandData, size_t initialSkipCount, bool definition ) const;

View File

@ -5715,18 +5715,24 @@ namespace VULKAN_HPP_NAMESPACE
{ {
VULKAN_HPP_ASSERT( d.getVkHeaderVersion() == VK_HEADER_VERSION ); VULKAN_HPP_ASSERT( d.getVkHeaderVersion() == VK_HEADER_VERSION );
std::vector<StructureChain, StructureChainAllocator> structureChains;
std::vector<VULKAN_HPP_NAMESPACE::QueueFamilyProperties2> queueFamilyProperties;
uint32_t queueFamilyPropertyCount; uint32_t queueFamilyPropertyCount;
d.vkGetPhysicalDeviceQueueFamilyProperties2( m_physicalDevice, &queueFamilyPropertyCount, nullptr ); d.vkGetPhysicalDeviceQueueFamilyProperties2( m_physicalDevice, &queueFamilyPropertyCount, nullptr );
std::vector<StructureChain, StructureChainAllocator> structureChains( queueFamilyPropertyCount ); structureChains.resize( queueFamilyPropertyCount );
std::vector<VULKAN_HPP_NAMESPACE::QueueFamilyProperties2> queueFamilyProperties( queueFamilyPropertyCount ); queueFamilyProperties.resize( queueFamilyPropertyCount );
for ( uint32_t i = 0; i < queueFamilyPropertyCount; i++ ) for ( uint32_t i = 0; i < queueFamilyPropertyCount; i++ )
{ {
queueFamilyProperties[i].pNext = structureChains[i].template get<VULKAN_HPP_NAMESPACE::QueueFamilyProperties2>().pNext; queueFamilyProperties[i].pNext = structureChains[i].template get<VULKAN_HPP_NAMESPACE::QueueFamilyProperties2>().pNext;
} }
d.vkGetPhysicalDeviceQueueFamilyProperties2( d.vkGetPhysicalDeviceQueueFamilyProperties2(
m_physicalDevice, &queueFamilyPropertyCount, reinterpret_cast<VkQueueFamilyProperties2 *>( queueFamilyProperties.data() ) ); m_physicalDevice, &queueFamilyPropertyCount, reinterpret_cast<VkQueueFamilyProperties2 *>( queueFamilyProperties.data() ) );
VULKAN_HPP_ASSERT( queueFamilyPropertyCount <= queueFamilyProperties.size() );
VULKAN_HPP_ASSERT( queueFamilyPropertyCount <= queueFamilyProperties.size() );
if ( queueFamilyPropertyCount < queueFamilyProperties.size() )
{
structureChains.resize( queueFamilyPropertyCount );
}
for ( uint32_t i = 0; i < queueFamilyPropertyCount; i++ ) for ( uint32_t i = 0; i < queueFamilyPropertyCount; i++ )
{ {
structureChains[i].template get<VULKAN_HPP_NAMESPACE::QueueFamilyProperties2>() = queueFamilyProperties[i]; structureChains[i].template get<VULKAN_HPP_NAMESPACE::QueueFamilyProperties2>() = queueFamilyProperties[i];
@ -5744,18 +5750,24 @@ namespace VULKAN_HPP_NAMESPACE
{ {
VULKAN_HPP_ASSERT( d.getVkHeaderVersion() == VK_HEADER_VERSION ); VULKAN_HPP_ASSERT( d.getVkHeaderVersion() == VK_HEADER_VERSION );
std::vector<StructureChain, StructureChainAllocator> structureChains( structureChainAllocator );
std::vector<VULKAN_HPP_NAMESPACE::QueueFamilyProperties2> queueFamilyProperties;
uint32_t queueFamilyPropertyCount; uint32_t queueFamilyPropertyCount;
d.vkGetPhysicalDeviceQueueFamilyProperties2( m_physicalDevice, &queueFamilyPropertyCount, nullptr ); d.vkGetPhysicalDeviceQueueFamilyProperties2( m_physicalDevice, &queueFamilyPropertyCount, nullptr );
std::vector<StructureChain, StructureChainAllocator> structureChains( queueFamilyPropertyCount, structureChainAllocator ); structureChains.resize( queueFamilyPropertyCount );
std::vector<VULKAN_HPP_NAMESPACE::QueueFamilyProperties2> queueFamilyProperties( queueFamilyPropertyCount ); queueFamilyProperties.resize( queueFamilyPropertyCount );
for ( uint32_t i = 0; i < queueFamilyPropertyCount; i++ ) for ( uint32_t i = 0; i < queueFamilyPropertyCount; i++ )
{ {
queueFamilyProperties[i].pNext = structureChains[i].template get<VULKAN_HPP_NAMESPACE::QueueFamilyProperties2>().pNext; queueFamilyProperties[i].pNext = structureChains[i].template get<VULKAN_HPP_NAMESPACE::QueueFamilyProperties2>().pNext;
} }
d.vkGetPhysicalDeviceQueueFamilyProperties2( d.vkGetPhysicalDeviceQueueFamilyProperties2(
m_physicalDevice, &queueFamilyPropertyCount, reinterpret_cast<VkQueueFamilyProperties2 *>( queueFamilyProperties.data() ) ); m_physicalDevice, &queueFamilyPropertyCount, reinterpret_cast<VkQueueFamilyProperties2 *>( queueFamilyProperties.data() ) );
VULKAN_HPP_ASSERT( queueFamilyPropertyCount <= queueFamilyProperties.size() );
VULKAN_HPP_ASSERT( queueFamilyPropertyCount <= queueFamilyProperties.size() );
if ( queueFamilyPropertyCount < queueFamilyProperties.size() )
{
structureChains.resize( queueFamilyPropertyCount );
}
for ( uint32_t i = 0; i < queueFamilyPropertyCount; i++ ) for ( uint32_t i = 0; i < queueFamilyPropertyCount; i++ )
{ {
structureChains[i].template get<VULKAN_HPP_NAMESPACE::QueueFamilyProperties2>() = queueFamilyProperties[i]; structureChains[i].template get<VULKAN_HPP_NAMESPACE::QueueFamilyProperties2>() = queueFamilyProperties[i];
@ -10819,18 +10831,24 @@ namespace VULKAN_HPP_NAMESPACE
{ {
VULKAN_HPP_ASSERT( d.getVkHeaderVersion() == VK_HEADER_VERSION ); VULKAN_HPP_ASSERT( d.getVkHeaderVersion() == VK_HEADER_VERSION );
std::vector<StructureChain, StructureChainAllocator> structureChains;
std::vector<VULKAN_HPP_NAMESPACE::QueueFamilyProperties2> queueFamilyProperties;
uint32_t queueFamilyPropertyCount; uint32_t queueFamilyPropertyCount;
d.vkGetPhysicalDeviceQueueFamilyProperties2KHR( m_physicalDevice, &queueFamilyPropertyCount, nullptr ); d.vkGetPhysicalDeviceQueueFamilyProperties2KHR( m_physicalDevice, &queueFamilyPropertyCount, nullptr );
std::vector<StructureChain, StructureChainAllocator> structureChains( queueFamilyPropertyCount ); structureChains.resize( queueFamilyPropertyCount );
std::vector<VULKAN_HPP_NAMESPACE::QueueFamilyProperties2> queueFamilyProperties( queueFamilyPropertyCount ); queueFamilyProperties.resize( queueFamilyPropertyCount );
for ( uint32_t i = 0; i < queueFamilyPropertyCount; i++ ) for ( uint32_t i = 0; i < queueFamilyPropertyCount; i++ )
{ {
queueFamilyProperties[i].pNext = structureChains[i].template get<VULKAN_HPP_NAMESPACE::QueueFamilyProperties2>().pNext; queueFamilyProperties[i].pNext = structureChains[i].template get<VULKAN_HPP_NAMESPACE::QueueFamilyProperties2>().pNext;
} }
d.vkGetPhysicalDeviceQueueFamilyProperties2KHR( d.vkGetPhysicalDeviceQueueFamilyProperties2KHR(
m_physicalDevice, &queueFamilyPropertyCount, reinterpret_cast<VkQueueFamilyProperties2 *>( queueFamilyProperties.data() ) ); m_physicalDevice, &queueFamilyPropertyCount, reinterpret_cast<VkQueueFamilyProperties2 *>( queueFamilyProperties.data() ) );
VULKAN_HPP_ASSERT( queueFamilyPropertyCount <= queueFamilyProperties.size() );
VULKAN_HPP_ASSERT( queueFamilyPropertyCount <= queueFamilyProperties.size() );
if ( queueFamilyPropertyCount < queueFamilyProperties.size() )
{
structureChains.resize( queueFamilyPropertyCount );
}
for ( uint32_t i = 0; i < queueFamilyPropertyCount; i++ ) for ( uint32_t i = 0; i < queueFamilyPropertyCount; i++ )
{ {
structureChains[i].template get<VULKAN_HPP_NAMESPACE::QueueFamilyProperties2>() = queueFamilyProperties[i]; structureChains[i].template get<VULKAN_HPP_NAMESPACE::QueueFamilyProperties2>() = queueFamilyProperties[i];
@ -10848,18 +10866,24 @@ namespace VULKAN_HPP_NAMESPACE
{ {
VULKAN_HPP_ASSERT( d.getVkHeaderVersion() == VK_HEADER_VERSION ); VULKAN_HPP_ASSERT( d.getVkHeaderVersion() == VK_HEADER_VERSION );
std::vector<StructureChain, StructureChainAllocator> structureChains( structureChainAllocator );
std::vector<VULKAN_HPP_NAMESPACE::QueueFamilyProperties2> queueFamilyProperties;
uint32_t queueFamilyPropertyCount; uint32_t queueFamilyPropertyCount;
d.vkGetPhysicalDeviceQueueFamilyProperties2KHR( m_physicalDevice, &queueFamilyPropertyCount, nullptr ); d.vkGetPhysicalDeviceQueueFamilyProperties2KHR( m_physicalDevice, &queueFamilyPropertyCount, nullptr );
std::vector<StructureChain, StructureChainAllocator> structureChains( queueFamilyPropertyCount, structureChainAllocator ); structureChains.resize( queueFamilyPropertyCount );
std::vector<VULKAN_HPP_NAMESPACE::QueueFamilyProperties2> queueFamilyProperties( queueFamilyPropertyCount ); queueFamilyProperties.resize( queueFamilyPropertyCount );
for ( uint32_t i = 0; i < queueFamilyPropertyCount; i++ ) for ( uint32_t i = 0; i < queueFamilyPropertyCount; i++ )
{ {
queueFamilyProperties[i].pNext = structureChains[i].template get<VULKAN_HPP_NAMESPACE::QueueFamilyProperties2>().pNext; queueFamilyProperties[i].pNext = structureChains[i].template get<VULKAN_HPP_NAMESPACE::QueueFamilyProperties2>().pNext;
} }
d.vkGetPhysicalDeviceQueueFamilyProperties2KHR( d.vkGetPhysicalDeviceQueueFamilyProperties2KHR(
m_physicalDevice, &queueFamilyPropertyCount, reinterpret_cast<VkQueueFamilyProperties2 *>( queueFamilyProperties.data() ) ); m_physicalDevice, &queueFamilyPropertyCount, reinterpret_cast<VkQueueFamilyProperties2 *>( queueFamilyProperties.data() ) );
VULKAN_HPP_ASSERT( queueFamilyPropertyCount <= queueFamilyProperties.size() );
VULKAN_HPP_ASSERT( queueFamilyPropertyCount <= queueFamilyProperties.size() );
if ( queueFamilyPropertyCount < queueFamilyProperties.size() )
{
structureChains.resize( queueFamilyPropertyCount );
}
for ( uint32_t i = 0; i < queueFamilyPropertyCount; i++ ) for ( uint32_t i = 0; i < queueFamilyPropertyCount; i++ )
{ {
structureChains[i].template get<VULKAN_HPP_NAMESPACE::QueueFamilyProperties2>() = queueFamilyProperties[i]; structureChains[i].template get<VULKAN_HPP_NAMESPACE::QueueFamilyProperties2>() = queueFamilyProperties[i];