Correct usage of noexcept on functions that need to check vector sizes.

This commit is contained in:
asuessenbach 2020-09-30 10:13:51 +02:00
parent 5fd780c189
commit 152353da3e
3 changed files with 120 additions and 96 deletions

View File

@ -4578,37 +4578,43 @@ std::string VulkanHppGenerator::constructCommandSimpleVoid( std::string const &
( commandData.params[vectorParamIndices.begin()->first].type.type == "void" ) )
? "typename T, "
: "";
std::pair<bool, std::map<size_t, std::vector<size_t>>> 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<std::string, std::string>(
{ { "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<std::string, std::string>(
{ { "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<std::string, std::string>(
{ { "argumentList", argumentList }, { "commandName", commandName }, { "typenameT", typenameT } } ) );
str = replaceWithMap( functionTemplate,
std::map<std::string, std::string>( { { "argumentList", argumentList },
{ "commandName", commandName },
{ "noexcept", noexceptString },
{ "typenameT", typenameT } } ) );
}
return str;
@ -5042,70 +5048,57 @@ std::string VulkanHppGenerator::constructSuccessCodeList( std::vector<std::strin
return successCodeList;
}
std::string VulkanHppGenerator::constructVectorSizeCheck( std::string const & name,
CommandData const & commandData,
std::map<size_t, size_t> const & vectorParamIndices ) const
std::string
VulkanHppGenerator::constructVectorSizeCheck( std::string const & name,
CommandData const & commandData,
std::map<size_t, std::vector<size_t>> const & countToVectorMap ) const
{
std::string str;
std::map<size_t, std::vector<size_t>> 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
@ -5113,8 +5106,7 @@ ${throws}
#endif /*VULKAN_HPP_NO_EXCEPTIONS*/
)#";
str = replaceWithMap( sizeCheckTemplate, { { "assertions", assertions }, { "throws", throws } } );
}
str = replaceWithMap( sizeCheckTemplate, { { "assertions", assertions }, { "throws", throws } } );
return str;
}
@ -6854,6 +6846,24 @@ bool VulkanHppGenerator::needsComplexBody( CommandData const & commandData ) con
!generateProtection( commandData.feature, commandData.extensions ).first.empty();
}
std::pair<bool, std::map<size_t, std::vector<size_t>>>
VulkanHppGenerator::needsVectorSizeCheck( std::map<size_t, size_t> const & vectorParamIndices ) const
{
std::map<size_t, std::vector<size_t>> 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<std::string, std::string> const & attributes )
{
@ -10091,6 +10101,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

View File

@ -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<std::string> const & successCodes ) const;
std::string constructVectorSizeCheck( std::string const & name,
CommandData const & commandData,
std::map<size_t, size_t> const & vectorParamIndices ) const;
std::string constructVectorSizeCheck( std::string const & name,
CommandData const & commandData,
std::map<size_t, std::vector<size_t>> 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<ParamData> const & params ) const;
bool isTwoStepAlgorithm( std::vector<ParamData> const & params ) const;
bool needsComplexBody( CommandData const & commandData ) const;
std::pair<bool, std::map<size_t, std::vector<size_t>>>
needsVectorSizeCheck( std::map<size_t, size_t> const & vectorParamIndices ) const;
void readBaseType( tinyxml2::XMLElement const * element, std::map<std::string, std::string> const & attributes );
void readBitmask( tinyxml2::XMLElement const * element, std::map<std::string, std::string> const & attributes );
void readBitmaskAlias( tinyxml2::XMLElement const * element, std::map<std::string, std::string> const & attributes );

View File

@ -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 VULKAN_HPP_NAMESPACE::DeviceSize> 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 <typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE>
@ -38003,7 +38008,7 @@ namespace VULKAN_HPP_NAMESPACE
ArrayProxy<const VULKAN_HPP_NAMESPACE::Buffer> const & buffers,
ArrayProxy<const VULKAN_HPP_NAMESPACE::DeviceSize> const & offsets,
ArrayProxy<const VULKAN_HPP_NAMESPACE::DeviceSize> 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 <typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE>
@ -38017,7 +38022,8 @@ namespace VULKAN_HPP_NAMESPACE
void bindVertexBuffers( uint32_t firstBinding,
ArrayProxy<const VULKAN_HPP_NAMESPACE::Buffer> const & buffers,
ArrayProxy<const VULKAN_HPP_NAMESPACE::DeviceSize> 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 <typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE>
@ -38037,7 +38043,7 @@ namespace VULKAN_HPP_NAMESPACE
ArrayProxy<const VULKAN_HPP_NAMESPACE::DeviceSize> const & offsets,
ArrayProxy<const VULKAN_HPP_NAMESPACE::DeviceSize> const & sizes VULKAN_HPP_DEFAULT_ARGUMENT_ASSIGNMENT,
ArrayProxy<const VULKAN_HPP_NAMESPACE::DeviceSize> 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 <typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE>
@ -38100,7 +38106,7 @@ namespace VULKAN_HPP_NAMESPACE
void buildAccelerationStructureKHR(
ArrayProxy<const VULKAN_HPP_NAMESPACE::AccelerationStructureBuildGeometryInfoKHR> const & infos,
ArrayProxy<const VULKAN_HPP_NAMESPACE::AccelerationStructureBuildOffsetInfoKHR * const> 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 <typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE>
void
endTransformFeedbackEXT( uint32_t firstCounterBuffer,
ArrayProxy<const VULKAN_HPP_NAMESPACE::Buffer> const & counterBuffers,
ArrayProxy<const VULKAN_HPP_NAMESPACE::DeviceSize> 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 VULKAN_HPP_NAMESPACE::Buffer> const & counterBuffers,
ArrayProxy<const VULKAN_HPP_NAMESPACE::DeviceSize> 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 <typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE>
@ -55478,7 +55484,8 @@ namespace VULKAN_HPP_NAMESPACE
template <typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE>
void setHdrMetadataEXT( ArrayProxy<const VULKAN_HPP_NAMESPACE::SwapchainKHR> const & swapchains,
ArrayProxy<const VULKAN_HPP_NAMESPACE::HdrMetadataEXT> 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 <typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE>
@ -89447,7 +89454,7 @@ namespace VULKAN_HPP_NAMESPACE
uint32_t firstCounterBuffer,
ArrayProxy<const VULKAN_HPP_NAMESPACE::Buffer> const & counterBuffers,
ArrayProxy<const VULKAN_HPP_NAMESPACE::DeviceSize> 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 VULKAN_HPP_NAMESPACE::Buffer> const & buffers,
ArrayProxy<const VULKAN_HPP_NAMESPACE::DeviceSize> const & offsets,
ArrayProxy<const VULKAN_HPP_NAMESPACE::DeviceSize> 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 VULKAN_HPP_NAMESPACE::Buffer> const & buffers,
ArrayProxy<const VULKAN_HPP_NAMESPACE::DeviceSize> 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 VULKAN_HPP_NAMESPACE::DeviceSize> const & offsets,
ArrayProxy<const VULKAN_HPP_NAMESPACE::DeviceSize> const & sizes,
ArrayProxy<const VULKAN_HPP_NAMESPACE::DeviceSize> 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 VULKAN_HPP_NAMESPACE::AccelerationStructureBuildGeometryInfoKHR> const & infos,
ArrayProxy<const VULKAN_HPP_NAMESPACE::AccelerationStructureBuildOffsetInfoKHR * const> 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 VULKAN_HPP_NAMESPACE::Buffer> const & counterBuffers,
ArrayProxy<const VULKAN_HPP_NAMESPACE::DeviceSize> 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() );
@ -99844,7 +99851,7 @@ namespace VULKAN_HPP_NAMESPACE
VULKAN_HPP_INLINE void
Device::setHdrMetadataEXT( ArrayProxy<const VULKAN_HPP_NAMESPACE::SwapchainKHR> const & swapchains,
ArrayProxy<const VULKAN_HPP_NAMESPACE::HdrMetadataEXT> 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() );