Fix handling of multiple vs. single success codes on handle creation with vulkan_raii.hpp. (#1550)

This commit is contained in:
Andreas Süßenbach 2023-04-03 12:10:39 +02:00 committed by GitHub
parent 91a92c6c5f
commit 35ab2bb711
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7861,7 +7861,10 @@ std::string VulkanHppGenerator::generateRAIIHandleConstructorTakeOwnership( std:
} }
#endif #endif
constructorArguments += ", VULKAN_HPP_NAMESPACE::Result successCode = VULKAN_HPP_NAMESPACE::Result::eSuccess"; constructorArguments += ", VULKAN_HPP_NAMESPACE::Result successCode = VULKAN_HPP_NAMESPACE::Result::eSuccess";
initializationList += ", m_constructorSuccessCode( successCode )"; if ( isMultiSuccessCodeConstructor( handle.second.constructorIts ) )
{
initializationList += ", m_constructorSuccessCode( successCode )";
}
} }
std::string dispatcherInitializer; std::string dispatcherInitializer;
@ -7988,18 +7991,25 @@ std::string
std::string callArguments = generateRAIIHandleConstructorCallArguments( handle, constructorIt, false, singularParams, true ); std::string callArguments = generateRAIIHandleConstructorCallArguments( handle, constructorIt, false, singularParams, true );
std::string initializationList = generateRAIIHandleConstructorInitializationList( handle, constructorIt, handle.second.destructorIt, false ); std::string initializationList = generateRAIIHandleConstructorInitializationList( handle, constructorIt, handle.second.destructorIt, false );
assert( !initializationList.empty() ); assert( !initializationList.empty() );
std::string failureCheck = generateFailureCheck( constructorIt->second.successCodes ); std::string resultVariable = "VULKAN_HPP_NAMESPACE::Result result";
failureCheck = std::regex_replace( failureCheck, std::regex( "result" ), "m_constructorSuccessCode" ); std::string failureCheck = generateFailureCheck( constructorIt->second.successCodes );
std::string result = "result";
if ( isMultiSuccessCodeConstructor( handle.second.constructorIts ) )
{
resultVariable = "m_constructorSuccessCode";
failureCheck = std::regex_replace( failureCheck, std::regex( "result" ), "m_constructorSuccessCode" );
result = "m_constructorSuccessCode";
}
const std::string singularConstructorTemplate = const std::string singularConstructorTemplate =
R"( R"(
${enter} ${handleType}( ${constructorArguments} ) ${enter} ${handleType}( ${constructorArguments} )
: ${initializationList}, m_dispatcher( ${firstArgument}.getDispatcher() ) : ${initializationList}, m_dispatcher( ${firstArgument}.getDispatcher() )
{ {
m_constructorSuccessCode = static_cast<VULKAN_HPP_NAMESPACE::Result>( getDispatcher()->${constructorCall}( ${callArguments} ) ); ${resultVariable} = static_cast<VULKAN_HPP_NAMESPACE::Result>( getDispatcher()->${constructorCall}( ${callArguments} ) );
if ( ${failureCheck} ) if ( ${failureCheck} )
{ {
throwResultException( m_constructorSuccessCode, "${constructorCall}" ); throwResultException( ${result}, "${constructorCall}" );
} }
} }
${leave})"; ${leave})";
@ -8013,7 +8023,9 @@ ${leave})";
{ "firstArgument", constructorIt->second.params[0].name }, { "firstArgument", constructorIt->second.params[0].name },
{ "failureCheck", failureCheck }, { "failureCheck", failureCheck },
{ "leave", leave }, { "leave", leave },
{ "handleType", stripPrefix( handle.first, "Vk" ) } } ); { "handleType", stripPrefix( handle.first, "Vk" ) },
{ "result", result },
{ "resultVariable", resultVariable } } );
} }
std::pair<std::string, std::string> VulkanHppGenerator::generateRAIIHandleConstructorVoid( std::pair<std::string, HandleData> const & handle, std::pair<std::string, std::string> VulkanHppGenerator::generateRAIIHandleConstructorVoid( std::pair<std::string, HandleData> const & handle,