Add support for enumerating commands with more than two success codes. (#1870)

This commit is contained in:
Andreas Süßenbach 2024-05-08 18:46:23 +02:00 committed by GitHub
parent d3f062dd68
commit c8dd4fb5ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 41 additions and 33 deletions

View File

@ -3181,6 +3181,7 @@ std::string VulkanHppGenerator::generateCallSequence( std::string const &
{ "vkCommand", name } } ); { "vkCommand", name } } );
} }
case 2: case 2:
case 3:
{ {
assert( ( commandData.successCodes[0] == "VK_SUCCESS" ) && ( commandData.successCodes[1] == "VK_INCOMPLETE" ) ); assert( ( commandData.successCodes[0] == "VK_SUCCESS" ) && ( commandData.successCodes[1] == "VK_INCOMPLETE" ) );
std::string const callSequenceTemplate = R"(VULKAN_HPP_NAMESPACE::Result result; std::string const callSequenceTemplate = R"(VULKAN_HPP_NAMESPACE::Result result;
@ -3420,7 +3421,7 @@ std::string VulkanHppGenerator::generateCommandEnhanced( std::string const &
std::string typenameCheck = generateTypenameCheck( returnParams, vectorParams, chainedReturnParams, definition, dataTypes, flavourFlags ); std::string typenameCheck = generateTypenameCheck( returnParams, vectorParams, chainedReturnParams, definition, dataTypes, flavourFlags );
std::string nodiscard = generateNoDiscard( !returnParams.empty(), 1 < commandData.successCodes.size(), 1 < commandData.errorCodes.size() ); std::string nodiscard = generateNoDiscard( !returnParams.empty(), 1 < commandData.successCodes.size(), 1 < commandData.errorCodes.size() );
std::string returnType = generateReturnType( returnParams, vectorParams, flavourFlags, false, dataTypes ); std::string returnType = generateReturnType( returnParams, vectorParams, flavourFlags, false, dataTypes );
std::string decoratedReturnType = generateDecoratedReturnType( name, commandData, returnParams, vectorParams, flavourFlags, false, returnType ); std::string decoratedReturnType = generateDecoratedReturnType( commandData, returnParams, vectorParams, flavourFlags, false, returnType );
std::string className = initialSkipCount ? stripPrefix( commandData.params[initialSkipCount - 1].type.type, "Vk" ) : ""; std::string className = initialSkipCount ? stripPrefix( commandData.params[initialSkipCount - 1].type.type, "Vk" ) : "";
std::string classSeparator = commandData.handle.empty() ? "" : "::"; std::string classSeparator = commandData.handle.empty() ? "" : "::";
std::string commandName = generateCommandName( name, commandData.params, initialSkipCount, flavourFlags ); std::string commandName = generateCommandName( name, commandData.params, initialSkipCount, flavourFlags );
@ -3767,7 +3768,7 @@ std::string VulkanHppGenerator::generateCommandResultMultiSuccessWithErrors2Retu
std::vector<size_t> const & returnParams, std::vector<size_t> const & returnParams,
bool raii ) const bool raii ) const
{ {
if ( ( commandData.successCodes.size() == 2 ) && ( commandData.successCodes[0] == "VK_SUCCESS" ) && ( commandData.successCodes[1] == "VK_INCOMPLETE" ) ) if ( ( 2 <= commandData.successCodes.size() ) && ( commandData.successCodes[0] == "VK_SUCCESS" ) && ( commandData.successCodes[1] == "VK_INCOMPLETE" ) )
{ {
if ( ( commandData.params[returnParams[0]].type.type == "size_t" ) || ( commandData.params[returnParams[0]].type.type == "uint32_t" ) ) if ( ( commandData.params[returnParams[0]].type.type == "size_t" ) || ( commandData.params[returnParams[0]].type.type == "uint32_t" ) )
{ {
@ -6219,8 +6220,7 @@ std::string VulkanHppGenerator::generateDebugReportObjectType( std::string const
return contains( enumIt->second.values, debugReportObjectType ) ? generateEnumValueName( enumIt->first, debugReportObjectType, false ) : "eUnknown"; return contains( enumIt->second.values, debugReportObjectType ) ? generateEnumValueName( enumIt->first, debugReportObjectType, false ) : "eUnknown";
} }
std::string VulkanHppGenerator::generateDecoratedReturnType( std::string const & name, std::string VulkanHppGenerator::generateDecoratedReturnType( CommandData const & commandData,
CommandData const & commandData,
std::vector<size_t> const & returnParams, std::vector<size_t> const & returnParams,
std::map<size_t, VectorParamData> const & vectorParams, std::map<size_t, VectorParamData> const & vectorParams,
CommandFlavourFlags flavourFlags, CommandFlavourFlags flavourFlags,
@ -6262,19 +6262,20 @@ std::string VulkanHppGenerator::generateDecoratedReturnType( std::string const &
{ {
assert( commandData.returnType == "VkResult" ); assert( commandData.returnType == "VkResult" );
assert( !commandData.successCodes.empty() && ( commandData.successCodes[0] == "VK_SUCCESS" ) ); assert( !commandData.successCodes.empty() && ( commandData.successCodes[0] == "VK_SUCCESS" ) );
// special handling for vkGetDeviceFaultInfoEXT, as it is an atypical enumeration function if ( ( commandData.successCodes.size() == 1 ) || ( ( commandData.successCodes.size() == 2 ) && ( commandData.successCodes[1] == "VK_INCOMPLETE" ) ) )
if ( ( 1 < commandData.successCodes.size() ) && ( ( returnParams.size() == 1 ) || ( ( returnParams.size() == 2 ) && vectorParams.empty() ) ) && {
( name != "vkGetDeviceFaultInfoEXT" ) ) decoratedReturnType = raii ? returnType : ( "typename ResultValueType<" + returnType + ">::type" );
}
else if ( !commandData.errorCodes.empty() && ( 1 < commandData.successCodes.size() ) &&
( ( returnParams.size() == 1 ) ||
( ( returnParams.size() == 2 ) && ( vectorParams.empty() || ( ( vectorParams.size() == 1 ) && ( commandData.successCodes.size() == 3 ) &&
( commandData.successCodes[1] == "VK_INCOMPLETE" ) ) ) ) ) )
{ {
assert( !commandData.errorCodes.empty() );
decoratedReturnType = ( raii ? "std::pair<VULKAN_HPP_NAMESPACE::Result, " : "ResultValue<" ) + returnType + ">"; decoratedReturnType = ( raii ? "std::pair<VULKAN_HPP_NAMESPACE::Result, " : "ResultValue<" ) + returnType + ">";
} }
else else
{ {
assert( assert( false );
( ( commandData.successCodes.size() == 1 ) || ( ( commandData.successCodes.size() == 2 ) && ( commandData.successCodes[1] == "VK_INCOMPLETE" ) ) ) &&
( returnParams.size() <= 3 ) );
decoratedReturnType = raii ? returnType : ( "typename ResultValueType<" + returnType + ">::type" );
} }
} }
return decoratedReturnType; return decoratedReturnType;
@ -8245,6 +8246,7 @@ std::string VulkanHppGenerator::generateRAIIFactoryReturnStatements( std::vector
auto handleIt = m_handles.find( vkType ); auto handleIt = m_handles.find( vkType );
assert( handleIt != m_handles.end() ); assert( handleIt != m_handles.end() );
std::string successCodePassToElement = ( enumerating ? ( successCodes.size() <= 2 ) : ( successCodes.size() <= 1 ) ) ? "" : ", result";
if ( returnType.starts_with( "std::vector" ) ) if ( returnType.starts_with( "std::vector" ) )
{ {
std::string const & returnTemplate = R"(${returnType} ${returnVariable}RAII; std::string const & returnTemplate = R"(${returnType} ${returnVariable}RAII;
@ -8259,7 +8261,6 @@ std::string VulkanHppGenerator::generateRAIIFactoryReturnStatements( std::vector
std::string handleConstructorArguments = generateRAIIHandleSingularConstructorArguments( *handleIt, params, true ); std::string handleConstructorArguments = generateRAIIHandleSingularConstructorArguments( *handleIt, params, true );
assert( !successCodes.empty() ); assert( !successCodes.empty() );
std::string successCodePassToElement = ( enumerating || ( successCodes.size() == 1 ) ) ? "" : ", result";
return replaceWithMap( returnTemplate, return replaceWithMap( returnTemplate,
{ { "element", element }, { { "element", element },
@ -8270,11 +8271,14 @@ std::string VulkanHppGenerator::generateRAIIFactoryReturnStatements( std::vector
} }
else else
{ {
std::string const & returnTemplate = "return ${returnType}( *this, ${handleConstructorArguments} );"; std::string const & returnTemplate = "return ${returnType}( *this, ${handleConstructorArguments}${successCodePassToElement} );";
std::string handleConstructorArguments = generateRAIIHandleSingularConstructorArguments( *handleIt, params, singular ); std::string handleConstructorArguments = generateRAIIHandleSingularConstructorArguments( *handleIt, params, singular );
return replaceWithMap( returnTemplate, { { "returnType", returnType }, { "handleConstructorArguments", handleConstructorArguments } } ); return replaceWithMap( returnTemplate,
{ { "returnType", returnType },
{ "handleConstructorArguments", handleConstructorArguments },
{ "successCodePassToElement", successCodePassToElement } } );
} }
} }
@ -8615,7 +8619,7 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandEnhanced( std::string c
needsVectorSizeCheck( commandData.params, vectorParams, returnParams, singularParams, skippedParams ); needsVectorSizeCheck( commandData.params, vectorParams, returnParams, singularParams, skippedParams );
std::string noexceptString = generateNoExcept( commandData.errorCodes, returnParams, vectorParams, flavourFlags, vectorSizeCheck.first, true ); std::string noexceptString = generateNoExcept( commandData.errorCodes, returnParams, vectorParams, flavourFlags, vectorSizeCheck.first, true );
std::string returnType = generateReturnType( returnParams, vectorParams, flavourFlags, true, dataTypes ); std::string returnType = generateReturnType( returnParams, vectorParams, flavourFlags, true, dataTypes );
std::string decoratedReturnType = generateDecoratedReturnType( name, commandData, returnParams, vectorParams, flavourFlags, true, returnType ); std::string decoratedReturnType = generateDecoratedReturnType( commandData, returnParams, vectorParams, flavourFlags, true, returnType );
if ( definition ) if ( definition )
{ {
@ -8961,7 +8965,7 @@ std::string VulkanHppGenerator::generateRAIIHandleConstructorArguments( std::pai
{ {
// this is supposed to be the returned size on an enumeration function! // this is supposed to be the returned size on an enumeration function!
#if !defined( NDEBUG ) #if !defined( NDEBUG )
assert( param.type.type == "uint32_t" ); assert( ( param.type.type == "size_t" ) || ( param.type.type == "uint32_t" ) );
auto typeIt = std::find_if( constructorIt->second.params.begin(), auto typeIt = std::find_if( constructorIt->second.params.begin(),
constructorIt->second.params.end(), constructorIt->second.params.end(),
[&handle]( ParamData const & pd ) { return pd.type.type == handle.first; } ); [&handle]( ParamData const & pd ) { return pd.type.type == handle.first; } );
@ -9157,6 +9161,7 @@ std::pair<std::string, std::string> VulkanHppGenerator::generateRAIIHandleConstr
} }
break; break;
case 2: case 2:
case 3:
if ( !constructorIt->second.errorCodes.empty() ) if ( !constructorIt->second.errorCodes.empty() )
{ {
std::vector<size_t> returnParams = determineReturnParams( constructorIt->second.params ); std::vector<size_t> returnParams = determineReturnParams( constructorIt->second.params );
@ -9173,7 +9178,8 @@ std::pair<std::string, std::string> VulkanHppGenerator::generateRAIIHandleConstr
} }
break; break;
case 2: case 2:
if ( constructorIt->second.params[returnParams[0]].type.type == "uint32_t" ) if ( ( constructorIt->second.params[returnParams[0]].type.type == "size_t" ) ||
( constructorIt->second.params[returnParams[0]].type.type == "uint32_t" ) )
{ {
assert( isHandleType( constructorIt->second.params[returnParams[1]].type.type ) ); assert( isHandleType( constructorIt->second.params[returnParams[1]].type.type ) );
std::map<size_t, VectorParamData> vectorParams = determineVectorParams( constructorIt->second.params ); std::map<size_t, VectorParamData> vectorParams = determineVectorParams( constructorIt->second.params );
@ -9301,7 +9307,8 @@ std::string VulkanHppGenerator::generateRAIIHandleConstructorTakeOwnership( std:
std::string constructorArguments = generateRAIIHandleConstructorArguments( handle, handle.second.destructorIt, false, true ); std::string constructorArguments = generateRAIIHandleConstructorArguments( handle, handle.second.destructorIt, false, true );
std::string initializationList = generateRAIIHandleConstructorInitializationList( handle, handle.second.destructorIt, handle.second.destructorIt, true ); std::string initializationList = generateRAIIHandleConstructorInitializationList( handle, handle.second.destructorIt, handle.second.destructorIt, true );
assert( !handle.second.constructorIts.empty() ); assert( !handle.second.constructorIts.empty() );
if ( 1 < handle.second.constructorIts[0]->second.successCodes.size() && ( handle.second.constructorIts[0]->second.successCodes[1] != "VK_INCOMPLETE" ) ) if ( ( 1 < handle.second.constructorIts[0]->second.successCodes.size() && ( handle.second.constructorIts[0]->second.successCodes[1] != "VK_INCOMPLETE" ) ) ||
( 2 < handle.second.constructorIts[0]->second.successCodes.size() ) )
{ {
#if !defined( NDEBUG ) #if !defined( NDEBUG )
for ( size_t i = 1; i < handle.second.constructorIts.size(); ++i ) for ( size_t i = 1; i < handle.second.constructorIts.size(); ++i )
@ -9894,7 +9901,8 @@ std::string VulkanHppGenerator::generateReturnStatement( std::string const & com
std::string returnStatement; std::string returnStatement;
if ( commandData.returnType.starts_with( "Vk" ) ) if ( commandData.returnType.starts_with( "Vk" ) )
{ {
if ( ( commandData.successCodes.size() == 1 ) || enumerating || ( commandName == "vkGetDeviceFaultInfoEXT" ) ) if ( ( commandData.successCodes.size() == 1 ) || ( enumerating && ( commandData.successCodes.size() == 2 ) ) ||
( commandName == "vkGetDeviceFaultInfoEXT" ) )
{ {
assert( commandData.successCodes[0] == "VK_SUCCESS" ); assert( commandData.successCodes[0] == "VK_SUCCESS" );
if ( raii || commandData.errorCodes.empty() ) if ( raii || commandData.errorCodes.empty() )
@ -11557,7 +11565,8 @@ std::string VulkanHppGenerator::generateSuccessCode( std::string const & code )
std::string VulkanHppGenerator::generateSuccessCodeList( std::vector<std::string> const & successCodes, bool enumerating ) const std::string VulkanHppGenerator::generateSuccessCodeList( std::vector<std::string> const & successCodes, bool enumerating ) const
{ {
std::string successCodeList; std::string successCodeList;
if ( ( 1 < successCodes.size() ) && !enumerating ) size_t skipSize = enumerating ? 2 : 1;
if ( skipSize < successCodes.size() )
{ {
successCodeList = ", { " + generateSuccessCode( successCodes[0] ); successCodeList = ", { " + generateSuccessCode( successCodes[0] );
for ( size_t i = 1; i < successCodes.size(); ++i ) for ( size_t i = 1; i < successCodes.size(); ++i )
@ -12607,9 +12616,9 @@ bool VulkanHppGenerator::isTypeUsed( std::string const & type ) const
void VulkanHppGenerator::markExtendedStructs() void VulkanHppGenerator::markExtendedStructs()
{ {
for (auto const& s : m_structs) for ( auto const & s : m_structs )
{ {
for (auto const& extends : s.second.structExtends) for ( auto const & extends : s.second.structExtends )
{ {
auto structIt = m_structs.find( extends ); auto structIt = m_structs.find( extends );
checkForError( structIt != m_structs.end(), s.second.xmlLine, "struct <" + s.first + "> extends unknown struct <" + extends + ">" ); checkForError( structIt != m_structs.end(), s.second.xmlLine, "struct <" + s.first + "> extends unknown struct <" + extends + ">" );

View File

@ -703,8 +703,7 @@ private:
std::set<size_t> const & templatedParams, std::set<size_t> const & templatedParams,
bool singular ) const; bool singular ) const;
std::string generateDebugReportObjectType( std::string const & objectType ) const; std::string generateDebugReportObjectType( std::string const & objectType ) const;
std::string generateDecoratedReturnType( std::string const & name, std::string generateDecoratedReturnType( CommandData const & commandData,
CommandData const & commandData,
std::vector<size_t> const & returnParams, std::vector<size_t> const & returnParams,
std::map<size_t, VectorParamData> const & vectorParams, std::map<size_t, VectorParamData> const & vectorParams,
CommandFlavourFlags flavourFlags, CommandFlavourFlags flavourFlags,

View File

@ -12904,7 +12904,7 @@ namespace VULKAN_HPP_NAMESPACE
# endif # endif
} }
return VULKAN_HPP_NAMESPACE::VULKAN_HPP_RAII_NAMESPACE::Pipeline( *this, *reinterpret_cast<VkPipeline *>( &pipeline ), allocator ); return VULKAN_HPP_NAMESPACE::VULKAN_HPP_RAII_NAMESPACE::Pipeline( *this, *reinterpret_cast<VkPipeline *>( &pipeline ), allocator, result );
} }
VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE
@ -12964,7 +12964,7 @@ namespace VULKAN_HPP_NAMESPACE
# endif # endif
} }
return VULKAN_HPP_NAMESPACE::VULKAN_HPP_RAII_NAMESPACE::Pipeline( *this, *reinterpret_cast<VkPipeline *>( &pipeline ), allocator ); return VULKAN_HPP_NAMESPACE::VULKAN_HPP_RAII_NAMESPACE::Pipeline( *this, *reinterpret_cast<VkPipeline *>( &pipeline ), allocator, result );
} }
VULKAN_HPP_NODISCARD VULKAN_HPP_NODISCARD
@ -17844,7 +17844,7 @@ namespace VULKAN_HPP_NAMESPACE
# endif # endif
} }
return VULKAN_HPP_NAMESPACE::VULKAN_HPP_RAII_NAMESPACE::Pipeline( *this, *reinterpret_cast<VkPipeline *>( &pipeline ), allocator ); return VULKAN_HPP_NAMESPACE::VULKAN_HPP_RAII_NAMESPACE::Pipeline( *this, *reinterpret_cast<VkPipeline *>( &pipeline ), allocator, result );
} }
VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE VULKAN_HPP_NAMESPACE::ExecutionGraphPipelineScratchSizeAMDX Pipeline::getExecutionGraphScratchSizeAMDX() const VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE VULKAN_HPP_NAMESPACE::ExecutionGraphPipelineScratchSizeAMDX Pipeline::getExecutionGraphScratchSizeAMDX() const
@ -18436,7 +18436,7 @@ namespace VULKAN_HPP_NAMESPACE
# endif # endif
} }
return VULKAN_HPP_NAMESPACE::VULKAN_HPP_RAII_NAMESPACE::Pipeline( *this, *reinterpret_cast<VkPipeline *>( &pipeline ), allocator ); return VULKAN_HPP_NAMESPACE::VULKAN_HPP_RAII_NAMESPACE::Pipeline( *this, *reinterpret_cast<VkPipeline *>( &pipeline ), allocator, result );
} }
template <typename DataType> template <typename DataType>
@ -18927,7 +18927,7 @@ namespace VULKAN_HPP_NAMESPACE
# endif # endif
} }
return VULKAN_HPP_NAMESPACE::VULKAN_HPP_RAII_NAMESPACE::Pipeline( *this, *reinterpret_cast<VkPipeline *>( &pipeline ), allocator ); return VULKAN_HPP_NAMESPACE::VULKAN_HPP_RAII_NAMESPACE::Pipeline( *this, *reinterpret_cast<VkPipeline *>( &pipeline ), allocator, result );
} }
template <typename DataType> template <typename DataType>
@ -22574,7 +22574,7 @@ namespace VULKAN_HPP_NAMESPACE
# endif # endif
} }
return VULKAN_HPP_NAMESPACE::VULKAN_HPP_RAII_NAMESPACE::ShaderEXT( *this, *reinterpret_cast<VkShaderEXT *>( &shader ), allocator ); return VULKAN_HPP_NAMESPACE::VULKAN_HPP_RAII_NAMESPACE::ShaderEXT( *this, *reinterpret_cast<VkShaderEXT *>( &shader ), allocator, result );
} }
VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE std::vector<uint8_t> ShaderEXT::getBinaryData() const VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE std::vector<uint8_t> ShaderEXT::getBinaryData() const

View File

@ -7209,7 +7209,7 @@ namespace VULKAN_HPP_NAMESPACE
# endif # endif
} }
return VULKAN_HPP_NAMESPACE::VULKAN_HPP_RAII_NAMESPACE::Pipeline( *this, *reinterpret_cast<VkPipeline *>( &pipeline ), allocator ); return VULKAN_HPP_NAMESPACE::VULKAN_HPP_RAII_NAMESPACE::Pipeline( *this, *reinterpret_cast<VkPipeline *>( &pipeline ), allocator, result );
} }
VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE
@ -7266,7 +7266,7 @@ namespace VULKAN_HPP_NAMESPACE
# endif # endif
} }
return VULKAN_HPP_NAMESPACE::VULKAN_HPP_RAII_NAMESPACE::Pipeline( *this, *reinterpret_cast<VkPipeline *>( &pipeline ), allocator ); return VULKAN_HPP_NAMESPACE::VULKAN_HPP_RAII_NAMESPACE::Pipeline( *this, *reinterpret_cast<VkPipeline *>( &pipeline ), allocator, result );
} }
VULKAN_HPP_NODISCARD VULKAN_HPP_NODISCARD