From f97633a2208957a22cf4a96a45a52e1d464ee2d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20S=C3=BC=C3=9Fenbach?= Date: Mon, 2 Oct 2023 14:57:52 +0200 Subject: [PATCH] Extend command generation to support not returning some return stuff and not templatizing a void pointer. (#1666) --- VulkanHppGenerator.cpp | 111 ++++++++++++++++++++++---------------- VulkanHppGenerator.hpp | 21 ++++++-- vulkan/vulkan_funcs.hpp | 11 ++++ vulkan/vulkan_handles.hpp | 5 ++ vulkan/vulkan_raii.hpp | 12 +++++ 5 files changed, 110 insertions(+), 50 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index cc880df..c253ac8 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -2350,10 +2350,18 @@ std::string VulkanHppGenerator::generateArgumentListEnhanced( std::vector const & singularParams, std::set const & templatedParams, - bool raiiHandleMemberFunction ) const + bool raiiHandleMemberFunction, + CommandFlavourFlags flavourFlags ) const { assert( initialSkipCount <= commandData.params.size() ); std::string arguments; @@ -2724,7 +2733,7 @@ std::string VulkanHppGenerator::generateCallArgumentsEnhanced( CommandData const { arguments += ", "; } - arguments += generateCallArgumentEnhanced( commandData.params, i, nonConstPointerAsNullptr, singularParams, templatedParams ); + arguments += generateCallArgumentEnhanced( commandData.params, i, nonConstPointerAsNullptr, singularParams, templatedParams, flavourFlags ); encounteredArgument = true; } return arguments; @@ -2809,7 +2818,8 @@ std::string VulkanHppGenerator::generateCallArgumentEnhanced( std::vector const & singularParams, - std::set const & templatedParams ) const + std::set const & templatedParams, + CommandFlavourFlags flavourFlags ) const { std::string argument; ParamData const & param = params[paramIndex]; @@ -2818,14 +2828,15 @@ std::string VulkanHppGenerator::generateCallArgumentEnhanced( std::vector const & params, size_t paramIndex, - std::set const & singularParams ) const + std::set const & singularParams, + CommandFlavourFlags flavourFlags ) const { std::string argument; ParamData const & param = params[paramIndex]; - assert( param.lenExpression.empty() ); + assert( ( flavourFlags & CommandFlavourFlagBits::keepVoidPtr ) || param.lenExpression.empty() ); // !keepVoidPtr -> no lenExpression if ( param.type.type.starts_with( "Vk" ) ) { if ( param.arraySizes.empty() ) @@ -2989,7 +3001,7 @@ std::string VulkanHppGenerator::generateCallArgumentEnhancedValue( std::vector

type.type == "void" ) && ( flavourFlags & CommandFlavourFlagBits::keepVoidPtr ) ) ) { // this parameter is the len of some other -> replace it with that parameter's size assert( param.arraySizes.empty() ); @@ -3059,8 +3071,8 @@ std::string VulkanHppGenerator::generateCallSequence( std::string const & assert( std::any_of( returnParams.begin(), returnParams.end(), [&vectorParamIt]( size_t rp ) { return rp == vectorParamIt->first; } ) ); assert( std::any_of( returnParams.begin(), returnParams.end(), [&vectorParamIt]( size_t rp ) { return rp == vectorParamIt->second.lenParam; } ) ); - std::string firstCallArguments = generateCallArgumentsEnhanced( commandData, initialSkipCount, true, {}, templatedParams, raii ); - std::string secondCallArguments = generateCallArgumentsEnhanced( commandData, initialSkipCount, false, {}, templatedParams, raii ); + std::string firstCallArguments = generateCallArgumentsEnhanced( commandData, initialSkipCount, true, {}, templatedParams, raii, flavourFlags ); + std::string secondCallArguments = generateCallArgumentsEnhanced( commandData, initialSkipCount, false, {}, templatedParams, raii, flavourFlags ); std::string vectorName = startLowerCase( stripPrefix( commandData.params[vectorParamIt->first].name, "p" ) ); std::string vectorSize = startLowerCase( stripPrefix( commandData.params[vectorParamIt->second.lenParam].name, "p" ) ); @@ -3196,7 +3208,7 @@ std::string VulkanHppGenerator::generateCallSequence( std::string const & { std::string const callSequenceTemplate = R"(${resultAssignment}${dispatcher}${vkCommand}( ${callArguments} );)"; - std::string callArguments = generateCallArgumentsEnhanced( commandData, initialSkipCount, false, singularParams, templatedParams, raii ); + std::string callArguments = generateCallArgumentsEnhanced( commandData, initialSkipCount, false, singularParams, templatedParams, raii, flavourFlags ); std::string resultAssignment = generateResultAssignment( commandData ); return replaceWithMap( @@ -3354,8 +3366,8 @@ std::string VulkanHppGenerator::generateCommandEnhanced( std::string const & assert( !singular || !returnParams.empty() ); // if singular is true, then there is at least one returnParam ! std::set skippedParams = determineSkippedParams( commandData.params, initialSkipCount, vectorParams, returnParams, singular ); - // special handling for vkGetMemoryHostPointerPropertiesEXT: here, we really need to stick with the const void * parameter ! - std::set templatedParams = ( name == "vkGetMemoryHostPointerPropertiesEXT" ) ? std::set() : determineVoidPointerParams( commandData.params ); + std::set templatedParams = + ( flavourFlags & CommandFlavourFlagBits::keepVoidPtr ) ? std::set() : determineVoidPointerParams( commandData.params ); std::vector chainedReturnParams; if ( chained ) { @@ -4149,17 +4161,16 @@ std::string VulkanHppGenerator::generateCommandResultSingleSuccessWithErrors1Ret switch ( vectorParams.size() ) { case 0: - return generateCommandSetInclusive( name, - commandData, - initialSkipCount, - definition, - { returnParam }, - vectorParams, - false, - { CommandFlavourFlagBits::enhanced }, - raii, - false, - { CommandFlavourFlagBits::enhanced } ); + { + CommandFlavourFlags flavourFlags = CommandFlavourFlagBits::enhanced; + if ( name == "vkGetMemoryHostPointerPropertiesEXT" ) + { + // special handling for this function: need to keep the void* argument as a void*! + flavourFlags |= CommandFlavourFlagBits::keepVoidPtr; + } + return generateCommandSetInclusive( + name, commandData, initialSkipCount, definition, { returnParam }, vectorParams, false, { flavourFlags }, raii, false, { flavourFlags } ); + } case 2: if ( returnParam == std::next( vectorParams.begin() )->first ) { @@ -4419,13 +4430,20 @@ std::string VulkanHppGenerator::generateCommandSetInclusive( std::string const & bool raiiFactory, std::vector const & raiiFlags ) const { + static const std::vector emptyReturnParams; + static const std::map emptyVectorParams; if ( raii ) { std::string raiiCommands; for ( auto flag : raiiFlags ) { - raiiCommands += raiiFactory ? generateRAIIHandleCommandFactory( name, commandData, initialSkipCount, returnParams, vectorParams, definition, flag ) - : generateRAIIHandleCommandEnhanced( name, commandData, initialSkipCount, returnParams, vectorParams, definition, flag ); + bool noReturn = flag & CommandFlavourFlagBits::noReturn; + assert( !noReturn || !raiiFactory ); // noReturn => !raiiFactory + raiiCommands += + raiiFactory + ? generateRAIIHandleCommandFactory( name, commandData, initialSkipCount, returnParams, vectorParams, definition, flag ) + : generateRAIIHandleCommandEnhanced( + name, commandData, initialSkipCount, noReturn ? emptyReturnParams : returnParams, noReturn ? emptyVectorParams : vectorParams, definition, flag ); } return raiiCommands; } @@ -4434,7 +4452,10 @@ std::string VulkanHppGenerator::generateCommandSetInclusive( std::string const & std::vector enhancedCommands, uniqueCommands; for ( auto flag : flags ) { - enhancedCommands.push_back( generateCommandEnhanced( name, commandData, initialSkipCount, definition, vectorParams, returnParams, flag ) ); + bool noReturn = flag & CommandFlavourFlagBits::noReturn; + assert( !noReturn || !unique ); // noReturn => !unique + enhancedCommands.push_back( generateCommandEnhanced( + name, commandData, initialSkipCount, definition, noReturn ? emptyVectorParams : vectorParams, noReturn ? emptyReturnParams : returnParams, flag ) ); if ( unique ) { uniqueCommands.push_back( @@ -4607,17 +4628,15 @@ std::string VulkanHppGenerator::generateCommandVoid1Return( { if ( name == stripPluralS( name ) ) { - return generateCommandSetInclusive( name, - commandData, - initialSkipCount, - definition, - { returnParam }, - vectorParams, - false, - { CommandFlavourFlagBits::singular }, - raii, - false, - { CommandFlavourFlagBits::singular } ); + std::vector flavourFlags; + if ( name == "vkGetDescriptorEXT" ) + { + // special handling for this function: do not return the void*, but keep its argument as it is + flavourFlags.push_back( CommandFlavourFlagBits::noReturn | CommandFlavourFlagBits::keepVoidPtr ); + } + flavourFlags.push_back( CommandFlavourFlagBits::singular ); + return generateCommandSetInclusive( + name, commandData, initialSkipCount, definition, { returnParam }, vectorParams, false, flavourFlags, raii, false, flavourFlags ); } } break; @@ -8340,8 +8359,8 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandEnhanced( std::string c std::set skippedParams = determineSkippedParams( commandData.params, initialSkipCount, vectorParams, returnParams, singular ); std::set singularParams = singular ? determineSingularParams( returnParams[0], vectorParams ) : std::set(); - // special handling for vkGetMemoryHostPointerPropertiesEXT: here, we really need to stick with the const void * parameter ! - std::set templatedParams = ( name == "vkGetMemoryHostPointerPropertiesEXT" ) ? std::set() : determineVoidPointerParams( commandData.params ); + std::set templatedParams = + ( flavourFlags & CommandFlavourFlagBits::keepVoidPtr ) ? std::set() : determineVoidPointerParams( commandData.params ); std::vector chainedReturnParams = ( flavourFlags & CommandFlavourFlagBits::chained ) ? determineChainedReturnParams( commandData.params, returnParams ) : std::vector(); assert( chainedReturnParams.size() <= 1 ); @@ -8788,7 +8807,7 @@ std::string else { assert( !param.optional ); - arguments += generateCallArgumentEnhanced( constructorIt->second.params, i, nonConstPointerAsNullptr, singularParams, {} ); + arguments += generateCallArgumentEnhanced( constructorIt->second.params, i, nonConstPointerAsNullptr, singularParams, {}, {} ); } encounteredArgument = true; } diff --git a/VulkanHppGenerator.hpp b/VulkanHppGenerator.hpp index 8752fd1..0264067 100644 --- a/VulkanHppGenerator.hpp +++ b/VulkanHppGenerator.hpp @@ -36,6 +36,12 @@ public: constexpr explicit Flags( MaskType flags ) noexcept : m_mask( flags ) {} + constexpr Flags & operator|=( Flags const & rhs ) noexcept + { + m_mask |= rhs.m_mask; + return *this; + } + constexpr bool operator!() const noexcept { return !m_mask; @@ -66,7 +72,9 @@ enum class CommandFlavourFlagBits : uint8_t chained = 1 << 1, singular = 1 << 2, unique = 1 << 3, - withAllocator = 1 << 4 + withAllocator = 1 << 4, + noReturn = 1 << 5, + keepVoidPtr = 1 << 6 }; using CommandFlavourFlags = Flags; @@ -479,7 +487,8 @@ private: bool nonConstPointerAsNullptr, std::set const & singularParams, std::set const & templatedParams, - bool raiiHandleMemberFunction ) const; + bool raiiHandleMemberFunction, + CommandFlavourFlags flavourFlags ) const; std::string generateCallArgumentsRAIIFactory( std::vector const & params, size_t initialSkipCount, std::set const & skippedParams, @@ -489,7 +498,8 @@ private: size_t paramIndex, bool nonConstPointerAsNullptr, std::set const & singularParams, - std::set const & templatedParams ) const; + std::set const & templatedParams, + CommandFlavourFlags flavourFlags ) const; std::string generateCallArgumentEnhancedConstPointer( ParamData const & param, size_t paramIndex, std::set const & singularParams, @@ -498,7 +508,10 @@ private: size_t paramIndex, bool nonConstPointerAsNullptr, std::set const & singularParams ) const; - std::string generateCallArgumentEnhancedValue( std::vector const & params, size_t paramIndex, std::set const & singularParams ) const; + std::string generateCallArgumentEnhancedValue( std::vector const & params, + size_t paramIndex, + std::set const & singularParams, + CommandFlavourFlags flavourFlags ) const; std::string generateCallSequence( std::string const & name, CommandData const & commandData, std::vector const & returnParams, diff --git a/vulkan/vulkan_funcs.hpp b/vulkan/vulkan_funcs.hpp index 9be7981..0de909b 100644 --- a/vulkan/vulkan_funcs.hpp +++ b/vulkan/vulkan_funcs.hpp @@ -19496,6 +19496,17 @@ namespace VULKAN_HPP_NAMESPACE } #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE + template + VULKAN_HPP_INLINE void Device::getDescriptorEXT( const VULKAN_HPP_NAMESPACE::DescriptorGetInfoEXT & descriptorInfo, + size_t dataSize, + void * pDescriptor, + Dispatch const & d ) const VULKAN_HPP_NOEXCEPT + { + VULKAN_HPP_ASSERT( d.getVkHeaderVersion() == VK_HEADER_VERSION ); + + d.vkGetDescriptorEXT( m_device, reinterpret_cast( &descriptorInfo ), dataSize, pDescriptor ); + } + template VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE DescriptorType Device::getDescriptorEXT( const VULKAN_HPP_NAMESPACE::DescriptorGetInfoEXT & descriptorInfo, Dispatch const & d ) const VULKAN_HPP_NOEXCEPT diff --git a/vulkan/vulkan_handles.hpp b/vulkan/vulkan_handles.hpp index 16f016f..528506c 100644 --- a/vulkan/vulkan_handles.hpp +++ b/vulkan/vulkan_handles.hpp @@ -12578,6 +12578,11 @@ namespace VULKAN_HPP_NAMESPACE void * pDescriptor, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const VULKAN_HPP_NOEXCEPT; #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE + template + void getDescriptorEXT( const VULKAN_HPP_NAMESPACE::DescriptorGetInfoEXT & descriptorInfo, + size_t dataSize, + void * pDescriptor, + Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const VULKAN_HPP_NOEXCEPT; template VULKAN_HPP_NODISCARD DescriptorType getDescriptorEXT( const VULKAN_HPP_NAMESPACE::DescriptorGetInfoEXT & descriptorInfo, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const VULKAN_HPP_NOEXCEPT; diff --git a/vulkan/vulkan_raii.hpp b/vulkan/vulkan_raii.hpp index 250fc80..12e22be 100644 --- a/vulkan/vulkan_raii.hpp +++ b/vulkan/vulkan_raii.hpp @@ -4203,6 +4203,8 @@ namespace VULKAN_HPP_NAMESPACE //=== VK_EXT_descriptor_buffer === + void getDescriptorEXT( const VULKAN_HPP_NAMESPACE::DescriptorGetInfoEXT & descriptorInfo, size_t dataSize, void * pDescriptor ) const VULKAN_HPP_NOEXCEPT; + template VULKAN_HPP_NODISCARD DescriptorType getDescriptorEXT( const VULKAN_HPP_NAMESPACE::DescriptorGetInfoEXT & descriptorInfo ) const VULKAN_HPP_NOEXCEPT; @@ -19151,6 +19153,16 @@ namespace VULKAN_HPP_NAMESPACE return offset; } + VULKAN_HPP_INLINE void Device::getDescriptorEXT( const VULKAN_HPP_NAMESPACE::DescriptorGetInfoEXT & descriptorInfo, + size_t dataSize, + void * pDescriptor ) const VULKAN_HPP_NOEXCEPT + { + VULKAN_HPP_ASSERT( getDispatcher()->vkGetDescriptorEXT && "Function requires " ); + + getDispatcher()->vkGetDescriptorEXT( + static_cast( m_device ), reinterpret_cast( &descriptorInfo ), dataSize, pDescriptor ); + } + template VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE DescriptorType Device::getDescriptorEXT( const VULKAN_HPP_NAMESPACE::DescriptorGetInfoEXT & descriptorInfo ) const VULKAN_HPP_NOEXCEPT