diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 3554aa1..9f7f24a 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -1230,7 +1230,7 @@ void VulkanHppGenerator::appendCommand( std::string & str, auto returnVectorParamIt = vectorParamIndices.find( nonConstPointerParamIndices[0] ); if ( returnVectorParamIt == vectorParamIndices.end() ) { - if ( ( commandData.returnType == "VkResult" ) || ( commandData.returnType == "void" ) ) + if ( ( commandData.returnType == "VkBool32" ) || ( commandData.returnType == "VkResult" ) || ( commandData.returnType == "void" ) ) { appendCommandStandardAndEnhanced( str, name, commandData, initialSkipCount, definition, vectorParamIndices, nonConstPointerParamIndices ); @@ -1534,16 +1534,21 @@ ${leave})"; } break; case 1: - if ( commandData.returnType == "void" ) + if ( commandData.returnType == "VkBool32" ) { - commandEnhanced = constructCommandVoidGetValue( - name, commandData, initialSkipCount, definition, vectorParamIndices, nonConstPointerParamIndices[0] ); + commandEnhanced = constructCommandBoolGetValue( + name, commandData, initialSkipCount, definition, nonConstPointerParamIndices[0] ); } else if ( commandData.returnType == "VkResult" ) { commandEnhanced = constructCommandResultGetValue( name, commandData, initialSkipCount, definition, nonConstPointerParamIndices[0] ); } + else if ( commandData.returnType == "void" ) + { + commandEnhanced = constructCommandVoidGetValue( + name, commandData, initialSkipCount, definition, vectorParamIndices, nonConstPointerParamIndices[0] ); + } break; case 2: if ( ( commandData.returnType == "VkResult" ) && ( 1 < commandData.successCodes.size() ) ) @@ -3829,7 +3834,6 @@ std::string VulkanHppGenerator::constructCallArgumentEnhanced( ParamData const & { // parameter is a non-const pointer (and none of the special pointer types, that are considered const-pointers, even // though they are not!) - assert( beginsWith( param.name, "p" ) ); std::string name = startLowerCase( stripPrefix( param.name, "p" ) ); if ( param.len.empty() ) { @@ -4034,6 +4038,64 @@ std::string VulkanHppGenerator::constructCallArgumentsStandard( std::string cons return arguments; } +std::string VulkanHppGenerator::constructCommandBoolGetValue( std::string const & name, + CommandData const & commandData, + size_t initialSkipCount, + bool definition, + size_t nonConstPointerIndex ) const +{ + assert( commandData.returnType == "VkBool32" ); + + std::set skippedParams = + determineSkippedParams( commandData.params, initialSkipCount, {}, { nonConstPointerIndex }, false ); + + std::string argumentList = + constructArgumentListEnhanced( commandData.params, skippedParams, INVALID_INDEX, definition, false, false, true ); + std::string commandName = + determineCommandName( name, initialSkipCount ? commandData.params[initialSkipCount - 1].type.type : "", m_tags ); + std::string returnType = stripPostfix( commandData.params[nonConstPointerIndex].type.compose(), "*" ); + assert( !beginsWith( returnType, "Vk" ) ); + + if ( definition ) + { + std::string const functionTemplate = + R"( template + VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE std::pair ${className}${classSeparator}${commandName}( ${argumentList} )${const} + { + std::pair result; + ${returnType} & ${returnValueName} = result.second; + result.first = static_cast( d.${vkCommand}( ${callArguments} ) ); + return result; + })"; + + return replaceWithMap( + functionTemplate, + { { "argumentList", argumentList }, + { "callArguments", + constructCallArgumentsEnhanced( commandData.params, initialSkipCount, false, INVALID_INDEX, false ) }, + { "className", + initialSkipCount ? stripPrefix( commandData.params[initialSkipCount - 1].type.type, "Vk" ) : "" }, + { "classSeparator", commandData.handle.empty() ? "" : "::" }, + { "const", commandData.handle.empty() ? "" : " const" }, + { "commandName", commandName }, + { "returnValueName", startLowerCase( stripPrefix( commandData.params[nonConstPointerIndex].name, "p" ) ) }, + { "returnType", returnType }, + { "vkCommand", name } } ); + } + else + { + std::string const functionTemplate = + R"( template + VULKAN_HPP_NODISCARD std::pair ${commandName}( ${argumentList} )${const};)"; + + return replaceWithMap( functionTemplate, + { { "argumentList", argumentList }, + { "commandName", commandName }, + { "const", commandData.handle.empty() ? "" : " const" }, + { "returnType", returnType } } ); + } +} + std::string VulkanHppGenerator::constructCommandResult( std::string const & name, CommandData const & commandData, size_t initialSkipCount, @@ -8089,7 +8151,13 @@ void VulkanHppGenerator::constructRAIIHandleMemberFunction( std::string & { // as the return type is not "VkResult", there are no success or error codes allowed assert( commandIt->second.successCodes.empty() && commandIt->second.errorCodes.empty() ); - if ( commandIt->second.returnType == "void" ) + if ( commandIt->second.returnType == "VkBool32" ) + { + std::tie( declaration, definition ) = constructRAIIHandleMemberFunctionBoolGetValue( + commandIt, initialSkipCount, vectorParamIndices, nonConstPointerParamIndices ); + commandConstructed = true; + } + else if ( commandIt->second.returnType == "void" ) { std::tie( declaration, definition ) = constructRAIIHandleMemberFunctionVoidGetValue( commandIt, initialSkipCount, vectorParamIndices, nonConstPointerParamIndices ); @@ -8329,6 +8397,77 @@ void VulkanHppGenerator::constructRAIIHandleMemberFunction( std::string & } } +std::pair VulkanHppGenerator::constructRAIIHandleMemberFunctionBoolGetValue( + std::map::const_iterator commandIt, + size_t initialSkipCount, + std::map const & vectorParamIndices, + std::vector const & nonConstPointerParamIndices ) const +{ + assert( nonConstPointerParamIndices.size() == 1 ); + + std::set skippedParameters = determineSkippedParams( + commandIt->second.params, initialSkipCount, vectorParamIndices, nonConstPointerParamIndices, false ); + std::string argumentListDeclaration = constructArgumentListEnhanced( + commandIt->second.params, skippedParameters, INVALID_INDEX, false, false, false, false ); + std::string argumentListDefinition = constructArgumentListEnhanced( + commandIt->second.params, skippedParameters, INVALID_INDEX, true, false, false, false ); + std::string commandName = + determineCommandName( commandIt->first, commandIt->second.params[initialSkipCount - 1].type.type, m_tags ); + std::string enter, leave; + std::tie( enter, leave ) = generateProtection( commandIt->second.feature, commandIt->second.extensions ); + std::string returnType = stripPostfix( commandIt->second.params[nonConstPointerParamIndices[0]].type.compose(), "*" ); + std::pair>> vectorSizeCheck = needsVectorSizeCheck( vectorParamIndices ); + std::string noexceptString = vectorSizeCheck.first ? "VULKAN_HPP_NOEXCEPT_WHEN_NO_EXCEPTIONS" : "VULKAN_HPP_NOEXCEPT"; + + std::string const declarationTemplate = + R"( +${enter} VULKAN_HPP_NODISCARD std::pair ${commandName}( ${argumentList} ) const ${noexcept}; +${leave})"; + + std::string declaration = replaceWithMap( declarationTemplate, + { + { "argumentList", argumentListDeclaration }, + { "commandName", commandName }, + { "enter", enter }, + { "leave", leave }, + { "noexcept", noexceptString }, + { "returnType", returnType }, + } ); + + std::string const definitionTemplate = + R"( +${enter} VULKAN_HPP_NODISCARD std::pair ${className}::${commandName}( ${argumentList} ) const ${noexcept} + {${vectorSizeCheck} + std::pair result; + ${returnType} & ${returnVariable} = result.second; + result.first = static_cast( getDispatcher()->${vkCommand}( ${callArguments} ) ); + return result; + } +${leave})"; + + std::string definition = replaceWithMap( + definitionTemplate, + { { "argumentList", argumentListDefinition }, + { "callArguments", + constructCallArgumentsEnhanced( commandIt->second.params, initialSkipCount, false, INVALID_INDEX, true ) }, + { "className", stripPrefix( commandIt->second.params[initialSkipCount - 1].type.type, "Vk" ) }, + { "commandName", commandName }, + { "enter", enter }, + { "leave", leave }, + { "noexcept", noexceptString }, + { "vectorSizeCheck", + vectorSizeCheck.first + ? constructVectorSizeCheck( + commandIt->first, commandIt->second, initialSkipCount, vectorSizeCheck.second, skippedParameters ) + : "" }, + { "returnType", returnType }, + { "returnVariable", + startLowerCase( stripPrefix( commandIt->second.params[nonConstPointerParamIndices[0]].name, "p" ) ) }, + { "vkCommand", commandIt->first } } ); + + return std::make_pair( declaration, definition ); +} + std::pair VulkanHppGenerator::constructRAIIHandleMemberFunctions( std::pair const & handle, std::set const & specialFunctions ) const diff --git a/VulkanHppGenerator.hpp b/VulkanHppGenerator.hpp index 0fa0141..de8a7a1 100644 --- a/VulkanHppGenerator.hpp +++ b/VulkanHppGenerator.hpp @@ -523,6 +523,11 @@ private: size_t singularParamIndex, bool raiiHandleMemberFunction ) const; std::string constructCallArgumentsStandard( std::string const & handle, std::vector const & params ) const; + std::string constructCommandBoolGetValue( std::string const & name, + CommandData const & commandData, + size_t initialSkipCount, + bool definition, + size_t nonConstPointerIndex ) const; std::string constructCommandResult( std::string const & name, CommandData const & commandData, size_t initialSkipCount, @@ -832,6 +837,11 @@ private: std::string const & command, size_t initialSkipCount, std::set const & specialFunctions ) const; + std::pair + constructRAIIHandleMemberFunctionBoolGetValue( std::map::const_iterator commandIt, + size_t initialSkipCount, + std::map const & vectorParamIndices, + std::vector const & nonConstPointerParamIndices ) const; std::pair constructRAIIHandleMemberFunctions( std::pair const & handle, std::set const & specialFunctions ) const;