mirror of
https://github.com/KhronosGroup/Vulkan-Hpp.git
synced 2024-10-14 16:32:17 +00:00
Merge pull request #683 from asuessenbach/allocator
Extend template argument list for functions returning a std::vector<Stuff> to help compilers detecting the correct function.
This commit is contained in:
commit
830bc53d62
@ -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 )
|
||||||
|
@ -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