diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index ceccdf0..6b669e7 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -1242,6 +1242,19 @@ std::string VulkanHppGenerator::addTitleAndProtection( std::string const & title return str; } +bool VulkanHppGenerator::allVectorSizesSupported( std::vector const & params, + std::map const & vectorParams ) const +{ + return std::find_if_not( vectorParams.begin(), + vectorParams.end(), + [¶ms]( std::pair const & vpi ) + { + return params[vpi.second].type.isValue() && + ( ( params[vpi.second].type.type == "uint32_t" ) || + ( params[vpi.second].type.type == "VkDeviceSize" ) ); + } ) == vectorParams.end(); +} + void VulkanHppGenerator::appendDispatchLoaderDynamicCommands( std::vector const & requireData, std::set & listedCommands, std::string const & title, @@ -3782,71 +3795,6 @@ std::string } } -std::string - VulkanHppGenerator::generateCommandResultGetTwoVectors( std::string const & name, - CommandData const & commandData, - size_t initialSkipCount, - bool definition, - std::map const & vectorParams ) const -{ - assert( commandData.returnType == "VkResult" ); - assert( commandData.params[0].type.type == commandData.handle ); -#if !defined( NDEBUG ) - auto firstVectorParamIt = vectorParams.begin(); - auto secondVectorParamIt = std::next( firstVectorParamIt ); - assert( firstVectorParamIt->second == secondVectorParamIt->second ); -#endif - - std::set skippedParams = - determineSkippedParams( commandData.params, initialSkipCount, vectorParams, {}, false ); - std::string argumentList = - generateArgumentListEnhanced( commandData.params, skippedParams, {}, {}, definition, false, false, true ); - std::string commandName = generateCommandName( name, commandData.params, initialSkipCount, m_tags ); - std::pair>> vectorSizeCheck = needsVectorSizeCheck( vectorParams ); - std::string noexceptString = vectorSizeCheck.first ? "VULKAN_HPP_NOEXCEPT_WHEN_NO_EXCEPTIONS" : "VULKAN_HPP_NOEXCEPT"; - - if ( definition ) - { - const std::string functionTemplate = - R"( template - VULKAN_HPP_INLINE Result ${className}${classSeparator}${commandName}( ${argumentList} ) const ${noexcept} - { - VULKAN_HPP_ASSERT( d.getVkHeaderVersion() == VK_HEADER_VERSION );${vectorSizeCheck} - Result result = static_cast( d.${vkCommand}( ${callArguments} ) ); - return createResultValue( result, VULKAN_HPP_NAMESPACE_STRING "::${className}${classSeparator}${commandName}"${successCodeList} ); - })"; - - return replaceWithMap( - functionTemplate, - { { "argumentList", argumentList }, - { "callArguments", generateCallArgumentsEnhanced( commandData, initialSkipCount, false, {}, {}, false ) }, - { "className", - initialSkipCount ? stripPrefix( commandData.params[initialSkipCount - 1].type.type, "Vk" ) : "" }, - { "classSeparator", commandData.handle.empty() ? "" : "::" }, - { "commandName", commandName }, - { "noexcept", noexceptString }, - { "successCodeList", generateSuccessCodeList( commandData.successCodes ) }, - { "vectorSizeCheck", - vectorSizeCheck.first - ? generateVectorSizeCheck( name, commandData, initialSkipCount, vectorSizeCheck.second, skippedParams ) - : "" }, - { "vkCommand", name } } ); - } - else - { - const std::string functionTemplate = - R"( template - Result ${commandName}( ${argumentList} ) const ${noexcept};)"; - - return replaceWithMap( functionTemplate, - { - { "argumentList", argumentList }, - { "commandName", commandName }, - { "noexcept", noexceptString }, - } ); - } -} - std::string VulkanHppGenerator::generateCommandResultGetValue( std::string const & name, CommandData const & commandData, size_t initialSkipCount, @@ -4569,68 +4517,87 @@ std::string VulkanHppGenerator::generateCommandResultMultiSuccessWithErrors0Retu bool definition ) const { std::map vectorParams = determineVectorParams( commandData.params ); - switch ( vectorParams.size() ) + if ( vectorParams.empty() && determineConstPointerParams( commandData.params ).empty() ) { - case 0: - { - std::vector constPointerParams = determineConstPointerParams( commandData.params ); - switch ( constPointerParams.size() ) - { - case 0: - return generateCommandSetStandardOrEnhanced( - generateCommandStandard( name, commandData, initialSkipCount, definition ), - generateCommandResult( name, commandData, initialSkipCount, definition, {} ) ); - break; - case 1: - if ( commandData.params[constPointerParams[0]].type.type != "void" ) - { - return generateCommandSetStandardEnhanced( - definition, - generateCommandStandard( name, commandData, initialSkipCount, definition ), - generateCommandResult( name, commandData, initialSkipCount, definition, {} ) ); - } - break; - } - } - break; - case 1: - if ( commandData.params[vectorParams.begin()->second].type.isValue() ) - { - if ( isHandleType( commandData.params[vectorParams.begin()->first].type.type ) ) - { - return generateCommandSetStandardEnhanced( - definition, - generateCommandStandard( name, commandData, initialSkipCount, definition ), - generateCommandResult( name, commandData, initialSkipCount, definition, vectorParams ) ); - } - } - break; - case 2: - if ( vectorParams.begin()->second == std::next( vectorParams.begin() )->second ) - { - if ( commandData.params[vectorParams.begin()->second].type.type == "uint32_t" ) - { - if ( ( commandData.params[vectorParams.begin()->first].type.type != "void" ) && - !isHandleType( commandData.params[vectorParams.begin()->first].type.type ) && - !isStructureChainAnchor( commandData.params[vectorParams.begin()->first].type.type ) ) - { - if ( ( commandData.params[std::next( vectorParams.begin() )->first].type.type != "void" ) && - !isHandleType( commandData.params[std::next( vectorParams.begin() )->first].type.type ) && - !isStructureChainAnchor( commandData.params[std::next( vectorParams.begin() )->first].type.type ) ) - { - return generateCommandSetStandardEnhanced( - definition, - generateCommandStandard( name, commandData, initialSkipCount, definition ), - generateCommandResultGetTwoVectors( name, commandData, initialSkipCount, definition, vectorParams ) ); - } - } - } - } - break; + return generateCommandSetStandardOrEnhanced( + generateCommandStandard( name, commandData, initialSkipCount, definition ), + generateCommandResultMultiSuccessWithErrors0ReturnNVector( + name, commandData, initialSkipCount, definition, vectorParams ) ); + } + else if ( allVectorSizesSupported( commandData.params, vectorParams ) ) + { + return generateCommandSetStandardEnhanced( + definition, + generateCommandStandard( name, commandData, initialSkipCount, definition ), + generateCommandResultMultiSuccessWithErrors0ReturnNVector( + name, commandData, initialSkipCount, definition, vectorParams ) ); } return ""; } +std::string VulkanHppGenerator::generateCommandResultMultiSuccessWithErrors0ReturnNVector( + std::string const & name, + CommandData const & commandData, + size_t initialSkipCount, + bool definition, + std::map const & vectorParams ) const +{ + std::set skippedParams = + determineSkippedParams( commandData.params, initialSkipCount, vectorParams, {}, false ); + std::set templatedParams = determineVoidPointerParams( commandData.params ); + std::string argumentList = generateArgumentListEnhanced( + commandData.params, skippedParams, {}, templatedParams, definition, false, false, true ); + std::string argumentTemplates = generateArgumentTemplates( commandData.params, templatedParams, false ); + std::string commandName = generateCommandName( name, commandData.params, initialSkipCount, m_tags ); + std::pair>> vectorSizeCheck = needsVectorSizeCheck( vectorParams ); + std::string nodiscard = generateNoDiscard( 1 < commandData.successCodes.size(), 1 < commandData.errorCodes.size() ); + std::string returnType = ( 1 < commandData.successCodes.size() ) ? "Result" : "typename ResultValueType::type"; + + if ( definition ) + { + std::string const functionTemplate = + R"( template <${argumentTemplates}typename Dispatch> + ${nodiscard}VULKAN_HPP_INLINE ${returnType} ${className}${classSeparator}${commandName}( ${argumentList} ) const + { + VULKAN_HPP_ASSERT( d.getVkHeaderVersion() == VK_HEADER_VERSION );${vectorSizeCheck} + Result result = static_cast( d.${vkCommand}( ${callArguments} ) ); + return createResultValue( result, VULKAN_HPP_NAMESPACE_STRING "::${className}${classSeparator}${commandName}"${successCodeList} ); + })"; + + return replaceWithMap( + functionTemplate, + { { "argumentList", argumentList }, + { "argumentTemplates", argumentTemplates }, + { "callArguments", + generateCallArgumentsEnhanced( commandData, initialSkipCount, false, {}, templatedParams, false ) }, + { "className", + initialSkipCount ? stripPrefix( commandData.params[initialSkipCount - 1].type.type, "Vk" ) : "" }, + { "classSeparator", commandData.handle.empty() ? "" : "::" }, + { "commandName", commandName }, + { "nodiscard", nodiscard }, + { "returnType", returnType }, + { "successCodeList", generateSuccessCodeList( commandData.successCodes ) }, + { "vectorSizeCheck", + vectorSizeCheck.first + ? generateVectorSizeCheck( name, commandData, initialSkipCount, vectorSizeCheck.second, skippedParams ) + : "" }, + { "vkCommand", name } } ); + } + else + { + std::string const functionTemplate = + R"( template <${argumentTemplates}typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE> + ${nodiscard}${returnType} ${commandName}( ${argumentList} ) const;)"; + + return replaceWithMap( functionTemplate, + { { "argumentList", argumentList }, + { "argumentTemplates", argumentTemplates }, + { "commandName", commandName }, + { "nodiscard", nodiscard }, + { "returnType", returnType } } ); + } +} + std::string VulkanHppGenerator::generateCommandResultMultiSuccessWithErrors1Return( std::string const & name, CommandData const & commandData, size_t initialSkipCount, @@ -4887,14 +4854,7 @@ std::string VulkanHppGenerator::generateCommandResultSingleSuccessWithErrors0Ret generateCommandResultSingleSuccessWithErrors0ReturnNVectors( name, commandData, initialSkipCount, definition, vectorParams ) ); } - else if ( std::find_if_not( vectorParams.begin(), - vectorParams.end(), - [&commandData]( std::pair const & vpi ) - { - return commandData.params[vpi.second].type.isValue() && - ( ( commandData.params[vpi.second].type.type == "uint32_t" ) || - ( commandData.params[vpi.second].type.type == "VkDeviceSize" ) ); - } ) == vectorParams.end() ) + else if ( allVectorSizesSupported( commandData.params, vectorParams ) ) { // All the vectorParams have a counter by value, of type "uint32_t" or "VkDeviceSize" return generateCommandSetStandardEnhanced( @@ -5689,14 +5649,7 @@ std::string VulkanHppGenerator::generateCommandVoid0Return( std::string const & { return generateCommandSetStandard( generateCommandStandard( name, commandData, initialSkipCount, definition ) ); } - else if ( std::find_if_not( vectorParams.begin(), - vectorParams.end(), - [&commandData]( std::pair const & vpi ) - { - return commandData.params[vpi.second].type.isValue() && - ( ( commandData.params[vpi.second].type.type == "uint32_t" ) || - ( commandData.params[vpi.second].type.type == "VkDeviceSize" ) ); - } ) == vectorParams.end() ) + else if ( allVectorSizesSupported( commandData.params, vectorParams ) ) { // All the vectorParams have a counter by value, of type "uint32_t" or "VkDeviceSize" return generateCommandSetStandardEnhanced( @@ -8070,14 +8023,16 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandResultMultiSuccessWithE { std::set skippedParams = determineSkippedParams( commandIt->second.params, initialSkipCount, vectorParams, {}, false ); - std::string argumentList = - generateArgumentListEnhanced( commandIt->second.params, skippedParams, {}, {}, definition, false, false, false ); + std::set templatedParams = determineVoidPointerParams( commandIt->second.params ); + std::string argumentList = generateArgumentListEnhanced( + commandIt->second.params, skippedParams, {}, templatedParams, definition, false, false, false ); + std::string argumentTemplates = generateArgumentTemplates( commandIt->second.params, templatedParams, true ); std::string commandName = generateCommandName( commandIt->first, commandIt->second.params, initialSkipCount, m_tags ); if ( definition ) { std::string const definitionTemplate = - R"( + R"(${argumentTemplates} VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE VULKAN_HPP_NAMESPACE::Result ${className}::${commandName}( ${argumentList} ) const {${functionPointerCheck}${vectorSizeCheck} VULKAN_HPP_NAMESPACE::Result result = static_cast( getDispatcher()->${vkCommand}( ${callArguments} ) ); @@ -8090,7 +8045,7 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandResultMultiSuccessWithE )"; std::string callArguments = - generateCallArgumentsEnhanced( commandIt->second, initialSkipCount, false, {}, {}, true ); + generateCallArgumentsEnhanced( commandIt->second, initialSkipCount, false, {}, templatedParams, true ); std::pair>> vectorSizeCheck = needsVectorSizeCheck( vectorParams ); std::string vectorSizeCheckString = vectorSizeCheck.first @@ -8101,6 +8056,7 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandResultMultiSuccessWithE return replaceWithMap( definitionTemplate, { { "argumentList", argumentList }, + { "argumentTemplates", argumentTemplates }, { "callArguments", callArguments }, { "className", stripPrefix( commandIt->second.params[initialSkipCount - 1].type.type, "Vk" ) }, { "commandName", commandName }, @@ -8112,13 +8068,14 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandResultMultiSuccessWithE else { std::string const declarationTemplate = - R"( + R"(${argumentTemplates} VULKAN_HPP_NODISCARD VULKAN_HPP_NAMESPACE::Result ${commandName}( ${argumentList} ) const; )"; return replaceWithMap( declarationTemplate, { { "argumentList", argumentList }, + { "argumentTemplates", argumentTemplates }, { "commandName", commandName }, } ); } diff --git a/VulkanHppGenerator.hpp b/VulkanHppGenerator.hpp index 3a88501..6b3f682 100644 --- a/VulkanHppGenerator.hpp +++ b/VulkanHppGenerator.hpp @@ -383,6 +383,8 @@ private: std::string addTitleAndProtection( std::string const & title, std::string const & strIf, std::string const & strElse = {} ) const; + bool allVectorSizesSupported( std::vector const & params, + std::map const & vectorParams ) const; void appendDispatchLoaderDynamicCommands( std::vector const & requireData, std::set & listedCommands, std::string const & title, @@ -540,11 +542,6 @@ private: bool definition, std::vector const & returnParamIndices, std::map const & vectorParamIndices ) const; - std::string generateCommandResultGetTwoVectors( std::string const & name, - CommandData const & commandData, - size_t initialSkipCount, - bool definition, - std::map const & vectorParamIndices ) const; std::string generateCommandResultGetValue( std::string const & name, CommandData const & commandData, size_t initialSkipCount, @@ -615,6 +612,12 @@ private: CommandData const & commandData, size_t initialSkipCount, bool definition ) const; + std::string + generateCommandResultMultiSuccessWithErrors0ReturnNVector( std::string const & name, + CommandData const & commandData, + size_t initialSkipCount, + bool definition, + std::map const & vectorParams ) const; std::string generateCommandResultMultiSuccessWithErrors1Return( std::string const & name, CommandData const & commandData, size_t initialSkipCount, diff --git a/vulkan/vulkan_funcs.hpp b/vulkan/vulkan_funcs.hpp index 4985eb0..e30ee82 100644 --- a/vulkan/vulkan_funcs.hpp +++ b/vulkan/vulkan_funcs.hpp @@ -13875,11 +13875,11 @@ namespace VULKAN_HPP_NAMESPACE #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE template - VULKAN_HPP_INLINE Result Device::buildAccelerationStructuresKHR( + VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE Result Device::buildAccelerationStructuresKHR( VULKAN_HPP_NAMESPACE::DeferredOperationKHR deferredOperation, ArrayProxy const & infos, ArrayProxy const & pBuildRangeInfos, - Dispatch const & d ) const VULKAN_HPP_NOEXCEPT_WHEN_NO_EXCEPTIONS + Dispatch const & d ) const { VULKAN_HPP_ASSERT( d.getVkHeaderVersion() == VK_HEADER_VERSION ); # ifdef VULKAN_HPP_NO_EXCEPTIONS diff --git a/vulkan/vulkan_handles.hpp b/vulkan/vulkan_handles.hpp index 6bc5a67..b63f7fb 100644 --- a/vulkan/vulkan_handles.hpp +++ b/vulkan/vulkan_handles.hpp @@ -10515,11 +10515,11 @@ namespace VULKAN_HPP_NAMESPACE Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const VULKAN_HPP_NOEXCEPT; #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE template - Result buildAccelerationStructuresKHR( + VULKAN_HPP_NODISCARD Result buildAccelerationStructuresKHR( VULKAN_HPP_NAMESPACE::DeferredOperationKHR deferredOperation, ArrayProxy const & infos, ArrayProxy const & pBuildRangeInfos, - Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const VULKAN_HPP_NOEXCEPT_WHEN_NO_EXCEPTIONS; + Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ template