From 8219ca081d7675ea161195d2b6d1a34b0ab81efc Mon Sep 17 00:00:00 2001 From: asuessenbach Date: Tue, 29 Sep 2020 12:21:27 +0200 Subject: [PATCH] Refactor generation of simple commands with up to one vector parameter --- VulkanHppGenerator.cpp | 93 ++++++++++++++++++++++++------------------ VulkanHppGenerator.hpp | 17 ++++---- vulkan/vulkan.hpp | 36 +++++++++++----- 3 files changed, 89 insertions(+), 57 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index aa78467..099eb83 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -1258,11 +1258,11 @@ void VulkanHppGenerator::appendCommand( std::string & str, appendCommandSimpleVoid( str, name, commandData, definition, vectorParamIndices ); appendedFunction = true; } - else if ( vectorParamIndices.empty() && ( commandData.returnType == "VkResult" ) && - ( commandData.successCodes.size() == 1 ) ) + else if ( ( commandData.returnType == "VkResult" ) && ( commandData.successCodes.size() == 1 ) && + ( vectorParamIndices.size() < 2 ) ) { // returns VkResult, but there's just one success code - appendCommandSimple( str, name, commandData, definition ); + appendCommandSimple( str, name, commandData, definition, vectorParamIndices ); appendedFunction = true; } else if ( ( vectorParamIndices.size() == 2 ) && ( vectorParamIndices.begin()->second != INVALID_INDEX ) && @@ -1702,10 +1702,11 @@ ${leave})"; { "newlineOnDefinition", definition ? "\n" : "" } } ) ); } -void VulkanHppGenerator::appendCommandSimple( std::string & str, - std::string const & name, - CommandData const & commandData, - bool definition ) const +void VulkanHppGenerator::appendCommandSimple( std::string & str, + std::string const & name, + CommandData const & commandData, + bool definition, + std::map const & vectorParamIndices ) const { const std::string functionTemplate = R"( ${enter}${commandStandard}${newlineOnDefinition} @@ -1717,13 +1718,14 @@ ${leave})"; std::string enter, leave; std::tie( enter, leave ) = generateProtection( commandData.feature, commandData.extensions ); - str += replaceWithMap( functionTemplate, - std::map( - { { "commandEnhanced", constructCommandSimple( name, commandData, definition ) }, - { "commandStandard", constructCommandStandard( name, commandData, definition ) }, - { "enter", enter }, - { "leave", leave }, - { "newlineOnDefinition", definition ? "\n" : "" } } ) ); + str += replaceWithMap( + functionTemplate, + std::map( + { { "commandEnhanced", constructCommandSimple( name, commandData, definition, vectorParamIndices ) }, + { "commandStandard", constructCommandStandard( name, commandData, definition ) }, + { "enter", enter }, + { "leave", leave }, + { "newlineOnDefinition", definition ? "\n" : "" } } ) ); } void VulkanHppGenerator::appendCommandSimpleVoid( std::string & str, @@ -1771,7 +1773,7 @@ ${leave} str += replaceWithMap( functionTemplate, std::map( - { { "commandEnhanced", constructCommandSimple( name, commandData, definition ) }, + { { "commandEnhanced", constructCommandSimple( name, commandData, definition, {} ) }, { "commandStandard", constructCommandStandard( name, commandData, definition ) }, { "enter", enter }, { "leave", leave } } ) ); @@ -3910,16 +3912,6 @@ std::string VulkanHppGenerator::constructCallArgument( ParamData const & param, return argument; } -std::string VulkanHppGenerator::constructCallArguments( std::vector const & params, bool enhanced ) const -{ - std::string arguments = "m_" + startLowerCase( stripPrefix( params[0].type.type, "Vk" ) ); - for ( size_t i = 1; i < params.size(); i++ ) - { - arguments += ", " + constructCallArgument( params[i], enhanced ); - } - return arguments; -} - std::string VulkanHppGenerator::constructCallArgumentsEnumerateVectors( std::vector const & params, std::map const & vectorParamIndices, @@ -4002,6 +3994,16 @@ std::string VulkanHppGenerator::constructCallArgumentsGetVector( std::vector const & params ) const +{ + std::string arguments = "m_" + startLowerCase( stripPrefix( params[0].type.type, "Vk" ) ); + for ( size_t i = 1; i < params.size(); i++ ) + { + arguments += ", " + constructCallArgument( params[i], false ); + } + return arguments; +} + std::string VulkanHppGenerator::constructCallArgumentsVectors( std::vector const & params, std::map const & vectorParamIndices ) const @@ -4496,13 +4498,23 @@ std::string VulkanHppGenerator::constructCommandGetVectorSingular( std::string c return str; } -std::string VulkanHppGenerator::constructCommandSimple( std::string const & name, - CommandData const & commandData, - bool definition ) const +std::string VulkanHppGenerator::constructCommandSimple( std::string const & name, + CommandData const & commandData, + bool definition, + std::map const & vectorParamIndices ) const { std::string str; - std::string argumentList = constructArgumentListEnhanced( commandData.params, { 0 }, definition, false ); + std::set skippedParameters = { 0 }; + for ( auto const & vpi : vectorParamIndices ) + { + if ( vpi.second != INVALID_INDEX ) + { + skippedParameters.insert( vpi.second ); + } + } + + std::string argumentList = constructArgumentListEnhanced( commandData.params, skippedParameters, definition, false ); std::string commandName = determineCommandName( name, commandData.params[0].type.type ); std::string nodiscard = constructNoDiscardEnhanced( commandData ); std::string returnType = constructReturnType( commandData, "void" ); @@ -4517,15 +4529,16 @@ std::string VulkanHppGenerator::constructCommandSimple( std::string const & name return createResultValue( result, VULKAN_HPP_NAMESPACE_STRING "::${className}::${commandName}" ); })"; - str = replaceWithMap( - functionTemplate, - std::map( { { "argumentList", argumentList }, - { "callArguments", constructCallArguments( commandData.params, true ) }, - { "className", stripPrefix( commandData.handle, "Vk" ) }, - { "commandName", commandName }, - { "nodiscard", nodiscard }, - { "returnType", returnType }, - { "vkCommand", name } } ) ); + str = + replaceWithMap( functionTemplate, + std::map( + { { "argumentList", argumentList }, + { "callArguments", constructCallArgumentsVectors( commandData.params, vectorParamIndices ) }, + { "className", stripPrefix( commandData.handle, "Vk" ) }, + { "commandName", commandName }, + { "nodiscard", nodiscard }, + { "returnType", returnType }, + { "vkCommand", name } } ) ); } else { @@ -4614,7 +4627,7 @@ std::string VulkanHppGenerator::constructCommandStandard( std::string const & na if ( definition ) { - std::string functionBody = "d." + name + "( " + constructCallArguments( commandData.params, false ) + " )"; + std::string functionBody = "d." + name + "( " + constructCallArgumentsStandard( commandData.params ) + " )"; if ( returnType != "void" ) { functionBody = "return static_cast<" + returnType + ">( " + functionBody + " )"; @@ -4672,7 +4685,7 @@ std::string VulkanHppGenerator::constructCommandStandardVoid( std::string const str = replaceWithMap( functionTemplate, std::map( { { "argumentList", argumentList }, - { "callArguments", constructCallArguments( commandData.params, false ) }, + { "callArguments", constructCallArgumentsStandard( commandData.params ) }, { "className", stripPrefix( commandData.handle, "Vk" ) }, { "commandName", commandName }, { "vkCommand", name }, diff --git a/VulkanHppGenerator.hpp b/VulkanHppGenerator.hpp index 84de530..877b8a8 100644 --- a/VulkanHppGenerator.hpp +++ b/VulkanHppGenerator.hpp @@ -331,10 +331,11 @@ private: CommandData const & commandData, std::map const & vectorParamIndices, bool definition ) const; - void appendCommandSimple( std::string & str, - std::string const & name, - CommandData const & commandData, - bool definition ) const; + void appendCommandSimple( std::string & str, + std::string const & name, + CommandData const & commandData, + bool definition, + std::map const & vectorParamIndices ) const; void appendCommandSimpleVoid( std::string & str, std::string const & name, CommandData const & commandData, @@ -539,13 +540,13 @@ private: std::set const & skippedParams, bool definition ) const; std::string constructCallArgument( ParamData const & param, bool enhanced ) const; - std::string constructCallArguments( std::vector const & params, bool enhanced ) const; std::string constructCallArgumentsEnumerateVectors( std::vector const & params, std::map const & vectorParamIndices, bool vectorAsNullptr ) const; std::string constructCallArgumentsGetVector( std::vector const & params, std::pair const & vectorParamIndices, bool singular ) const; + std::string constructCallArgumentsStandard( std::vector const & params ) const; std::string constructCallArgumentsVectors( std::vector const & params, std::map const & vectorParamIndices ) const; std::string constructCommandEnumerateTwoVectors( std::string const & name, @@ -575,8 +576,10 @@ private: CommandData const & commandData, std::map const & vectorParamIndices, bool definition ) const; - std::string - constructCommandSimple( std::string const & name, CommandData const & commandData, bool definition ) const; + std::string constructCommandSimple( std::string const & name, + CommandData const & commandData, + bool definition, + std::map const & vectorParamIndices ) const; std::string constructCommandSimpleVoid( std::string const & name, CommandData const & commandData, bool definition, diff --git a/vulkan/vulkan.hpp b/vulkan/vulkan.hpp index ff23486..9552fb7 100644 --- a/vulkan/vulkan.hpp +++ b/vulkan/vulkan.hpp @@ -47752,13 +47752,13 @@ namespace VULKAN_HPP_NAMESPACE VULKAN_HPP_NODISCARD Result bindSparse( uint32_t bindInfoCount, const VULKAN_HPP_NAMESPACE::BindSparseInfo * pBindInfo, - VULKAN_HPP_NAMESPACE::Fence fence, + VULKAN_HPP_NAMESPACE::Fence fence VULKAN_HPP_DEFAULT_ARGUMENT_ASSIGNMENT, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const VULKAN_HPP_NOEXCEPT; #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE template VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS typename ResultValueType::type bindSparse( ArrayProxy const & bindInfo, - VULKAN_HPP_NAMESPACE::Fence fence, + VULKAN_HPP_NAMESPACE::Fence fence VULKAN_HPP_DEFAULT_ARGUMENT_ASSIGNMENT, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ @@ -47802,13 +47802,13 @@ namespace VULKAN_HPP_NAMESPACE VULKAN_HPP_NODISCARD Result submit( uint32_t submitCount, const VULKAN_HPP_NAMESPACE::SubmitInfo * pSubmits, - VULKAN_HPP_NAMESPACE::Fence fence, + VULKAN_HPP_NAMESPACE::Fence fence VULKAN_HPP_DEFAULT_ARGUMENT_ASSIGNMENT, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const VULKAN_HPP_NOEXCEPT; #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE template VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS typename ResultValueType::type submit( ArrayProxy const & submits, - VULKAN_HPP_NAMESPACE::Fence fence, + VULKAN_HPP_NAMESPACE::Fence fence VULKAN_HPP_DEFAULT_ARGUMENT_ASSIGNMENT, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ @@ -55410,9 +55410,10 @@ namespace VULKAN_HPP_NAMESPACE #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ template - Result resetFences( uint32_t fenceCount, - const VULKAN_HPP_NAMESPACE::Fence * pFences, - Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const VULKAN_HPP_NOEXCEPT; + VULKAN_HPP_NODISCARD Result + resetFences( uint32_t fenceCount, + const VULKAN_HPP_NAMESPACE::Fence * pFences, + Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const VULKAN_HPP_NOEXCEPT; #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE template typename ResultValueType::type @@ -92216,6 +92217,7 @@ namespace VULKAN_HPP_NAMESPACE return static_cast( d.vkBindAccelerationStructureMemoryKHR( m_device, bindInfoCount, reinterpret_cast( pBindInfos ) ) ); } + # ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE template VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE typename ResultValueType::type @@ -92241,6 +92243,7 @@ namespace VULKAN_HPP_NAMESPACE return static_cast( d.vkBindAccelerationStructureMemoryNV( m_device, bindInfoCount, reinterpret_cast( pBindInfos ) ) ); } + #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE template VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE typename ResultValueType::type @@ -92293,6 +92296,7 @@ namespace VULKAN_HPP_NAMESPACE return static_cast( d.vkBindBufferMemory2( m_device, bindInfoCount, reinterpret_cast( pBindInfos ) ) ); } + #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE template VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE typename ResultValueType::type @@ -92314,6 +92318,7 @@ namespace VULKAN_HPP_NAMESPACE return static_cast( d.vkBindBufferMemory2KHR( m_device, bindInfoCount, reinterpret_cast( pBindInfos ) ) ); } + #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE template VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE typename ResultValueType::type @@ -92363,6 +92368,7 @@ namespace VULKAN_HPP_NAMESPACE return static_cast( d.vkBindImageMemory2( m_device, bindInfoCount, reinterpret_cast( pBindInfos ) ) ); } + #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE template VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE typename ResultValueType::type @@ -92384,6 +92390,7 @@ namespace VULKAN_HPP_NAMESPACE return static_cast( d.vkBindImageMemory2KHR( m_device, bindInfoCount, reinterpret_cast( pBindInfos ) ) ); } + #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE template VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE typename ResultValueType::type @@ -96389,6 +96396,7 @@ namespace VULKAN_HPP_NAMESPACE return static_cast( d.vkFlushMappedMemoryRanges( m_device, memoryRangeCount, reinterpret_cast( pMemoryRanges ) ) ); } + #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE template VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE typename ResultValueType::type @@ -96464,6 +96472,7 @@ namespace VULKAN_HPP_NAMESPACE descriptorSetCount, reinterpret_cast( pDescriptorSets ) ) ); } + #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE template VULKAN_HPP_INLINE typename ResultValueType::type @@ -96492,6 +96501,7 @@ namespace VULKAN_HPP_NAMESPACE descriptorSetCount, reinterpret_cast( pDescriptorSets ) ) ); } + #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE template VULKAN_HPP_INLINE typename ResultValueType::type @@ -99403,6 +99413,7 @@ namespace VULKAN_HPP_NAMESPACE return static_cast( d.vkInvalidateMappedMemoryRanges( m_device, memoryRangeCount, reinterpret_cast( pMemoryRanges ) ) ); } + #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE template VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE typename ResultValueType::type @@ -99462,6 +99473,7 @@ namespace VULKAN_HPP_NAMESPACE srcCacheCount, reinterpret_cast( pSrcCaches ) ) ); } + #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE template VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE typename ResultValueType::type @@ -99491,6 +99503,7 @@ namespace VULKAN_HPP_NAMESPACE srcCacheCount, reinterpret_cast( pSrcCaches ) ) ); } + #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE template VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE typename ResultValueType::type @@ -99720,12 +99733,13 @@ namespace VULKAN_HPP_NAMESPACE #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ template - VULKAN_HPP_INLINE Result Device::resetFences( uint32_t fenceCount, - const VULKAN_HPP_NAMESPACE::Fence * pFences, - Dispatch const & d ) const VULKAN_HPP_NOEXCEPT + VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE Result Device::resetFences( uint32_t fenceCount, + const VULKAN_HPP_NAMESPACE::Fence * pFences, + Dispatch const & d ) const VULKAN_HPP_NOEXCEPT { return static_cast( d.vkResetFences( m_device, fenceCount, reinterpret_cast( pFences ) ) ); } + #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE template VULKAN_HPP_INLINE typename ResultValueType::type @@ -104657,6 +104671,7 @@ namespace VULKAN_HPP_NAMESPACE reinterpret_cast( pBindInfo ), static_cast( fence ) ) ); } + #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE template VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE typename ResultValueType::type @@ -104743,6 +104758,7 @@ namespace VULKAN_HPP_NAMESPACE return static_cast( d.vkQueueSubmit( m_queue, submitCount, reinterpret_cast( pSubmits ), static_cast( fence ) ) ); } + #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE template VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE typename ResultValueType::type