diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 75575d4..afbb0d9 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -4579,37 +4579,43 @@ std::string VulkanHppGenerator::constructCommandSimpleVoid( std::string const & ( commandData.params[vectorParamIndices.begin()->first].type.type == "void" ) ) ? "typename T, " : ""; + std::pair>> vectorSizeCheck = + needsVectorSizeCheck( vectorParamIndices ); + std::string noexceptString = vectorSizeCheck.first ? "VULKAN_HPP_NOEXCEPT_WHEN_NO_EXCEPTIONS" : "VULKAN_HPP_NOEXCEPT"; if ( definition ) { std::string const functionTemplate = R"( template <${typenameT}typename Dispatch> - VULKAN_HPP_INLINE void ${className}::${commandName}( ${argumentList} ) const VULKAN_HPP_NOEXCEPT + VULKAN_HPP_INLINE void ${className}::${commandName}( ${argumentList} ) const ${noexcept} {${vectorSizeCheck} d.${vkCommand}( ${callArguments} ); })"; - str = - replaceWithMap( functionTemplate, - std::map( - { { "argumentList", argumentList }, - { "callArguments", constructCallArgumentsVectors( commandData.params, vectorParamIndices ) }, - { "className", stripPrefix( commandData.handle, "Vk" ) }, - { "commandName", commandName }, - { "typenameT", typenameT }, - { "vectorSizeCheck", constructVectorSizeCheck( name, commandData, vectorParamIndices ) }, - { "vkCommand", name } } ) ); + str = replaceWithMap( + functionTemplate, + std::map( + { { "argumentList", argumentList }, + { "callArguments", constructCallArgumentsVectors( commandData.params, vectorParamIndices ) }, + { "className", stripPrefix( commandData.handle, "Vk" ) }, + { "commandName", commandName }, + { "noexcept", noexceptString }, + { "typenameT", typenameT }, + { "vectorSizeCheck", + vectorSizeCheck.first ? constructVectorSizeCheck( name, commandData, vectorSizeCheck.second ) : "" }, + { "vkCommand", name } } ) ); } else { std::string const functionTemplate = R"( template <${typenameT}typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE> - void ${commandName}( ${argumentList} ) const VULKAN_HPP_NOEXCEPT;)"; + void ${commandName}( ${argumentList} ) const ${noexcept};)"; - str = replaceWithMap( - functionTemplate, - std::map( - { { "argumentList", argumentList }, { "commandName", commandName }, { "typenameT", typenameT } } ) ); + str = replaceWithMap( functionTemplate, + std::map( { { "argumentList", argumentList }, + { "commandName", commandName }, + { "noexcept", noexceptString }, + { "typenameT", typenameT } } ) ); } return str; @@ -5043,70 +5049,57 @@ std::string VulkanHppGenerator::constructSuccessCodeList( std::vector const & vectorParamIndices ) const +std::string + VulkanHppGenerator::constructVectorSizeCheck( std::string const & name, + CommandData const & commandData, + std::map> const & countToVectorMap ) const { std::string str; - std::map> countToVectorMap; - for ( auto const & vpi : vectorParamIndices ) + std::string const assertTemplate = + " VULKAN_HPP_ASSERT( ${zeroSizeCheck}${firstVectorName}.size() == ${secondVectorName}.size() );"; + std::string const throwTemplate = + R"#( if ( ${zeroSizeCheck}${firstVectorName}.size() != ${secondVectorName}.size() ) { - if ( vpi.second != INVALID_INDEX ) + throw LogicError( VULKAN_HPP_NAMESPACE_STRING "::${className}::${commandName}: ${firstVectorName}.size() != ${secondVectorName}.size()" ); + })#"; + + std::string commandName = determineCommandName( name, commandData.params[0].type.type ); + + std::string assertions, throws; + for ( auto const & cvm : countToVectorMap ) + { + assert( !commandData.params[cvm.second[0]].optional ); + + size_t defaultStartIndex = determineDefaultStartIndex( commandData.params ); + std::string firstVectorName = startLowerCase( stripPrefix( commandData.params[cvm.second[0]].name, "p" ) ); + + for ( size_t i = 1; i < cvm.second.size(); i++ ) { - countToVectorMap[vpi.second].push_back( vpi.first ); + std::string secondVectorName = startLowerCase( stripPrefix( commandData.params[cvm.second[i]].name, "p" ) ); + bool withZeroSizeCheck = commandData.params[cvm.second[i]].optional && ( defaultStartIndex <= cvm.second[i] ); + assertions += + replaceWithMap( assertTemplate, + { { "firstVectorName", firstVectorName }, + { "secondVectorName", secondVectorName }, + { "zeroSizeCheck", withZeroSizeCheck ? ( secondVectorName + ".empty() || " ) : "" } } ); + throws += + replaceWithMap( throwTemplate, + { { "firstVectorName", firstVectorName }, + { "className", stripPrefix( commandData.handle, "Vk" ) }, + { "commandName", commandName }, + { "secondVectorName", secondVectorName }, + { "zeroSizeCheck", withZeroSizeCheck ? ( "!" + secondVectorName + ".empty() && " ) : "" } } ); + if ( i + 1 < cvm.second.size() ) + { + assertions += "\n"; + throws += "\n"; + } } } - // check if there's at least one count used multiple times - if ( std::find_if( countToVectorMap.begin(), countToVectorMap.end(), []( auto const & cvm ) { - return 1 < cvm.second.size(); - } ) != countToVectorMap.end() ) - { - std::string const assertTemplate = - " VULKAN_HPP_ASSERT( ${zeroSizeCheck}${firstVectorName}.size() == ${secondVectorName}.size() );"; - std::string const throwTemplate = - R"#( if ( ${zeroSizeCheck}${firstVectorName}.size() != ${secondVectorName}.size() ) - { - throw LogicError( VULKAN_HPP_NAMESPACE_STRING "::${className}::${commandName}: ${firstVectorName}.size() != ${secondVectorName}.size()" ); - })#"; - - std::string commandName = determineCommandName( name, commandData.params[0].type.type ); - - std::string assertions, throws; - for ( auto const & cvm : countToVectorMap ) - { - assert( !commandData.params[cvm.second[0]].optional ); - - size_t defaultStartIndex = determineDefaultStartIndex( commandData.params ); - std::string firstVectorName = startLowerCase( stripPrefix( commandData.params[cvm.second[0]].name, "p" ) ); - - for ( size_t i = 1; i < cvm.second.size(); i++ ) - { - std::string secondVectorName = startLowerCase( stripPrefix( commandData.params[cvm.second[i]].name, "p" ) ); - bool withZeroSizeCheck = commandData.params[cvm.second[i]].optional && ( defaultStartIndex <= cvm.second[i] ); - assertions += - replaceWithMap( assertTemplate, - { { "firstVectorName", firstVectorName }, - { "secondVectorName", secondVectorName }, - { "zeroSizeCheck", withZeroSizeCheck ? ( secondVectorName + ".empty() || " ) : "" } } ); - throws += replaceWithMap( - throwTemplate, - { { "firstVectorName", firstVectorName }, - { "className", stripPrefix( commandData.handle, "Vk" ) }, - { "commandName", commandName }, - { "secondVectorName", secondVectorName }, - { "zeroSizeCheck", withZeroSizeCheck ? ( "!" + secondVectorName + ".empty() && " ) : "" } } ); - if ( i + 1 < cvm.second.size() ) - { - assertions += "\n"; - throws += "\n"; - } - } - } - - std::string const sizeCheckTemplate = - R"#( + std::string const sizeCheckTemplate = + R"#( #ifdef VULKAN_HPP_NO_EXCEPTIONS ${assertions} #else @@ -5114,8 +5107,7 @@ ${throws} #endif /*VULKAN_HPP_NO_EXCEPTIONS*/ )#"; - str = replaceWithMap( sizeCheckTemplate, { { "assertions", assertions }, { "throws", throws } } ); - } + str = replaceWithMap( sizeCheckTemplate, { { "assertions", assertions }, { "throws", throws } } ); return str; } @@ -6855,6 +6847,24 @@ bool VulkanHppGenerator::needsComplexBody( CommandData const & commandData ) con !generateProtection( commandData.feature, commandData.extensions ).first.empty(); } +std::pair>> + VulkanHppGenerator::needsVectorSizeCheck( std::map const & vectorParamIndices ) const +{ + std::map> countToVectorMap; + for ( auto const & vpi : vectorParamIndices ) + { + if ( vpi.second != INVALID_INDEX ) + { + countToVectorMap[vpi.second].push_back( vpi.first ); + } + } + return std::make_pair( std::find_if( countToVectorMap.begin(), + countToVectorMap.end(), + []( auto const & cvm ) { return 1 < cvm.second.size(); } ) != + countToVectorMap.end(), + countToVectorMap ); +} + void VulkanHppGenerator::readBaseType( tinyxml2::XMLElement const * element, std::map const & attributes ) { @@ -10092,6 +10102,11 @@ int main( int argc, char ** argv ) # else # define VULKAN_HPP_NOEXCEPT noexcept # define VULKAN_HPP_HAS_NOEXCEPT 1 +# if defined(VULKAN_HPP_NO_EXCEPTIONS) +# define VULKAN_HPP_NOEXCEPT_WHEN_NO_EXCEPTIONS noexcept +# else +# define VULKAN_HPP_NOEXCEPT_WHEN_NO_EXCEPTIONS +# endif # endif #endif diff --git a/VulkanHppGenerator.hpp b/VulkanHppGenerator.hpp index 877b8a8..0490653 100644 --- a/VulkanHppGenerator.hpp +++ b/VulkanHppGenerator.hpp @@ -628,9 +628,9 @@ private: std::string constructNoDiscardStandard( CommandData const & commandData ) const; std::string constructReturnType( CommandData const & commandData, std::string const & baseType ) const; std::string constructSuccessCodeList( std::vector const & successCodes ) const; - std::string constructVectorSizeCheck( std::string const & name, - CommandData const & commandData, - std::map const & vectorParamIndices ) const; + std::string constructVectorSizeCheck( std::string const & name, + CommandData const & commandData, + std::map> const & countToVectorMap ) const; void checkCorrectness(); bool containsArray( std::string const & type ) const; bool containsUnion( std::string const & type ) const; @@ -664,6 +664,8 @@ private: 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>> + needsVectorSizeCheck( std::map const & vectorParamIndices ) const; void readBaseType( tinyxml2::XMLElement const * element, std::map const & attributes ); void readBitmask( tinyxml2::XMLElement const * element, std::map const & attributes ); void readBitmaskAlias( tinyxml2::XMLElement const * element, std::map const & attributes ); diff --git a/vulkan/vulkan.hpp b/vulkan/vulkan.hpp index 98d91fd..03f8483 100644 --- a/vulkan/vulkan.hpp +++ b/vulkan/vulkan.hpp @@ -174,6 +174,11 @@ static_assert( VK_HEADER_VERSION == 155, "Wrong VK_HEADER_VERSION!" ); # else # define VULKAN_HPP_NOEXCEPT noexcept # define VULKAN_HPP_HAS_NOEXCEPT 1 +# if defined( VULKAN_HPP_NO_EXCEPTIONS ) +# define VULKAN_HPP_NOEXCEPT_WHEN_NO_EXCEPTIONS noexcept +# else +# define VULKAN_HPP_NOEXCEPT_WHEN_NO_EXCEPTIONS +# endif # endif #endif @@ -37942,7 +37947,7 @@ namespace VULKAN_HPP_NAMESPACE ArrayProxy const & counterBufferOffsets VULKAN_HPP_DEFAULT_ARGUMENT_ASSIGNMENT, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const - VULKAN_HPP_NOEXCEPT; + VULKAN_HPP_NOEXCEPT_WHEN_NO_EXCEPTIONS; #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ template @@ -38003,7 +38008,7 @@ namespace VULKAN_HPP_NAMESPACE ArrayProxy const & buffers, ArrayProxy const & offsets, ArrayProxy const & sizes VULKAN_HPP_DEFAULT_ARGUMENT_ASSIGNMENT, - Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const VULKAN_HPP_NOEXCEPT; + Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const VULKAN_HPP_NOEXCEPT_WHEN_NO_EXCEPTIONS; #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ template @@ -38017,7 +38022,8 @@ namespace VULKAN_HPP_NAMESPACE void bindVertexBuffers( uint32_t firstBinding, ArrayProxy const & buffers, ArrayProxy const & offsets, - Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const VULKAN_HPP_NOEXCEPT; + Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const + VULKAN_HPP_NOEXCEPT_WHEN_NO_EXCEPTIONS; #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ template @@ -38037,7 +38043,7 @@ namespace VULKAN_HPP_NAMESPACE ArrayProxy const & offsets, ArrayProxy const & sizes VULKAN_HPP_DEFAULT_ARGUMENT_ASSIGNMENT, ArrayProxy const & strides VULKAN_HPP_DEFAULT_ARGUMENT_ASSIGNMENT, - Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const VULKAN_HPP_NOEXCEPT; + Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const VULKAN_HPP_NOEXCEPT_WHEN_NO_EXCEPTIONS; #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ template @@ -38100,7 +38106,7 @@ namespace VULKAN_HPP_NAMESPACE void buildAccelerationStructureKHR( ArrayProxy const & infos, ArrayProxy const & pOffsetInfos, - Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const VULKAN_HPP_NOEXCEPT; + Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const VULKAN_HPP_NOEXCEPT_WHEN_NO_EXCEPTIONS; # endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ #endif /*VK_ENABLE_BETA_EXTENSIONS*/ @@ -38549,12 +38555,12 @@ namespace VULKAN_HPP_NAMESPACE Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const VULKAN_HPP_NOEXCEPT; #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE template - void - endTransformFeedbackEXT( uint32_t firstCounterBuffer, - ArrayProxy const & counterBuffers, - ArrayProxy const & counterBufferOffsets - VULKAN_HPP_DEFAULT_ARGUMENT_ASSIGNMENT, - Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const VULKAN_HPP_NOEXCEPT; + void endTransformFeedbackEXT( uint32_t firstCounterBuffer, + ArrayProxy const & counterBuffers, + ArrayProxy const & counterBufferOffsets + VULKAN_HPP_DEFAULT_ARGUMENT_ASSIGNMENT, + Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const + VULKAN_HPP_NOEXCEPT_WHEN_NO_EXCEPTIONS; #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ template @@ -55478,7 +55484,8 @@ namespace VULKAN_HPP_NAMESPACE template void setHdrMetadataEXT( ArrayProxy const & swapchains, ArrayProxy const & metadata, - Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const VULKAN_HPP_NOEXCEPT; + Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const + VULKAN_HPP_NOEXCEPT_WHEN_NO_EXCEPTIONS; #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ template @@ -89447,7 +89454,7 @@ namespace VULKAN_HPP_NAMESPACE uint32_t firstCounterBuffer, ArrayProxy const & counterBuffers, ArrayProxy const & counterBufferOffsets, - Dispatch const & d ) const VULKAN_HPP_NOEXCEPT + Dispatch const & d ) const VULKAN_HPP_NOEXCEPT_WHEN_NO_EXCEPTIONS { # ifdef VULKAN_HPP_NO_EXCEPTIONS VULKAN_HPP_ASSERT( counterBufferOffsets.empty() || counterBuffers.size() == counterBufferOffsets.size() ); @@ -89576,7 +89583,7 @@ namespace VULKAN_HPP_NAMESPACE ArrayProxy const & buffers, ArrayProxy const & offsets, ArrayProxy const & sizes, - Dispatch const & d ) const VULKAN_HPP_NOEXCEPT + Dispatch const & d ) const VULKAN_HPP_NOEXCEPT_WHEN_NO_EXCEPTIONS { # ifdef VULKAN_HPP_NO_EXCEPTIONS VULKAN_HPP_ASSERT( buffers.size() == offsets.size() ); @@ -89623,7 +89630,7 @@ namespace VULKAN_HPP_NAMESPACE CommandBuffer::bindVertexBuffers( uint32_t firstBinding, ArrayProxy const & buffers, ArrayProxy const & offsets, - Dispatch const & d ) const VULKAN_HPP_NOEXCEPT + Dispatch const & d ) const VULKAN_HPP_NOEXCEPT_WHEN_NO_EXCEPTIONS { # ifdef VULKAN_HPP_NO_EXCEPTIONS VULKAN_HPP_ASSERT( buffers.size() == offsets.size() ); @@ -89669,7 +89676,7 @@ namespace VULKAN_HPP_NAMESPACE ArrayProxy const & offsets, ArrayProxy const & sizes, ArrayProxy const & strides, - Dispatch const & d ) const VULKAN_HPP_NOEXCEPT + Dispatch const & d ) const VULKAN_HPP_NOEXCEPT_WHEN_NO_EXCEPTIONS { # ifdef VULKAN_HPP_NO_EXCEPTIONS VULKAN_HPP_ASSERT( buffers.size() == offsets.size() ); @@ -89816,7 +89823,7 @@ namespace VULKAN_HPP_NAMESPACE VULKAN_HPP_INLINE void CommandBuffer::buildAccelerationStructureKHR( ArrayProxy const & infos, ArrayProxy const & pOffsetInfos, - Dispatch const & d ) const VULKAN_HPP_NOEXCEPT + Dispatch const & d ) const VULKAN_HPP_NOEXCEPT_WHEN_NO_EXCEPTIONS { # ifdef VULKAN_HPP_NO_EXCEPTIONS VULKAN_HPP_ASSERT( infos.size() == pOffsetInfos.size() ); @@ -90663,7 +90670,7 @@ namespace VULKAN_HPP_NAMESPACE uint32_t firstCounterBuffer, ArrayProxy const & counterBuffers, ArrayProxy const & counterBufferOffsets, - Dispatch const & d ) const VULKAN_HPP_NOEXCEPT + Dispatch const & d ) const VULKAN_HPP_NOEXCEPT_WHEN_NO_EXCEPTIONS { # ifdef VULKAN_HPP_NO_EXCEPTIONS VULKAN_HPP_ASSERT( counterBufferOffsets.empty() || counterBuffers.size() == counterBufferOffsets.size() ); @@ -99847,7 +99854,7 @@ namespace VULKAN_HPP_NAMESPACE VULKAN_HPP_INLINE void Device::setHdrMetadataEXT( ArrayProxy const & swapchains, ArrayProxy const & metadata, - Dispatch const & d ) const VULKAN_HPP_NOEXCEPT + Dispatch const & d ) const VULKAN_HPP_NOEXCEPT_WHEN_NO_EXCEPTIONS { # ifdef VULKAN_HPP_NO_EXCEPTIONS VULKAN_HPP_ASSERT( swapchains.size() == metadata.size() );