Merge pull request #797 from asuessenbach/refactor

Refactor command that returns a vector of data and potentially gets vector(s) of data as input.
This commit is contained in:
Andreas Süßenbach 2020-10-21 22:47:14 +02:00 committed by GitHub
commit 9d8acb901b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 113 additions and 38 deletions

View File

@ -631,7 +631,14 @@ std::string stripPluralS( std::string const & name )
size_t pos = strippedName.rfind( 's' );
if ( pos != std::string::npos )
{
strippedName.erase( pos, 1 );
if ( ( 2 <= pos ) && ( strippedName.substr( pos - 2, 3 ) == "ies" ) )
{
strippedName.replace( pos - 2, 3, "y" );
}
else
{
strippedName.erase( pos, 1 );
}
}
return strippedName;
}
@ -1229,13 +1236,12 @@ void VulkanHppGenerator::appendCommand( std::string & str,
appendedFunction = true;
}
}
else if ( ( vectorParamIndices.size() == 1 ) &&
( commandData.params[returnVectorParamIt->first].type.type == "void" ) &&
else if ( ( commandData.params[returnVectorParamIt->first].type.type == "void" ) &&
( commandData.params[returnVectorParamIt->second].type.isValue() ) )
{
// provide standard, enhanced, and singular calls
appendCommandSingular(
str, name, commandData, vectorParamIndices, nonConstPointerParamIndices[0], definition );
str, name, commandData, definition, vectorParamIndices, nonConstPointerParamIndices[0] );
appendedFunction = true;
}
}
@ -1262,7 +1268,7 @@ void VulkanHppGenerator::appendCommand( std::string & str,
if ( ( commandData.returnType == "VkResult" ) || ( commandData.returnType == "void" ) )
{
// provide standard, enhanced, and vector calls
appendCommandVector( str, name, commandData, *vectorParamIndexIt, definition );
appendCommandVector( str, name, commandData, definition, *vectorParamIndexIt );
appendedFunction = true;
}
}
@ -1516,9 +1522,9 @@ ${leave})";
void VulkanHppGenerator::appendCommandSingular( std::string & str,
std::string const & name,
CommandData const & commandData,
bool definition,
std::map<size_t, size_t> const & vectorParamIndices,
size_t returnParamIndex,
bool definition ) const
size_t returnParamIndex ) const
{
assert( commandData.returnType == "VkResult" );
@ -1738,8 +1744,8 @@ ${leave})";
void VulkanHppGenerator::appendCommandVector( std::string & str,
std::string const & name,
CommandData const & commandData,
std::pair<size_t, size_t> const & vectorParamIndex,
bool definition ) const
bool definition,
std::pair<size_t, size_t> const & vectorParamIndex ) const
{
assert( ( commandData.returnType == "VkResult" ) || ( commandData.returnType == "void" ) );
@ -3878,6 +3884,10 @@ std::string VulkanHppGenerator::constructCallArgumentsGetVector( std::string con
else if ( params[lenIt->second].type.isValue() )
{
arguments += startLowerCase( stripPrefix( params[lenIt->first].name, "p" ) ) + ".size()";
if ( params[lenIt->first].type.type == "void" )
{
arguments += " * sizeof( T )";
}
}
else
{
@ -4047,7 +4057,7 @@ std::string VulkanHppGenerator::constructCommandResultEnumerate( std::string con
std::set<size_t> skippedParams = determineSkippedParams( commandData.handle,
commandData.params,
{ vectorParamIndices },
{ vectorParamIndices.second, vectorParamIndices.first } );
{ vectorParamIndices.second, vectorParamIndices.first }, false );
std::string argumentList =
constructArgumentListEnhanced( commandData.params, skippedParams, INVALID_INDEX, definition, withAllocator );
@ -4712,8 +4722,11 @@ std::string VulkanHppGenerator::constructCommandResultGetVector( std::string con
std::string str;
std::set<size_t> skippedParams =
determineSkippedParams( commandData.handle, commandData.params, vectorParamIndices, { returnParamIndex }, false );
std::string argumentList =
constructArgumentListEnhanced( commandData.params, { 0, returnParamIndex }, INVALID_INDEX, definition, false );
constructArgumentListEnhanced( commandData.params, skippedParams, INVALID_INDEX, definition, false );
std::string commandName = determineCommandName( name, commandData.params[0].type.type );
std::string nodiscard = constructNoDiscardEnhanced( commandData );
std::string returnType = constructReturnType( commandData, "std::vector<T,Allocator>" );
@ -4931,7 +4944,7 @@ std::string
std::string str;
std::set<size_t> skippedParams =
determineSkippedParams( commandData.handle, commandData.params, vectorParamIndices, { returnParamIndex } );
determineSkippedParams( commandData.handle, commandData.params, vectorParamIndices, { returnParamIndex }, false );
std::string argumentList =
constructArgumentListEnhanced( commandData.params, skippedParams, INVALID_INDEX, definition, withAllocator );
@ -5015,7 +5028,7 @@ std::string VulkanHppGenerator::constructCommandResultGetVectorOfHandlesSingular
std::string str;
std::set<size_t> skippedParams =
determineSkippedParams( commandData.handle, commandData.params, vectorParamIndices, { returnParamIndex } );
determineSkippedParams( commandData.handle, commandData.params, vectorParamIndices, { returnParamIndex }, true );
size_t singularParam = ( returnParamIndex == vectorParamIndices.begin()->first )
? std::next( vectorParamIndices.begin() )->first
: vectorParamIndices.begin()->first;
@ -5086,7 +5099,7 @@ std::string VulkanHppGenerator::constructCommandResultGetVectorOfHandlesUnique(
std::string str;
std::set<size_t> skippedParams =
determineSkippedParams( commandData.handle, commandData.params, vectorParamIndices, { returnParamIndex } );
determineSkippedParams( commandData.handle, commandData.params, vectorParamIndices, { returnParamIndex }, false );
std::string argumentList =
constructArgumentListEnhanced( commandData.params, skippedParams, INVALID_INDEX, definition, withAllocator );
@ -5210,7 +5223,7 @@ std::string VulkanHppGenerator::constructCommandResultGetVectorOfHandlesUniqueSi
std::string str;
std::set<size_t> skippedParams =
determineSkippedParams( commandData.handle, commandData.params, vectorParamIndices, { returnParamIndex } );
determineSkippedParams( commandData.handle, commandData.params, vectorParamIndices, { returnParamIndex }, true );
size_t singularParam = ( returnParamIndex == vectorParamIndices.begin()->first )
? std::next( vectorParamIndices.begin() )->first
: vectorParamIndices.begin()->first;
@ -5282,12 +5295,11 @@ std::string
std::string str;
std::string argumentList = constructArgumentListEnhanced(
commandData.params,
determineSkippedParams( commandData.handle, commandData.params, vectorParamIndices, { returnParamIndex } ),
INVALID_INDEX,
definition,
false );
std::set<size_t> skippedParams =
determineSkippedParams( commandData.handle, commandData.params, vectorParamIndices, { returnParamIndex }, true );
std::string argumentList =
constructArgumentListEnhanced( commandData.params, skippedParams, INVALID_INDEX, definition, false );
std::string commandName = stripPluralS( determineCommandName( name, commandData.params[0].type.type ) );
std::string nodiscard = constructNoDiscardEnhanced( commandData );
std::string returnType = constructReturnType( commandData, "T" );
@ -7312,7 +7324,7 @@ size_t VulkanHppGenerator::determineReturnParamIndex( CommandData const &
std::set<size_t> VulkanHppGenerator::determineSkippedParams( std::string const & handleType,
std::vector<ParamData> const & params,
std::map<size_t, size_t> const & vectorParamIndices,
std::vector<size_t> const & returnParamIndices ) const
std::vector<size_t> const & returnParamIndices, bool singular ) const
{
std::set<size_t> skippedParams = { returnParamIndices.begin(), returnParamIndices.end() };
@ -7326,7 +7338,7 @@ std::set<size_t> VulkanHppGenerator::determineSkippedParams( std::string const &
if ( ( std::find_if( returnParamIndices.begin(),
returnParamIndices.end(),
[&vpi]( size_t rpi ) { return vpi.first == rpi; } ) == returnParamIndices.end() ) ||
params[vpi.second].type.isValue() )
( singular && params[vpi.second].type.isValue() ) )
{
skippedParams.insert( vpi.second );
}

View File

@ -320,9 +320,9 @@ private:
void appendCommandSingular( std::string & str,
std::string const & name,
CommandData const & commandData,
bool definition,
std::map<size_t, size_t> const & vectorParamIndices,
size_t returnParamIndex,
bool definition ) const;
size_t returnParamIndex ) const;
void appendCommandStandard( std::string & str,
std::string const & name,
CommandData const & commandData,
@ -352,8 +352,8 @@ private:
void appendCommandVector( std::string & str,
std::string const & name,
CommandData const & commandData,
std::pair<size_t, size_t> const & vectorParamIndex,
bool definition ) const;
bool definition,
std::pair<size_t, size_t> const & vectorParamIndex ) const;
void appendCommandVectorDeprecated( std::string & str,
std::string const & name,
CommandData const & commandData,
@ -679,16 +679,17 @@ private:
bool containsUnion( std::string const & type ) const;
size_t determineDefaultStartIndex( std::vector<ParamData> const & params,
std::set<size_t> const & skippedParams ) const;
std::string determineEnhancedReturnType( CommandData const & commandData,
size_t returnParamIndex,
bool isStructureChain ) const;
std::string determineEnhancedReturnType( CommandData const & commandData,
size_t returnParamIndex,
bool isStructureChain ) const;
size_t determineReturnParamIndex( CommandData const & commandData,
std::map<size_t, size_t> const & vectorParamIndices,
bool twoStep ) const;
std::set<size_t> determineSkippedParams( std::string const & handleType,
std::vector<ParamData> const & params,
std::map<size_t, size_t> const & vectorParamIndices,
std::vector<size_t> const & returnParamIndex ) const;
std::vector<size_t> const & returnParamIndex,
bool singular ) const;
std::string determineSubStruct( std::pair<std::string, StructureData> const & structure ) const;
size_t determineTemplateParamIndex( std::vector<ParamData> const & params,
std::map<size_t, size_t> const & vectorParamIndices ) const;

View File

@ -55995,6 +55995,22 @@ namespace VULKAN_HPP_NAMESPACE
ArrayProxy<T> const & data,
size_t stride,
Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const;
template <typename T,
typename Allocator = std::allocator<T>,
typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE>
VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS typename ResultValueType<std::vector<T, Allocator>>::type
writeAccelerationStructuresPropertiesKHR(
ArrayProxy<const VULKAN_HPP_NAMESPACE::AccelerationStructureKHR> const & accelerationStructures,
VULKAN_HPP_NAMESPACE::QueryType queryType,
size_t dataSize,
size_t stride,
Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const;
template <typename T, typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE>
VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS typename ResultValueType<T>::type writeAccelerationStructuresPropertyKHR(
ArrayProxy<const VULKAN_HPP_NAMESPACE::AccelerationStructureKHR> const & accelerationStructures,
VULKAN_HPP_NAMESPACE::QueryType queryType,
size_t stride,
Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const;
# endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/
#endif /*VK_ENABLE_BETA_EXTENSIONS*/
@ -98139,7 +98155,7 @@ namespace VULKAN_HPP_NAMESPACE
Result result = static_cast<Result>(
d.vkGetAccelerationStructureHandleNV( m_device,
static_cast<VkAccelerationStructureKHR>( accelerationStructure ),
data.size(),
data.size() * sizeof( T ),
reinterpret_cast<void *>( data.data() ) ) );
return createResultValue( result, data, VULKAN_HPP_NAMESPACE_STRING "::Device::getAccelerationStructureHandleNV" );
}
@ -100245,7 +100261,7 @@ namespace VULKAN_HPP_NAMESPACE
static_cast<VkQueryPool>( queryPool ),
firstQuery,
queryCount,
data.size(),
data.size() * sizeof( T ),
reinterpret_cast<void *>( data.data() ),
static_cast<VkDeviceSize>( stride ),
static_cast<VkQueryResultFlags>( flags ) ) );
@ -100331,7 +100347,7 @@ namespace VULKAN_HPP_NAMESPACE
static_cast<VkPipeline>( pipeline ),
firstGroup,
groupCount,
data.size(),
data.size() * sizeof( T ),
reinterpret_cast<void *>( data.data() ) ) );
return createResultValue(
result, data, VULKAN_HPP_NAMESPACE_STRING "::Device::getRayTracingCaptureReplayShaderGroupHandlesKHR" );
@ -100408,7 +100424,7 @@ namespace VULKAN_HPP_NAMESPACE
static_cast<VkPipeline>( pipeline ),
firstGroup,
groupCount,
data.size(),
data.size() * sizeof( T ),
reinterpret_cast<void *>( data.data() ) ) );
return createResultValue(
result, data, VULKAN_HPP_NAMESPACE_STRING "::Device::getRayTracingShaderGroupHandlesKHR" );
@ -100482,7 +100498,7 @@ namespace VULKAN_HPP_NAMESPACE
static_cast<VkPipeline>( pipeline ),
firstGroup,
groupCount,
data.size(),
data.size() * sizeof( T ),
reinterpret_cast<void *>( data.data() ) ) );
return createResultValue( result, data, VULKAN_HPP_NAMESPACE_STRING "::Device::getRayTracingShaderGroupHandlesNV" );
}
@ -101800,10 +101816,12 @@ namespace VULKAN_HPP_NAMESPACE
pData,
stride ) );
}
# ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE
template <typename T, typename Dispatch>
VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE typename ResultValueType<void>::type
Device::writeAccelerationStructuresPropertiesKHR(
VULKAN_HPP_DEPRECATED( "This function is deprecated. Use one of the other flavours of it." )
VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE
typename ResultValueType<void>::type Device::writeAccelerationStructuresPropertiesKHR(
ArrayProxy<const VULKAN_HPP_NAMESPACE::AccelerationStructureKHR> const & accelerationStructures,
VULKAN_HPP_NAMESPACE::QueryType queryType,
ArrayProxy<T> const & data,
@ -101821,6 +101839,50 @@ namespace VULKAN_HPP_NAMESPACE
return createResultValue( result,
VULKAN_HPP_NAMESPACE_STRING "::Device::writeAccelerationStructuresPropertiesKHR" );
}
template <typename T, typename Allocator, typename Dispatch>
VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE typename ResultValueType<std::vector<T, Allocator>>::type
Device::writeAccelerationStructuresPropertiesKHR(
ArrayProxy<const VULKAN_HPP_NAMESPACE::AccelerationStructureKHR> const & accelerationStructures,
VULKAN_HPP_NAMESPACE::QueryType queryType,
size_t dataSize,
size_t stride,
Dispatch const & d ) const
{
VULKAN_HPP_ASSERT( dataSize % sizeof( T ) == 0 );
std::vector<T, Allocator> data( dataSize / sizeof( T ) );
Result result = static_cast<Result>( d.vkWriteAccelerationStructuresPropertiesKHR(
m_device,
accelerationStructures.size(),
reinterpret_cast<const VkAccelerationStructureKHR *>( accelerationStructures.data() ),
static_cast<VkQueryType>( queryType ),
data.size() * sizeof( T ),
reinterpret_cast<void *>( data.data() ),
stride ) );
return createResultValue(
result, data, VULKAN_HPP_NAMESPACE_STRING "::Device::writeAccelerationStructuresPropertiesKHR" );
}
template <typename T, typename Dispatch>
VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE typename ResultValueType<T>::type
Device::writeAccelerationStructuresPropertyKHR(
ArrayProxy<const VULKAN_HPP_NAMESPACE::AccelerationStructureKHR> const & accelerationStructures,
VULKAN_HPP_NAMESPACE::QueryType queryType,
size_t stride,
Dispatch const & d ) const
{
T data;
Result result = static_cast<Result>( d.vkWriteAccelerationStructuresPropertiesKHR(
m_device,
1,
reinterpret_cast<const VkAccelerationStructureKHR *>( &accelerationStructure ),
static_cast<VkQueryType>( queryType ),
sizeof( T ),
reinterpret_cast<void *>( &data ),
stride ) );
return createResultValue(
result, data, VULKAN_HPP_NAMESPACE_STRING "::Device::writeAccelerationStructuresPropertyKHR" );
}
# endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/
#endif /*VK_ENABLE_BETA_EXTENSIONS*/