From 1da76e4b4a9b3718685e7e5b347e420b51081244 Mon Sep 17 00:00:00 2001 From: asuessenbach Date: Tue, 20 Oct 2020 23:29:00 +0200 Subject: [PATCH] Refactor commands that enumerate some oqaque data behind a void pointer. --- VulkanHppGenerator.cpp | 64 ++++++++++-------- vulkan/vulkan.hpp | 147 ++++++++++++++++++++++------------------- 2 files changed, 113 insertions(+), 98 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index f31e24f..7d2da3a 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -57,7 +57,7 @@ std::string createEnumValueName( std::string const & name, std::string createSuccessCode( std::string const & code, std::set const & tags ); std::string determineCommandName( std::string const & vulkanCommandName, std::string const & firstArgumentType ); std::set determineSkippedParams( size_t returnParamIndex, std::map const & vectorParamIndices ); -std::string extractTag( int line, std::string const & name, std::set const & tags ); +std::string extractTag( int line, std::string const & name, std::set const & tags ); std::string findTag( std::set const & tags, std::string const & name, std::string const & postfix = "" ); std::pair generateFunctionBodyStandardReturn( std::string const & returnType ); std::map getAttributes( tinyxml2::XMLElement const * element ); @@ -1247,8 +1247,7 @@ void VulkanHppGenerator::appendCommand( std::string & str, // two returns but just one vector auto vectorParamIndexIt = vectorParamIndices.begin(); if ( ( vectorParamIndexIt->second == nonConstPointerParamIndices[0] ) && - ( vectorParamIndexIt->first == nonConstPointerParamIndices[1] ) && - ( commandData.params[vectorParamIndexIt->first].type.type != "void" ) ) + ( vectorParamIndexIt->first == nonConstPointerParamIndices[1] ) ) { // the size is a return value as well -> enumerate the values // and the vector data is not of type void @@ -2863,8 +2862,8 @@ void VulkanHppGenerator::appendFunctionHeaderArgumentEnhancedVector( std::string // use our ArrayProxy bool isConst = ( param.type.prefix.find( "const" ) != std::string::npos ); str += optionalBegin + "ArrayProxy<" + - ( isTemplateParam ? ( isConst ? "const T" : "T" ) : stripPostfix( param.type.compose(), "*" ) ) + - "> const &" + optionalEnd + strippedParameterName; + ( isTemplateParam ? ( isConst ? "const T" : "T" ) : stripPostfix( param.type.compose(), "*" ) ) + "> const &" + + optionalEnd + strippedParameterName; } void VulkanHppGenerator::appendFunctionHeaderArguments( std::string & str, @@ -3565,9 +3564,8 @@ std::string VulkanHppGenerator::constructArgumentListEnhanced( std::vector " + - name + - ( ( definition || withAllocators ) ? "" : " VULKAN_HPP_DEFAULT_ARGUMENT_NULLPTR_ASSIGNMENT" ); + "Optional " + name + + ( ( definition || withAllocators ) ? "" : " VULKAN_HPP_DEFAULT_ARGUMENT_NULLPTR_ASSIGNMENT" ); hasDefaultAssignment = true; } else @@ -3636,7 +3634,8 @@ std::string VulkanHppGenerator::constructArgumentListEnhanced( std::vector - ${nodiscard}VULKAN_HPP_INLINE typename ResultValueType>::type ${className}${commandName}( ${argumentList} )${const} + R"( template + ${nodiscard}VULKAN_HPP_INLINE typename ResultValueType>::type ${className}${commandName}( ${argumentList} )${const} { - std::vector<${vectorElementType}, ${vectorElementType}Allocator> ${vectorName}${vectorAllocator}; + std::vector<${vectorElementType}, ${allocatorType}> ${vectorName}${vectorAllocator}; ${counterType} ${counterName}; Result result; do @@ -4079,7 +4084,8 @@ std::string VulkanHppGenerator::constructCommandResultEnumerate( std::string con str = replaceWithMap( functionTemplate, std::map( - { { "argumentList", argumentList }, + { { "allocatorType", allocatorType }, + { "argumentList", argumentList }, { "className", commandData.handle.empty() ? "" : ( stripPrefix( commandData.handle, "Vk" ) + "::" ) }, { "commandName", commandName }, { "const", commandData.handle.empty() ? "" : " const" }, @@ -4092,7 +4098,7 @@ std::string VulkanHppGenerator::constructCommandResultEnumerate( std::string con { "secondCallArguments", constructCallArgumentsEnumerateVectors( commandData.handle, commandData.params, { vectorParamIndices }, false ) }, - { "vectorAllocator", withAllocator ? ( "( " + startLowerCase( vectorElementType ) + "Allocator )" ) : "" }, + { "vectorAllocator", withAllocator ? ( "( " + startLowerCase( allocatorType ) + " )" ) : "" }, { "vectorElementType", vectorElementType }, { "vectorName", startLowerCase( stripPrefix( commandData.params[vectorParamIndices.first].name, "p" ) ) }, { "vkCommand", name }, @@ -4101,17 +4107,17 @@ std::string VulkanHppGenerator::constructCommandResultEnumerate( std::string con else { const std::string functionTemplate = - R"( template , typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE${withAllocatorTypenameCheck}> - ${nodiscard}typename ResultValueType>::type ${commandName}( ${argumentList} )${const};)"; + R"( template , typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE${withAllocatorTypenameCheck}> + ${nodiscard}typename ResultValueType>::type ${commandName}( ${argumentList} )${const};)"; - std::string withAllocatorsTypenameCheck = - ", typename B = " + vectorElementType + - "Allocator, typename std::enable_if::value, int>::type = 0"; + std::string withAllocatorsTypenameCheck = ", typename B = " + allocatorType + + ", typename std::enable_if::value, int>::type = 0"; str = replaceWithMap( functionTemplate, std::map( - { { "argumentList", argumentList }, + { { "allocatorType", allocatorType }, + { "argumentList", argumentList }, { "const", commandData.handle.empty() ? "" : " const" }, { "commandName", commandName }, { "nodiscard", nodiscard }, @@ -7215,9 +7221,9 @@ size_t VulkanHppGenerator::determineDefaultStartIndex( std::vector co return defaultStartIndex; } -std::string VulkanHppGenerator::determineEnhancedReturnType( CommandData const & commandData, - size_t returnParamIndex, - bool isStructureChain ) const +std::string VulkanHppGenerator::determineEnhancedReturnType( CommandData const & commandData, + size_t returnParamIndex, + bool isStructureChain ) const { assert( ( returnParamIndex == INVALID_INDEX ) || ( returnParamIndex < commandData.params.size() ) ); @@ -7229,12 +7235,12 @@ std::string VulkanHppGenerator::determineEnhancedReturnType( CommandData const & assert( ( commandData.returnType == "void" ) || ( commandData.returnType == "VkResult" ) ); assert( commandData.successCodes.empty() || ( commandData.successCodes[0] == "VK_SUCCESS" ) ); enhancedReturnType = ( commandData.params[returnParamIndex].type.type == "void" ) - ? "std::vector" // the return parameter is a vector-type parameter - : isStructureChain - ? "std::vector" // for structureChain returns, it's just + ? "std::vector" // the return parameter is a vector-type parameter + : isStructureChain + ? "std::vector" // for structureChain returns, it's just // a vector of StrutureChains - : "std::vector<" + stripPrefix( commandData.params[returnParamIndex].type.type, "Vk" ) + - ",Allocator>"; // for the other parameters, we use a vector of the pure type + : "std::vector<" + stripPrefix( commandData.params[returnParamIndex].type.type, "Vk" ) + + ",Allocator>"; // for the other parameters, we use a vector of the pure type } else if ( ( commandData.returnType == "VkResult" ) && ( commandData.successCodes.size() == 1 ) ) { diff --git a/vulkan/vulkan.hpp b/vulkan/vulkan.hpp index 210f3b8..3f4f2d2 100644 --- a/vulkan/vulkan.hpp +++ b/vulkan/vulkan.hpp @@ -55095,20 +55095,21 @@ namespace VULKAN_HPP_NAMESPACE VULKAN_HPP_NODISCARD Result getPipelineCacheData( VULKAN_HPP_NAMESPACE::PipelineCache pipelineCache, size_t * pDataSize, - void * pData, + void * pData VULKAN_HPP_DEFAULT_ARGUMENT_ASSIGNMENT, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const VULKAN_HPP_NOEXCEPT; #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE - template , typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE> - VULKAN_HPP_NODISCARD typename ResultValueType>::type + template , + typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE> + VULKAN_HPP_NODISCARD typename ResultValueType>::type getPipelineCacheData( VULKAN_HPP_NAMESPACE::PipelineCache pipelineCache, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; - template , - typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE, - typename B = Allocator, + template , + typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE, + typename B = Uint8_tAllocator, typename std::enable_if::value, int>::type = 0> - VULKAN_HPP_NODISCARD typename ResultValueType>::type + VULKAN_HPP_NODISCARD typename ResultValueType>::type getPipelineCacheData( VULKAN_HPP_NAMESPACE::PipelineCache pipelineCache, - Allocator const & vectorAllocator, + Uint8_tAllocator & uint8_tAllocator, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ @@ -55440,24 +55441,25 @@ namespace VULKAN_HPP_NAMESPACE VULKAN_HPP_NAMESPACE::ShaderStageFlagBits shaderStage, VULKAN_HPP_NAMESPACE::ShaderInfoTypeAMD infoType, size_t * pInfoSize, - void * pInfo, + void * pInfo VULKAN_HPP_DEFAULT_ARGUMENT_ASSIGNMENT, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const VULKAN_HPP_NOEXCEPT; #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE - template , typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE> - VULKAN_HPP_NODISCARD typename ResultValueType>::type + template , + typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE> + VULKAN_HPP_NODISCARD typename ResultValueType>::type getShaderInfoAMD( VULKAN_HPP_NAMESPACE::Pipeline pipeline, VULKAN_HPP_NAMESPACE::ShaderStageFlagBits shaderStage, VULKAN_HPP_NAMESPACE::ShaderInfoTypeAMD infoType, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; - template , - typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE, - typename B = Allocator, + template , + typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE, + typename B = Uint8_tAllocator, typename std::enable_if::value, int>::type = 0> - VULKAN_HPP_NODISCARD typename ResultValueType>::type + VULKAN_HPP_NODISCARD typename ResultValueType>::type getShaderInfoAMD( VULKAN_HPP_NAMESPACE::Pipeline pipeline, VULKAN_HPP_NAMESPACE::ShaderStageFlagBits shaderStage, VULKAN_HPP_NAMESPACE::ShaderInfoTypeAMD infoType, - Allocator const & vectorAllocator, + Uint8_tAllocator & uint8_tAllocator, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ @@ -55511,20 +55513,21 @@ namespace VULKAN_HPP_NAMESPACE VULKAN_HPP_NODISCARD Result getValidationCacheDataEXT( VULKAN_HPP_NAMESPACE::ValidationCacheEXT validationCache, size_t * pDataSize, - void * pData, + void * pData VULKAN_HPP_DEFAULT_ARGUMENT_ASSIGNMENT, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const VULKAN_HPP_NOEXCEPT; #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE - template , typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE> - VULKAN_HPP_NODISCARD typename ResultValueType>::type + template , + typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE> + VULKAN_HPP_NODISCARD typename ResultValueType>::type getValidationCacheDataEXT( VULKAN_HPP_NAMESPACE::ValidationCacheEXT validationCache, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; - template , - typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE, - typename B = Allocator, + template , + typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE, + typename B = Uint8_tAllocator, typename std::enable_if::value, int>::type = 0> - VULKAN_HPP_NODISCARD typename ResultValueType>::type + VULKAN_HPP_NODISCARD typename ResultValueType>::type getValidationCacheDataEXT( VULKAN_HPP_NAMESPACE::ValidationCacheEXT validationCache, - Allocator const & vectorAllocator, + Uint8_tAllocator & uint8_tAllocator, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ @@ -99806,14 +99809,15 @@ namespace VULKAN_HPP_NAMESPACE return static_cast( d.vkGetPipelineCacheData( m_device, static_cast( pipelineCache ), pDataSize, pData ) ); } + #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE - template - VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE typename ResultValueType>::type + template + VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE typename ResultValueType>::type Device::getPipelineCacheData( VULKAN_HPP_NAMESPACE::PipelineCache pipelineCache, Dispatch const & d ) const { - std::vector data; - size_t dataSize; - Result result; + std::vector data; + size_t dataSize; + Result result; do { result = static_cast( @@ -99825,27 +99829,28 @@ namespace VULKAN_HPP_NAMESPACE static_cast( pipelineCache ), &dataSize, reinterpret_cast( data.data() ) ) ); + VULKAN_HPP_ASSERT( dataSize <= data.size() ); } } while ( result == Result::eIncomplete ); - if ( result == Result::eSuccess ) + if ( ( result == Result::eSuccess ) && ( dataSize < data.size() ) ) { - VULKAN_HPP_ASSERT( dataSize <= data.size() ); data.resize( dataSize ); } return createResultValue( result, data, VULKAN_HPP_NAMESPACE_STRING "::Device::getPipelineCacheData" ); } - template ::value, int>::type> - VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE typename ResultValueType>::type + VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE typename ResultValueType>::type Device::getPipelineCacheData( VULKAN_HPP_NAMESPACE::PipelineCache pipelineCache, - Allocator const & vectorAllocator, + Uint8_tAllocator & uint8_tAllocator, Dispatch const & d ) const { - std::vector data( vectorAllocator ); - size_t dataSize; - Result result; + std::vector data( uint8_tAllocator ); + size_t dataSize; + Result result; do { result = static_cast( @@ -99857,11 +99862,11 @@ namespace VULKAN_HPP_NAMESPACE static_cast( pipelineCache ), &dataSize, reinterpret_cast( data.data() ) ) ); + VULKAN_HPP_ASSERT( dataSize <= data.size() ); } } while ( result == Result::eIncomplete ); - if ( result == Result::eSuccess ) + if ( ( result == Result::eSuccess ) && ( dataSize < data.size() ) ) { - VULKAN_HPP_ASSERT( dataSize <= data.size() ); data.resize( dataSize ); } return createResultValue( result, data, VULKAN_HPP_NAMESPACE_STRING "::Device::getPipelineCacheData" ); @@ -100652,17 +100657,18 @@ namespace VULKAN_HPP_NAMESPACE pInfoSize, pInfo ) ); } + #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE - template - VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE typename ResultValueType>::type + template + VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE typename ResultValueType>::type Device::getShaderInfoAMD( VULKAN_HPP_NAMESPACE::Pipeline pipeline, VULKAN_HPP_NAMESPACE::ShaderStageFlagBits shaderStage, VULKAN_HPP_NAMESPACE::ShaderInfoTypeAMD infoType, Dispatch const & d ) const { - std::vector info; - size_t infoSize; - Result result; + std::vector info; + size_t infoSize; + Result result; do { result = static_cast( d.vkGetShaderInfoAMD( m_device, @@ -100680,29 +100686,30 @@ namespace VULKAN_HPP_NAMESPACE static_cast( infoType ), &infoSize, reinterpret_cast( info.data() ) ) ); + VULKAN_HPP_ASSERT( infoSize <= info.size() ); } } while ( result == Result::eIncomplete ); - if ( result == Result::eSuccess ) + if ( ( result == Result::eSuccess ) && ( infoSize < info.size() ) ) { - VULKAN_HPP_ASSERT( infoSize <= info.size() ); info.resize( infoSize ); } return createResultValue( result, info, VULKAN_HPP_NAMESPACE_STRING "::Device::getShaderInfoAMD" ); } - template ::value, int>::type> - VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE typename ResultValueType>::type + VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE typename ResultValueType>::type Device::getShaderInfoAMD( VULKAN_HPP_NAMESPACE::Pipeline pipeline, VULKAN_HPP_NAMESPACE::ShaderStageFlagBits shaderStage, VULKAN_HPP_NAMESPACE::ShaderInfoTypeAMD infoType, - Allocator const & vectorAllocator, + Uint8_tAllocator & uint8_tAllocator, Dispatch const & d ) const { - std::vector info( vectorAllocator ); - size_t infoSize; - Result result; + std::vector info( uint8_tAllocator ); + size_t infoSize; + Result result; do { result = static_cast( d.vkGetShaderInfoAMD( m_device, @@ -100720,11 +100727,11 @@ namespace VULKAN_HPP_NAMESPACE static_cast( infoType ), &infoSize, reinterpret_cast( info.data() ) ) ); + VULKAN_HPP_ASSERT( infoSize <= info.size() ); } } while ( result == Result::eIncomplete ); - if ( result == Result::eSuccess ) + if ( ( result == Result::eSuccess ) && ( infoSize < info.size() ) ) { - VULKAN_HPP_ASSERT( infoSize <= info.size() ); info.resize( infoSize ); } return createResultValue( result, info, VULKAN_HPP_NAMESPACE_STRING "::Device::getShaderInfoAMD" ); @@ -100868,15 +100875,16 @@ namespace VULKAN_HPP_NAMESPACE return static_cast( d.vkGetValidationCacheDataEXT( m_device, static_cast( validationCache ), pDataSize, pData ) ); } + #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE - template - VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE typename ResultValueType>::type + template + VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE typename ResultValueType>::type Device::getValidationCacheDataEXT( VULKAN_HPP_NAMESPACE::ValidationCacheEXT validationCache, Dispatch const & d ) const { - std::vector data; - size_t dataSize; - Result result; + std::vector data; + size_t dataSize; + Result result; do { result = static_cast( d.vkGetValidationCacheDataEXT( @@ -100889,27 +100897,28 @@ namespace VULKAN_HPP_NAMESPACE static_cast( validationCache ), &dataSize, reinterpret_cast( data.data() ) ) ); + VULKAN_HPP_ASSERT( dataSize <= data.size() ); } } while ( result == Result::eIncomplete ); - if ( result == Result::eSuccess ) + if ( ( result == Result::eSuccess ) && ( dataSize < data.size() ) ) { - VULKAN_HPP_ASSERT( dataSize <= data.size() ); data.resize( dataSize ); } return createResultValue( result, data, VULKAN_HPP_NAMESPACE_STRING "::Device::getValidationCacheDataEXT" ); } - template ::value, int>::type> - VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE typename ResultValueType>::type + VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE typename ResultValueType>::type Device::getValidationCacheDataEXT( VULKAN_HPP_NAMESPACE::ValidationCacheEXT validationCache, - Allocator const & vectorAllocator, + Uint8_tAllocator & uint8_tAllocator, Dispatch const & d ) const { - std::vector data( vectorAllocator ); - size_t dataSize; - Result result; + std::vector data( uint8_tAllocator ); + size_t dataSize; + Result result; do { result = static_cast( d.vkGetValidationCacheDataEXT( @@ -100922,11 +100931,11 @@ namespace VULKAN_HPP_NAMESPACE static_cast( validationCache ), &dataSize, reinterpret_cast( data.data() ) ) ); + VULKAN_HPP_ASSERT( dataSize <= data.size() ); } } while ( result == Result::eIncomplete ); - if ( result == Result::eSuccess ) + if ( ( result == Result::eSuccess ) && ( dataSize < data.size() ) ) { - VULKAN_HPP_ASSERT( dataSize <= data.size() ); data.resize( dataSize ); } return createResultValue( result, data, VULKAN_HPP_NAMESPACE_STRING "::Device::getValidationCacheDataEXT" );