Refactor simple functions returning some value.

This commit is contained in:
asuessenbach 2020-10-13 14:39:12 +02:00
parent 045a9f0417
commit 28cc3e6ae7
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, void VulkanHppGenerator::appendArgumentVulkanType( std::string & str, ParamData const & paramData ) const
ParamData const & paramData ) const
{ {
// this parameter is a vulkan type // this parameter is a vulkan type
if ( !paramData.type.postfix.empty() || !paramData.arraySizes.empty() ) if ( !paramData.type.postfix.empty() || !paramData.arraySizes.empty() )
@ -1200,7 +1199,7 @@ void VulkanHppGenerator::appendCommand( std::string & str,
appendCommandTrivialVoid( str, name, commandData, definition ); appendCommandTrivialVoid( str, name, commandData, definition );
appendedFunction = true; appendedFunction = true;
} }
else if (commandData.returnType == "VkResult") else if ( commandData.returnType == "VkResult" )
{ {
// function returning a result // function returning a result
appendCommandTrivial( str, name, commandData, definition ); appendCommandTrivial( str, name, commandData, definition );
@ -1215,20 +1214,31 @@ void VulkanHppGenerator::appendCommand( std::string & str,
appendCommandSimpleVoid( str, name, commandData, definition, vectorParamIndices ); appendCommandSimpleVoid( str, name, commandData, definition, vectorParamIndices );
appendedFunction = true; appendedFunction = true;
} }
else if ( ( commandData.returnType == "VkResult" ) && ( vectorParamIndices.size() < 2 ) ) else if ( commandData.returnType == "VkResult" )
{ {
switch ( vectorParamIndices.size() )
{
case 0: // fallthtrough
case 1:
// returns VkResult, but there's just one success code // returns VkResult, but there's just one success code
appendCommandSimple( str, name, commandData, definition, vectorParamIndices ); appendCommandSimple( str, name, commandData, definition, vectorParamIndices );
appendedFunction = true; appendedFunction = true;
} break;
else if ( ( vectorParamIndices.size() == 2 ) && ( vectorParamIndices.begin()->second != INVALID_INDEX ) && case 2:
( vectorParamIndices.begin()->second == std::next( vectorParamIndices.begin() )->second ) ) assert( vectorParamIndices.begin()->second != INVALID_INDEX );
{ assert( vectorParamIndices.begin()->second == std::next( vectorParamIndices.begin() )->second );
assert( commandData.params[vectorParamIndices.begin()->second].type.isValue() ); 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 // size is given by value and the vectors are const pointers, that is input parameters
appendCommandTwoVectors( str, name, commandData, vectorParamIndices, definition ); appendCommandTwoVectors( str, name, commandData, vectorParamIndices, definition );
appendedFunction = true; appendedFunction = true;
break;
default: assert( false ); break;
}
}
else
{
appendCommandSimpleReturn( str, name, commandData, definition, vectorParamIndices );
appendedFunction = true;
} }
} }
} }
@ -1779,6 +1789,32 @@ ${leave})";
std::string enter, leave; std::string enter, leave;
std::tie( enter, leave ) = generateProtection( commandData.feature, commandData.extensions ); 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( str += replaceWithMap(
functionTemplate, functionTemplate,
std::map<std::string, std::string>( std::map<std::string, std::string>(
@ -1834,7 +1870,7 @@ ${leave}
str += replaceWithMap( functionTemplate, str += replaceWithMap( functionTemplate,
std::map<std::string, std::string>( std::map<std::string, std::string>(
{ { "commandEnhanced", constructCommandSimple( name, commandData, definition, {} ) }, { { "commandEnhanced", constructCommandSimpleResult( name, commandData, definition, {} ) },
{ "commandStandard", constructCommandStandard( name, commandData, definition ) }, { "commandStandard", constructCommandStandard( name, commandData, definition ) },
{ "enter", enter }, { "enter", enter },
{ "leave", leave } } ) ); { "leave", leave } } ) );
@ -4923,6 +4959,67 @@ std::string VulkanHppGenerator::constructCommandSimple( std::string const &
CommandData const & commandData, CommandData const & commandData,
bool definition, bool definition,
std::map<size_t, size_t> const & vectorParamIndices ) const 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; std::string str;
@ -5072,10 +5169,14 @@ std::string VulkanHppGenerator::constructCommandStandard( std::string const & na
} }
std::string functionBody = std::string functionBody =
"d." + name + "( " + constructCallArgumentsStandard( commandData.handle, commandData.params ) + " )"; "d." + name + "( " + constructCallArgumentsStandard( commandData.handle, commandData.params ) + " )";
if ( returnType != "void" ) if ( beginsWith(commandData.returnType, "Vk"))
{ {
functionBody = "return static_cast<" + returnType + ">( " + functionBody + " )"; functionBody = "return static_cast<" + returnType + ">( " + functionBody + " )";
} }
else if ( commandData.returnType != "void" )
{
functionBody = "return " + functionBody;
}
std::string const functionTemplate = std::string const functionTemplate =
R"( template <typename Dispatch> R"( template <typename Dispatch>

View File

@ -74,7 +74,7 @@ private:
struct TypeInfo struct TypeInfo
{ {
std::string compose( bool inNamespace = true) const; std::string compose( bool inNamespace = true ) const;
bool operator==( TypeInfo const & rhs ) const bool operator==( TypeInfo const & rhs ) const
{ {
@ -356,6 +356,11 @@ private:
CommandData const & commandData, CommandData const & commandData,
bool definition, bool definition,
std::map<size_t, size_t> const & vectorParamIndices ) const; 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, void appendCommandSimpleVoid( std::string & str,
std::string const & name, std::string const & name,
CommandData const & commandData, CommandData const & commandData,
@ -602,6 +607,10 @@ private:
CommandData const & commandData, CommandData const & commandData,
bool definition, bool definition,
std::map<size_t, size_t> const & vectorParamIndices ) const; 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, std::string constructCommandSimpleVoid( std::string const & name,
CommandData const & commandData, CommandData const & commandData,
bool definition, bool definition,

View File

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