From de7127a96367720d4d63f8b4a7f7c6342a124b25 Mon Sep 17 00:00:00 2001 From: asuessenbach Date: Wed, 15 Jun 2022 11:48:06 +0200 Subject: [PATCH] Combine two types of commands into one generation function --- VulkanHppGenerator.cpp | 103 ++++++++--------------------------------- VulkanHppGenerator.hpp | 6 +-- vulkan/vulkan_raii.hpp | 85 ++++++++++++++++------------------ 3 files changed, 61 insertions(+), 133 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 43c73f7..d3ba417 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -1913,6 +1913,7 @@ std::string VulkanHppGenerator::combineDataTypes( std::map const bool singular, bool enumerating, std::vector const & dataTypes, + bool unique, bool raii ) const { assert( dataTypes.size() == returnParams.size() ); @@ -1924,7 +1925,7 @@ std::string VulkanHppGenerator::combineDataTypes( std::map const modifiedDataTypes[i] = ( vectorParamIt == vectorParams.end() || singular ) ? dataTypes[i] : ( "std::vector<" + dataTypes[i] + - ( raii ? ">" : ( ", " + startUpperCase( stripPrefix( dataTypes[i], "VULKAN_HPP_NAMESPACE::" ) ) + "Allocator>" ) ) ); + ( raii || unique ? ">" : ( ", " + startUpperCase( stripPrefix( dataTypes[i], "VULKAN_HPP_NAMESPACE::" ) ) + "Allocator>" ) ) ); } std::string combinedType; @@ -3446,7 +3447,7 @@ std::string VulkanHppGenerator::generateCommandEnhanced( std::string const & bool enumerating = determineEnumeration( vectorParams, returnParams ); std::vector dataTypes = determineDataTypes( commandData.params, vectorParams, returnParams, templatedParams ); - std::string dataType = combineDataTypes( vectorParams, returnParams, singular, enumerating, dataTypes, false ); + std::string dataType = combineDataTypes( vectorParams, returnParams, singular, enumerating, dataTypes, unique, false ); std::string argumentTemplates = generateArgumentTemplates( commandData.params, returnParams, vectorParams, templatedParams, chained, false ); auto [allocatorTemplates, uniqueHandleAllocatorTemplates] = @@ -4683,20 +4684,15 @@ std::string VulkanHppGenerator::generateDataDeclarations( CommandData const & } else { - std::string allocator = stripPrefix( dataTypes[0], "VULKAN_HPP_NAMESPACE::" ) + "Allocator"; - std::string dataTypeAllocator = !unique ? ( ", " + startUpperCase( allocator ) ) : ""; - std::string vectorAllocator = ( withAllocator && !unique ) ? ( ", " + startLowerCase( allocator ) ) : ""; - std::string vectorSize = getVectorSize( commandData.params, vectorParams, returnParams[0], dataTypes[0], templatedParams ); + std::string allocator = stripPrefix( dataTypes[0], "VULKAN_HPP_NAMESPACE::" ) + "Allocator"; + std::string vectorAllocator = ( withAllocator && !unique ) ? ( ", " + startLowerCase( allocator ) ) : ""; + std::string vectorSize = getVectorSize( commandData.params, vectorParams, returnParams[0], dataTypes[0], templatedParams ); - std::string const dataDeclarationsTemplate = - R"(std::vector<${dataType}${dataTypeAllocator}> ${returnVariable}( ${vectorSize}${vectorAllocator} );)"; + std::string const dataDeclarationsTemplate = R"(${dataType} ${returnVariable}( ${vectorSize}${vectorAllocator} );)"; - dataDeclarations = replaceWithMap( dataDeclarationsTemplate, - { { "dataType", dataTypes[0] }, - { "dataTypeAllocator", dataTypeAllocator }, - { "returnVariable", returnVariable }, - { "vectorAllocator", vectorAllocator }, - { "vectorSize", vectorSize } } ); + dataDeclarations = replaceWithMap( + dataDeclarationsTemplate, + { { "dataType", dataType }, { "returnVariable", returnVariable }, { "vectorAllocator", vectorAllocator }, { "vectorSize", vectorSize } } ); } } else @@ -6143,7 +6139,7 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandEnhanced( std::map dataTypes = determineDataTypes( commandIt->second.params, vectorParams, returnParams, templatedParams ); - std::string dataType = combineDataTypes( vectorParams, returnParams, false, enumerating, dataTypes, true ); + std::string dataType = combineDataTypes( vectorParams, returnParams, false, enumerating, dataTypes, false, true ); std::string argumentTemplates = generateArgumentTemplates( commandIt->second.params, returnParams, vectorParams, templatedParams, chained, true ); std::string argumentList = @@ -6167,6 +6163,7 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandEnhanced( std::mapsecond, returnParams, vectorParams, templatedParams, false, false, chained, false, dataTypes, dataType, returnType, returnVariable ); std::string dataPreparation = generateDataPreparation( commandIt->second, initialSkipCount, returnParams, vectorParams, templatedParams, false, false, false, chained, enumerating ); + std::string dataSizeChecks = generateDataSizeChecks( commandIt->second, returnParams, dataTypes, vectorParams, templatedParams, false ); std::string resultCheck = generateResultCheck( commandIt->second, className, "::", commandName, enumerating ); std::string returnStatement = generateReturnStatement( commandIt->first, commandIt->second, @@ -6206,6 +6204,7 @@ ${vectorSizeCheck} { "commandName", commandName }, { "dataDeclarations", dataDeclarations }, { "dataPreparation", dataPreparation }, + { "dataSizeChecks", dataSizeChecks }, { "functionPointerCheck", generateFunctionPointerCheck( commandIt->first, commandIt->second.referencedIn ) }, { "nodiscard", nodiscard }, { "noexcept", noexceptString }, @@ -7197,7 +7196,7 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandResultSingleSuccessWith { if ( commandIt->second.params[vectorParams.begin()->second].type.type == "size_t" ) { - str = generateRAIIHandleCommandResultSingleSuccessWithErrors1ReturnVoidVector( commandIt, initialSkipCount, vectorParams, returnParam, definition ); + str = generateRAIIHandleCommandEnhanced( commandIt, initialSkipCount, { returnParam }, vectorParams, definition, false ); str += generateRAIIHandleCommandResultSingleSuccessWithErrors1ReturnVoidSingular( commandIt, initialSkipCount, vectorParams, returnParam, definition ); } @@ -7212,8 +7211,7 @@ std::string VulkanHppGenerator::generateRAIIHandleCommandResultSingleSuccessWith { if ( commandIt->second.params[std::next( vectorParams.begin() )->second].type.type == "size_t" ) { - str = - generateRAIIHandleCommandResultSingleSuccessWithErrors1ReturnVoidVector( commandIt, initialSkipCount, vectorParams, returnParam, definition ); + str = generateRAIIHandleCommandEnhanced( commandIt, initialSkipCount, { returnParam }, vectorParams, definition, false ); str += generateRAIIHandleCommandResultSingleSuccessWithErrors1ReturnVoidSingular( commandIt, initialSkipCount, vectorParams, returnParam, definition ); } @@ -7468,68 +7466,6 @@ std::string } } -std::string - VulkanHppGenerator::generateRAIIHandleCommandResultSingleSuccessWithErrors1ReturnVoidVector( std::map::const_iterator commandIt, - size_t initialSkipCount, - std::map const & vectorParams, - size_t returnParam, - bool definition ) const -{ - std::set skippedParams = determineSkippedParams( commandIt->second.params, initialSkipCount, vectorParams, { returnParam }, false ); - std::string argumentList = generateArgumentListEnhanced( - commandIt->second.params, { returnParam }, vectorParams, skippedParams, {}, { returnParam }, definition, false, false, false ); - std::string argumentTemplates = generateArgumentTemplates( commandIt->second.params, { returnParam }, vectorParams, { returnParam }, false, true ); - std::string commandName = generateCommandName( commandIt->first, commandIt->second.params, initialSkipCount, m_tags, false, false ); - std::string dataType = stripPrefix( commandIt->second.params[returnParam].name, "p" ) + "Type"; - - if ( definition ) - { - std::string const definitionTemplate = - R"( - ${argumentTemplates} - VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE std::vector<${dataType}> ${className}::${commandName}( ${argumentList} ) const - {${functionPointerCheck} - VULKAN_HPP_ASSERT( ${dataSize} % sizeof( ${dataType} ) == 0 ); - std::vector<${dataType}> ${dataName}( ${dataSize} / sizeof( ${dataType} ) ); - Result result = static_cast( getDispatcher()->${vkCommand}( ${callArguments} ) ); - if ( ${failureCheck} ) - { - throwResultException( result, VULKAN_HPP_NAMESPACE_STRING"::${className}::${commandName}" ); - } - return ${dataName}; - } -)"; - - std::string callArguments = generateCallArgumentsEnhanced( commandIt->second, initialSkipCount, false, {}, {}, true ); - std::string dataName = startLowerCase( stripPrefix( commandIt->second.params[returnParam].name, "p" ) ); - - return replaceWithMap( definitionTemplate, - { { "argumentList", argumentList }, - { "argumentTemplates", argumentTemplates }, - { "callArguments", callArguments }, - { "className", stripPrefix( commandIt->second.params[initialSkipCount - 1].type.type, "Vk" ) }, - { "commandName", commandName }, - { "dataName", dataName }, - { "dataType", dataType }, - { "dataSize", commandIt->second.params[returnParam].len }, - { "failureCheck", generateFailureCheck( commandIt->second.successCodes ) }, - { "functionPointerCheck", generateFunctionPointerCheck( commandIt->first, commandIt->second.referencedIn ) }, - { "vkCommand", commandIt->first } } ); - } - else - { - std::string const declarationTemplate = - R"( - ${argumentTemplates} - VULKAN_HPP_NODISCARD std::vector<${dataType}> ${commandName}( ${argumentList} ) const; -)"; - - return replaceWithMap( - declarationTemplate, - { { "argumentList", argumentList }, { "argumentTemplates", argumentTemplates }, { "commandName", commandName }, { "dataType", dataType } } ); - } -} - std::string VulkanHppGenerator::generateRAIIHandleCommandResultSingleSuccessWithErrors2Return( std::map::const_iterator commandIt, size_t initialSkipCount, bool definition, @@ -9421,10 +9357,11 @@ std::string VulkanHppGenerator::generateReturnType( { auto from = dataType.find( '<' ) + 1; assert( from != std::string::npos ); - auto to = dataType.find( ',', from ); - assert( to != std::string::npos ); + auto to = dataType.find( '>', from ); + assert( to == dataType.length() - 1 ); std::string type = dataType.substr( from, to - from ); - modifiedDataType.replace( from, to - from, "UniqueHandle<" + type + ", Dispatch>" ); + assert( beginsWith( type, "VULKAN_HPP_NAMESPACE::" ) ); + modifiedDataType.replace( from, to - from, "UniqueHandle<" + type + ", Dispatch>, " + stripPrefix( type, "VULKAN_HPP_NAMESPACE::" ) + "Allocator" ); } else { diff --git a/VulkanHppGenerator.hpp b/VulkanHppGenerator.hpp index bff422e..c96dd33 100644 --- a/VulkanHppGenerator.hpp +++ b/VulkanHppGenerator.hpp @@ -401,6 +401,7 @@ private: bool singular, bool enumerating, std::vector const & dataTypes, + bool unique, bool raii ) const; bool containsArray( std::string const & type ) const; bool containsFuncPointer( std::string const & type ) const; @@ -781,11 +782,6 @@ private: std::map const & vectorParamIndices, size_t returnParam, bool definition ) const; - std::string generateRAIIHandleCommandResultSingleSuccessWithErrors1ReturnVoidVector( std::map::const_iterator commandIt, - size_t initialSkipCount, - std::map const & vectorParamIndices, - size_t returnParam, - bool definition ) const; std::string generateRAIIHandleCommandResultSingleSuccessWithErrors2Return( std::map::const_iterator commandIt, size_t initialSkipCount, bool definition, diff --git a/vulkan/vulkan_raii.hpp b/vulkan/vulkan_raii.hpp index 7ea28bd..2ae56fb 100644 --- a/vulkan/vulkan_raii.hpp +++ b/vulkan/vulkan_raii.hpp @@ -14913,20 +14913,19 @@ namespace VULKAN_HPP_NAMESPACE { VULKAN_HPP_ASSERT( getDispatcher()->vkWriteAccelerationStructuresPropertiesKHR && "Function needs extension enabled!" ); + VULKAN_HPP_ASSERT( dataSize % sizeof( DataType ) == 0 ); std::vector data( dataSize / sizeof( DataType ) ); - Result result = static_cast( + VkResult result = getDispatcher()->vkWriteAccelerationStructuresPropertiesKHR( static_cast( m_device ), accelerationStructures.size(), reinterpret_cast( accelerationStructures.data() ), static_cast( queryType ), data.size() * sizeof( DataType ), reinterpret_cast( data.data() ), - stride ) ); - if ( result != VULKAN_HPP_NAMESPACE::Result::eSuccess ) - { - throwResultException( result, VULKAN_HPP_NAMESPACE_STRING "::Device::writeAccelerationStructuresPropertiesKHR" ); - } + stride ); + resultCheck( static_cast( result ), VULKAN_HPP_NAMESPACE_STRING "::Device::writeAccelerationStructuresPropertiesKHR" ); + return data; } @@ -15337,18 +15336,17 @@ namespace VULKAN_HPP_NAMESPACE { VULKAN_HPP_ASSERT( getDispatcher()->vkGetRayTracingShaderGroupHandlesNV && "Function needs extension enabled!" ); + VULKAN_HPP_ASSERT( dataSize % sizeof( DataType ) == 0 ); std::vector data( dataSize / sizeof( DataType ) ); - Result result = static_cast( getDispatcher()->vkGetRayTracingShaderGroupHandlesNV( static_cast( m_device ), - static_cast( m_pipeline ), - firstGroup, - groupCount, - data.size() * sizeof( DataType ), - reinterpret_cast( data.data() ) ) ); - if ( result != VULKAN_HPP_NAMESPACE::Result::eSuccess ) - { - throwResultException( result, VULKAN_HPP_NAMESPACE_STRING "::Pipeline::getRayTracingShaderGroupHandlesNV" ); - } + VkResult result = getDispatcher()->vkGetRayTracingShaderGroupHandlesNV( static_cast( m_device ), + static_cast( m_pipeline ), + firstGroup, + groupCount, + data.size() * sizeof( DataType ), + reinterpret_cast( data.data() ) ); + resultCheck( static_cast( result ), VULKAN_HPP_NAMESPACE_STRING "::Pipeline::getRayTracingShaderGroupHandlesNV" ); + return data; } @@ -15374,17 +15372,15 @@ namespace VULKAN_HPP_NAMESPACE { VULKAN_HPP_ASSERT( getDispatcher()->vkGetAccelerationStructureHandleNV && "Function needs extension enabled!" ); + VULKAN_HPP_ASSERT( dataSize % sizeof( DataType ) == 0 ); std::vector data( dataSize / sizeof( DataType ) ); - Result result = - static_cast( getDispatcher()->vkGetAccelerationStructureHandleNV( static_cast( m_device ), - static_cast( m_accelerationStructure ), - data.size() * sizeof( DataType ), - reinterpret_cast( data.data() ) ) ); - if ( result != VULKAN_HPP_NAMESPACE::Result::eSuccess ) - { - throwResultException( result, VULKAN_HPP_NAMESPACE_STRING "::AccelerationStructureNV::getHandle" ); - } + VkResult result = getDispatcher()->vkGetAccelerationStructureHandleNV( static_cast( m_device ), + static_cast( m_accelerationStructure ), + data.size() * sizeof( DataType ), + reinterpret_cast( data.data() ) ); + resultCheck( static_cast( result ), VULKAN_HPP_NAMESPACE_STRING "::AccelerationStructureNV::getHandle" ); + return data; } @@ -16920,18 +16916,17 @@ namespace VULKAN_HPP_NAMESPACE { VULKAN_HPP_ASSERT( getDispatcher()->vkGetRayTracingShaderGroupHandlesKHR && "Function needs extension enabled!" ); + VULKAN_HPP_ASSERT( dataSize % sizeof( DataType ) == 0 ); std::vector data( dataSize / sizeof( DataType ) ); - Result result = static_cast( getDispatcher()->vkGetRayTracingShaderGroupHandlesKHR( static_cast( m_device ), - static_cast( m_pipeline ), - firstGroup, - groupCount, - data.size() * sizeof( DataType ), - reinterpret_cast( data.data() ) ) ); - if ( result != VULKAN_HPP_NAMESPACE::Result::eSuccess ) - { - throwResultException( result, VULKAN_HPP_NAMESPACE_STRING "::Pipeline::getRayTracingShaderGroupHandlesKHR" ); - } + VkResult result = getDispatcher()->vkGetRayTracingShaderGroupHandlesKHR( static_cast( m_device ), + static_cast( m_pipeline ), + firstGroup, + groupCount, + data.size() * sizeof( DataType ), + reinterpret_cast( data.data() ) ); + resultCheck( static_cast( result ), VULKAN_HPP_NAMESPACE_STRING "::Pipeline::getRayTracingShaderGroupHandlesKHR" ); + return data; } @@ -16958,18 +16953,18 @@ namespace VULKAN_HPP_NAMESPACE { VULKAN_HPP_ASSERT( getDispatcher()->vkGetRayTracingCaptureReplayShaderGroupHandlesKHR && "Function needs extension enabled!" ); + VULKAN_HPP_ASSERT( dataSize % sizeof( DataType ) == 0 ); std::vector data( dataSize / sizeof( DataType ) ); - Result result = static_cast( getDispatcher()->vkGetRayTracingCaptureReplayShaderGroupHandlesKHR( static_cast( m_device ), - static_cast( m_pipeline ), - firstGroup, - groupCount, - data.size() * sizeof( DataType ), - reinterpret_cast( data.data() ) ) ); - if ( result != VULKAN_HPP_NAMESPACE::Result::eSuccess ) - { - throwResultException( result, VULKAN_HPP_NAMESPACE_STRING "::Pipeline::getRayTracingCaptureReplayShaderGroupHandlesKHR" ); - } + VkResult result = getDispatcher()->vkGetRayTracingCaptureReplayShaderGroupHandlesKHR( static_cast( m_device ), + static_cast( m_pipeline ), + firstGroup, + groupCount, + data.size() * sizeof( DataType ), + reinterpret_cast( data.data() ) ); + resultCheck( static_cast( result ), + VULKAN_HPP_NAMESPACE_STRING "::Pipeline::getRayTracingCaptureReplayShaderGroupHandlesKHR" ); + return data; }