Merge pull request #767 from asuessenbach/refactor

Refactor command consuming two vectors.
This commit is contained in:
Andreas Süßenbach 2020-10-08 22:52:21 +02:00 committed by GitHub
commit 976ed77a8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 81 additions and 83 deletions

View File

@ -1271,14 +1271,10 @@ void VulkanHppGenerator::appendCommand( std::string & str,
( vectorParamIndices.begin()->second == std::next( vectorParamIndices.begin() )->second ) ) ( vectorParamIndices.begin()->second == std::next( vectorParamIndices.begin() )->second ) )
{ {
assert( commandData.params[vectorParamIndices.begin()->second].type.isValue() ); assert( commandData.params[vectorParamIndices.begin()->second].type.isValue() );
if ( commandData.params[vectorParamIndices.begin()->second].type.isValue() && assert( commandData.returnType == "VkResult" );
( commandData.returnType == "void" ) ) // size is given by value and the vectors are const pointers, that is input parameters
{ appendCommandTwoVectors( str, name, commandData, vectorParamIndices, definition );
// size is given by value and the vectors are const pointers, that is input parameters; function returns appendedFunction = true;
// void
appendCommandTwoVectorsVoid( str, name, commandData, vectorParamIndices, definition );
appendedFunction = true;
}
} }
} }
} }
@ -1944,13 +1940,12 @@ ${commandStandard}
} ) ); } ) );
} }
void VulkanHppGenerator::appendCommandTwoVectorsVoid( std::string & str, void VulkanHppGenerator::appendCommandTwoVectors( std::string & str,
std::string const & name, std::string const & name,
CommandData const & commandData, CommandData const & commandData,
std::map<size_t, size_t> const & vectorParamIndices, std::map<size_t, size_t> const & vectorParamIndices,
bool definition ) const bool definition ) const
{ {
assert( commandData.returnType == "void" );
assert( vectorParamIndices.size() == 2 ); assert( vectorParamIndices.size() == 2 );
std::string enter, leave; std::string enter, leave;
@ -1963,15 +1958,14 @@ ${commandEnhanced}
#endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/
${leave})"; ${leave})";
str += str += replaceWithMap(
replaceWithMap( functionTemplate, functionTemplate,
std::map<std::string, std::string>( std::map<std::string, std::string>(
{ { "commandEnhanced", { { "commandEnhanced", constructCommandTwoVectors( name, commandData, vectorParamIndices, definition ) },
constructCommandTwoVectorsVoid( name, commandData, vectorParamIndices, definition, false ) }, { "commandStandard", constructCommandStandard( name, commandData, definition ) },
{ "commandStandard", constructCommandStandard( name, commandData, definition ) }, { "enter", enter },
{ "enter", enter }, { "leave", leave },
{ "leave", leave }, { "newlineOnDefinition", definition ? "\n" : "" } } ) );
{ "newlineOnDefinition", definition ? "\n" : "" } } ) );
} }
void VulkanHppGenerator::appendDispatchLoaderDynamic( std::string & str ) void VulkanHppGenerator::appendDispatchLoaderDynamic( std::string & str )
@ -4854,7 +4848,8 @@ std::string
R"( template <typename ${handleType}Allocator = std::allocator<${handleType}>, typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE${typenameCheck}> R"( template <typename ${handleType}Allocator = std::allocator<${handleType}>, typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE${typenameCheck}>
${nodiscard}typename ResultValueType<std::vector<${handleType}, ${handleType}Allocator>>::type ${commandName}( ${argumentList} ) const;)"; ${nodiscard}typename ResultValueType<std::vector<${handleType}, ${handleType}Allocator>>::type ${commandName}( ${argumentList} ) const;)";
std::string typenameCheck = ", typename B = " + handleType + "Allocator, typename std::enable_if<std::is_same<typename B::value_type, " + std::string typenameCheck = ", typename B = " + handleType +
"Allocator, typename std::enable_if<std::is_same<typename B::value_type, " +
handleType + ">::value, int>::type = 0"; handleType + ">::value, int>::type = 0";
str = replaceWithMap( str = replaceWithMap(
@ -4913,8 +4908,9 @@ std::string
std::string poolType, poolName; std::string poolType, poolName;
std::tie( poolType, poolName ) = getPoolTypeAndName( commandData.params[vectorParamIndices.second].type.type ); std::tie( poolType, poolName ) = getPoolTypeAndName( commandData.params[vectorParamIndices.second].type.type );
assert( !poolType.empty() ); assert( !poolType.empty() );
std::string typenameCheck = ", typename B, typename std::enable_if<std::is_same<typename B::value_type, UniqueHandle<" + std::string typenameCheck =
handleType + ", Dispatch>>::value, int>::type "; ", typename B, typename std::enable_if<std::is_same<typename B::value_type, UniqueHandle<" + handleType +
", Dispatch>>::value, int>::type ";
std::string vectorName = startLowerCase( stripPrefix( commandData.params[vectorParamIndices.first].name, "p" ) ); std::string vectorName = startLowerCase( stripPrefix( commandData.params[vectorParamIndices.first].name, "p" ) );
str = replaceWithMap( str = replaceWithMap(
@ -4941,15 +4937,18 @@ std::string
R"( template <typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE, typename ${handleType}Allocator = std::allocator<UniqueHandle<${handleType}, Dispatch>>${typenameCheck}> R"( template <typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE, typename ${handleType}Allocator = std::allocator<UniqueHandle<${handleType}, Dispatch>>${typenameCheck}>
${nodiscard}typename ResultValueType<std::vector<UniqueHandle<${handleType}, Dispatch>, ${handleType}Allocator>>::type ${commandName}Unique( ${argumentList} ) const;)"; ${nodiscard}typename ResultValueType<std::vector<UniqueHandle<${handleType}, Dispatch>, ${handleType}Allocator>>::type ${commandName}Unique( ${argumentList} ) const;)";
std::string typenameCheck = ", typename B = " + handleType + "Allocator, typename std::enable_if<std::is_same<typename B::value_type, UniqueHandle<" + std::string typenameCheck =
handleType + ", Dispatch>>::value, int>::type = 0"; ", typename B = " + handleType +
"Allocator, typename std::enable_if<std::is_same<typename B::value_type, UniqueHandle<" + handleType +
", Dispatch>>::value, int>::type = 0";
str = replaceWithMap( functionTemplate, str = replaceWithMap(
std::map<std::string, std::string>( { { "argumentList", argumentList }, functionTemplate,
{ "commandName", commandName }, std::map<std::string, std::string>( { { "argumentList", argumentList },
{ "handleType", handleType }, { "commandName", commandName },
{ "nodiscard", nodiscard }, { "handleType", handleType },
{ "typenameCheck", withAllocator ? typenameCheck : "" } } ) ); { "nodiscard", nodiscard },
{ "typenameCheck", withAllocator ? typenameCheck : "" } } ) );
} }
return str; return str;
@ -5313,12 +5312,12 @@ std::string VulkanHppGenerator::constructCommandStandardVoid( std::string const
return str; return str;
} }
std::string VulkanHppGenerator::constructCommandTwoVectorsVoid( std::string const & name, std::string VulkanHppGenerator::constructCommandTwoVectors( std::string const & name,
CommandData const & commandData, CommandData const & commandData,
std::map<size_t, size_t> const & vectorParamIndices, std::map<size_t, size_t> const & vectorParamIndices,
bool definition, bool definition ) const
bool withAllocators ) const
{ {
assert( !commandData.handle.empty() );
std::string str; std::string str;
auto firstVectorParamIt = vectorParamIndices.begin(); auto firstVectorParamIt = vectorParamIndices.begin();
@ -5327,33 +5326,22 @@ std::string VulkanHppGenerator::constructCommandTwoVectorsVoid( std::string cons
assert( commandData.params[0].type.type == commandData.handle ); assert( commandData.params[0].type.type == commandData.handle );
assert( firstVectorParamIt->second == secondVectorParamIt->second ); assert( firstVectorParamIt->second == secondVectorParamIt->second );
std::string argumentList = std::set<size_t> skippedParameters = { 0, firstVectorParamIt->second };
constructArgumentListEnhanced( commandData.params, { 0, firstVectorParamIt->second }, definition, withAllocators );
std::string commandName = determineCommandName( name, commandData.params[0].type.type ); std::string argumentList = constructArgumentListEnhanced( commandData.params, skippedParameters, definition, false );
std::string commandName = determineCommandName( name, commandData.params[0].type.type );
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 ) if ( definition )
{ {
const std::string functionTemplate = const std::string functionTemplate =
R"x( template <typename Dispatch> R"( template <typename Dispatch>
VULKAN_HPP_INLINE void ${className}::${commandName}( ${argumentList} ) const VULKAN_HPP_INLINE Result ${className}::${commandName}( ${argumentList} ) const ${noexcept}
{ {${vectorSizeCheck}
# ifdef VULKAN_HPP_NO_EXCEPTIONS Result result = static_cast<Result>( d.${vkCommand}( ${callArguments} ) );
VULKAN_HPP_ASSERT( ${firstVectorName}.size() == ${secondVectorName}.size() ); return createResultValue( result, VULKAN_HPP_NAMESPACE_STRING "::${className}::${commandName}"${successCodeList} );
# else })";
if ( ${firstVectorName}.size() != ${secondVectorName}.size() )
{
throw LogicError( VULKAN_HPP_NAMESPACE_STRING "::${className}::${commandName}: ${firstVectorName}.size() != ${secondVectorName}.size()" );
}
#endif /*VULKAN_HPP_NO_EXCEPTIONS*/
d.${vkCommand}( ${callArguments} );
})x";
assert( beginsWith( commandData.params[firstVectorParamIt->first].name, "p" ) );
std::string firstVectorName =
startLowerCase( stripPrefix( commandData.params[firstVectorParamIt->first].name, "p" ) );
assert( beginsWith( commandData.params[secondVectorParamIt->first].name, "p" ) );
std::string secondVectorName =
startLowerCase( stripPrefix( commandData.params[secondVectorParamIt->first].name, "p" ) );
str = str =
replaceWithMap( functionTemplate, replaceWithMap( functionTemplate,
@ -5362,19 +5350,26 @@ std::string VulkanHppGenerator::constructCommandTwoVectorsVoid( std::string cons
{ "callArguments", constructCallArgumentsVectors( commandData.params, vectorParamIndices ) }, { "callArguments", constructCallArgumentsVectors( commandData.params, vectorParamIndices ) },
{ "className", stripPrefix( commandData.handle, "Vk" ) }, { "className", stripPrefix( commandData.handle, "Vk" ) },
{ "commandName", commandName }, { "commandName", commandName },
{ "firstVectorName", firstVectorName }, { "noexcept", noexceptString },
{ "secondVectorName", secondVectorName }, { "successCodeList", constructSuccessCodeList( commandData.successCodes ) },
{ "vectorSizeCheck",
vectorSizeCheck.first
? constructVectorSizeCheck( name, commandData, vectorSizeCheck.second, skippedParameters )
: "" },
{ "vkCommand", name } } ) ); { "vkCommand", name } } ) );
} }
else else
{ {
const std::string functionTemplate = const std::string functionTemplate =
R"( template <typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE> R"( template <typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE>
void ${commandName}( ${argumentList} ) const;)"; Result ${commandName}( ${argumentList} ) const ${noexcept};)";
str = replaceWithMap( str = replaceWithMap( functionTemplate,
functionTemplate, std::map<std::string, std::string>( {
std::map<std::string, std::string>( { { "argumentList", argumentList }, { "commandName", commandName } } ) ); { "argumentList", argumentList },
{ "commandName", commandName },
{ "noexcept", noexceptString },
} ) );
} }
return str; return str;
} }

View File

@ -364,11 +364,11 @@ private:
std::string const & name, std::string const & name,
CommandData const & commandData, CommandData const & commandData,
bool definition ) const; bool definition ) const;
void appendCommandTwoVectorsVoid( std::string & str, void appendCommandTwoVectors( std::string & str,
std::string const & name, std::string const & name,
CommandData const & commandData, CommandData const & commandData,
std::map<size_t, size_t> const & vectorParamIndices, std::map<size_t, size_t> const & vectorParamIndices,
bool definition ) const; bool definition ) const;
void appendDispatchLoaderDynamicCommand( std::string & str, void appendDispatchLoaderDynamicCommand( std::string & str,
std::string & emptyFunctions, std::string & emptyFunctions,
std::string & deviceFunctions, std::string & deviceFunctions,
@ -597,11 +597,13 @@ private:
std::string constructCommandGetVectorOfHandles( std::string const & name, std::string constructCommandGetVectorOfHandles( std::string const & name,
CommandData const & commandData, CommandData const & commandData,
std::pair<size_t, size_t> const & vectorParamIndices, std::pair<size_t, size_t> const & vectorParamIndices,
bool definition, bool withAllocator ) const; bool definition,
bool withAllocator ) const;
std::string constructCommandGetVectorOfUniqueHandles( std::string const & name, std::string constructCommandGetVectorOfUniqueHandles( std::string const & name,
CommandData const & commandData, CommandData const & commandData,
std::pair<size_t, size_t> const & vectorParamIndices, std::pair<size_t, size_t> const & vectorParamIndices,
bool definition, bool withAllocator ) const; bool definition,
bool withAllocator ) const;
std::string std::string
constructCommandGetVectorOfUniqueHandlesWithAllocator( std::string const & name, constructCommandGetVectorOfUniqueHandlesWithAllocator( std::string const & name,
CommandData const & commandData, CommandData const & commandData,
@ -623,11 +625,10 @@ private:
constructCommandStandard( std::string const & name, CommandData const & commandData, bool definition ) const; constructCommandStandard( std::string const & name, CommandData const & commandData, bool definition ) const;
std::string std::string
constructCommandStandardVoid( std::string const & name, CommandData const & commandData, bool definition ) const; constructCommandStandardVoid( std::string const & name, CommandData const & commandData, bool definition ) const;
std::string constructCommandTwoVectorsVoid( std::string const & name, std::string constructCommandTwoVectors( std::string const & name,
CommandData const & commandData, CommandData const & commandData,
std::map<size_t, size_t> const & vectorParamIndices, std::map<size_t, size_t> const & vectorParamIndices,
bool definition, bool definition ) const;
bool withAllocators ) const;
std::string constructConstexprString( std::pair<std::string, StructureData> const & structData ) const; std::string constructConstexprString( std::pair<std::string, StructureData> const & structData ) const;
std::string constructFunctionBodyEnhanced( std::string const & indentation, std::string constructFunctionBodyEnhanced( std::string const & indentation,
std::string const & name, std::string const & name,

View File

@ -52317,10 +52317,10 @@ namespace VULKAN_HPP_NAMESPACE
Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const VULKAN_HPP_NOEXCEPT; Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const VULKAN_HPP_NOEXCEPT;
# ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE # ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE
template <typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE> template <typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE>
VULKAN_HPP_NODISCARD Result buildAccelerationStructureKHR( Result buildAccelerationStructureKHR(
ArrayProxy<const VULKAN_HPP_NAMESPACE::AccelerationStructureBuildGeometryInfoKHR> const & infos, ArrayProxy<const VULKAN_HPP_NAMESPACE::AccelerationStructureBuildGeometryInfoKHR> const & infos,
ArrayProxy<const VULKAN_HPP_NAMESPACE::AccelerationStructureBuildOffsetInfoKHR * const> const & pOffsetInfos, ArrayProxy<const VULKAN_HPP_NAMESPACE::AccelerationStructureBuildOffsetInfoKHR * const> const & pOffsetInfos,
Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const VULKAN_HPP_NOEXCEPT_WHEN_NO_EXCEPTIONS;
# endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ # endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/
#endif /*VK_ENABLE_BETA_EXTENSIONS*/ #endif /*VK_ENABLE_BETA_EXTENSIONS*/
@ -92924,12 +92924,13 @@ namespace VULKAN_HPP_NAMESPACE
reinterpret_cast<const VkAccelerationStructureBuildGeometryInfoKHR *>( pInfos ), reinterpret_cast<const VkAccelerationStructureBuildGeometryInfoKHR *>( pInfos ),
reinterpret_cast<const VkAccelerationStructureBuildOffsetInfoKHR * const *>( ppOffsetInfos ) ) ); reinterpret_cast<const VkAccelerationStructureBuildOffsetInfoKHR * const *>( ppOffsetInfos ) ) );
} }
# ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE # ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE
template <typename Dispatch> template <typename Dispatch>
VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE Result Device::buildAccelerationStructureKHR( VULKAN_HPP_INLINE Result Device::buildAccelerationStructureKHR(
ArrayProxy<const VULKAN_HPP_NAMESPACE::AccelerationStructureBuildGeometryInfoKHR> const & infos, ArrayProxy<const VULKAN_HPP_NAMESPACE::AccelerationStructureBuildGeometryInfoKHR> const & infos,
ArrayProxy<const VULKAN_HPP_NAMESPACE::AccelerationStructureBuildOffsetInfoKHR * const> const & pOffsetInfos, ArrayProxy<const VULKAN_HPP_NAMESPACE::AccelerationStructureBuildOffsetInfoKHR * const> const & pOffsetInfos,
Dispatch const & d ) const Dispatch const & d ) const VULKAN_HPP_NOEXCEPT_WHEN_NO_EXCEPTIONS
{ {
# ifdef VULKAN_HPP_NO_EXCEPTIONS # ifdef VULKAN_HPP_NO_EXCEPTIONS
VULKAN_HPP_ASSERT( infos.size() == pOffsetInfos.size() ); VULKAN_HPP_ASSERT( infos.size() == pOffsetInfos.size() );
@ -92937,9 +92938,10 @@ namespace VULKAN_HPP_NAMESPACE
if ( infos.size() != pOffsetInfos.size() ) if ( infos.size() != pOffsetInfos.size() )
{ {
throw LogicError( VULKAN_HPP_NAMESPACE_STRING throw LogicError( VULKAN_HPP_NAMESPACE_STRING
"::VkDevice::buildAccelerationStructureKHR: infos.size() != pOffsetInfos.size()" ); "::Device::buildAccelerationStructureKHR: infos.size() != pOffsetInfos.size()" );
} }
# endif /*VULKAN_HPP_NO_EXCEPTIONS*/ # endif /*VULKAN_HPP_NO_EXCEPTIONS*/
Result result = static_cast<Result>( d.vkBuildAccelerationStructureKHR( Result result = static_cast<Result>( d.vkBuildAccelerationStructureKHR(
m_device, m_device,
infos.size(), infos.size(),