From 77b401d4a95537a240a47ad1c2fe8cd3695e937c Mon Sep 17 00:00:00 2001 From: asuessenbach Date: Thu, 3 Sep 2020 11:20:57 +0200 Subject: [PATCH] correct enhanced version of vkGetQueryPoolResults - mark wrong version as deprecated (C++14) - introduce new version returning ResultValue> - introduce new singular version returning ResultValue --- VulkanHppGenerator.cpp | 124 ++++++++++++++-------- VulkanHppGenerator.hpp | 9 +- samples/OcclusionQuery/OcclusionQuery.cpp | 22 ++-- vulkan/vulkan.hpp | 111 ++++++++++++++++--- 4 files changed, 191 insertions(+), 75 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index 6182177..497cd68 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -1204,21 +1204,20 @@ void VulkanHppGenerator::appendCommand( std::string & str, CommandData const & commandData, bool definition ) const { - if ( commandData.params.back().type.isNonConstPointer() && ( commandData.params.back().type.type == "void" ) && - !commandData.params.back().len.empty() ) + std::map vectorParamIndices = determineVectorParamIndices( commandData.params ); + if ( vectorParamIndices.size() == 1 ) { - std::string const & len = commandData.params.back().len; - auto lenIt = std::find_if( - commandData.params.begin(), commandData.params.end(), [&len]( ParamData const & pd ) { return pd.name == len; } ); - if ( ( lenIt != commandData.params.end() ) && lenIt->type.isValue() ) + auto vectorParamIndexIt = vectorParamIndices.begin(); + if ( commandData.params[vectorParamIndexIt->first].type.isNonConstPointer() && + ( commandData.params[vectorParamIndexIt->first].type.type == "void" ) && + commandData.params[vectorParamIndexIt->second].type.isValue() ) { - appendCommandFixedSizeVector( str, name, commandData, definition ); + appendCommandFixedSizeVector( str, name, commandData, vectorParamIndices, definition ); return; } } - bool twoStep = isTwoStepAlgorithm( commandData.params ); - std::map vectorParamIndices = determineVectorParamIndices( commandData.params ); + bool twoStep = isTwoStepAlgorithm( commandData.params ); size_t returnParamIndex = determineReturnParamIndex( commandData, vectorParamIndices, twoStep ); bool isStructureChain = @@ -1465,24 +1464,32 @@ void VulkanHppGenerator::appendCommand( std::string & str, } } -void VulkanHppGenerator::appendCommandFixedSizeVector( std::string & str, - std::string const & name, - CommandData const & commandData, - bool definition ) const +void VulkanHppGenerator::appendCommandFixedSizeVector( std::string & str, + std::string const & name, + CommandData const & commandData, + std::map const & vectorParamIndices, + bool definition ) const { assert( commandData.returnType == "VkResult" ); - assert( commandData.successCodes.size() == 1 ); + assert( vectorParamIndices.size() == 1 ); + std::map::const_iterator vectorParamIndexIt = vectorParamIndices.begin(); - std::map vectorParamIndices = determineVectorParamIndices( commandData.params ); - std::string enter, leave; - std::tie( enter, leave ) = generateProtection( commandData.feature, commandData.extensions ); - size_t templateParamIndex = commandData.params.size() - 1; - - assert( ( vectorParamIndices.size() == 1 ) && - ( vectorParamIndices.find( templateParamIndex ) != vectorParamIndices.end() ) ); + std::string enter, leave; + std::tie( enter, leave ) = generateProtection( commandData.feature, commandData.extensions ); std::string commandName = startLowerCase( stripPrefix( name, "vk" ) ); std::string commandNameSingular = stripPluralS( commandName ); + std::string nodiscard = + ( 1 < commandData.successCodes.size() ) + ? "VULKAN_HPP_NODISCARD " + : ( ( 1 < commandData.errorCodes.size() ) ? "VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS " : "" ); + std::string returnType = ( 1 < commandData.successCodes.size() ) + ? "ResultValue>" + : "typename ResultValueType>::type"; + std::string returnTypeDeprecated = + ( 1 < commandData.successCodes.size() ) ? "Result" : "typename ResultValueType::type"; + std::string returnTypeSingular = + ( 1 < commandData.successCodes.size() ) ? "ResultValue" : "typename ResultValueType::type"; if ( definition ) { @@ -1496,61 +1503,76 @@ ${enter} template #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE template VULKAN_HPP_DEPRECATED( "This function is deprecated. Use one of the other flavours of it.") - VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE typename ResultValueType::type ${className}::${commandName}( ${argumentListEnhancedDeprecated} ) const + ${nodiscard}VULKAN_HPP_INLINE ${returnTypeDeprecated} ${className}::${commandName}( ${argumentListEnhancedDeprecated} ) const { ${functionBodyEnhancedDeprecated} } template - VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE typename ResultValueType>::type ${className}::${commandName}( ${argumentListEnhanced} ) const + ${nodiscard}VULKAN_HPP_INLINE ${returnType} ${className}::${commandName}( ${argumentListEnhanced} ) const { VULKAN_HPP_ASSERT( ${dataSize} % sizeof( T ) == 0 ); std::vector ${dataName}( ${dataSize} / sizeof( T ) ); ${functionCall} - return createResultValue( result, ${dataName}, VULKAN_HPP_NAMESPACE_STRING "::${className}::${commandName}" ); + return createResultValue( result, ${dataName}, VULKAN_HPP_NAMESPACE_STRING "::${className}::${commandName}"${successCodeList} ); } template - VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS typename ResultValueType::type ${className}::${commandNameSingular}( ${argumentListEnhancedSingular} ) const + ${nodiscard}VULKAN_HPP_INLINE ${returnTypeSingular} ${className}::${commandNameSingular}( ${argumentListEnhancedSingular} ) const { T ${dataName}; ${functionCallSingular} - return createResultValue( result, ${dataName}, VULKAN_HPP_NAMESPACE_STRING "::${className}::${commandName}" ); + return createResultValue( result, ${dataName}, VULKAN_HPP_NAMESPACE_STRING "::${className}::${commandName}"${successCodeList} ); } #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ ${leave} )"; std::string functionCall = constructFunctionBodyEnhancedSingleStep( - " ", name, commandData, templateParamIndex, templateParamIndex, vectorParamIndices, false ); + " ", name, commandData, vectorParamIndexIt->first, vectorParamIndexIt->first, vectorParamIndices, false ); std::string functionCallSingular = constructFunctionBodyEnhancedSingleStep( - " ", name, commandData, templateParamIndex, templateParamIndex, vectorParamIndices, true ); + " ", name, commandData, vectorParamIndexIt->first, vectorParamIndexIt->first, vectorParamIndices, true ); + std::string successCodeList; + if ( 1 < commandData.successCodes.size() ) + { + successCodeList = ", { Result::" + createSuccessCode( commandData.successCodes[0], m_tags ); + for ( size_t i = 1; i < commandData.successCodes.size(); ++i ) + { + successCodeList += ", Result::" + createSuccessCode( commandData.successCodes[i], m_tags ); + } + successCodeList += " }"; + } str += replaceWithMap( functionTemplate, std::map( { { "argumentListEnhanced", constructFunctionHeaderArgumentsEnhanced( - commandData, templateParamIndex, templateParamIndex, {}, false, false, false ) }, + commandData, vectorParamIndexIt->first, vectorParamIndexIt->first, {}, false, false, false ) }, { "argumentListEnhancedDeprecated", constructFunctionHeaderArgumentsEnhanced( - commandData, INVALID_INDEX, templateParamIndex, vectorParamIndices, false, false, false ) }, + commandData, INVALID_INDEX, vectorParamIndexIt->first, vectorParamIndices, false, false, false ) }, { "argumentListEnhancedSingular", - constructFunctionHeaderArgumentsEnhanced( - commandData, templateParamIndex, templateParamIndex, vectorParamIndices, true, false, false ) }, + constructFunctionHeaderArgumentsEnhanced( commandData, + vectorParamIndexIt->first, + vectorParamIndexIt->first, + vectorParamIndices, + true, + false, + false ) }, { "argumentListStandard", constructFunctionHeaderArgumentsStandard( commandData, false ) }, { "className", stripPrefix( commandData.handle, "Vk" ) }, { "commandName", commandName }, { "commandNameSingular", commandNameSingular }, - { "dataName", startLowerCase( stripPrefix( commandData.params[templateParamIndex].name, "p" ) ) }, - { "dataSize", commandData.params[templateParamIndex].len }, + { "dataName", startLowerCase( stripPrefix( commandData.params[vectorParamIndexIt->first].name, "p" ) ) }, + { "dataSize", commandData.params[vectorParamIndexIt->first].len }, { "enter", enter }, { "functionBodyEnhancedDeprecated", constructFunctionBodyEnhanced( " ", name, commandData, INVALID_INDEX, - templateParamIndex, + vectorParamIndexIt->first, vectorParamIndices, false, "void", @@ -1562,6 +1584,11 @@ ${leave} { "functionCall", functionCall }, { "functionCallSingular", functionCallSingular }, { "leave", leave }, + { "nodiscard", nodiscard }, + { "successCodeList", successCodeList }, + { "returnType", returnType }, + { "returnTypeDeprecated", returnTypeDeprecated }, + { "returnTypeSingular", returnTypeSingular }, { "vkCommandName", name } } ) ); } else @@ -1571,11 +1598,11 @@ ${enter} template VULKAN_HPP_NODISCARD Result ${commandName}( ${argumentListStandard} ) const VULKAN_HPP_NOEXCEPT; #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE template - VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS typename ResultValueType::type ${commandName}( ${argumentListEnhancedDeprecated} ) const; + ${nodiscard}${returnTypeDeprecated} ${commandName}( ${argumentListEnhancedDeprecated} ) const; template , typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE> - VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS typename ResultValueType>::type ${commandName}( ${argumentListEnhanced} ) const; + ${nodiscard}${returnType} ${commandName}( ${argumentListEnhanced} ) const; template - VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS typename ResultValueType::type ${commandNameSingular}( ${argumentListEnhancedSingular} ) const; + ${nodiscard}${returnTypeSingular} ${commandNameSingular}( ${argumentListEnhancedSingular} ) const; #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ ${leave} )"; @@ -1585,18 +1612,27 @@ ${leave} std::map( { { "argumentListEnhanced", constructFunctionHeaderArgumentsEnhanced( - commandData, templateParamIndex, templateParamIndex, {}, false, true, false ) }, + commandData, vectorParamIndexIt->first, vectorParamIndexIt->first, {}, false, true, false ) }, { "argumentListEnhancedDeprecated", constructFunctionHeaderArgumentsEnhanced( - commandData, INVALID_INDEX, templateParamIndex, vectorParamIndices, false, true, false ) }, + commandData, INVALID_INDEX, vectorParamIndexIt->first, vectorParamIndices, false, true, false ) }, { "argumentListEnhancedSingular", - constructFunctionHeaderArgumentsEnhanced( - commandData, templateParamIndex, templateParamIndex, vectorParamIndices, true, true, false ) }, + constructFunctionHeaderArgumentsEnhanced( commandData, + vectorParamIndexIt->first, + vectorParamIndexIt->first, + vectorParamIndices, + true, + true, + false ) }, { "argumentListStandard", constructFunctionHeaderArgumentsStandard( commandData, true ) }, { "commandName", commandName }, { "commandNameSingular", commandNameSingular }, { "enter", enter }, - { "leave", leave } } ) ); + { "leave", leave }, + { "nodiscard", nodiscard }, + { "returnType", returnType }, + { "returnTypeDeprecated", returnTypeDeprecated }, + { "returnTypeSingular", returnTypeSingular } } ) ); } if ( !commandData.aliasData.empty() ) @@ -1608,7 +1644,7 @@ ${leave} aliasCommandData.extensions = ad.second.extensions; aliasCommandData.feature = ad.second.feature; aliasCommandData.xmlLine = ad.second.xmlLine; - appendCommandFixedSizeVector( str, ad.first, aliasCommandData, definition ); + appendCommandFixedSizeVector( str, ad.first, aliasCommandData, vectorParamIndices, definition ); } } } diff --git a/VulkanHppGenerator.hpp b/VulkanHppGenerator.hpp index 39c1af4..eca0f49 100644 --- a/VulkanHppGenerator.hpp +++ b/VulkanHppGenerator.hpp @@ -311,10 +311,11 @@ private: std::string const & name, CommandData const & commandData, bool definition ) const; - void appendCommandFixedSizeVector( std::string & str, - std::string const & name, - CommandData const & commandData, - bool definition ) const; + void appendCommandFixedSizeVector( std::string & str, + std::string const & name, + CommandData const & commandData, + std::map const & vectorParamIndices, + bool definition ) const; void appendDispatchLoaderDynamicCommand( std::string & str, std::string & emptyFunctions, std::string & deviceFunctions, diff --git a/samples/OcclusionQuery/OcclusionQuery.cpp b/samples/OcclusionQuery/OcclusionQuery.cpp index b2c139b..47d3b0c 100644 --- a/samples/OcclusionQuery/OcclusionQuery.cpp +++ b/samples/OcclusionQuery/OcclusionQuery.cpp @@ -202,14 +202,14 @@ int main( int /*argc*/, char ** /*argv*/ ) graphicsQueue.waitIdle(); - uint64_t samplesPassed[2]; - vk::Result result = device->getQueryPoolResults( queryPool.get(), - 0, - 2, - vk::ArrayProxy( 4, samplesPassed ), - sizeof( uint64_t ), - vk::QueryResultFlagBits::e64 | vk::QueryResultFlagBits::eWait ); - switch ( result ) + vk::ResultValue> rv = + device->getQueryPoolResults( *queryPool, + 0, + 2, + 2 * sizeof( uint64_t ), + sizeof( uint64_t ), + vk::QueryResultFlagBits::e64 | vk::QueryResultFlagBits::eWait ); + switch ( rv.result ) { case vk::Result::eSuccess: break; case vk::Result::eNotReady: std::cout << "vk::Device::getQueryPoolResults returned vk::Result::eNotReady !\n"; @@ -217,8 +217,8 @@ int main( int /*argc*/, char ** /*argv*/ ) } std::cout << "vkGetQueryPoolResults data\n"; - std::cout << "samples_passed[0] = " << samplesPassed[0] << "\n"; - std::cout << "samples_passed[1] = " << samplesPassed[1] << "\n"; + std::cout << "samples_passed[0] = " << rv.value[0] << "\n"; + std::cout << "samples_passed[1] = " << rv.value[1] << "\n"; /* Read back query result from buffer */ uint64_t * samplesPassedPtr = static_cast( @@ -233,7 +233,7 @@ int main( int /*argc*/, char ** /*argv*/ ) while ( vk::Result::eTimeout == device->waitForFences( drawFence.get(), VK_TRUE, vk::su::FenceTimeout ) ) ; - result = presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) ); + vk::Result result = presentQueue.presentKHR( vk::PresentInfoKHR( {}, *swapChainData.swapChain, currentBuffer.value ) ); switch ( result ) { case vk::Result::eSuccess: break; diff --git a/vulkan/vulkan.hpp b/vulkan/vulkan.hpp index 196d59e..87b9dfd 100644 --- a/vulkan/vulkan.hpp +++ b/vulkan/vulkan.hpp @@ -53721,6 +53721,25 @@ namespace VULKAN_HPP_NAMESPACE VULKAN_HPP_NAMESPACE::DeviceSize stride, VULKAN_HPP_NAMESPACE::QueryResultFlags flags, Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; + template , + typename Dispatch = VULKAN_HPP_DEFAULT_DISPATCHER_TYPE> + VULKAN_HPP_NODISCARD ResultValue> + getQueryPoolResults( VULKAN_HPP_NAMESPACE::QueryPool queryPool, + uint32_t firstQuery, + uint32_t queryCount, + size_t dataSize, + VULKAN_HPP_NAMESPACE::DeviceSize stride, + VULKAN_HPP_NAMESPACE::QueryResultFlags flags, + Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; + template + VULKAN_HPP_NODISCARD ResultValue + getQueryPoolResult( VULKAN_HPP_NAMESPACE::QueryPool queryPool, + uint32_t firstQuery, + uint32_t queryCount, + VULKAN_HPP_NAMESPACE::DeviceSize stride, + VULKAN_HPP_NAMESPACE::QueryResultFlags flags, + Dispatch const & d VULKAN_HPP_DEFAULT_DISPATCHER_ASSIGNMENT ) const; #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ #ifdef VK_ENABLE_BETA_EXTENSIONS @@ -95606,8 +95625,8 @@ namespace VULKAN_HPP_NAMESPACE } template - VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS typename ResultValueType::type - Device::getAccelerationStructureHandleNV( VULKAN_HPP_NAMESPACE::AccelerationStructureKHR accelerationStructure, + VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE typename ResultValueType::type + Device::getAccelerationStructureHandleNV( VULKAN_HPP_NAMESPACE::AccelerationStructureKHR accelerationStructure, Dispatch const & d ) const { T data; @@ -97519,16 +97538,18 @@ namespace VULKAN_HPP_NAMESPACE static_cast( stride ), static_cast( flags ) ) ); } + #ifndef VULKAN_HPP_DISABLE_ENHANCED_MODE template - VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE Result - Device::getQueryPoolResults( VULKAN_HPP_NAMESPACE::QueryPool queryPool, - uint32_t firstQuery, - uint32_t queryCount, - ArrayProxy const & data, - VULKAN_HPP_NAMESPACE::DeviceSize stride, - VULKAN_HPP_NAMESPACE::QueryResultFlags flags, - Dispatch const & d ) const + VULKAN_HPP_DEPRECATED( "This function is deprecated. Use one of the other flavours of it." ) + VULKAN_HPP_NODISCARD + VULKAN_HPP_INLINE Result Device::getQueryPoolResults( VULKAN_HPP_NAMESPACE::QueryPool queryPool, + uint32_t firstQuery, + uint32_t queryCount, + ArrayProxy const & data, + VULKAN_HPP_NAMESPACE::DeviceSize stride, + VULKAN_HPP_NAMESPACE::QueryResultFlags flags, + Dispatch const & d ) const { Result result = static_cast( d.vkGetQueryPoolResults( m_device, static_cast( queryPool ), @@ -97541,6 +97562,58 @@ namespace VULKAN_HPP_NAMESPACE return createResultValue( result, VULKAN_HPP_NAMESPACE_STRING "::Device::getQueryPoolResults", { Result::eSuccess, Result::eNotReady } ); } + + template + VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE ResultValue> + Device::getQueryPoolResults( VULKAN_HPP_NAMESPACE::QueryPool queryPool, + uint32_t firstQuery, + uint32_t queryCount, + size_t dataSize, + VULKAN_HPP_NAMESPACE::DeviceSize stride, + VULKAN_HPP_NAMESPACE::QueryResultFlags flags, + Dispatch const & d ) const + { + VULKAN_HPP_ASSERT( dataSize % sizeof( T ) == 0 ); + std::vector data( dataSize / sizeof( T ) ); + Result result = static_cast( d.vkGetQueryPoolResults( m_device, + static_cast( queryPool ), + firstQuery, + queryCount, + data.size() * sizeof( T ), + reinterpret_cast( data.data() ), + static_cast( stride ), + static_cast( flags ) ) ); + + return createResultValue( result, + data, + VULKAN_HPP_NAMESPACE_STRING "::Device::getQueryPoolResults", + { Result::eSuccess, Result::eNotReady } ); + } + + template + VULKAN_HPP_NODISCARD VULKAN_HPP_INLINE ResultValue + Device::getQueryPoolResult( VULKAN_HPP_NAMESPACE::QueryPool queryPool, + uint32_t firstQuery, + uint32_t queryCount, + VULKAN_HPP_NAMESPACE::DeviceSize stride, + VULKAN_HPP_NAMESPACE::QueryResultFlags flags, + Dispatch const & d ) const + { + T data; + Result result = static_cast( d.vkGetQueryPoolResults( m_device, + static_cast( queryPool ), + firstQuery, + queryCount, + 1 * sizeof( T ), + reinterpret_cast( &data ), + static_cast( stride ), + static_cast( flags ) ) ); + + return createResultValue( result, + data, + VULKAN_HPP_NAMESPACE_STRING "::Device::getQueryPoolResults", + { Result::eSuccess, Result::eNotReady } ); + } #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ #ifdef VK_ENABLE_BETA_EXTENSIONS @@ -97602,8 +97675,8 @@ namespace VULKAN_HPP_NAMESPACE } template - VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS typename ResultValueType::type - Device::getRayTracingCaptureReplayShaderGroupHandleKHR( VULKAN_HPP_NAMESPACE::Pipeline pipeline, + VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE typename ResultValueType::type + Device::getRayTracingCaptureReplayShaderGroupHandleKHR( VULKAN_HPP_NAMESPACE::Pipeline pipeline, uint32_t firstGroup, uint32_t groupCount, Dispatch const & d ) const @@ -97681,8 +97754,11 @@ namespace VULKAN_HPP_NAMESPACE } template - VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS typename ResultValueType::type Device::getRayTracingShaderGroupHandleKHR( - VULKAN_HPP_NAMESPACE::Pipeline pipeline, uint32_t firstGroup, uint32_t groupCount, Dispatch const & d ) const + VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE typename ResultValueType::type + Device::getRayTracingShaderGroupHandleKHR( VULKAN_HPP_NAMESPACE::Pipeline pipeline, + uint32_t firstGroup, + uint32_t groupCount, + Dispatch const & d ) const { T data; Result result = static_cast( d.vkGetRayTracingShaderGroupHandlesKHR( m_device, @@ -97754,8 +97830,11 @@ namespace VULKAN_HPP_NAMESPACE } template - VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS typename ResultValueType::type Device::getRayTracingShaderGroupHandleNV( - VULKAN_HPP_NAMESPACE::Pipeline pipeline, uint32_t firstGroup, uint32_t groupCount, Dispatch const & d ) const + VULKAN_HPP_NODISCARD_WHEN_NO_EXCEPTIONS VULKAN_HPP_INLINE typename ResultValueType::type + Device::getRayTracingShaderGroupHandleNV( VULKAN_HPP_NAMESPACE::Pipeline pipeline, + uint32_t firstGroup, + uint32_t groupCount, + Dispatch const & d ) const { T data; Result result = static_cast( d.vkGetRayTracingShaderGroupHandlesNV( m_device,