Extend template argument list for functions returning a std::vector<Stuff> to help compilers detecting the correct function.

+ change the order of Allocator and Dispatch template arguments for functions returning a std::vector<UniqueStuff>, as the Allocator needs to use the Dispatch in those cases!
This commit is contained in:
asuessenbach 2020-07-23 18:14:05 +02:00
parent 2a5a0a2798
commit 99f990afa1
4 changed files with 583 additions and 201 deletions

View File

@ -1952,7 +1952,7 @@ void VulkanHppGenerator::appendFunction( std::string & str,
bool singular,
bool unique,
bool isStructureChain,
bool withAllocator ) const
bool withAllocatorArgument ) const
{
appendFunctionHeaderTemplate( str,
indentation,
@ -1963,7 +1963,8 @@ void VulkanHppGenerator::appendFunction( std::string & str,
singular,
unique,
!definition,
isStructureChain );
isStructureChain,
withAllocatorArgument );
str += indentation;
@ -2013,7 +2014,7 @@ void VulkanHppGenerator::appendFunction( std::string & str,
enhanced,
singular,
!definition,
withAllocator );
withAllocatorArgument );
// Any function that originally does not return VkResult can be marked noexcept,
// if it is enhanced it must not include anything with an Allocator or needs size checks on multiple vectors
@ -2045,7 +2046,7 @@ void VulkanHppGenerator::appendFunction( std::string & str,
singular,
unique,
isStructureChain,
withAllocator );
withAllocatorArgument );
}
else
{
@ -3044,9 +3045,11 @@ void VulkanHppGenerator::appendFunctionHeaderTemplate( std::string & str,
bool singular,
bool unique,
bool withDefault,
bool isStructureChain ) const
bool isStructureChain,
bool withAllocatorArgument ) const
{
bool withAllocator = ( enhancedReturnType.find( "Allocator" ) != std::string::npos );
std::string enhancedReturnTypeBase;
str += indentation + "template<";
if ( enhanced )
{
@ -3060,27 +3063,43 @@ void VulkanHppGenerator::appendFunctionHeaderTemplate( std::string & str,
assert( !withAllocator );
str += "typename T, ";
}
if ( !singular && withAllocator )
}
std::string dispatch =
std::string( "typename Dispatch" ) + ( withDefault ? " = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE" : "" );
if ( enhanced && !singular && withAllocator )
{
// otherwise, if there's an Allocator used in the enhanced return type, we templatize on that Allocator
assert( ( enhancedReturnType.substr( 0, 12 ) == "std::vector<" ) &&
( enhancedReturnType.find( ',' ) != std::string::npos ) && ( 12 < enhancedReturnType.find( ',' ) ) );
str += "typename Allocator";
std::string allocator = "typename Allocator ";
enhancedReturnTypeBase = enhancedReturnType.substr( 12, enhancedReturnType.find( ',' ) - 12 );
if ( unique )
{
enhancedReturnTypeBase = "UniqueHandle<" + enhancedReturnTypeBase + ", Dispatch>";
}
if ( withDefault )
{
// for the default type get the type from the enhancedReturnType, which is of the form
// 'std::vector<Type,Allocator>'
assert( !isStructureChain || !unique );
str += " = std::allocator<" +
( isStructureChain ? "StructureChain"
: ( unique ? "Unique" : "" ) +
enhancedReturnType.substr( 12, enhancedReturnType.find( ',' ) - 12 ) ) +
">";
allocator += " = std::allocator<" + ( isStructureChain ? "StructureChain" : enhancedReturnTypeBase ) + ">";
}
str += ", ";
// Use first Dispatch, then Allocator template argument for functions returning a std::vector<UniqueHandle>, as they
// need the Dispatch in the Allocator. For all other functions keep the previous order: first Allocator, then
// Dispatch
str += unique ? ( dispatch + ", " + allocator ) : ( allocator + ", " + dispatch );
}
else
{
str += dispatch;
}
str += std::string( "typename Dispatch" ) + ( withDefault ? " = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE" : "" ) + ">\n";
if ( enhanced && !singular && withAllocatorArgument )
{
str += std::string( ", typename B" ) + ( withDefault ? " = Allocator" : "" );
str += ", typename std::enable_if<std::is_same<typename B::value_type, " + enhancedReturnTypeBase +
">::value, int>::type" + ( withDefault ? " = 0" : "" );
}
str += ">\n";
}
void VulkanHppGenerator::appendHandle( std::string & str, std::pair<std::string, HandleData> const & handleData )

View File

@ -312,7 +312,7 @@ private:
bool singular,
bool unique,
bool isStructureChain,
bool withAllocator ) const;
bool withAllocatorArgument ) const;
void appendFunctionBodyEnhanced( std::string & str,
std::string const & indentation,
std::string const & name,
@ -466,11 +466,10 @@ private:
bool singular,
bool unique,
bool withDefault,
bool isStructureChain ) const;
void appendHandle( std::string & str,
std::pair<std::string, HandleData> const & handle );
void appendStruct( std::string & str,
std::pair<std::string, StructureData> const & structure );
bool isStructureChain,
bool withAllocatorArgument ) const;
void appendHandle( std::string & str, std::pair<std::string, HandleData> const & handle );
void appendStruct( std::string & str, std::pair<std::string, StructureData> const & structure );
void appendStructAssignmentOperators( std::string & str,
std::pair<std::string, StructureData> const & structure,
std::string const & prefix ) const;

View File

@ -30,6 +30,9 @@ int main( int /*argc*/, char ** /*argv*/ )
vk::UniqueInstance instance = vk::createInstanceUnique( vk::InstanceCreateInfo( {}, &appInfo ) );
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
uint32_t propertyCount;
physicalDevice.getQueueFamilyProperties( &propertyCount, nullptr );
// get the QueueFamilyProperties of the first PhysicalDevice
std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties();

File diff suppressed because it is too large Load Diff