From dd1855a820c495ca1d95566bf0736c981855014a Mon Sep 17 00:00:00 2001 From: asuessenbach Date: Tue, 14 Sep 2021 15:38:35 +0200 Subject: [PATCH] Add support for commands returning two values. --- VulkanHppGenerator.cpp | 99 +++++++++++++++++++++++++++++++++++++++--- VulkanHppGenerator.hpp | 7 ++- 2 files changed, 100 insertions(+), 6 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index a20070e..1e8949c 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -3198,6 +3198,79 @@ std::string VulkanHppGenerator::generateCommandResultGetHandleUnique( std::strin } } +std::string VulkanHppGenerator::generateCommandResultGetTwoValues( std::string const & name, + CommandData const & commandData, + size_t initialSkipCount, + bool definition, + std::vector returnParamIndices ) const +{ + assert( returnParamIndices.size() == 2 ); + assert( commandData.params[returnParamIndices[0]].type.type != "void" ); + assert( commandData.params[returnParamIndices[1]].type.type != "void" ); + assert( 1 < commandData.successCodes.size() ); + + std::set skippedParams = + determineSkippedParams( commandData.params, initialSkipCount, {}, returnParamIndices, false ); + + std::string argumentList = + generateArgumentListEnhanced( commandData.params, skippedParams, {}, definition, false, false, true ); + std::string commandName = generateCommandName( name, commandData.params, initialSkipCount, m_tags ); + std::string nodiscard = generateNoDiscard( 1 < commandData.successCodes.size(), 1 < commandData.errorCodes.size() ); + std::string firstReturnType = commandData.params[returnParamIndices[0]].type.compose(); + assert( endsWith( firstReturnType, "*" ) ); + firstReturnType.pop_back(); + std::string secondReturnType = commandData.params[returnParamIndices[1]].type.compose(); + assert( endsWith( secondReturnType, "*" ) ); + secondReturnType.pop_back(); + + if ( definition ) + { + std::string const functionTemplate = + R"( template + ${nodiscard}VULKAN_HPP_INLINE typename ResultValue> ${className}${classSeparator}${commandName}( ${argumentList} )${const} + { + VULKAN_HPP_ASSERT( d.getVkHeaderVersion() == VK_HEADER_VERSION ); + std::pair<${firstReturnType}, ${secondReturnType}> returnValue; + ${firstReturnType} & ${firstReturnName} = returnValue.first; + ${secondReturnType} & ${secondReturnName} = returnValue.second; + Result result = static_cast( d.${vkCommand}( ${callArguments} ) ); + return createResultValue( result, returnValue, VULKAN_HPP_NAMESPACE_STRING "::${className}${classSeparator}${commandName}"${successCodeList} ); + })"; + + return replaceWithMap( + functionTemplate, + { { "argumentList", argumentList }, + { "callArguments", + generateCallArgumentsEnhanced( commandData.params, initialSkipCount, false, {}, returnParamIndices, false ) }, + { "className", + initialSkipCount ? stripPrefix( commandData.params[initialSkipCount - 1].type.type, "Vk" ) : "" }, + { "classSeparator", commandData.handle.empty() ? "" : "::" }, + { "const", commandData.handle.empty() ? "" : " const" }, + { "commandName", commandName }, + { "firstReturnName", startLowerCase( stripPrefix( commandData.params[returnParamIndices[0]].name, "p" ) ) }, + { "firstReturnType", firstReturnType }, + { "secondReturnName", startLowerCase( stripPrefix( commandData.params[returnParamIndices[1]].name, "p" ) ) }, + { "secondReturnType", secondReturnType }, + { "nodiscard", nodiscard }, + { "successCodeList", generateSuccessCodeList( commandData.successCodes ) }, + { "vkCommand", name } } ); + } + else + { + std::string const functionTemplate = + R"( template + ${nodiscard}typename ResultValue> ${commandName}( ${argumentList} )${const};)"; + + return replaceWithMap( functionTemplate, + { { "argumentList", argumentList }, + { "commandName", commandName }, + { "const", commandData.handle.empty() ? "" : " const" }, + { "firstReturnType", firstReturnType }, + { "nodiscard", nodiscard }, + { "secondReturnType", secondReturnType } } ); + } +} + std::string VulkanHppGenerator::generateCommandResultGetTwoVectors( std::string const & name, CommandData const & commandData, @@ -3271,18 +3344,18 @@ std::string VulkanHppGenerator::generateCommandResultGetValue( std::string const CommandData const & commandData, size_t initialSkipCount, bool definition, - size_t nonConstPointerIndex ) const + size_t returnParamIndex ) const { assert( commandData.returnType == "VkResult" ); std::set skippedParams = - determineSkippedParams( commandData.params, initialSkipCount, {}, { nonConstPointerIndex }, false ); + determineSkippedParams( commandData.params, initialSkipCount, {}, { returnParamIndex }, false ); std::string argumentList = generateArgumentListEnhanced( commandData.params, skippedParams, {}, definition, false, false, true ); std::string commandName = generateCommandName( name, commandData.params, initialSkipCount, m_tags ); std::string nodiscard = generateNoDiscard( 1 < commandData.successCodes.size(), 1 < commandData.errorCodes.size() ); - std::string returnBaseType = commandData.params[nonConstPointerIndex].type.compose(); + std::string returnBaseType = commandData.params[returnParamIndex].type.compose(); assert( endsWith( returnBaseType, "*" ) ); returnBaseType.pop_back(); std::string typenameT; @@ -3310,14 +3383,14 @@ std::string VulkanHppGenerator::generateCommandResultGetValue( std::string const { { "argumentList", argumentList }, { "callArguments", generateCallArgumentsEnhanced( - commandData.params, initialSkipCount, false, {}, { nonConstPointerIndex }, false ) }, + commandData.params, initialSkipCount, false, {}, { returnParamIndex }, false ) }, { "className", initialSkipCount ? stripPrefix( commandData.params[initialSkipCount - 1].type.type, "Vk" ) : "" }, { "classSeparator", commandData.handle.empty() ? "" : "::" }, { "const", commandData.handle.empty() ? "" : " const" }, { "commandName", commandName }, { "returnBaseType", returnBaseType }, - { "returnValueName", startLowerCase( stripPrefix( commandData.params[nonConstPointerIndex].name, "p" ) ) }, + { "returnValueName", startLowerCase( stripPrefix( commandData.params[returnParamIndex].name, "p" ) ) }, { "nodiscard", nodiscard }, { "returnType", returnType }, { "successCodeList", generateSuccessCodeList( commandData.successCodes ) }, @@ -4167,6 +4240,22 @@ std::string VulkanHppGenerator::generateCommandSetResultMultiSuccessWithErrors0V generateCommandResultGetValue( name, commandData, initialSkipCount, definition, returnParamIndices[0] ) ); } break; + case 2: + if ( ( commandData.params[returnParamIndices[0]].type.type != "void" ) && + !isHandleType( commandData.params[returnParamIndices[0]].type.type ) && + !isStructureChainAnchor( commandData.params[returnParamIndices[0]].type.type ) ) + { + if ( ( commandData.params[returnParamIndices[1]].type.type != "void" ) && + !isHandleType( commandData.params[returnParamIndices[1]].type.type ) && + !isStructureChainAnchor( commandData.params[returnParamIndices[1]].type.type ) ) + { + return generateCommandSetStandardEnhanced( + definition, + generateCommandStandard( name, commandData, initialSkipCount, definition ), + generateCommandResultGetTwoValues( name, commandData, initialSkipCount, definition, returnParamIndices ) ); + } + } + break; } return ""; } diff --git a/VulkanHppGenerator.hpp b/VulkanHppGenerator.hpp index 5b04a81..8680266 100644 --- a/VulkanHppGenerator.hpp +++ b/VulkanHppGenerator.hpp @@ -476,6 +476,11 @@ private: size_t initialSkipCount, bool definition, size_t nonConstPointerIndex ) const; + std::string generateCommandResultGetTwoValues( std::string const & name, + CommandData const & commandData, + size_t initialSkipCount, + bool definition, + std::vector returnParamIndices ) const; std::string generateCommandResultGetTwoVectors( std::string const & name, CommandData const & commandData, size_t initialSkipCount, @@ -485,7 +490,7 @@ private: CommandData const & commandData, size_t initialSkipCount, bool definition, - size_t nonConstPointerIndex ) const; + size_t returnParamIndex ) const; std::string generateCommandResultGetValueDeprecated( std::string const & name, CommandData const & commandData, size_t initialSkipCount,