diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index c0cfe3a..e530542 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -3032,7 +3032,6 @@ std::string VulkanHppGenerator::generateCallSequence( std::string const & size_t initialSkipCount, std::set const & singularParams, std::set const & templatedParams, - bool withAllocator, bool chained ) const { // if at least one returnParam is a size value of a vector param (and no singular params), we need two calls @@ -3058,26 +3057,54 @@ std::string VulkanHppGenerator::generateCallSequence( std::string const & // chained data needs some more handling!! std::string vectorElementType = stripPostfix( commandData.params[vectorParamIt->first].type.compose( "VULKAN_HPP_NAMESPACE" ), " *" ); - const std::string callSequenceTemplate = - R"(d.${vkCommand}( ${firstCallArguments} ); - std::vector structureChains( ${counterName}${structureChainAllocator} ); - std::vector<${vectorElementType}> ${vectorName}( ${counterName} ); + if ( commandData.returnType == "VkResult" ) + { + const std::string callSequenceTemplate = R"(VkResult result; + do + { + result = d.${vkCommand}( ${firstCallArguments} ); + if ( ( result == VK_SUCCESS ) && ${counterName} ) + { + structureChains.resize( ${counterName} ); + ${vectorName}.resize( ${counterName} ); + for ( ${counterType} i = 0; i < ${counterName}; i++ ) + { + ${vectorName}[i].pNext = structureChains[i].template get<${vectorElementType}>().pNext; + } + result = d.${vkCommand}( ${secondCallArguments} ); + } + } while ( result == VK_INCOMPLETE );)"; + + 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 + { + 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} ); - VULKAN_HPP_ASSERT( ${counterName} <= ${vectorName}.size() );)"; + 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 }, - { "structureChainAllocator", withAllocator ? ( ", structureChainAllocator" ) : "" }, - { "vectorElementType", vectorElementType }, - { "vectorName", vectorName }, - { "vkCommand", name } } ); + 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" ) { @@ -3434,7 +3461,7 @@ std::string VulkanHppGenerator::generateCommandEnhanced( std::string const & commandData, initialSkipCount, returnParams, vectorParams, templatedParams, singular, withAllocator, unique, chained, enumerating ); std::string dataSizeChecks = generateDataSizeChecks( commandData, returnParams, dataTypes, vectorParams, templatedParams, singular ); 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 returnStatement = generateReturnStatement( 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 ( !isStructureChainAnchor( commandData.params[returnParams[1]].type.type ) ) + if ( isStructureChainAnchor( commandData.params[returnParams[1]].type.type ) ) + { + std::map 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 vectorParams = determineVectorParams( commandData.params ); if ( vectorParams.size() == 1 ) @@ -4642,11 +4689,18 @@ std::string VulkanHppGenerator::generateDataDeclarations( CommandData const & assert( vectorParamIt != vectorParams.end() ); assert( vectorParamIt->second == returnParams[0] ); - std::string const dataDeclarationTemplate = R"(${counterType} ${counterName};)"; + std::string const dataDeclarationTemplate = R"(std::vector structureChains${structureChainAllocator}; + std::vector<${vectorElementType}> ${vectorName}; + ${counterType} ${counterName};)"; - dataDeclarations = replaceWithMap( - dataDeclarationTemplate, - { { "counterName", startLowerCase( stripPrefix( commandData.params[returnParams[0]].name, "p" ) ) }, { "counterType", dataTypes[0] } } ); + dataDeclarations = replaceWithMap( dataDeclarationTemplate, + { + { "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 { @@ -4784,17 +4838,39 @@ std::string VulkanHppGenerator::generateDataPreparation( CommandData const & std::string vectorElementType = stripPostfix( commandData.params[vectorParamIt->first].type.compose( "VULKAN_HPP_NAMESPACE" ), " *" ); - std::string const dataPreparationTemplate = - R"(for ( ${counterType} i = 0; i < ${counterName}; i++ ) + 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 = + R"(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 } } ); + return replaceWithMap( dataPreparationTemplate, + { { "counterName", startLowerCase( stripPrefix( commandData.params[vectorParamIt->second].name, "p" ) ) }, + { "counterType", commandData.params[vectorParamIt->second].type.type }, + { "vectorElementType", vectorElementType }, + { "vectorName", vectorName } } ); + } } else if ( enumerating ) { @@ -9961,7 +10037,8 @@ std::string VulkanHppGenerator::generateReturnType( CommandData const & else { 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] ); assert( ( vectorIt != vectorParams.end() ) && ( vectorIt->second == returnParams[0] ) ); returnType = "std::vector"; diff --git a/VulkanHppGenerator.hpp b/VulkanHppGenerator.hpp index 9bae735..4d41b2f 100644 --- a/VulkanHppGenerator.hpp +++ b/VulkanHppGenerator.hpp @@ -474,7 +474,6 @@ private: size_t initialSkipCount, std::set const & singularParams, std::set const & templatedParams, - bool withAllocator, bool chained ) const; std::string generateChainTemplates( std::vector const & returnParams, bool chained ) const; std::string generateCommand( std::string const & name, CommandData const & commandData, size_t initialSkipCount, bool definition ) const; diff --git a/vulkan/vulkan_funcs.hpp b/vulkan/vulkan_funcs.hpp index 89f16f1..4e80445 100644 --- a/vulkan/vulkan_funcs.hpp +++ b/vulkan/vulkan_funcs.hpp @@ -5715,18 +5715,24 @@ namespace VULKAN_HPP_NAMESPACE { VULKAN_HPP_ASSERT( d.getVkHeaderVersion() == VK_HEADER_VERSION ); - uint32_t queueFamilyPropertyCount; + std::vector structureChains; + std::vector queueFamilyProperties; + uint32_t queueFamilyPropertyCount; d.vkGetPhysicalDeviceQueueFamilyProperties2( m_physicalDevice, &queueFamilyPropertyCount, nullptr ); - std::vector structureChains( queueFamilyPropertyCount ); - std::vector queueFamilyProperties( queueFamilyPropertyCount ); + structureChains.resize( queueFamilyPropertyCount ); + queueFamilyProperties.resize( queueFamilyPropertyCount ); for ( uint32_t i = 0; i < queueFamilyPropertyCount; i++ ) { queueFamilyProperties[i].pNext = structureChains[i].template get().pNext; } d.vkGetPhysicalDeviceQueueFamilyProperties2( m_physicalDevice, &queueFamilyPropertyCount, reinterpret_cast( 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++ ) { structureChains[i].template get() = queueFamilyProperties[i]; @@ -5744,18 +5750,24 @@ namespace VULKAN_HPP_NAMESPACE { VULKAN_HPP_ASSERT( d.getVkHeaderVersion() == VK_HEADER_VERSION ); - uint32_t queueFamilyPropertyCount; + std::vector structureChains( structureChainAllocator ); + std::vector queueFamilyProperties; + uint32_t queueFamilyPropertyCount; d.vkGetPhysicalDeviceQueueFamilyProperties2( m_physicalDevice, &queueFamilyPropertyCount, nullptr ); - std::vector structureChains( queueFamilyPropertyCount, structureChainAllocator ); - std::vector queueFamilyProperties( queueFamilyPropertyCount ); + structureChains.resize( queueFamilyPropertyCount ); + queueFamilyProperties.resize( queueFamilyPropertyCount ); for ( uint32_t i = 0; i < queueFamilyPropertyCount; i++ ) { queueFamilyProperties[i].pNext = structureChains[i].template get().pNext; } d.vkGetPhysicalDeviceQueueFamilyProperties2( m_physicalDevice, &queueFamilyPropertyCount, reinterpret_cast( 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++ ) { structureChains[i].template get() = queueFamilyProperties[i]; @@ -10819,18 +10831,24 @@ namespace VULKAN_HPP_NAMESPACE { VULKAN_HPP_ASSERT( d.getVkHeaderVersion() == VK_HEADER_VERSION ); - uint32_t queueFamilyPropertyCount; + std::vector structureChains; + std::vector queueFamilyProperties; + uint32_t queueFamilyPropertyCount; d.vkGetPhysicalDeviceQueueFamilyProperties2KHR( m_physicalDevice, &queueFamilyPropertyCount, nullptr ); - std::vector structureChains( queueFamilyPropertyCount ); - std::vector queueFamilyProperties( queueFamilyPropertyCount ); + structureChains.resize( queueFamilyPropertyCount ); + queueFamilyProperties.resize( queueFamilyPropertyCount ); for ( uint32_t i = 0; i < queueFamilyPropertyCount; i++ ) { queueFamilyProperties[i].pNext = structureChains[i].template get().pNext; } d.vkGetPhysicalDeviceQueueFamilyProperties2KHR( m_physicalDevice, &queueFamilyPropertyCount, reinterpret_cast( 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++ ) { structureChains[i].template get() = queueFamilyProperties[i]; @@ -10848,18 +10866,24 @@ namespace VULKAN_HPP_NAMESPACE { VULKAN_HPP_ASSERT( d.getVkHeaderVersion() == VK_HEADER_VERSION ); - uint32_t queueFamilyPropertyCount; + std::vector structureChains( structureChainAllocator ); + std::vector queueFamilyProperties; + uint32_t queueFamilyPropertyCount; d.vkGetPhysicalDeviceQueueFamilyProperties2KHR( m_physicalDevice, &queueFamilyPropertyCount, nullptr ); - std::vector structureChains( queueFamilyPropertyCount, structureChainAllocator ); - std::vector queueFamilyProperties( queueFamilyPropertyCount ); + structureChains.resize( queueFamilyPropertyCount ); + queueFamilyProperties.resize( queueFamilyPropertyCount ); for ( uint32_t i = 0; i < queueFamilyPropertyCount; i++ ) { queueFamilyProperties[i].pNext = structureChains[i].template get().pNext; } d.vkGetPhysicalDeviceQueueFamilyProperties2KHR( m_physicalDevice, &queueFamilyPropertyCount, reinterpret_cast( 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++ ) { structureChains[i].template get() = queueFamilyProperties[i];