From 9c99d1b2ce49b0bed36781da763436cce39d3df1 Mon Sep 17 00:00:00 2001 From: asuessenbach Date: Thu, 14 Apr 2022 08:03:15 +0200 Subject: [PATCH] Combine two types of commands into one generation function --- VulkanHppGenerator.cpp | 58 ++++++----------------------------- VulkanHppGenerator.hpp | 2 -- vulkan/vulkan_funcs.hpp | 63 ++++++++++++++++++++++----------------- vulkan/vulkan_handles.hpp | 10 +++---- 4 files changed, 49 insertions(+), 84 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index a2ae8f3..8d756b6 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -3445,51 +3445,6 @@ std::string VulkanHppGenerator::generateCommandResultEnumerateTwoVectors( std::s } } -std::string VulkanHppGenerator::generateCommandResultGetChain( - std::string const & name, CommandData const & commandData, size_t initialSkipCount, bool definition, size_t returnParam ) const -{ - assert( !commandData.handle.empty() && ( commandData.returnType == "VkResult" ) && !commandData.errorCodes.empty() ); - - std::set skippedParams = determineSkippedParams( commandData.params, initialSkipCount, {}, { returnParam }, false ); - std::string argumentList = generateArgumentListEnhanced( commandData.params, skippedParams, {}, {}, definition, false, false, true ); - std::string commandName = generateCommandName( name, commandData.params, initialSkipCount, m_tags, false, false ); - std::string nodiscard = generateNoDiscard( true, 1 < commandData.successCodes.size(), 1 < commandData.errorCodes.size() ); - std::string returnType = stripPostfix( commandData.params[returnParam].type.compose( "VULKAN_HPP_NAMESPACE" ), " *" ); - - if ( definition ) - { - std::string const functionTemplate = - R"( template - VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE typename ResultValueType>::type ${className}${classSeparator}${commandName}( ${argumentList} ) const - { - VULKAN_HPP_ASSERT( d.getVkHeaderVersion() == VK_HEADER_VERSION ); - StructureChain structureChain; - ${returnType} & ${returnVariable} = structureChain.template get<${returnType}>(); - Result result = static_cast( d.${vkCommand}( ${callArguments} ) ); - return createResultValue( result, structureChain, VULKAN_HPP_NAMESPACE_STRING"::${className}${classSeparator}${commandName}"${successCodeList} ); - })"; - - return replaceWithMap( functionTemplate, - { { "argumentList", argumentList }, - { "callArguments", generateCallArgumentsEnhanced( commandData, initialSkipCount, false, {}, {}, false ) }, - { "className", initialSkipCount ? stripPrefix( commandData.params[initialSkipCount - 1].type.type, "Vk" ) : "" }, - { "classSeparator", commandData.handle.empty() ? "" : "::" }, - { "commandName", commandName }, - { "returnVariable", startLowerCase( stripPrefix( commandData.params[returnParam].name, "p" ) ) }, - { "returnType", returnType }, - { "successCodeList", generateSuccessCodeList( commandData.successCodes ) }, - { "vkCommand", name } } ); - } - else - { - std::string const functionTemplate = - R"( template - VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS typename ResultValueType>::type ${commandName}( ${argumentList} ) const;)"; - - return replaceWithMap( functionTemplate, { { "argumentList", argumentList }, { "commandName", commandName } } ); - } -} - std::string VulkanHppGenerator::generateCommandResultGetVectorAndValue( std::string const & name, CommandData const & commandData, size_t initialSkipCount, @@ -4007,7 +3962,7 @@ std::string VulkanHppGenerator::generateCommandResultSingleSuccessWithErrors1Ret definition, generateCommandStandard( name, commandData, initialSkipCount, definition ), generateCommandSingle( name, commandData, initialSkipCount, definition, vectorParams, { returnParam }, false, false, false, false ), - generateCommandResultGetChain( name, commandData, initialSkipCount, definition, returnParam ) ); + generateCommandSingle( name, commandData, initialSkipCount, definition, vectorParams, { returnParam }, false, false, true, false ) ); } return ""; } @@ -5030,7 +4985,7 @@ std::string VulkanHppGenerator::generateDataDeclarations( CommandData const & case 1: if ( chained ) { - assert( commandData.returnType == "void" ); + assert( ( commandData.returnType == "void" ) || ( commandData.returnType == "VkResult" ) ); assert( vectorParams.empty() ); std::string const dataDeclarationsTemplate = R"(${returnType} ${returnVariable}; ${dataType} & ${dataVariable} = ${returnVariable}.template get<${dataType}>();)"; @@ -5038,7 +4993,7 @@ std::string VulkanHppGenerator::generateDataDeclarations( CommandData const & dataDeclarations = replaceWithMap( dataDeclarationsTemplate, { { "dataType", dataTypes[0] }, { "dataVariable", startLowerCase( stripPrefix( commandData.params[returnParams[0]].name, "p" ) ) }, - { "returnType", returnType }, + { "returnType", ( commandData.returnType == "void" ) ? returnType : "StructureChain" }, { "returnVariable", returnVariable } } ); } else @@ -10129,9 +10084,14 @@ std::string VulkanHppGenerator::generateReturnType( CommandData const & std::string returnType; if ( chained ) { - assert( ( commandData.returnType == "void" ) && ( returnParams.size() == 1 ) ); + assert( ( commandData.returnType == "void" ) || ( commandData.returnType == "VkResult" ) ); + assert( returnParams.size() == 1 ); assert( isStructureChainAnchor( commandData.params[returnParams[0]].type.type ) ); returnType = "StructureChain"; + if ( commandData.returnType == "VkResult" ) + { + returnType = "typename ResultValueType<" + returnType + ">::type"; + } } else if ( commandData.returnType == "VkResult" ) { diff --git a/VulkanHppGenerator.hpp b/VulkanHppGenerator.hpp index a6779d5..a2d8b3d 100644 --- a/VulkanHppGenerator.hpp +++ b/VulkanHppGenerator.hpp @@ -484,8 +484,6 @@ private: std::map const & vectorParamIndices, std::vector const & returnParamIndices, bool withAllocators ) const; - std::string generateCommandResultGetChain( - std::string const & name, CommandData const & commandData, size_t initialSkipCount, bool definition, size_t returnParam ) const; std::string generateCommandResultGetVectorAndValue( std::string const & name, CommandData const & commandData, size_t initialSkipCount, diff --git a/vulkan/vulkan_funcs.hpp b/vulkan/vulkan_funcs.hpp index 2326fbb..677b02c 100644 --- a/vulkan/vulkan_funcs.hpp +++ b/vulkan/vulkan_funcs.hpp @@ -5528,17 +5528,18 @@ namespace VULKAN_HPP_NAMESPACE } template - VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE typename ResultValueType>::type + VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE typename ResultValueType>::type PhysicalDevice::getImageFormatProperties2( const VULKAN_HPP_NAMESPACE::PhysicalDeviceImageFormatInfo2 & imageFormatInfo, Dispatch const & d ) const { VULKAN_HPP_ASSERT( d.getVkHeaderVersion() == VK_HEADER_VERSION ); + StructureChain structureChain; VULKAN_HPP_NAMESPACE::ImageFormatProperties2 & imageFormatProperties = structureChain.template get(); - Result result = - static_cast( d.vkGetPhysicalDeviceImageFormatProperties2( m_physicalDevice, - reinterpret_cast( &imageFormatInfo ), - reinterpret_cast( &imageFormatProperties ) ) ); - return createResultValue( result, structureChain, VULKAN_HPP_NAMESPACE_STRING "::PhysicalDevice::getImageFormatProperties2" ); + VkResult result = d.vkGetPhysicalDeviceImageFormatProperties2( m_physicalDevice, + reinterpret_cast( &imageFormatInfo ), + reinterpret_cast( &imageFormatProperties ) ); + resultCheck( static_cast( result ), VULKAN_HPP_NAMESPACE_STRING "::PhysicalDevice::getImageFormatProperties2" ); + return createResultValueType( static_cast( result ), structureChain ); } #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ @@ -9117,15 +9118,17 @@ namespace VULKAN_HPP_NAMESPACE } template - VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE typename ResultValueType>::type - PhysicalDevice::getVideoCapabilitiesKHR( const VULKAN_HPP_NAMESPACE::VideoProfileKHR & videoProfile, Dispatch const & d ) const + VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE typename ResultValueType>::type + PhysicalDevice::getVideoCapabilitiesKHR( const VULKAN_HPP_NAMESPACE::VideoProfileKHR & videoProfile, Dispatch const & d ) const { VULKAN_HPP_ASSERT( d.getVkHeaderVersion() == VK_HEADER_VERSION ); + StructureChain structureChain; VULKAN_HPP_NAMESPACE::VideoCapabilitiesKHR & capabilities = structureChain.template get(); - Result result = static_cast( d.vkGetPhysicalDeviceVideoCapabilitiesKHR( - m_physicalDevice, reinterpret_cast( &videoProfile ), reinterpret_cast( &capabilities ) ) ); - return createResultValue( result, structureChain, VULKAN_HPP_NAMESPACE_STRING "::PhysicalDevice::getVideoCapabilitiesKHR" ); + VkResult result = d.vkGetPhysicalDeviceVideoCapabilitiesKHR( + m_physicalDevice, reinterpret_cast( &videoProfile ), reinterpret_cast( &capabilities ) ); + resultCheck( static_cast( result ), VULKAN_HPP_NAMESPACE_STRING "::PhysicalDevice::getVideoCapabilitiesKHR" ); + return createResultValueType( static_cast( result ), structureChain ); } # endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ @@ -10545,17 +10548,18 @@ namespace VULKAN_HPP_NAMESPACE } template - VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE typename ResultValueType>::type + VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE typename ResultValueType>::type PhysicalDevice::getImageFormatProperties2KHR( const VULKAN_HPP_NAMESPACE::PhysicalDeviceImageFormatInfo2 & imageFormatInfo, Dispatch const & d ) const { VULKAN_HPP_ASSERT( d.getVkHeaderVersion() == VK_HEADER_VERSION ); + StructureChain structureChain; VULKAN_HPP_NAMESPACE::ImageFormatProperties2 & imageFormatProperties = structureChain.template get(); - Result result = - static_cast( d.vkGetPhysicalDeviceImageFormatProperties2KHR( m_physicalDevice, - reinterpret_cast( &imageFormatInfo ), - reinterpret_cast( &imageFormatProperties ) ) ); - return createResultValue( result, structureChain, VULKAN_HPP_NAMESPACE_STRING "::PhysicalDevice::getImageFormatProperties2KHR" ); + VkResult result = d.vkGetPhysicalDeviceImageFormatProperties2KHR( m_physicalDevice, + reinterpret_cast( &imageFormatInfo ), + reinterpret_cast( &imageFormatProperties ) ); + resultCheck( static_cast( result ), VULKAN_HPP_NAMESPACE_STRING "::PhysicalDevice::getImageFormatProperties2KHR" ); + return createResultValueType( static_cast( result ), structureChain ); } #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ @@ -12360,17 +12364,18 @@ namespace VULKAN_HPP_NAMESPACE } template - VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE typename ResultValueType>::type + VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE typename ResultValueType>::type PhysicalDevice::getSurfaceCapabilities2KHR( const VULKAN_HPP_NAMESPACE::PhysicalDeviceSurfaceInfo2KHR & surfaceInfo, Dispatch const & d ) const { VULKAN_HPP_ASSERT( d.getVkHeaderVersion() == VK_HEADER_VERSION ); + StructureChain structureChain; VULKAN_HPP_NAMESPACE::SurfaceCapabilities2KHR & surfaceCapabilities = structureChain.template get(); - Result result = - static_cast( d.vkGetPhysicalDeviceSurfaceCapabilities2KHR( m_physicalDevice, - reinterpret_cast( &surfaceInfo ), - reinterpret_cast( &surfaceCapabilities ) ) ); - return createResultValue( result, structureChain, VULKAN_HPP_NAMESPACE_STRING "::PhysicalDevice::getSurfaceCapabilities2KHR" ); + VkResult result = d.vkGetPhysicalDeviceSurfaceCapabilities2KHR( m_physicalDevice, + reinterpret_cast( &surfaceInfo ), + reinterpret_cast( &surfaceCapabilities ) ); + resultCheck( static_cast( result ), VULKAN_HPP_NAMESPACE_STRING "::PhysicalDevice::getSurfaceCapabilities2KHR" ); + return createResultValueType( static_cast( result ), structureChain ); } #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ @@ -13126,16 +13131,18 @@ namespace VULKAN_HPP_NAMESPACE } template - VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE typename ResultValueType>::type - Device::getAndroidHardwareBufferPropertiesANDROID( const struct AHardwareBuffer & buffer, Dispatch const & d ) const + VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE typename ResultValueType>::type + Device::getAndroidHardwareBufferPropertiesANDROID( const struct AHardwareBuffer & buffer, Dispatch const & d ) const { VULKAN_HPP_ASSERT( d.getVkHeaderVersion() == VK_HEADER_VERSION ); + StructureChain structureChain; VULKAN_HPP_NAMESPACE::AndroidHardwareBufferPropertiesANDROID & properties = structureChain.template get(); - Result result = static_cast( - d.vkGetAndroidHardwareBufferPropertiesANDROID( m_device, &buffer, reinterpret_cast( &properties ) ) ); - return createResultValue( result, structureChain, VULKAN_HPP_NAMESPACE_STRING "::Device::getAndroidHardwareBufferPropertiesANDROID" ); + VkResult result = + d.vkGetAndroidHardwareBufferPropertiesANDROID( m_device, &buffer, reinterpret_cast( &properties ) ); + resultCheck( static_cast( result ), VULKAN_HPP_NAMESPACE_STRING "::Device::getAndroidHardwareBufferPropertiesANDROID" ); + return createResultValueType( static_cast( result ), structureChain ); } # endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ diff --git a/vulkan/vulkan_handles.hpp b/vulkan/vulkan_handles.hpp index f64a1e2..6a856c5 100644 --- a/vulkan/vulkan_handles.hpp +++ b/vulkan/vulkan_handles.hpp @@ -9806,7 +9806,7 @@ namespace VULKAN_HPP_NAMESPACE VULKAN_HPP_NODISCARD typename ResultValueType::type getAndroidHardwareBufferPropertiesANDROID( const struct AHardwareBuffer & buffer, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; template - VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS typename ResultValueType>::type + VULKAN_HPP_NODISCARD typename ResultValueType>::type getAndroidHardwareBufferPropertiesANDROID( const struct AHardwareBuffer & buffer, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; # endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ @@ -11620,7 +11620,7 @@ namespace VULKAN_HPP_NAMESPACE getImageFormatProperties2( const VULKAN_HPP_NAMESPACE::PhysicalDeviceImageFormatInfo2 & imageFormatInfo, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; template - VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS typename ResultValueType>::type + VULKAN_HPP_NODISCARD typename ResultValueType>::type getImageFormatProperties2( const VULKAN_HPP_NAMESPACE::PhysicalDeviceImageFormatInfo2 & imageFormatInfo, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ @@ -11996,7 +11996,7 @@ namespace VULKAN_HPP_NAMESPACE VULKAN_HPP_NODISCARD typename ResultValueType::type getVideoCapabilitiesKHR( const VULKAN_HPP_NAMESPACE::VideoProfileKHR & videoProfile, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; template - VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS typename ResultValueType>::type + VULKAN_HPP_NODISCARD typename ResultValueType>::type getVideoCapabilitiesKHR( const VULKAN_HPP_NAMESPACE::VideoProfileKHR & videoProfile, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; # endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ @@ -12091,7 +12091,7 @@ namespace VULKAN_HPP_NAMESPACE getImageFormatProperties2KHR( const VULKAN_HPP_NAMESPACE::PhysicalDeviceImageFormatInfo2 & imageFormatInfo, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; template - VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS typename ResultValueType>::type + VULKAN_HPP_NODISCARD typename ResultValueType>::type getImageFormatProperties2KHR( const VULKAN_HPP_NAMESPACE::PhysicalDeviceImageFormatInfo2 & imageFormatInfo, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ @@ -12304,7 +12304,7 @@ namespace VULKAN_HPP_NAMESPACE getSurfaceCapabilities2KHR( const VULKAN_HPP_NAMESPACE::PhysicalDeviceSurfaceInfo2KHR & surfaceInfo, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; template - VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS typename ResultValueType>::type + VULKAN_HPP_NODISCARD typename ResultValueType>::type getSurfaceCapabilities2KHR( const VULKAN_HPP_NAMESPACE::PhysicalDeviceSurfaceInfo2KHR & surfaceInfo, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/