mirror of
https://github.com/KhronosGroup/Vulkan-Hpp.git
synced 2024-10-14 16:32:17 +00:00
Merge pull request #1431 from asuessenbach/structs
Support structs holding arrays of data, where the data size is given by a pointer-type.
This commit is contained in:
commit
294df9235e
@ -118,10 +118,8 @@ ${indexTypeTraits}
|
|||||||
#endif
|
#endif
|
||||||
)";
|
)";
|
||||||
|
|
||||||
std::string str = replaceWithMap( vulkanEnumsHppTemplate,
|
std::string str = replaceWithMap(
|
||||||
{ { "enums", generateEnums() },
|
vulkanEnumsHppTemplate, { { "enums", generateEnums() }, { "indexTypeTraits", generateIndexTypeTraits() }, { "licenseHeader", m_vulkanLicenseHeader } } );
|
||||||
{ "indexTypeTraits", generateIndexTypeTraits() },
|
|
||||||
{ "licenseHeader", m_vulkanLicenseHeader } } );
|
|
||||||
|
|
||||||
writeToFile( str, vulkan_enums_hpp );
|
writeToFile( str, vulkan_enums_hpp );
|
||||||
}
|
}
|
||||||
@ -161,7 +159,7 @@ void VulkanHppGenerator::generateVulkanFuncsHppFile() const
|
|||||||
namespace VULKAN_HPP_NAMESPACE
|
namespace VULKAN_HPP_NAMESPACE
|
||||||
{
|
{
|
||||||
${commandDefinitions}
|
${commandDefinitions}
|
||||||
} // namespace VULKAN_HPP_NAMESPACE
|
} // namespace VULKAN_HPP_NAMESPACE
|
||||||
#endif
|
#endif
|
||||||
)";
|
)";
|
||||||
|
|
||||||
@ -184,7 +182,7 @@ namespace VULKAN_HPP_NAMESPACE
|
|||||||
{
|
{
|
||||||
${structForwardDeclarations}
|
${structForwardDeclarations}
|
||||||
${handles}
|
${handles}
|
||||||
} // namespace VULKAN_HPP_NAMESPACE
|
} // namespace VULKAN_HPP_NAMESPACE
|
||||||
#endif
|
#endif
|
||||||
)";
|
)";
|
||||||
|
|
||||||
@ -368,7 +366,7 @@ void VulkanHppGenerator::generateVulkanRAIIHppFile() const
|
|||||||
|
|
||||||
std::string const vulkanHandlesHppTemplate = R"(${licenseHeader}
|
std::string const vulkanHandlesHppTemplate = R"(${licenseHeader}
|
||||||
#ifndef VULKAN_RAII_HPP
|
#ifndef VULKAN_RAII_HPP
|
||||||
# define VULKAN_RAII_HPP
|
#define VULKAN_RAII_HPP
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <utility> // std::exchange, std::forward
|
#include <utility> // std::exchange, std::forward
|
||||||
@ -378,12 +376,11 @@ void VulkanHppGenerator::generateVulkanRAIIHppFile() const
|
|||||||
# define VULKAN_HPP_RAII_NAMESPACE raii
|
# define VULKAN_HPP_RAII_NAMESPACE raii
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined( VULKAN_HPP_DISABLE_ENHANCED_MODE ) && !defined(VULKAN_HPP_NO_EXCEPTIONS)
|
||||||
namespace VULKAN_HPP_NAMESPACE
|
namespace VULKAN_HPP_NAMESPACE
|
||||||
{
|
{
|
||||||
namespace VULKAN_HPP_RAII_NAMESPACE
|
namespace VULKAN_HPP_RAII_NAMESPACE
|
||||||
{
|
{
|
||||||
#if !defined( VULKAN_HPP_DISABLE_ENHANCED_MODE ) && !defined(VULKAN_HPP_NO_EXCEPTIONS)
|
|
||||||
|
|
||||||
template <class T, class U = T>
|
template <class T, class U = T>
|
||||||
VULKAN_HPP_CONSTEXPR_14 VULKAN_HPP_INLINE T exchange( T & obj, U && newValue )
|
VULKAN_HPP_CONSTEXPR_14 VULKAN_HPP_INLINE T exchange( T & obj, U && newValue )
|
||||||
{
|
{
|
||||||
@ -399,10 +396,10 @@ namespace VULKAN_HPP_NAMESPACE
|
|||||||
${RAIIDispatchers}
|
${RAIIDispatchers}
|
||||||
${RAIIHandles}
|
${RAIIHandles}
|
||||||
${RAIICommandDefinitions}
|
${RAIICommandDefinitions}
|
||||||
#endif
|
|
||||||
} // namespace VULKAN_HPP_RAII_NAMESPACE
|
} // namespace VULKAN_HPP_RAII_NAMESPACE
|
||||||
} // namespace VULKAN_HPP_NAMESPACE
|
} // namespace VULKAN_HPP_NAMESPACE
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
)";
|
)";
|
||||||
|
|
||||||
std::string str = replaceWithMap( vulkanHandlesHppTemplate,
|
std::string str = replaceWithMap( vulkanHandlesHppTemplate,
|
||||||
@ -9149,16 +9146,15 @@ std::string VulkanHppGenerator::generateStructConstructors( std::pair<std::strin
|
|||||||
|
|
||||||
std::string VulkanHppGenerator::generateStructConstructorsEnhanced( std::pair<std::string, StructureData> const & structData ) const
|
std::string VulkanHppGenerator::generateStructConstructorsEnhanced( std::pair<std::string, StructureData> const & structData ) const
|
||||||
{
|
{
|
||||||
auto hasLen = []( MemberData const & md )
|
if ( std::find_if( structData.second.members.begin(),
|
||||||
{ return !md.len.empty() && !( md.len[0] == "null-terminated" ) && ( ( altLens.find( md.len[0] ) == altLens.end() ) || ( md.len[0] == "codeSize / 4" ) ); };
|
structData.second.members.end(),
|
||||||
|
[this, &structData]( MemberData const & md ) { return hasLen( structData.second.members, md ); } ) != structData.second.members.end() )
|
||||||
if ( std::find_if( structData.second.members.begin(), structData.second.members.end(), hasLen ) != structData.second.members.end() )
|
|
||||||
{
|
{
|
||||||
// map from len-members to all the array members using that len
|
// map from len-members to all the array members using that len
|
||||||
std::map<std::vector<MemberData>::const_iterator, std::vector<std::vector<MemberData>::const_iterator>> lenIts;
|
std::map<std::vector<MemberData>::const_iterator, std::vector<std::vector<MemberData>::const_iterator>> lenIts;
|
||||||
for ( auto mit = structData.second.members.begin(); mit != structData.second.members.end(); ++mit )
|
for ( auto mit = structData.second.members.begin(); mit != structData.second.members.end(); ++mit )
|
||||||
{
|
{
|
||||||
if ( hasLen( *mit ) )
|
if ( hasLen( structData.second.members, *mit ) )
|
||||||
{
|
{
|
||||||
std::string lenName = ( mit->len.front() == "codeSize / 4" ) ? "codeSize" : mit->len.front();
|
std::string lenName = ( mit->len.front() == "codeSize / 4" ) ? "codeSize" : mit->len.front();
|
||||||
auto lenIt = findStructMemberIt( lenName, structData.second.members );
|
auto lenIt = findStructMemberIt( lenName, structData.second.members );
|
||||||
@ -9190,7 +9186,7 @@ std::string VulkanHppGenerator::generateStructConstructorsEnhanced( std::pair<st
|
|||||||
( firstArgument ? ": " : ", " ) + mit->name + "( " + generateLenInitializer( mit, litit, structData.second.mutualExclusiveLens ) + " )";
|
( firstArgument ? ": " : ", " ) + mit->name + "( " + generateLenInitializer( mit, litit, structData.second.mutualExclusiveLens ) + " )";
|
||||||
sizeChecks += generateSizeCheck( litit->second, stripPrefix( structData.first, "Vk" ), structData.second.mutualExclusiveLens );
|
sizeChecks += generateSizeCheck( litit->second, stripPrefix( structData.first, "Vk" ), structData.second.mutualExclusiveLens );
|
||||||
}
|
}
|
||||||
else if ( hasLen( *mit ) )
|
else if ( hasLen( structData.second.members, *mit ) )
|
||||||
{
|
{
|
||||||
assert( mit->name.starts_with( "p" ) );
|
assert( mit->name.starts_with( "p" ) );
|
||||||
std::string argumentName = startLowerCase( stripPrefix( mit->name, "p" ) ) + "_";
|
std::string argumentName = startLowerCase( stripPrefix( mit->name, "p" ) ) + "_";
|
||||||
@ -9814,8 +9810,7 @@ std::string VulkanHppGenerator::generateStructSetter( std::string const & struct
|
|||||||
{ "reference", ( member.type.postfix.empty() && ( m_structures.find( member.type.type ) != m_structures.end() ) ) ? "const & " : "" },
|
{ "reference", ( member.type.postfix.empty() && ( m_structures.find( member.type.type ) != m_structures.end() ) ) ? "const & " : "" },
|
||||||
{ "structureName", structureName } } );
|
{ "structureName", structureName } } );
|
||||||
|
|
||||||
if ( !member.len.empty() && ( member.len[0] != "null-terminated" ) &&
|
if ( hasLen( memberData, member ) )
|
||||||
( ( altLens.find( member.len[0] ) == altLens.end() ) || ( member.len[0] == "codeSize / 4" ) ) )
|
|
||||||
{
|
{
|
||||||
assert( member.name.front() == 'p' );
|
assert( member.name.front() == 'p' );
|
||||||
std::string arrayName = startLowerCase( stripPrefix( member.name, "p" ) );
|
std::string arrayName = startLowerCase( stripPrefix( member.name, "p" ) );
|
||||||
@ -10444,6 +10439,16 @@ std::string VulkanHppGenerator::getVectorSize( std::vector<ParamData> const &
|
|||||||
return vectorSize;
|
return vectorSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool VulkanHppGenerator::hasLen( std::vector<MemberData> const & members, MemberData const & md ) const
|
||||||
|
{
|
||||||
|
if ( !md.len.empty() && !( md.len[0] == "null-terminated" ) && ( ( altLens.find( md.len[0] ) == altLens.end() ) || ( md.len[0] == "codeSize / 4" ) ) )
|
||||||
|
{
|
||||||
|
auto lenIt = findStructMemberIt( md.len.front(), members );
|
||||||
|
return ( lenIt == members.end() ) || lenIt->type.isValue();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool VulkanHppGenerator::hasParentHandle( std::string const & handle, std::string const & parent ) const
|
bool VulkanHppGenerator::hasParentHandle( std::string const & handle, std::string const & parent ) const
|
||||||
{
|
{
|
||||||
std::string candidate = handle;
|
std::string candidate = handle;
|
||||||
@ -12815,7 +12820,7 @@ void VulkanHppGenerator::readTypesTypeStructMember( tinyxml2::XMLElement const *
|
|||||||
"member attribute <len> holds unknown value <" + memberData.len[0] + ">" );
|
"member attribute <len> holds unknown value <" + memberData.len[0] + ">" );
|
||||||
if ( lenMember != members.end() )
|
if ( lenMember != members.end() )
|
||||||
{
|
{
|
||||||
checkForError( lenMember->type.prefix.empty() && lenMember->type.postfix.empty(),
|
checkForError( lenMember->type.prefix.empty(),
|
||||||
line,
|
line,
|
||||||
"member attribute <len> references a member of unexpected type <" + lenMember->type.compose( "VULKAN_HPP_NAMESPACE" ) + ">" );
|
"member attribute <len> references a member of unexpected type <" + lenMember->type.compose( "VULKAN_HPP_NAMESPACE" ) + ">" );
|
||||||
}
|
}
|
||||||
|
@ -935,6 +935,7 @@ private:
|
|||||||
size_t returnParam,
|
size_t returnParam,
|
||||||
std::string const & returnParamType,
|
std::string const & returnParamType,
|
||||||
std::set<size_t> const & templatedParams ) const;
|
std::set<size_t> const & templatedParams ) const;
|
||||||
|
bool hasLen( std::vector<MemberData> const & members, MemberData const & md ) const;
|
||||||
bool hasParentHandle( std::string const & handle, std::string const & parent ) const;
|
bool hasParentHandle( std::string const & handle, std::string const & parent ) const;
|
||||||
bool isDeviceCommand( CommandData const & commandData ) const;
|
bool isDeviceCommand( CommandData const & commandData ) const;
|
||||||
bool isHandleType( std::string const & type ) const;
|
bool isHandleType( std::string const & type ) const;
|
||||||
|
@ -16,12 +16,11 @@
|
|||||||
# define VULKAN_HPP_RAII_NAMESPACE raii
|
# define VULKAN_HPP_RAII_NAMESPACE raii
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined( VULKAN_HPP_DISABLE_ENHANCED_MODE ) && !defined( VULKAN_HPP_NO_EXCEPTIONS )
|
||||||
namespace VULKAN_HPP_NAMESPACE
|
namespace VULKAN_HPP_NAMESPACE
|
||||||
{
|
{
|
||||||
namespace VULKAN_HPP_RAII_NAMESPACE
|
namespace VULKAN_HPP_RAII_NAMESPACE
|
||||||
{
|
{
|
||||||
#if !defined( VULKAN_HPP_DISABLE_ENHANCED_MODE ) && !defined( VULKAN_HPP_NO_EXCEPTIONS )
|
|
||||||
|
|
||||||
template <class T, class U = T>
|
template <class T, class U = T>
|
||||||
VULKAN_HPP_CONSTEXPR_14 VULKAN_HPP_INLINE T exchange( T & obj, U && newValue )
|
VULKAN_HPP_CONSTEXPR_14 VULKAN_HPP_INLINE T exchange( T & obj, U && newValue )
|
||||||
{
|
{
|
||||||
@ -18607,7 +18606,7 @@ namespace VULKAN_HPP_NAMESPACE
|
|||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
} // namespace VULKAN_HPP_RAII_NAMESPACE
|
} // namespace VULKAN_HPP_RAII_NAMESPACE
|
||||||
} // namespace VULKAN_HPP_NAMESPACE
|
} // namespace VULKAN_HPP_NAMESPACE
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user