Merge pull request #773 from asuessenbach/refactor

Refactor simple functions returning some value.
This commit is contained in:
Andreas Süßenbach 2020-10-13 19:31:32 +02:00 committed by GitHub
commit 9af818b180
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 149 additions and 27 deletions

View File

@ -932,8 +932,7 @@ void VulkanHppGenerator::appendArgumentVector( std::string & str,
}
}
void VulkanHppGenerator::appendArgumentVulkanType( std::string & str,
ParamData const & paramData ) const
void VulkanHppGenerator::appendArgumentVulkanType( std::string & str, ParamData const & paramData ) const
{
// this parameter is a vulkan type
if ( !paramData.type.postfix.empty() || !paramData.arraySizes.empty() )
@ -1200,7 +1199,7 @@ void VulkanHppGenerator::appendCommand( std::string & str,
appendCommandTrivialVoid( str, name, commandData, definition );
appendedFunction = true;
}
else if (commandData.returnType == "VkResult")
else if ( commandData.returnType == "VkResult" )
{
// function returning a result
appendCommandTrivial( str, name, commandData, definition );
@ -1215,19 +1214,30 @@ void VulkanHppGenerator::appendCommand( std::string & str,
appendCommandSimpleVoid( str, name, commandData, definition, vectorParamIndices );
appendedFunction = true;
}
else if ( ( commandData.returnType == "VkResult" ) && ( vectorParamIndices.size() < 2 ) )
else if ( commandData.returnType == "VkResult" )
{
// returns VkResult, but there's just one success code
appendCommandSimple( str, name, commandData, definition, vectorParamIndices );
appendedFunction = true;
switch ( vectorParamIndices.size() )
{
case 0: // fallthtrough
case 1:
// returns VkResult, but there's just one success code
appendCommandSimple( str, name, commandData, definition, vectorParamIndices );
appendedFunction = true;
break;
case 2:
assert( vectorParamIndices.begin()->second != INVALID_INDEX );
assert( vectorParamIndices.begin()->second == std::next( vectorParamIndices.begin() )->second );
assert( commandData.params[vectorParamIndices.begin()->second].type.isValue() );
// size is given by value and the vectors are const pointers, that is input parameters
appendCommandTwoVectors( str, name, commandData, vectorParamIndices, definition );
appendedFunction = true;
break;
default: assert( false ); break;
}
}
else if ( ( vectorParamIndices.size() == 2 ) && ( vectorParamIndices.begin()->second != INVALID_INDEX ) &&
( vectorParamIndices.begin()->second == std::next( vectorParamIndices.begin() )->second ) )
else
{
assert( commandData.params[vectorParamIndices.begin()->second].type.isValue() );
assert( commandData.returnType == "VkResult" );
// size is given by value and the vectors are const pointers, that is input parameters
appendCommandTwoVectors( str, name, commandData, vectorParamIndices, definition );
appendCommandSimpleReturn( str, name, commandData, definition, vectorParamIndices );
appendedFunction = true;
}
}
@ -1779,6 +1789,32 @@ ${leave})";
std::string enter, leave;
std::tie( enter, leave ) = generateProtection( commandData.feature, commandData.extensions );
str += replaceWithMap(
functionTemplate,
std::map<std::string, std::string>(
{ { "commandEnhanced", constructCommandSimpleResult( name, commandData, definition, vectorParamIndices ) },
{ "commandStandard", constructCommandStandard( name, commandData, definition ) },
{ "enter", enter },
{ "leave", leave },
{ "newlineOnDefinition", definition ? "\n" : "" } } ) );
}
void VulkanHppGenerator::appendCommandSimpleReturn( std::string & str,
std::string const & name,
CommandData const & commandData,
bool definition,
std::map<size_t, size_t> const & vectorParamIndices ) const
{
const std::string functionTemplate = R"(
${enter}${commandStandard}${newlineOnDefinition}
#ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE
${commandEnhanced}
#endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/
${leave})";
std::string enter, leave;
std::tie( enter, leave ) = generateProtection( commandData.feature, commandData.extensions );
str += replaceWithMap(
functionTemplate,
std::map<std::string, std::string>(
@ -1834,7 +1870,7 @@ ${leave}
str += replaceWithMap( functionTemplate,
std::map<std::string, std::string>(
{ { "commandEnhanced", constructCommandSimple( name, commandData, definition, {} ) },
{ { "commandEnhanced", constructCommandSimpleResult( name, commandData, definition, {} ) },
{ "commandStandard", constructCommandStandard( name, commandData, definition ) },
{ "enter", enter },
{ "leave", leave } } ) );
@ -4923,6 +4959,67 @@ std::string VulkanHppGenerator::constructCommandSimple( std::string const &
CommandData const & commandData,
bool definition,
std::map<size_t, size_t> const & vectorParamIndices ) const
{
assert( commandData.successCodes.empty() && commandData.errorCodes.empty() );
std::string str;
std::set<size_t> skippedParameters = { 0 };
for ( auto const & vpi : vectorParamIndices )
{
if ( vpi.second != INVALID_INDEX )
{
skippedParameters.insert( vpi.second );
}
}
std::string argumentList =
constructArgumentListEnhanced( commandData.params, skippedParameters, INVALID_INDEX, definition, false );
std::string commandName = determineCommandName( name, commandData.params[0].type.type );
std::string nodiscard = constructNoDiscardEnhanced( commandData );
std::string returnType = stripPrefix( commandData.returnType, "Vk" );
if ( definition )
{
std::string const functionTemplate =
R"( template <typename Dispatch>
${nodiscard}VULKAN_HPP_INLINE ${returnType} ${className}::${commandName}( ${argumentList} ) const VULKAN_HPP_NOEXCEPT
{
return d.${vkCommand}( ${callArguments} );
})";
str =
replaceWithMap( functionTemplate,
std::map<std::string, std::string>(
{ { "argumentList", argumentList },
{ "callArguments", constructCallArgumentsVectors( commandData.params, vectorParamIndices ) },
{ "className", stripPrefix( commandData.handle, "Vk" ) },
{ "commandName", commandName },
{ "nodiscard", nodiscard },
{ "returnType", returnType },
{ "vkCommand", name } } ) );
}
else
{
std::string const functionTemplate =
R"( template <typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE>
${nodiscard}${returnType} ${commandName}( ${argumentList} ) const VULKAN_HPP_NOEXCEPT;)";
str = replaceWithMap( functionTemplate,
std::map<std::string, std::string>( { { "argumentList", argumentList },
{ "commandName", commandName },
{ "nodiscard", nodiscard },
{ "returnType", returnType } } ) );
}
return str;
}
std::string
VulkanHppGenerator::constructCommandSimpleResult( std::string const & name,
CommandData const & commandData,
bool definition,
std::map<size_t, size_t> const & vectorParamIndices ) const
{
std::string str;
@ -5072,10 +5169,14 @@ std::string VulkanHppGenerator::constructCommandStandard( std::string const & na
}
std::string functionBody =
"d." + name + "( " + constructCallArgumentsStandard( commandData.handle, commandData.params ) + " )";
if ( returnType != "void" )
if ( beginsWith(commandData.returnType, "Vk"))
{
functionBody = "return static_cast<" + returnType + ">( " + functionBody + " )";
}
else if ( commandData.returnType != "void" )
{
functionBody = "return " + functionBody;
}
std::string const functionTemplate =
R"( template <typename Dispatch>
@ -6678,8 +6779,8 @@ void VulkanHppGenerator::checkCorrectness()
else
{
check( sTypeValues.erase( enumValue.vulkanValue ) == 1,
enumValue.xmlLine,
"VkStructureType enum value <" + enumValue.vulkanValue + "> never used" );
enumValue.xmlLine,
"VkStructureType enum value <" + enumValue.vulkanValue + "> never used" );
}
}
assert( sTypeValues.empty() );

View File

@ -74,7 +74,7 @@ private:
struct TypeInfo
{
std::string compose( bool inNamespace = true) const;
std::string compose( bool inNamespace = true ) const;
bool operator==( TypeInfo const & rhs ) const
{
@ -356,6 +356,11 @@ private:
CommandData const & commandData,
bool definition,
std::map<size_t, size_t> const & vectorParamIndices ) const;
void appendCommandSimpleReturn( std::string & str,
std::string const & name,
CommandData const & commandData,
bool definition,
std::map<size_t, size_t> const & vectorParamIndices ) const;
void appendCommandSimpleVoid( std::string & str,
std::string const & name,
CommandData const & commandData,
@ -468,13 +473,13 @@ private:
bool withDefaults,
bool withAllocator ) const;
bool appendFunctionHeaderArgumentStandard( std::string & str, ParamData const & param, bool argEncountered ) const;
void appendFunctionHeaderReturnType( std::string & str,
CommandData const & commandData,
size_t returnParamIndex,
std::string const & enhancedReturnType,
bool enhanced,
bool twoStep,
bool isStructureChain ) const;
void appendFunctionHeaderReturnType( std::string & str,
CommandData const & commandData,
size_t returnParamIndex,
std::string const & enhancedReturnType,
bool enhanced,
bool twoStep,
bool isStructureChain ) const;
void appendFunctionHeaderTemplate( std::string & str,
std::string const & indentation,
size_t returnParamIndex,
@ -602,6 +607,10 @@ private:
CommandData const & commandData,
bool definition,
std::map<size_t, size_t> const & vectorParamIndices ) const;
std::string constructCommandSimpleResult( std::string const & name,
CommandData const & commandData,
bool definition,
std::map<size_t, size_t> const & vectorParamIndices ) const;
std::string constructCommandSimpleVoid( std::string const & name,
CommandData const & commandData,
bool definition,
@ -644,8 +653,8 @@ private:
std::string constructNoDiscardEnhanced( CommandData const & commandData ) const;
std::string constructNoDiscardStandard( CommandData const & commandData ) const;
std::string constructReturnType( CommandData const & commandData, std::string const & baseType ) const;
std::string constructSuccessCheck( std::vector<std::string> const & successCodes ) const;
std::string constructSuccessCodeList( std::vector<std::string> const & successCodes ) const;
std::string constructSuccessCheck( std::vector<std::string> const & successCodes ) const;
std::string constructSuccessCodeList( std::vector<std::string> const & successCodes ) const;
std::string constructVectorSizeCheck( std::string const & name,
CommandData const & commandData,
std::map<size_t, std::vector<size_t>> const & countToVectorMap,

View File

@ -97255,6 +97255,7 @@ namespace VULKAN_HPP_NAMESPACE
return static_cast<DeviceAddress>( d.vkGetAccelerationStructureDeviceAddressKHR(
m_device, reinterpret_cast<const VkAccelerationStructureDeviceAddressInfoKHR *>( pInfo ) ) );
}
# ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE
template <typename Dispatch>
VULKAN_HPP_INLINE DeviceAddress Device::getAccelerationStructureAddressKHR(
@ -97451,6 +97452,7 @@ namespace VULKAN_HPP_NAMESPACE
return static_cast<DeviceAddress>(
d.vkGetBufferDeviceAddress( m_device, reinterpret_cast<const VkBufferDeviceAddressInfo *>( pInfo ) ) );
}
#ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE
template <typename Dispatch>
VULKAN_HPP_INLINE DeviceAddress Device::getBufferAddress( const BufferDeviceAddressInfo & info,
@ -97467,6 +97469,7 @@ namespace VULKAN_HPP_NAMESPACE
return static_cast<DeviceAddress>(
d.vkGetBufferDeviceAddressEXT( m_device, reinterpret_cast<const VkBufferDeviceAddressInfo *>( pInfo ) ) );
}
#ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE
template <typename Dispatch>
VULKAN_HPP_INLINE DeviceAddress Device::getBufferAddressEXT( const BufferDeviceAddressInfo & info,
@ -97483,6 +97486,7 @@ namespace VULKAN_HPP_NAMESPACE
return static_cast<DeviceAddress>(
d.vkGetBufferDeviceAddressKHR( m_device, reinterpret_cast<const VkBufferDeviceAddressInfo *>( pInfo ) ) );
}
#ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE
template <typename Dispatch>
VULKAN_HPP_INLINE DeviceAddress Device::getBufferAddressKHR( const BufferDeviceAddressInfo & info,
@ -97594,6 +97598,7 @@ namespace VULKAN_HPP_NAMESPACE
{
return d.vkGetBufferOpaqueCaptureAddress( m_device, reinterpret_cast<const VkBufferDeviceAddressInfo *>( pInfo ) );
}
#ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE
template <typename Dispatch>
VULKAN_HPP_INLINE uint64_t Device::getBufferOpaqueCaptureAddress( const BufferDeviceAddressInfo & info,
@ -97610,6 +97615,7 @@ namespace VULKAN_HPP_NAMESPACE
return d.vkGetBufferOpaqueCaptureAddressKHR( m_device,
reinterpret_cast<const VkBufferDeviceAddressInfo *>( pInfo ) );
}
#ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE
template <typename Dispatch>
VULKAN_HPP_INLINE uint64_t Device::getBufferOpaqueCaptureAddressKHR( const BufferDeviceAddressInfo & info,
@ -97975,6 +97981,7 @@ namespace VULKAN_HPP_NAMESPACE
return d.vkGetDeviceMemoryOpaqueCaptureAddress(
m_device, reinterpret_cast<const VkDeviceMemoryOpaqueCaptureAddressInfo *>( pInfo ) );
}
#ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE
template <typename Dispatch>
VULKAN_HPP_INLINE uint64_t Device::getMemoryOpaqueCaptureAddress( const DeviceMemoryOpaqueCaptureAddressInfo & info,
@ -97993,6 +98000,7 @@ namespace VULKAN_HPP_NAMESPACE
return d.vkGetDeviceMemoryOpaqueCaptureAddressKHR(
m_device, reinterpret_cast<const VkDeviceMemoryOpaqueCaptureAddressInfo *>( pInfo ) );
}
#ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE
template <typename Dispatch>
VULKAN_HPP_INLINE uint64_t Device::getMemoryOpaqueCaptureAddressKHR(
@ -98009,6 +98017,7 @@ namespace VULKAN_HPP_NAMESPACE
{
return d.vkGetDeviceProcAddr( m_device, pName );
}
#ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE
template <typename Dispatch>
VULKAN_HPP_INLINE PFN_vkVoidFunction Device::getProcAddr( const std::string & name,
@ -98558,6 +98567,7 @@ namespace VULKAN_HPP_NAMESPACE
{
return d.vkGetImageViewHandleNVX( m_device, reinterpret_cast<const VkImageViewHandleInfoNVX *>( pInfo ) );
}
#ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE
template <typename Dispatch>
VULKAN_HPP_INLINE uint32_t Device::getImageViewHandleNVX( const ImageViewHandleInfoNVX & info,
@ -102193,6 +102203,7 @@ namespace VULKAN_HPP_NAMESPACE
{
return d.vkGetInstanceProcAddr( m_instance, pName );
}
#ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE
template <typename Dispatch>
VULKAN_HPP_INLINE PFN_vkVoidFunction Instance::getProcAddr( const std::string & name,
@ -105367,6 +105378,7 @@ namespace VULKAN_HPP_NAMESPACE
return static_cast<Bool32>(
d.vkGetPhysicalDeviceXlibPresentationSupportKHR( m_physicalDevice, queueFamilyIndex, dpy, visualID ) );
}
# ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE
template <typename Dispatch>
VULKAN_HPP_INLINE Bool32 PhysicalDevice::getXlibPresentationSupportKHR( uint32_t queueFamilyIndex,