mirror of
https://github.com/KhronosGroup/Vulkan-Hpp
synced 2024-11-29 07:01:08 +00:00
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:
parent
2a5a0a2798
commit
99f990afa1
@ -1952,7 +1952,7 @@ void VulkanHppGenerator::appendFunction( std::string & str,
|
|||||||
bool singular,
|
bool singular,
|
||||||
bool unique,
|
bool unique,
|
||||||
bool isStructureChain,
|
bool isStructureChain,
|
||||||
bool withAllocator ) const
|
bool withAllocatorArgument ) const
|
||||||
{
|
{
|
||||||
appendFunctionHeaderTemplate( str,
|
appendFunctionHeaderTemplate( str,
|
||||||
indentation,
|
indentation,
|
||||||
@ -1963,7 +1963,8 @@ void VulkanHppGenerator::appendFunction( std::string & str,
|
|||||||
singular,
|
singular,
|
||||||
unique,
|
unique,
|
||||||
!definition,
|
!definition,
|
||||||
isStructureChain );
|
isStructureChain,
|
||||||
|
withAllocatorArgument );
|
||||||
|
|
||||||
str += indentation;
|
str += indentation;
|
||||||
|
|
||||||
@ -2013,7 +2014,7 @@ void VulkanHppGenerator::appendFunction( std::string & str,
|
|||||||
enhanced,
|
enhanced,
|
||||||
singular,
|
singular,
|
||||||
!definition,
|
!definition,
|
||||||
withAllocator );
|
withAllocatorArgument );
|
||||||
|
|
||||||
// Any function that originally does not return VkResult can be marked noexcept,
|
// 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
|
// 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,
|
singular,
|
||||||
unique,
|
unique,
|
||||||
isStructureChain,
|
isStructureChain,
|
||||||
withAllocator );
|
withAllocatorArgument );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -3044,9 +3045,11 @@ void VulkanHppGenerator::appendFunctionHeaderTemplate( std::string & str,
|
|||||||
bool singular,
|
bool singular,
|
||||||
bool unique,
|
bool unique,
|
||||||
bool withDefault,
|
bool withDefault,
|
||||||
bool isStructureChain ) const
|
bool isStructureChain,
|
||||||
|
bool withAllocatorArgument ) const
|
||||||
{
|
{
|
||||||
bool withAllocator = ( enhancedReturnType.find( "Allocator" ) != std::string::npos );
|
bool withAllocator = ( enhancedReturnType.find( "Allocator" ) != std::string::npos );
|
||||||
|
std::string enhancedReturnTypeBase;
|
||||||
str += indentation + "template<";
|
str += indentation + "template<";
|
||||||
if ( enhanced )
|
if ( enhanced )
|
||||||
{
|
{
|
||||||
@ -3060,27 +3063,43 @@ void VulkanHppGenerator::appendFunctionHeaderTemplate( std::string & str,
|
|||||||
assert( !withAllocator );
|
assert( !withAllocator );
|
||||||
str += "typename T, ";
|
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
|
// otherwise, if there's an Allocator used in the enhanced return type, we templatize on that Allocator
|
||||||
assert( ( enhancedReturnType.substr( 0, 12 ) == "std::vector<" ) &&
|
assert( ( enhancedReturnType.substr( 0, 12 ) == "std::vector<" ) &&
|
||||||
( enhancedReturnType.find( ',' ) != std::string::npos ) && ( 12 < enhancedReturnType.find( ',' ) ) );
|
( 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 )
|
if ( withDefault )
|
||||||
{
|
{
|
||||||
// for the default type get the type from the enhancedReturnType, which is of the form
|
// for the default type get the type from the enhancedReturnType, which is of the form
|
||||||
// 'std::vector<Type,Allocator>'
|
// 'std::vector<Type,Allocator>'
|
||||||
assert( !isStructureChain || !unique );
|
assert( !isStructureChain || !unique );
|
||||||
str += " = std::allocator<" +
|
allocator += " = std::allocator<" + ( isStructureChain ? "StructureChain" : enhancedReturnTypeBase ) + ">";
|
||||||
( isStructureChain ? "StructureChain"
|
|
||||||
: ( unique ? "Unique" : "" ) +
|
|
||||||
enhancedReturnType.substr( 12, enhancedReturnType.find( ',' ) - 12 ) ) +
|
|
||||||
">";
|
|
||||||
}
|
}
|
||||||
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 )
|
void VulkanHppGenerator::appendHandle( std::string & str, std::pair<std::string, HandleData> const & handleData )
|
||||||
|
@ -116,7 +116,7 @@ private:
|
|||||||
struct EnumValueData
|
struct EnumValueData
|
||||||
{
|
{
|
||||||
EnumValueData( int line, std::string const & vulkan, std::string const & vk, bool singleBit_ )
|
EnumValueData( int line, std::string const & vulkan, std::string const & vk, bool singleBit_ )
|
||||||
: vulkanValue( vulkan ), vkValue( vk ), singleBit( singleBit_ ), xmlLine(line)
|
: vulkanValue( vulkan ), vkValue( vk ), singleBit( singleBit_ ), xmlLine( line )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
std::string vulkanValue;
|
std::string vulkanValue;
|
||||||
@ -312,7 +312,7 @@ private:
|
|||||||
bool singular,
|
bool singular,
|
||||||
bool unique,
|
bool unique,
|
||||||
bool isStructureChain,
|
bool isStructureChain,
|
||||||
bool withAllocator ) const;
|
bool withAllocatorArgument ) const;
|
||||||
void appendFunctionBodyEnhanced( std::string & str,
|
void appendFunctionBodyEnhanced( std::string & str,
|
||||||
std::string const & indentation,
|
std::string const & indentation,
|
||||||
std::string const & name,
|
std::string const & name,
|
||||||
@ -466,11 +466,10 @@ private:
|
|||||||
bool singular,
|
bool singular,
|
||||||
bool unique,
|
bool unique,
|
||||||
bool withDefault,
|
bool withDefault,
|
||||||
bool isStructureChain ) const;
|
bool isStructureChain,
|
||||||
void appendHandle( std::string & str,
|
bool withAllocatorArgument ) const;
|
||||||
std::pair<std::string, HandleData> const & handle );
|
void appendHandle( std::string & str, std::pair<std::string, HandleData> const & handle );
|
||||||
void appendStruct( std::string & str,
|
void appendStruct( std::string & str, std::pair<std::string, StructureData> const & structure );
|
||||||
std::pair<std::string, StructureData> const & structure );
|
|
||||||
void appendStructAssignmentOperators( std::string & str,
|
void appendStructAssignmentOperators( std::string & str,
|
||||||
std::pair<std::string, StructureData> const & structure,
|
std::pair<std::string, StructureData> const & structure,
|
||||||
std::string const & prefix ) const;
|
std::string const & prefix ) const;
|
||||||
|
@ -30,6 +30,9 @@ int main( int /*argc*/, char ** /*argv*/ )
|
|||||||
vk::UniqueInstance instance = vk::createInstanceUnique( vk::InstanceCreateInfo( {}, &appInfo ) );
|
vk::UniqueInstance instance = vk::createInstanceUnique( vk::InstanceCreateInfo( {}, &appInfo ) );
|
||||||
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
|
vk::PhysicalDevice physicalDevice = instance->enumeratePhysicalDevices().front();
|
||||||
|
|
||||||
|
uint32_t propertyCount;
|
||||||
|
physicalDevice.getQueueFamilyProperties( &propertyCount, nullptr );
|
||||||
|
|
||||||
// get the QueueFamilyProperties of the first PhysicalDevice
|
// get the QueueFamilyProperties of the first PhysicalDevice
|
||||||
std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties();
|
std::vector<vk::QueueFamilyProperties> queueFamilyProperties = physicalDevice.getQueueFamilyProperties();
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user