From 429e610f7e292098f5461024fee4a0b581b13458 Mon Sep 17 00:00:00 2001 From: asuessenbach Date: Tue, 28 Jun 2022 08:41:36 +0200 Subject: [PATCH] Combine two types of commands into one generation function --- VulkanHppGenerator.cpp | 113 +++++++---------------------------------- VulkanHppGenerator.hpp | 5 -- vulkan/vulkan_raii.hpp | 43 ++++++++-------- 3 files changed, 39 insertions(+), 122 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index aa2e14c..522a30c 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -4824,19 +4824,25 @@ std::string VulkanHppGenerator::generateDataDeclarations( CommandData const & ( returnParams[2] == std::next( vectorParams.begin() )->first ) && ( returnParams[0] == std::next( vectorParams.begin() )->second ) && templatedParams.empty() && !singular && !chained && !unique ); - std::string counterVariable = startLowerCase( stripPrefix( commandData.params[returnParams[0]].name, "p" ) ); - std::string firstVectorAllocatorType = startUpperCase( stripPrefix( dataTypes[1], "VULKAN_HPP_NAMESPACE::" ) ) + "Allocator"; - std::string firstVectorVariable = startLowerCase( stripPrefix( commandData.params[returnParams[1]].name, "p" ) ); - std::string secondVectorAllocatorType = startUpperCase( stripPrefix( dataTypes[2], "VULKAN_HPP_NAMESPACE::" ) ) + "Allocator"; - std::string secondVectorVariable = startLowerCase( stripPrefix( commandData.params[returnParams[2]].name, "p" ) ); - std::string pairConstructor = withAllocator ? ( "( std::piecewise_construct, std::forward_as_tuple( " + startLowerCase( firstVectorAllocatorType ) + - " ), std::forward_as_tuple( " + startLowerCase( secondVectorAllocatorType ) + " ) )" ) + std::string counterVariable = startLowerCase( stripPrefix( commandData.params[returnParams[0]].name, "p" ) ); + std::string firstVectorVariable = startLowerCase( stripPrefix( commandData.params[returnParams[1]].name, "p" ) ); + std::string secondVectorVariable = startLowerCase( stripPrefix( commandData.params[returnParams[2]].name, "p" ) ); + std::string firstVectorAllocatorType, secondVectorAllocatorType, pairConstructor; + if ( !raii ) + { + firstVectorAllocatorType = startUpperCase( stripPrefix( dataTypes[1], "VULKAN_HPP_NAMESPACE::" ) ) + "Allocator"; + secondVectorAllocatorType = startUpperCase( stripPrefix( dataTypes[2], "VULKAN_HPP_NAMESPACE::" ) ) + "Allocator"; + pairConstructor = withAllocator ? ( "( std::piecewise_construct, std::forward_as_tuple( " + startLowerCase( firstVectorAllocatorType ) + + " ), std::forward_as_tuple( " + startLowerCase( secondVectorAllocatorType ) + " ) )" ) : ""; + firstVectorAllocatorType = ", " + firstVectorAllocatorType; + secondVectorAllocatorType = ", " + secondVectorAllocatorType; + } std::string const dataDeclarationsTemplate = - R"(std::pair, std::vector<${secondVectorElementType}, ${secondVectorAllocatorType}>> data${pairConstructor}; - std::vector<${firstVectorElementType}, ${firstVectorAllocatorType}> & ${firstVectorVariable} = data.first; - std::vector<${secondVectorElementType}, ${secondVectorAllocatorType}> & ${secondVectorVariable} = data.second; + R"(std::pair, std::vector<${secondVectorElementType}${secondVectorAllocatorType}>> data${pairConstructor}; + std::vector<${firstVectorElementType}${firstVectorAllocatorType}> & ${firstVectorVariable} = data.first; + std::vector<${secondVectorElementType}${secondVectorAllocatorType}> & ${secondVectorVariable} = data.second; ${counterType} ${counterVariable};)"; dataDeclarations = replaceWithMap( dataDeclarationsTemplate, @@ -6860,8 +6866,7 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandResultMultiSuccessWithE if ( ( commandIt->second.successCodes.size() == 2 ) && ( commandIt->second.successCodes[0] == "VK_SUCCESS" ) && ( commandIt->second.successCodes[1] == "VK_INCOMPLETE" ) ) { - return generateRAIIHandleCommandResultMultiSuccessWithErrors3Return2VectorEnumerate( - commandIt, initialSkipCount, vectorParams, returnParams, definition ); + return generateRAIIHandleCommandEnhanced( commandIt, initialSkipCount, returnParams, vectorParams, definition, false, false ); } } } @@ -6874,90 +6879,6 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandResultMultiSuccessWithE return ""; } -std::string VulkanHppGenerator::generateRAIIHandleCommandResultMultiSuccessWithErrors3Return2VectorEnumerate( - std::map::const_iterator commandIt, - size_t initialSkipCount, - std::map const & vectorParams, - std::vector const & returnParams, - bool definition ) const -{ - std::set skippedParams = determineSkippedParams( commandIt->second.params, initialSkipCount, vectorParams, returnParams, false ); - std::string argumentList = - generateArgumentListEnhanced( commandIt->second.params, returnParams, vectorParams, skippedParams, {}, {}, definition, false, false, false ); - auto firstVectorParamIt = vectorParams.begin(); - auto secondVectorParamIt = std::next( firstVectorParamIt ); - std::string commandName = generateCommandName( commandIt->first, commandIt->second.params, initialSkipCount, m_tags, false, false ); - std::string counterName = startLowerCase( stripPrefix( stripPluralS( commandIt->second.params[firstVectorParamIt->second].name ), "p" ) ); - std::string firstType = stripPrefix( commandIt->second.params[firstVectorParamIt->first].type.type, "Vk" ); - std::string secondType = stripPrefix( commandIt->second.params[secondVectorParamIt->first].type.type, "Vk" ); - - if ( definition ) - { - const std::string definitionTemplate = - R"( - VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE std::pair, std::vector<${secondType}>> ${className}::${commandName}( ${argumentList} ) const - {${functionPointerCheck} - std::pair, std::vector<${secondType}>> data; - std::vector<${firstType}> & ${firstVectorName} = data.first; - std::vector<${secondType}> & ${secondVectorName} = data.second; - ${counterType} ${counterName}; - VULKAN_HPP_NAMESPACE::Result result; - do - { - result = static_cast( getDispatcher()->${vkCommand}( ${firstCallArguments} ) ); - if ( ( result == VULKAN_HPP_NAMESPACE::Result::eSuccess ) && counterCount ) - { - ${firstVectorName}.resize( ${counterName} ); - ${secondVectorName}.resize( ${counterName} ); - result = static_cast( getDispatcher()->${vkCommand}( ${secondCallArguments} ) ); - VULKAN_HPP_ASSERT( ${counterName} <= ${firstVectorName}.size() ); - } - } while ( result == VULKAN_HPP_NAMESPACE::Result::eIncomplete ); - if ( ( result == VULKAN_HPP_NAMESPACE::Result::eSuccess ) && ( ${counterName} < ${firstVectorName}.size() ) ) - { - ${firstVectorName}.resize( ${counterName} ); - ${secondVectorName}.resize( ${counterName} ); - } - if ( result != VULKAN_HPP_NAMESPACE::Result::eSuccess ) - { - throwResultException( result, VULKAN_HPP_NAMESPACE_STRING"::${className}::${commandName}" ); - } - return data; - } -)"; - - std::string firstCallArguments = generateCallArgumentsEnhanced( commandIt->second, initialSkipCount, true, {}, {}, true ); - std::string firstVectorName = startLowerCase( stripPrefix( commandIt->second.params[firstVectorParamIt->first].name, "p" ) ); - std::string secondCallArguments = generateCallArgumentsEnhanced( commandIt->second, initialSkipCount, false, {}, {}, true ); - std::string secondVectorName = startLowerCase( stripPrefix( commandIt->second.params[secondVectorParamIt->first].name, "p" ) ); - - return replaceWithMap( definitionTemplate, - { { "argumentList", argumentList }, - { "className", stripPrefix( commandIt->second.params[initialSkipCount - 1].type.type, "Vk" ) }, - { "commandName", commandName }, - { "counterName", counterName }, - { "counterType", commandIt->second.params[firstVectorParamIt->second].type.type }, - { "firstCallArguments", firstCallArguments }, - { "firstType", firstType }, - { "firstVectorName", firstVectorName }, - { "functionPointerCheck", generateFunctionPointerCheck( commandIt->first, commandIt->second.referencedIn ) }, - { "secondCallArguments", secondCallArguments }, - { "secondType", secondType }, - { "secondVectorName", secondVectorName }, - { "vkCommand", commandIt->first } } ); - } - else - { - std::string const declarationTemplate = - R"( - VULKAN_HPP_NODISCARD std::pair, std::vector<${secondType}>> ${commandName}( ${argumentList} ) const; -)"; - - return replaceWithMap( declarationTemplate, - { { "argumentList", argumentList }, { "commandName", commandName }, { "firstType", firstType }, { "secondType", secondType } } ); - } -} - std::string VulkanHppGenerator::generateRAIIHandleCommandResultSingleSuccessNoErrors( std::map::const_iterator commandIt, size_t initialSkipCount, bool definition ) const diff --git a/VulkanHppGenerator.hpp b/VulkanHppGenerator.hpp index 1516960..b39b06b 100644 --- a/VulkanHppGenerator.hpp +++ b/VulkanHppGenerator.hpp @@ -740,11 +740,6 @@ private: size_t initialSkipCount, bool definition, std::vector const & returnParamIndices ) const; - std::string generateRAIIHandleCommandResultMultiSuccessWithErrors3Return2VectorEnumerate( std::map::const_iterator commandIt, - size_t initialSkipCount, - std::map const & vectorParamIndices, - std::vector const & returnParamIndices, - bool definition ) const; std::string generateRAIIHandleCommandResultSingleSuccessNoErrors( std::map::const_iterator commandIt, size_t initialSkipCount, bool definition ) const; diff --git a/vulkan/vulkan_raii.hpp b/vulkan/vulkan_raii.hpp index 7c8ba59..ce7223f 100644 --- a/vulkan/vulkan_raii.hpp +++ b/vulkan/vulkan_raii.hpp @@ -2894,8 +2894,9 @@ namespace VULKAN_HPP_NAMESPACE //=== VK_KHR_performance_query === - VULKAN_HPP_NODISCARD std::pair, std::vector> - enumerateQueueFamilyPerformanceQueryCountersKHR( uint32_t queueFamilyIndex ) const; + VULKAN_HPP_NODISCARD + std::pair, std::vector> + enumerateQueueFamilyPerformanceQueryCountersKHR( uint32_t queueFamilyIndex ) const; VULKAN_HPP_NODISCARD uint32_t getQueueFamilyPerformanceQueryPassesKHR( const VULKAN_HPP_NAMESPACE::QueryPoolPerformanceCreateInfoKHR & performanceQueryCreateInfo ) const VULKAN_HPP_NOEXCEPT; @@ -14066,42 +14067,42 @@ namespace VULKAN_HPP_NAMESPACE //=== VK_KHR_performance_query === - VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE std::pair, std::vector> - PhysicalDevice::enumerateQueueFamilyPerformanceQueryCountersKHR( uint32_t queueFamilyIndex ) const + VULKAN_HPP_NODISCARD + VULKAN_HPP_INLINE std::pair, std::vector> + PhysicalDevice::enumerateQueueFamilyPerformanceQueryCountersKHR( uint32_t queueFamilyIndex ) const { VULKAN_HPP_ASSERT( getDispatcher()->vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR && "Function needs extension enabled!" ); - std::pair, std::vector> data; - std::vector & counters = data.first; - std::vector & counterDescriptions = data.second; - uint32_t counterCount; - VULKAN_HPP_NAMESPACE::Result result; + + std::pair, std::vector> data; + std::vector & counters = data.first; + std::vector & counterDescriptions = data.second; + uint32_t counterCount; + VkResult result; do { - result = static_cast( getDispatcher()->vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR( - static_cast( m_physicalDevice ), queueFamilyIndex, &counterCount, nullptr, nullptr ) ); - if ( ( result == VULKAN_HPP_NAMESPACE::Result::eSuccess ) && counterCount ) + result = getDispatcher()->vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR( + static_cast( m_physicalDevice ), queueFamilyIndex, &counterCount, nullptr, nullptr ); + if ( ( result == VK_SUCCESS ) && counterCount ) { counters.resize( counterCount ); counterDescriptions.resize( counterCount ); - result = static_cast( getDispatcher()->vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR( + result = getDispatcher()->vkEnumeratePhysicalDeviceQueueFamilyPerformanceQueryCountersKHR( static_cast( m_physicalDevice ), queueFamilyIndex, &counterCount, reinterpret_cast( counters.data() ), - reinterpret_cast( counterDescriptions.data() ) ) ); - VULKAN_HPP_ASSERT( counterCount <= counters.size() ); + reinterpret_cast( counterDescriptions.data() ) ); } - } while ( result == VULKAN_HPP_NAMESPACE::Result::eIncomplete ); - if ( ( result == VULKAN_HPP_NAMESPACE::Result::eSuccess ) && ( counterCount < counters.size() ) ) + } while ( result == VK_INCOMPLETE ); + resultCheck( static_cast( result ), + VULKAN_HPP_NAMESPACE_STRING "::PhysicalDevice::enumerateQueueFamilyPerformanceQueryCountersKHR" ); + VULKAN_HPP_ASSERT( counterCount <= counters.size() ); + if ( counterCount < counters.size() ) { counters.resize( counterCount ); counterDescriptions.resize( counterCount ); } - if ( result != VULKAN_HPP_NAMESPACE::Result::eSuccess ) - { - throwResultException( result, VULKAN_HPP_NAMESPACE_STRING "::PhysicalDevice::enumerateQueueFamilyPerformanceQueryCountersKHR" ); - } return data; }