diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 668f1db..75b89cc 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -1311,14 +1311,21 @@ void VulkanHppGenerator::appendCommand( std::string & str, { // the return parameter is the only vector parameter auto vectorParamIndexIt = vectorParamIndices.begin(); - assert( vectorParamIndexIt->first == *nonConstPointerParamIndices.begin() ); - assert( commandData.params[vectorParamIndexIt->second].type.isValue() ); - if ( commandData.params[vectorParamIndexIt->first].type.type == "void" ) + assert( vectorParamIndexIt->first == nonConstPointerParamIndices[0] ); + if ( isHandleType( commandData.params[nonConstPointerParamIndices[0]].type.type ) ) + { + assert( isParamIndirect( commandData.params[vectorParamIndexIt->first].len, + commandData.params[vectorParamIndexIt->second] ) ); + appendCommandGetVectorOfHandles( str, name, commandData, *vectorParamIndexIt, definition ); + } + else { // the size of the vector parameter is given by a value -> just get that stuff - appendCommandGetVector( str, name, commandData, vectorParamIndices, definition ); - appendedFunction = true; + assert( commandData.params[vectorParamIndexIt->first].type.type == "void" ); + assert( commandData.params[vectorParamIndexIt->second].type.isValue() ); + appendCommandGetVector( str, name, commandData, *vectorParamIndexIt, definition ); } + appendedFunction = true; } break; default: break; @@ -1767,14 +1774,13 @@ ${leave})"; { "newlineOnDefinition", definition ? "\n" : "" } } ) ); } -void VulkanHppGenerator::appendCommandGetVector( std::string & str, - std::string const & name, - CommandData const & commandData, - std::map const & vectorParamIndices, - bool definition ) const +void VulkanHppGenerator::appendCommandGetVector( std::string & str, + std::string const & name, + CommandData const & commandData, + std::pair const & vectorParamIndices, + bool definition ) const { assert( commandData.returnType == "VkResult" ); - assert( vectorParamIndices.size() == 1 ); std::string const functionTemplate = R"( ${enter}${commandStandard}${newlineOnDefinition} @@ -1802,6 +1808,46 @@ ${leave})"; { "newlineOnDefinition", definition ? "\n" : "" } } ) ); } +void VulkanHppGenerator::appendCommandGetVectorOfHandles( std::string & str, + std::string const & name, + CommandData const & commandData, + std::pair const & vectorParamIndices, + bool definition ) const +{ + assert( commandData.returnType == "VkResult" ); + + std::string const functionTemplate = R"( +${enter}${commandStandard}${newlineOnDefinition} +#ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE +${commandEnhanced}${newlineOnDefinition} +${commandEnhancedWithAllocators}${newlineOnDefinition} +# ifndef VULKAN_HPP_NO_SMART_HANDLE +${commandEnhancedUnique}${newlineOnDefinition} +${commandEnhancedUniqueWithAllocators} +# endif /*VULKAN_HPP_NO_SMART_HANDLE*/ +#endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ +${leave})"; + + std::string enter, leave; + std::tie( enter, leave ) = generateProtection( commandData.feature, commandData.extensions ); + + str += replaceWithMap( + functionTemplate, + std::map( + { { "commandEnhanced", + constructCommandGetVectorOfHandles( name, commandData, vectorParamIndices, definition, false ) }, + { "commandEnhancedUnique", + constructCommandGetVectorOfUniqueHandles( name, commandData, vectorParamIndices, definition, false ) }, + { "commandEnhancedUniqueWithAllocators", + constructCommandGetVectorOfUniqueHandles( name, commandData, vectorParamIndices, definition, true ) }, + { "commandEnhancedWithAllocators", + constructCommandGetVectorOfHandles( name, commandData, vectorParamIndices, definition, true ) }, + { "commandStandard", constructCommandStandard( name, commandData, definition ) }, + { "enter", enter }, + { "leave", leave }, + { "newlineOnDefinition", definition ? "\n" : "" } } ) ); +} + void VulkanHppGenerator::appendCommandSimple( std::string & str, std::string const & name, CommandData const & commandData, @@ -2633,7 +2679,7 @@ std::string VulkanHppGenerator::appendFunctionBodyEnhancedLocalReturnVariable( if ( vpiIt != vectorParamIndices.end() && !twoStep ) { appendFunctionBodyEnhancedLocalReturnVariableVectorSize( - str, commandData.params, *vpiIt, returnParamIndex, vectorParamIndices, withAllocator ); + str, commandData.params, *vpiIt, vectorParamIndices, withAllocator ); } else if ( withAllocator ) { @@ -2649,40 +2695,21 @@ void VulkanHppGenerator::appendFunctionBodyEnhancedLocalReturnVariableVectorSize std::string & str, std::vector const & params, std::pair const & vectorParamIndex, - size_t returnParamIndex, std::map const & vectorParamIndices, bool withAllocator ) const { // if the return parameter is a vector parameter, and not part of a two-step algorithm, initialize its size std::string size; - if ( vectorParamIndex.second == INVALID_INDEX ) + assert( vectorParamIndex.second != INVALID_INDEX ); + // the size of the vector is given by an other parameter + // first check, if that size has become the size of some other vector parameter + // -> look for it and get it's actual size + for ( auto const & vpi : vectorParamIndices ) { - assert( !params[returnParamIndex].len.empty() ); - // the size of the vector is not given by an other parameter, but by some member of a parameter, described as - // 'parameter->member' - // -> replace the '->' by '.' and filter out the leading 'p' to access that value - size = startLowerCase( stripPrefix( params[returnParamIndex].len, "p" ) ); - size_t pos = size.find( "->" ); - if ( pos == std::string::npos ) + if ( ( vpi.first != vectorParamIndex.first ) && ( vpi.second == vectorParamIndex.second ) ) { - // other notation possibility: :: - pos = size.find( "::" ); - } - assert( pos != std::string::npos ); - size.replace( pos, 2, "." ); - } - else - { - // the size of the vector is given by an other parameter - // first check, if that size has become the size of some other vector parameter - // -> look for it and get it's actual size - for ( auto const & vpi : vectorParamIndices ) - { - if ( ( vpi.first != vectorParamIndex.first ) && ( vpi.second == vectorParamIndex.second ) ) - { - size = startLowerCase( stripPrefix( params[vpi.first].name, "p" ) ) + ".size()"; - break; - } + size = startLowerCase( stripPrefix( params[vpi.first].name, "p" ) ) + ".size()"; + break; } } assert( !size.empty() ); @@ -4429,7 +4456,7 @@ std::string VulkanHppGenerator::constructCommandEnumerateVoid( std::string const if ( definition ) { const std::string functionTemplate = - R"( template + R"( template VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE std::vector<${vectorElementType}, ${vectorElementType}Allocator> ${className}::${commandName}( ${argumentList} ) const { std::vector<${vectorElementType}, ${vectorElementType}Allocator> ${vectorName}${vectorAllocator}; @@ -4441,10 +4468,9 @@ std::string VulkanHppGenerator::constructCommandEnumerateVoid( std::string const return ${vectorName}; })"; - std::string vectorName = startLowerCase( stripPrefix( commandData.params[vectorParamIndex.first].name, "p" ) ); - std::string withAllocatorsTypenameCheck = - ", typename B, typename std::enable_if::value, int>::type "; + std::string vectorName = startLowerCase( stripPrefix( commandData.params[vectorParamIndex.first].name, "p" ) ); + std::string typenameCheck = ", typename B, typename std::enable_if::value, int>::type "; str = replaceWithMap( functionTemplate, @@ -4458,11 +4484,11 @@ std::string VulkanHppGenerator::constructCommandEnumerateVoid( std::string const constructCallArgumentsEnumerateVectors( commandData.params, { vectorParamIndex }, true ) }, { "secondCallArguments", constructCallArgumentsEnumerateVectors( commandData.params, { vectorParamIndex }, false ) }, + { "typenameCheck", withAllocators ? typenameCheck : "" }, { "vectorAllocator", withAllocators ? ( "( " + vectorName + "Allocator )" ) : "" }, { "vectorElementType", vectorElementType }, { "vectorName", vectorName }, - { "vkCommand", name }, - { "withAllocatorTypenameCheck", withAllocators ? withAllocatorsTypenameCheck : "" } } ) ); + { "vkCommand", name } } ) ); } else { @@ -4470,17 +4496,16 @@ std::string VulkanHppGenerator::constructCommandEnumerateVoid( std::string const R"( template , typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE${withAllocatorTypenameCheck}> VULKAN_HPP_NODISCARD std::vector<${vectorElementType}, ${vectorElementType}Allocator> ${commandName}( ${argumentList} ) const;)"; - std::string withAllocatorsTypenameCheck = - ", typename B = " + vectorElementType + - "Allocator, typename std::enable_if::value, int>::type = 0"; + std::string typenameCheck = ", typename B = " + vectorElementType + + "Allocator, typename std::enable_if::value, int>::type = 0"; - str = replaceWithMap( functionTemplate, - std::map( - { { "argumentList", argumentList }, - { "commandName", commandName }, - { "vectorElementType", vectorElementType }, - { "withAllocatorTypenameCheck", withAllocators ? withAllocatorsTypenameCheck : "" } } ) ); + str = replaceWithMap( + functionTemplate, + std::map( { { "argumentList", argumentList }, + { "commandName", commandName }, + { "vectorElementType", vectorElementType }, + { "withAllocatorTypenameCheck", withAllocators ? typenameCheck : "" } } ) ); } return str; } @@ -4656,18 +4681,15 @@ std::string VulkanHppGenerator::constructCommandGetValue( std::string const & na return str; } -std::string VulkanHppGenerator::constructCommandGetVector( std::string const & name, - CommandData const & commandData, - std::map const & vectorParamIndices, - bool definition ) const +std::string VulkanHppGenerator::constructCommandGetVector( std::string const & name, + CommandData const & commandData, + std::pair const & vectorParamIndices, + bool definition ) const { - assert( vectorParamIndices.size() == 1 ); - std::string str; - size_t vectorParamIndex = vectorParamIndices.begin()->first; std::string argumentList = - constructArgumentListEnhanced( commandData.params, { 0, vectorParamIndex }, definition, false ); + constructArgumentListEnhanced( commandData.params, { 0, vectorParamIndices.first }, definition, false ); std::string commandName = determineCommandName( name, commandData.params[0].type.type ); std::string nodiscard = constructNoDiscardEnhanced( commandData ); std::string returnType = constructReturnType( commandData, "std::vector" ); @@ -4688,12 +4710,11 @@ std::string VulkanHppGenerator::constructCommandGetVector( std::string const & functionTemplate, std::map( { { "argumentList", argumentList }, - { "callArguments", - constructCallArgumentsGetVector( commandData.params, *vectorParamIndices.begin(), false ) }, + { "callArguments", constructCallArgumentsGetVector( commandData.params, vectorParamIndices, false ) }, { "className", stripPrefix( commandData.handle, "Vk" ) }, { "commandName", commandName }, - { "dataName", startLowerCase( stripPrefix( commandData.params[vectorParamIndex].name, "p" ) ) }, - { "dataSize", commandData.params[vectorParamIndex].len }, + { "dataName", startLowerCase( stripPrefix( commandData.params[vectorParamIndices.first].name, "p" ) ) }, + { "dataSize", commandData.params[vectorParamIndices.first].len }, { "nodiscard", nodiscard }, { "returnType", returnType }, { "successCodeList", constructSuccessCodeList( commandData.successCodes ) }, @@ -4716,16 +4737,15 @@ std::string VulkanHppGenerator::constructCommandGetVector( std::string const & } std::string - VulkanHppGenerator::constructCommandGetVectorDeprecated( std::string const & name, - CommandData const & commandData, - std::map const & vectorParamIndices, - bool definition ) const + VulkanHppGenerator::constructCommandGetVectorDeprecated( std::string const & name, + CommandData const & commandData, + std::pair const & vectorParamIndices, + bool definition ) const { std::string str; - std::map::const_iterator vectorParamIndexIt = vectorParamIndices.begin(); - std::string argumentList = constructFunctionHeaderArgumentsEnhanced( - commandData, INVALID_INDEX, vectorParamIndexIt->first, vectorParamIndices, false, !definition, false ); + std::string argumentList = constructFunctionHeaderArgumentsEnhanced( + commandData, INVALID_INDEX, vectorParamIndices.first, { vectorParamIndices }, false, !definition, false ); std::string commandName = determineCommandName( name, commandData.params[0].type.type ); std::string nodiscard = constructNoDiscardEnhanced( commandData ); std::string returnType = constructReturnType( commandData, "void" ); @@ -4750,8 +4770,8 @@ std::string name, commandData, INVALID_INDEX, - vectorParamIndexIt->first, - vectorParamIndices, + vectorParamIndices.first, + { vectorParamIndices }, false, "void", false, @@ -4777,19 +4797,249 @@ std::string return str; } -std::string VulkanHppGenerator::constructCommandGetVectorSingular( std::string const & name, - CommandData const & commandData, - std::map const & vectorParamIndices, - bool definition ) const +std::string + VulkanHppGenerator::constructCommandGetVectorOfHandles( std::string const & name, + CommandData const & commandData, + std::pair const & vectorParamIndices, + bool definition, + bool withAllocator ) const { - assert( vectorParamIndices.size() == 1 ); + assert( !commandData.handle.empty() ); + assert( commandData.successCodes.size() == 1 ); std::string str; - size_t vectorParamIndex = vectorParamIndices.begin()->first; - size_t sizeParamIndex = vectorParamIndices.begin()->second; std::string argumentList = - constructArgumentListEnhanced( commandData.params, { 0, sizeParamIndex, vectorParamIndex }, definition, false ); + constructArgumentListEnhanced( commandData.params, { 0, vectorParamIndices.first }, definition, withAllocator ); + std::string commandName = determineCommandName( name, commandData.params[0].type.type ); + std::string nodiscard = constructNoDiscardEnhanced( commandData ); + std::string handleType = stripPrefix( commandData.params[vectorParamIndices.first].type.type, "Vk" ); + + if ( definition ) + { + std::string const functionTemplate = + R"( template + ${nodiscard}VULKAN_HPP_INLINE typename ResultValueType>::type ${className}::${commandName}( ${argumentList} ) const + { + std::vector<${handleType}, ${handleType}Allocator> ${vectorName}( ${vectorSize}${vectorAllocator} ); + Result result = static_cast( d.${vkCommand}( ${callArguments} ) ); + return createResultValue( result, ${vectorName}, VULKAN_HPP_NAMESPACE_STRING "::${className}::${commandName}" ); + })"; + + std::vector lenParts = tokenize( commandData.params[vectorParamIndices.first].len, "->" ); + assert( lenParts.size() == 2 ); + + std::string typenameCheck = ", typename B, typename std::enable_if::value, int>::type "; + std::string vectorName = startLowerCase( stripPrefix( commandData.params[vectorParamIndices.first].name, "p" ) ); + + str = replaceWithMap( + functionTemplate, + std::map( + { { "argumentList", argumentList }, + { "callArguments", constructCallArgumentsGetVector( commandData.params, vectorParamIndices, false ) }, + { "className", stripPrefix( commandData.handle, "Vk" ) }, + { "commandName", commandName }, + { "nodiscard", nodiscard }, + { "handleType", handleType }, + { "typenameCheck", withAllocator ? typenameCheck : "" }, + { "vectorAllocator", withAllocator ? ( ", " + vectorName + "Allocator" ) : "" }, + { "vectorName", vectorName }, + { "vectorSize", startLowerCase( stripPrefix( lenParts[0], "p" ) ) + "." + lenParts[1] }, + { "vkCommand", name } } ) ); + } + else + { + std::string const functionTemplate = + R"( template , typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE${typenameCheck}> + ${nodiscard}typename ResultValueType>::type ${commandName}( ${argumentList} ) const;)"; + + std::string typenameCheck = ", typename B = " + handleType + "Allocator, typename std::enable_if::value, int>::type = 0"; + + str = replaceWithMap( + functionTemplate, + std::map( { { "argumentList", argumentList }, + { "commandName", commandName }, + { "handleType", handleType }, + { "nodiscard", nodiscard }, + { "typenameCheck", withAllocator ? typenameCheck : "" } } ) ); + } + + return str; +} + +std::string + VulkanHppGenerator::constructCommandGetVectorOfUniqueHandles( std::string const & name, + CommandData const & commandData, + std::pair const & vectorParamIndices, + bool definition, + bool withAllocator ) const +{ + assert( !commandData.handle.empty() ); + assert( commandData.successCodes.size() == 1 ); + + std::string str; + + std::string argumentList = + constructArgumentListEnhanced( commandData.params, { 0, vectorParamIndices.first }, definition, withAllocator ); + std::string commandName = determineCommandName( name, commandData.params[0].type.type ); + std::string nodiscard = constructNoDiscardEnhanced( commandData ); + std::string handleType = stripPrefix( commandData.params[vectorParamIndices.first].type.type, "Vk" ); + + if ( definition ) + { + std::string const functionTemplate = + R"( template + ${nodiscard}VULKAN_HPP_INLINE typename ResultValueType, ${handleType}Allocator>>::type ${className}::${commandName}Unique( ${argumentList} ) const + { + std::vector, ${handleType}Allocator> ${uniqueVectorName}${vectorAllocator}; + std::vector<${handleType}> ${vectorName}( ${vectorSize} ); + Result result = static_cast( d.${vkCommand}( ${callArguments} ) ); + if ( result == VULKAN_HPP_NAMESPACE::Result::eSuccess ) + { + ${uniqueVectorName}.reserve( ${vectorSize} ); + PoolFree<${className}, ${poolType}, Dispatch> deleter( *this, ${poolName}, d ); + for ( size_t i=0; i < ${vectorSize}; i++ ) + { + ${uniqueVectorName}.push_back( UniqueHandle<${handleType}, Dispatch>( ${vectorName}[i], deleter ) ); + } + } + return createResultValue( result, std::move( ${uniqueVectorName} ), VULKAN_HPP_NAMESPACE_STRING "::${className}::${commandName}Unique" ); + })"; + + std::vector lenParts = tokenize( commandData.params[vectorParamIndices.first].len, "->" ); + assert( lenParts.size() == 2 ); + std::string poolType, poolName; + std::tie( poolType, poolName ) = getPoolTypeAndName( commandData.params[vectorParamIndices.second].type.type ); + assert( !poolType.empty() ); + std::string typenameCheck = ", typename B, typename std::enable_if>::value, int>::type "; + std::string vectorName = startLowerCase( stripPrefix( commandData.params[vectorParamIndices.first].name, "p" ) ); + + str = replaceWithMap( + functionTemplate, + std::map( + { { "argumentList", argumentList }, + { "callArguments", constructCallArgumentsGetVector( commandData.params, vectorParamIndices, false ) }, + { "className", stripPrefix( commandData.handle, "Vk" ) }, + { "commandName", commandName }, + { "handleType", handleType }, + { "nodiscard", nodiscard }, + { "poolName", startLowerCase( stripPrefix( lenParts[0], "p" ) ) + "." + poolName }, + { "poolType", stripPrefix( poolType, "Vk" ) }, + { "typenameCheck", withAllocator ? typenameCheck : "" }, + { "uniqueVectorName", "unique" + stripPrefix( commandData.params[vectorParamIndices.first].name, "p" ) }, + { "vectorAllocator", withAllocator ? ( "( " + vectorName + "Allocator )" ) : "" }, + { "vectorName", vectorName }, + { "vectorSize", startLowerCase( stripPrefix( lenParts[0], "p" ) ) + "." + lenParts[1] }, + { "vkCommand", name } } ) ); + } + else + { + std::string const functionTemplate = + R"( template >${typenameCheck}> + ${nodiscard}typename ResultValueType, ${handleType}Allocator>>::type ${commandName}Unique( ${argumentList} ) const;)"; + + std::string typenameCheck = ", typename B = " + handleType + "Allocator, typename std::enable_if>::value, int>::type = 0"; + + str = replaceWithMap( functionTemplate, + std::map( { { "argumentList", argumentList }, + { "commandName", commandName }, + { "handleType", handleType }, + { "nodiscard", nodiscard }, + { "typenameCheck", withAllocator ? typenameCheck : "" } } ) ); + } + + return str; +} + +std::string VulkanHppGenerator::constructCommandGetVectorOfUniqueHandlesWithAllocator( + std::string const & name, + CommandData const & commandData, + std::pair const & vectorParamIndices, + bool definition ) const +{ + assert( !commandData.handle.empty() ); + assert( commandData.successCodes.size() == 1 ); + + std::string str; + + std::string argumentList = + constructArgumentListEnhanced( commandData.params, { 0, vectorParamIndices.first }, definition, true ); + std::string commandName = determineCommandName( name, commandData.params[0].type.type ); + std::string nodiscard = constructNoDiscardEnhanced( commandData ); + std::string handleType = stripPrefix( commandData.params[vectorParamIndices.first].type.type, "Vk" ); + + if ( definition ) + { + std::string const functionTemplate = + R"( template >::value, int>::type> + ${nodiscard}VULKAN_HPP_INLINE typename ResultValueType, Allocator>>::type ${className}::${commandName}Unique( ${argumentList} ) const + { + std::vector, Allocator> ${uniqueVectorName}( ${vectorName}Allocator ); + std::vector<${handleType}> ${vectorName}( ${vectorSize} ); + Result result = static_cast( d.${vkCommand}( ${callArguments} ) ); + if ( result == VULKAN_HPP_NAMESPACE::Result::eSuccess ) + { + ${uniqueVectorName}.reserve( ${vectorSize} ); + PoolFree<${className}, ${poolType}, Dispatch> deleter( *this, ${poolName}, d ); + for ( size_t i=0; i < ${vectorSize}; i++ ) + { + ${uniqueVectorName}.push_back( UniqueHandle<${handleType}, Dispatch>( ${vectorName}[i], deleter ) ); + } + } + return createResultValue( result, std::move( ${uniqueVectorName} ), VULKAN_HPP_NAMESPACE_STRING "::${className}::${commandName}Unique" ); + })"; + + std::vector lenParts = tokenize( commandData.params[vectorParamIndices.first].len, "->" ); + assert( lenParts.size() == 2 ); + std::string poolType, poolName; + std::tie( poolType, poolName ) = getPoolTypeAndName( commandData.params[vectorParamIndices.second].type.type ); + assert( !poolType.empty() ); + + str = replaceWithMap( + functionTemplate, + std::map( + { { "argumentList", argumentList }, + { "callArguments", constructCallArgumentsGetVector( commandData.params, vectorParamIndices, false ) }, + { "className", stripPrefix( commandData.handle, "Vk" ) }, + { "commandName", commandName }, + { "handleType", handleType }, + { "nodiscard", nodiscard }, + { "poolName", startLowerCase( stripPrefix( lenParts[0], "p" ) ) + "." + poolName }, + { "poolType", stripPrefix( poolType, "Vk" ) }, + { "uniqueVectorName", "unique" + stripPrefix( commandData.params[vectorParamIndices.first].name, "p" ) }, + { "vectorName", startLowerCase( stripPrefix( commandData.params[vectorParamIndices.first].name, "p" ) ) }, + { "vectorSize", startLowerCase( stripPrefix( lenParts[0], "p" ) ) + "." + lenParts[1] }, + { "vkCommand", name } } ) ); + } + else + { + std::string const functionTemplate = + R"( template >, typename B = Allocator, typename std::enable_if>::value, int>::type = 0> + ${nodiscard}typename ResultValueType, Allocator>>::type ${commandName}Unique( ${argumentList} ) const;)"; + + str = replaceWithMap( functionTemplate, + std::map( { { "argumentList", argumentList }, + { "commandName", commandName }, + { "handleType", handleType }, + { "nodiscard", nodiscard } } ) ); + } + + return str; +} + +std::string VulkanHppGenerator::constructCommandGetVectorSingular( std::string const & name, + CommandData const & commandData, + std::pair const & vectorParamIndices, + bool definition ) const +{ + std::string str; + + std::string argumentList = constructArgumentListEnhanced( + commandData.params, { 0, vectorParamIndices.second, vectorParamIndices.first }, definition, false ); std::string commandName = stripPluralS( determineCommandName( name, commandData.params[0].type.type ) ); std::string nodiscard = constructNoDiscardEnhanced( commandData ); std::string returnType = constructReturnType( commandData, "T" ); @@ -4809,10 +5059,10 @@ std::string VulkanHppGenerator::constructCommandGetVectorSingular( std::string c functionTemplate, std::map( { { "argumentList", argumentList }, - { "callArguments", constructCallArgumentsGetVector( commandData.params, *vectorParamIndices.begin(), true ) }, + { "callArguments", constructCallArgumentsGetVector( commandData.params, vectorParamIndices, true ) }, { "className", stripPrefix( commandData.handle, "Vk" ) }, { "commandName", commandName }, - { "dataName", startLowerCase( stripPrefix( commandData.params[vectorParamIndex].name, "p" ) ) }, + { "dataName", startLowerCase( stripPrefix( commandData.params[vectorParamIndices.first].name, "p" ) ) }, { "nodiscard", nodiscard }, { "returnType", returnType }, { "successCodeList", constructSuccessCodeList( commandData.successCodes ) }, @@ -6872,7 +7122,7 @@ std::map if ( !it->len.empty() ) { auto findIt = std::find_if( params.begin(), it, [this, ¶ms, &it]( ParamData const & pd ) { - return ( pd.name == it->len ) || isParamIndirect( it->len, params ); + return ( pd.name == it->len ) || isParamIndirect( it->len, pd ); } ); if ( findIt < it ) @@ -7143,6 +7393,20 @@ std::set VulkanHppGenerator::getPlatforms( std::set co return platforms; } +std::pair VulkanHppGenerator::getPoolTypeAndName( std::string const & type ) const +{ + auto structIt = m_structures.find( type ); + assert( structIt != m_structures.end() ); + auto memberIt = std::find_if( structIt->second.members.begin(), + structIt->second.members.end(), + []( MemberData const & md ) { return md.name.find( "Pool" ) != std::string::npos; } ); + assert( memberIt != structIt->second.members.end() ); + assert( std::find_if( std::next( memberIt ), structIt->second.members.end(), []( MemberData const & md ) { + return md.name.find( "Pool" ) != std::string::npos; + } ) == structIt->second.members.end() ); + return std::make_pair( memberIt->type.type, memberIt->name ); +} + bool VulkanHppGenerator::isChainableStructure( std::string const & type ) const { if ( beginsWith( type, "Vk" ) ) @@ -7212,6 +7476,28 @@ bool VulkanHppGenerator::isParamIndirect( std::string const & name, std::vector< return false; } +bool VulkanHppGenerator::isParamIndirect( std::string const & name, ParamData const & param ) const +{ + // check if name specifies a member of a struct + std::vector nameParts = tokenize( name, "->" ); + if ( nameParts.size() == 1 ) + { + // older versions of vk.xml used the notation parameter::member + nameParts = tokenize( name, "::" ); + } + if ( ( nameParts.size() == 2 ) && ( nameParts[0] == param.name ) ) + { + auto structureIt = m_structures.find( param.type.type ); + assert( structureIt != m_structures.end() ); + assert( std::find_if( structureIt->second.members.begin(), + structureIt->second.members.end(), + [&n = nameParts[1]]( MemberData const & md ) { return md.name == n; } ) != + structureIt->second.members.end() ); + return true; + } + return false; +} + bool VulkanHppGenerator::isTwoStepAlgorithm( std::vector const & params ) const { // we generate a two-step algorithm for functions returning a vector of stuff, where the length is specified as a diff --git a/VulkanHppGenerator.hpp b/VulkanHppGenerator.hpp index 73fd166..d8fd142 100644 --- a/VulkanHppGenerator.hpp +++ b/VulkanHppGenerator.hpp @@ -336,11 +336,16 @@ private: CommandData const & commandData, size_t nonConstPointerIndex, bool definition ) const; - void appendCommandGetVector( std::string & str, - std::string const & name, - CommandData const & commandData, - std::map const & vectorParamIndices, - bool definition ) const; + void appendCommandGetVector( std::string & str, + std::string const & name, + CommandData const & commandData, + std::pair const & vectorParamIndices, + bool definition ) const; + void appendCommandGetVectorOfHandles( std::string & str, + std::string const & name, + CommandData const & commandData, + std::pair const & vectorParamIndices, + bool definition ) const; void appendCommandSimple( std::string & str, std::string const & name, CommandData const & commandData, @@ -405,7 +410,6 @@ private: void appendFunctionBodyEnhancedLocalReturnVariableVectorSize( std::string & str, std::vector const & params, std::pair const & vectorParamIndex, - size_t returnParamIndex, std::map const & vectorParamIndices, bool withAllocator ) const; void appendFunctionBodyEnhancedMultiVectorSizeCheck( std::string & str, @@ -582,18 +586,31 @@ private: CommandData const & commandData, size_t nonConstPointerIndex, bool definition ) const; - std::string constructCommandGetVector( std::string const & name, - CommandData const & commandData, - std::map const & vectorParamIndices, - bool definition ) const; - std::string constructCommandGetVectorDeprecated( std::string const & name, - CommandData const & commandData, - std::map const & vectorParamIndices, - bool definition ) const; - std::string constructCommandGetVectorSingular( std::string const & name, - CommandData const & commandData, - std::map const & vectorParamIndices, - bool definition ) const; + std::string constructCommandGetVector( std::string const & name, + CommandData const & commandData, + std::pair const & vectorParamIndices, + bool definition ) const; + std::string constructCommandGetVectorDeprecated( std::string const & name, + CommandData const & commandData, + std::pair const & vectorParamIndices, + bool definition ) const; + std::string constructCommandGetVectorOfHandles( std::string const & name, + CommandData const & commandData, + std::pair const & vectorParamIndices, + bool definition, bool withAllocator ) const; + std::string constructCommandGetVectorOfUniqueHandles( std::string const & name, + CommandData const & commandData, + std::pair const & vectorParamIndices, + bool definition, bool withAllocator ) const; + std::string + constructCommandGetVectorOfUniqueHandlesWithAllocator( std::string const & name, + CommandData const & commandData, + std::pair const & vectorParamIndices, + bool definition ) const; + std::string constructCommandGetVectorSingular( std::string const & name, + CommandData const & commandData, + std::pair const & vectorParamIndices, + bool definition ) const; std::string constructCommandSimple( std::string const & name, CommandData const & commandData, bool definition, @@ -680,12 +697,14 @@ private: std::string const & structName, std::string const & prefix ) const; std::set getPlatforms( std::set const & extensions ) const; - bool isChainableStructure( std::string const & type ) const; - bool isHandleType( std::string const & type ) const; - bool isParam( std::string const & name, std::vector const & params ) const; - bool isParamIndirect( std::string const & name, std::vector const & params ) const; - bool isTwoStepAlgorithm( std::vector const & params ) const; - bool needsComplexBody( CommandData const & commandData ) const; + std::pair getPoolTypeAndName( std::string const & type ) const; + bool isChainableStructure( std::string const & type ) const; + bool isHandleType( std::string const & type ) const; + bool isParam( std::string const & name, std::vector const & params ) const; + bool isParamIndirect( std::string const & name, std::vector const & params ) const; + bool isParamIndirect( std::string const & name, ParamData const & param ) const; + bool isTwoStepAlgorithm( std::vector const & params ) const; + bool needsComplexBody( CommandData const & commandData ) const; std::pair>> needsVectorSizeCheck( std::map const & vectorParamIndices ) const; void readBaseType( tinyxml2::XMLElement const * element, std::map const & attributes ); diff --git a/vulkan/vulkan.hpp b/vulkan/vulkan.hpp index 6191d78..b1d8cf4 100644 --- a/vulkan/vulkan.hpp +++ b/vulkan/vulkan.hpp @@ -52101,36 +52101,38 @@ namespace VULKAN_HPP_NAMESPACE VULKAN_HPP_NAMESPACE::CommandBuffer * pCommandBuffers, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const VULKAN_HPP_NOEXCEPT; #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE - template , - typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE> - VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS typename ResultValueType>::type + template , + typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE> + VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS + typename ResultValueType>::type allocateCommandBuffers( const CommandBufferAllocateInfo & allocateInfo, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; - template , - typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE, - typename B = Allocator, + template , + typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE, + typename B = CommandBufferAllocator, typename std::enable_if::value, int>::type = 0> - VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS typename ResultValueType>::type + VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS + typename ResultValueType>::type allocateCommandBuffers( const CommandBufferAllocateInfo & allocateInfo, - Allocator const & vectorAllocator, + CommandBufferAllocator & commandBuffersAllocator, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; # ifndef VULKAN_HPP_NO_SMART_HANDLE - template >> + template >> VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS - typename ResultValueType, Allocator>>::type + typename ResultValueType, CommandBufferAllocator>>::type allocateCommandBuffersUnique( const CommandBufferAllocateInfo & allocateInfo, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; template < typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE, - typename Allocator = std::allocator>, - typename B = Allocator, + typename CommandBufferAllocator = std::allocator>, + typename B = CommandBufferAllocator, typename std::enable_if>::value, int>::type = 0> VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS - typename ResultValueType, Allocator>>::type + typename ResultValueType, CommandBufferAllocator>>::type allocateCommandBuffersUnique( const CommandBufferAllocateInfo & allocateInfo, - Allocator const & vectorAllocator, + CommandBufferAllocator & commandBuffersAllocator, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; # endif /*VULKAN_HPP_NO_SMART_HANDLE*/ #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ @@ -52141,36 +52143,38 @@ namespace VULKAN_HPP_NAMESPACE VULKAN_HPP_NAMESPACE::DescriptorSet * pDescriptorSets, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const VULKAN_HPP_NOEXCEPT; #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE - template , - typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE> - VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS typename ResultValueType>::type + template , + typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE> + VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS + typename ResultValueType>::type allocateDescriptorSets( const DescriptorSetAllocateInfo & allocateInfo, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; - template , - typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE, - typename B = Allocator, + template , + typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE, + typename B = DescriptorSetAllocator, typename std::enable_if::value, int>::type = 0> - VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS typename ResultValueType>::type + VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS + typename ResultValueType>::type allocateDescriptorSets( const DescriptorSetAllocateInfo & allocateInfo, - Allocator const & vectorAllocator, + DescriptorSetAllocator & descriptorSetsAllocator, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; # ifndef VULKAN_HPP_NO_SMART_HANDLE - template >> + template >> VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS - typename ResultValueType, Allocator>>::type + typename ResultValueType, DescriptorSetAllocator>>::type allocateDescriptorSetsUnique( const DescriptorSetAllocateInfo & allocateInfo, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; template < typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE, - typename Allocator = std::allocator>, - typename B = Allocator, + typename DescriptorSetAllocator = std::allocator>, + typename B = DescriptorSetAllocator, typename std::enable_if>::value, int>::type = 0> VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS - typename ResultValueType, Allocator>>::type + typename ResultValueType, DescriptorSetAllocator>>::type allocateDescriptorSetsUnique( const DescriptorSetAllocateInfo & allocateInfo, - Allocator const & vectorAllocator, + DescriptorSetAllocator & descriptorSetsAllocator, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; # endif /*VULKAN_HPP_NO_SMART_HANDLE*/ #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ @@ -92462,45 +92466,49 @@ namespace VULKAN_HPP_NAMESPACE reinterpret_cast( pAllocateInfo ), reinterpret_cast( pCommandBuffers ) ) ); } + #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE - template + template VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE - typename ResultValueType>::type + typename ResultValueType>::type Device::allocateCommandBuffers( const CommandBufferAllocateInfo & allocateInfo, Dispatch const & d ) const { - std::vector commandBuffers( allocateInfo.commandBufferCount ); - Result result = static_cast( + std::vector commandBuffers( allocateInfo.commandBufferCount ); + Result result = static_cast( d.vkAllocateCommandBuffers( m_device, reinterpret_cast( &allocateInfo ), reinterpret_cast( commandBuffers.data() ) ) ); return createResultValue( result, commandBuffers, VULKAN_HPP_NAMESPACE_STRING "::Device::allocateCommandBuffers" ); } - template ::value, int>::type> VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE - typename ResultValueType>::type + typename ResultValueType>::type Device::allocateCommandBuffers( const CommandBufferAllocateInfo & allocateInfo, - Allocator const & vectorAllocator, + CommandBufferAllocator & commandBuffersAllocator, Dispatch const & d ) const { - std::vector commandBuffers( allocateInfo.commandBufferCount, vectorAllocator ); - Result result = static_cast( + std::vector commandBuffers( allocateInfo.commandBufferCount, + commandBuffersAllocator ); + Result result = static_cast( d.vkAllocateCommandBuffers( m_device, reinterpret_cast( &allocateInfo ), reinterpret_cast( commandBuffers.data() ) ) ); return createResultValue( result, commandBuffers, VULKAN_HPP_NAMESPACE_STRING "::Device::allocateCommandBuffers" ); } + # ifndef VULKAN_HPP_NO_SMART_HANDLE - template + template VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE - typename ResultValueType, Allocator>>::type + typename ResultValueType, CommandBufferAllocator>>::type Device::allocateCommandBuffersUnique( const CommandBufferAllocateInfo & allocateInfo, Dispatch const & d ) const { - std::vector, Allocator> uniqueCommandBuffers; - std::vector commandBuffers( allocateInfo.commandBufferCount ); - Result result = static_cast( + std::vector, CommandBufferAllocator> uniqueCommandBuffers; + std::vector commandBuffers( allocateInfo.commandBufferCount ); + Result result = static_cast( d.vkAllocateCommandBuffers( m_device, reinterpret_cast( &allocateInfo ), reinterpret_cast( commandBuffers.data() ) ) ); @@ -92513,24 +92521,25 @@ namespace VULKAN_HPP_NAMESPACE uniqueCommandBuffers.push_back( UniqueHandle( commandBuffers[i], deleter ) ); } } - return createResultValue( result, std::move( uniqueCommandBuffers ), VULKAN_HPP_NAMESPACE_STRING "::Device::allocateCommandBuffersUnique" ); } + template >::value, int>::type> VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE - typename ResultValueType, Allocator>>::type + typename ResultValueType, CommandBufferAllocator>>::type Device::allocateCommandBuffersUnique( const CommandBufferAllocateInfo & allocateInfo, - Allocator const & vectorAllocator, + CommandBufferAllocator & commandBuffersAllocator, Dispatch const & d ) const { - std::vector, Allocator> uniqueCommandBuffers( vectorAllocator ); - std::vector commandBuffers( allocateInfo.commandBufferCount ); - Result result = static_cast( + std::vector, CommandBufferAllocator> uniqueCommandBuffers( + commandBuffersAllocator ); + std::vector commandBuffers( allocateInfo.commandBufferCount ); + Result result = static_cast( d.vkAllocateCommandBuffers( m_device, reinterpret_cast( &allocateInfo ), reinterpret_cast( commandBuffers.data() ) ) ); @@ -92543,7 +92552,6 @@ namespace VULKAN_HPP_NAMESPACE uniqueCommandBuffers.push_back( UniqueHandle( commandBuffers[i], deleter ) ); } } - return createResultValue( result, std::move( uniqueCommandBuffers ), VULKAN_HPP_NAMESPACE_STRING "::Device::allocateCommandBuffersUnique" ); } @@ -92561,45 +92569,49 @@ namespace VULKAN_HPP_NAMESPACE reinterpret_cast( pAllocateInfo ), reinterpret_cast( pDescriptorSets ) ) ); } + #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE - template + template VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE - typename ResultValueType>::type + typename ResultValueType>::type Device::allocateDescriptorSets( const DescriptorSetAllocateInfo & allocateInfo, Dispatch const & d ) const { - std::vector descriptorSets( allocateInfo.descriptorSetCount ); - Result result = static_cast( + std::vector descriptorSets( allocateInfo.descriptorSetCount ); + Result result = static_cast( d.vkAllocateDescriptorSets( m_device, reinterpret_cast( &allocateInfo ), reinterpret_cast( descriptorSets.data() ) ) ); return createResultValue( result, descriptorSets, VULKAN_HPP_NAMESPACE_STRING "::Device::allocateDescriptorSets" ); } - template ::value, int>::type> VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE - typename ResultValueType>::type + typename ResultValueType>::type Device::allocateDescriptorSets( const DescriptorSetAllocateInfo & allocateInfo, - Allocator const & vectorAllocator, + DescriptorSetAllocator & descriptorSetsAllocator, Dispatch const & d ) const { - std::vector descriptorSets( allocateInfo.descriptorSetCount, vectorAllocator ); - Result result = static_cast( + std::vector descriptorSets( allocateInfo.descriptorSetCount, + descriptorSetsAllocator ); + Result result = static_cast( d.vkAllocateDescriptorSets( m_device, reinterpret_cast( &allocateInfo ), reinterpret_cast( descriptorSets.data() ) ) ); return createResultValue( result, descriptorSets, VULKAN_HPP_NAMESPACE_STRING "::Device::allocateDescriptorSets" ); } + # ifndef VULKAN_HPP_NO_SMART_HANDLE - template + template VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE - typename ResultValueType, Allocator>>::type + typename ResultValueType, DescriptorSetAllocator>>::type Device::allocateDescriptorSetsUnique( const DescriptorSetAllocateInfo & allocateInfo, Dispatch const & d ) const { - std::vector, Allocator> uniqueDescriptorSets; - std::vector descriptorSets( allocateInfo.descriptorSetCount ); - Result result = static_cast( + std::vector, DescriptorSetAllocator> uniqueDescriptorSets; + std::vector descriptorSets( allocateInfo.descriptorSetCount ); + Result result = static_cast( d.vkAllocateDescriptorSets( m_device, reinterpret_cast( &allocateInfo ), reinterpret_cast( descriptorSets.data() ) ) ); @@ -92612,24 +92624,25 @@ namespace VULKAN_HPP_NAMESPACE uniqueDescriptorSets.push_back( UniqueHandle( descriptorSets[i], deleter ) ); } } - return createResultValue( result, std::move( uniqueDescriptorSets ), VULKAN_HPP_NAMESPACE_STRING "::Device::allocateDescriptorSetsUnique" ); } + template >::value, int>::type> VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE - typename ResultValueType, Allocator>>::type + typename ResultValueType, DescriptorSetAllocator>>::type Device::allocateDescriptorSetsUnique( const DescriptorSetAllocateInfo & allocateInfo, - Allocator const & vectorAllocator, + DescriptorSetAllocator & descriptorSetsAllocator, Dispatch const & d ) const { - std::vector, Allocator> uniqueDescriptorSets( vectorAllocator ); - std::vector descriptorSets( allocateInfo.descriptorSetCount ); - Result result = static_cast( + std::vector, DescriptorSetAllocator> uniqueDescriptorSets( + descriptorSetsAllocator ); + std::vector descriptorSets( allocateInfo.descriptorSetCount ); + Result result = static_cast( d.vkAllocateDescriptorSets( m_device, reinterpret_cast( &allocateInfo ), reinterpret_cast( descriptorSets.data() ) ) ); @@ -92642,7 +92655,6 @@ namespace VULKAN_HPP_NAMESPACE uniqueDescriptorSets.push_back( UniqueHandle( descriptorSets[i], deleter ) ); } } - return createResultValue( result, std::move( uniqueDescriptorSets ), VULKAN_HPP_NAMESPACE_STRING "::Device::allocateDescriptorSetsUnique" ); }