From e850963599fb17cbb7576befe55bc7b3c9997584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20S=C3=BC=C3=9Fenbach?= Date: Wed, 13 Nov 2019 10:04:50 +0100 Subject: [PATCH] Extend functions returning a std::vector to use an additional local vector for getting the information, and then copy the heads of the StructureChains over to the return vector (#432) Fixes #400 --- VulkanHppGenerator.cpp | 44 +++++++++++++++++++ VulkanHppGenerator.hpp | 1 + .../PhysicalDeviceQueueFamilyProperties.cpp | 26 ----------- vulkan/vulkan.hpp | 44 +++++++++++++++++-- 4 files changed, 85 insertions(+), 30 deletions(-) diff --git a/VulkanHppGenerator.cpp b/VulkanHppGenerator.cpp index e5d1e5e..d527c4b 100644 --- a/VulkanHppGenerator.cpp +++ b/VulkanHppGenerator.cpp @@ -1479,6 +1479,10 @@ void VulkanHppGenerator::appendFunctionBodyEnhanced(std::string & str, std::stri { appendFunctionBodyEnhancedVectorOfUniqueHandles(str, indentation, commandName, commandData, returnParamIndex, templateParamIndex, vectorParamIndices, twoStep, singular, withAllocator); } + else if (isStructureChain && (vectorParamIndices.find(returnParamIndex) != vectorParamIndices.end())) + { + appendFunctionBodyEnhancedVectorOfStructureChain(str, indentation, commandData, returnParamIndex, vectorParamIndices, withAllocator); + } else { if (1 < vectorParamIndices.size()) @@ -1775,6 +1779,46 @@ ${i} ${call2}; }); } +void VulkanHppGenerator::appendFunctionBodyEnhancedVectorOfStructureChain(std::string & str, std::string const& indentation, std::pair const& commandData, size_t returnParamIndex, std::map const& vectorParamIndices, bool withAllocator) const +{ + std::string const stringTemplate = + R"(${i} std::vector ${returnName}${vectorAllocator}; +${i} uint32_t ${sizeName}; +${i} d.${commandName}( m_${handleName}, &${sizeName}, nullptr ); +${i} ${returnName}.resize( ${sizeName} ); +${i} std::vector localVector( ${sizeName} ); +${i} for ( uint32_t i = 0; i < ${sizeName} ; i++ ) +${i} { +${i} localVector[i].pNext = ${returnName}[i].template get().pNext; +${i} } +${i} d.${commandName}( m_${handleName}, &${sizeName}, reinterpret_cast<${VkReturnType}*>( localVector.data() ) ); +${i} for ( uint32_t i = 0; i < ${sizeName} ; i++ ) +${i} { +${i} ${returnName}[i].template get() = localVector[i]; +${i} } +${i} return ${returnName}; +)"; + + // local count variable to hold the size of the vector to fill + std::map::const_iterator returnit = vectorParamIndices.find(returnParamIndex); + assert(returnit != vectorParamIndices.end() && (returnit->second != INVALID_INDEX)); + + assert(m_commandToHandle.find(commandData.first)->second == commandData.second.params[0].type.type); // make sure, the first argument is the handle + assert(commandData.second.params.size() == 3); // make sure, there are three args: the handle, the pointer to size, and the data pointer + + str += replaceWithMap(stringTemplate, + { + { "commandName", commandData.first}, + { "handleName", startLowerCase(stripPrefix(commandData.second.params[0].type.type, "Vk")) }, + { "i", indentation }, + { "returnName", startLowerCase(stripPrefix(commandData.second.params[returnParamIndex].name, "p")) }, + { "returnType", stripPrefix(commandData.second.params[returnParamIndex].type.type, "Vk")}, + { "sizeName", startLowerCase(stripPrefix(commandData.second.params[returnit->second].name, "p"))}, + { "vectorAllocator", withAllocator ? "( vectorAllocator )" : "" }, + { "VkReturnType", commandData.second.params[returnParamIndex].type.type} + }); +} + void VulkanHppGenerator::appendFunctionBodyEnhancedVectorOfUniqueHandles(std::string & str, std::string const& indentation, std::string const& commandName, std::pair const& commandData, size_t returnParamIndex, size_t templateParamIndex, std::map const& vectorParamIndices, bool twoStep, bool singular, bool withAllocator) const { std::string const stringTemplate = diff --git a/VulkanHppGenerator.hpp b/VulkanHppGenerator.hpp index af3a279..75936d4 100644 --- a/VulkanHppGenerator.hpp +++ b/VulkanHppGenerator.hpp @@ -176,6 +176,7 @@ class VulkanHppGenerator void appendFunctionBodyEnhancedReturnResultValue(std::string & str, std::string const& indentation, std::string const& returnName, std::string const& commandName, std::pair const& commandData, size_t returnParamIndex, bool twoStep, bool singular, bool unique) const; void appendFunctionBodyEnhancedSingleStep(std::string & str, std::string const& indentation, std::pair const& commandData, size_t returnParamIndex, size_t templateParamIndex, std::map const& vectorParamIndices, bool singular) const; void appendFunctionBodyEnhancedTwoStep(std::string & str, std::string const& indentation, std::pair const& commandData, size_t returnParamIndex, size_t templateParamIndex, std::map const& vectorParamIndices, bool singular, std::string const& returnName) const; + void appendFunctionBodyEnhancedVectorOfStructureChain(std::string & str, std::string const& indentation, std::pair const& commandData, size_t returnParamIndex, std::map const& vectorParamIndices, bool withAllocator) const; void appendFunctionBodyEnhancedVectorOfUniqueHandles(std::string & str, std::string const& indentation, std::string const& commandName, std::pair const& commandData, size_t returnParamIndex, size_t templateParamIndex, std::map const& vectorParamIndices, bool twoStep, bool singular, bool withAllocator) const; void appendFunctionBodyStandard(std::string & str, std::string const& indentation, std::pair const& commandData) const; void appendFunctionBodyStandardArgument(std::string & str, TypeData const& typeData, std::string const& name) const; diff --git a/samples/PhysicalDeviceQueueFamilyProperties/PhysicalDeviceQueueFamilyProperties.cpp b/samples/PhysicalDeviceQueueFamilyProperties/PhysicalDeviceQueueFamilyProperties.cpp index ae73e12..b70dd4c 100644 --- a/samples/PhysicalDeviceQueueFamilyProperties/PhysicalDeviceQueueFamilyProperties.cpp +++ b/samples/PhysicalDeviceQueueFamilyProperties/PhysicalDeviceQueueFamilyProperties.cpp @@ -24,8 +24,6 @@ static char const* AppName = "PhysicalDeviceQueueFamilyProperties"; static char const* EngineName = "Vulkan.hpp"; -#define USE_WORKAROUND 1 - int main(int /*argc*/, char ** /*argv*/) { try @@ -48,29 +46,13 @@ int main(int /*argc*/, char ** /*argv*/) std::cout << "PhysicalDevice " << i << "\n"; -#if USE_WORKAROUND - uint32_t queueFamilyPropertyCount; - VULKAN_HPP_DEFAULT_DISPATCHER.vkGetPhysicalDeviceQueueFamilyProperties2(physicalDevices[i], &queueFamilyPropertyCount, nullptr); - std::vector queueFamilyProperties2(queueFamilyPropertyCount); - std::vector queueFamilyCheckpointProperties(queueFamilyPropertyCount); - for (uint32_t j=0 ; j(queueFamilyProperties2.data())); -#else // need to explicitly specify all the template arguments for getQueueFamilyProperties2 to make the compiler happy using Chain = vk::StructureChain; auto queueFamilyProperties2 = physicalDevices[i].getQueueFamilyProperties2, vk::DispatchLoaderDynamic>(); -#endif for (size_t j = 0; j < queueFamilyProperties2.size(); j++) { std::cout << "\t" << "QueueFamily " << j << "\n"; -#if USE_WORKAROUND - vk::QueueFamilyProperties const& properties = queueFamilyProperties2[j].queueFamilyProperties; -#else vk::QueueFamilyProperties const& properties = queueFamilyProperties2[j].get().queueFamilyProperties; -#endif std::cout << "\t\t" << "QueueFamilyProperties:\n"; std::cout << "\t\t\t" << "queueFlags = " << vk::to_string(properties.queueFlags) << "\n"; std::cout << "\t\t\t" << "queueCount = " << properties.queueCount << "\n"; @@ -80,17 +62,9 @@ int main(int /*argc*/, char ** /*argv*/) if (vk::su::contains(extensionProperties, "VK_NV_device_diagnostic_checkpoints")) { -#if USE_WORKAROUND - vk::QueueFamilyCheckpointPropertiesNV const* checkpointProperties = static_cast(queueFamilyProperties2[j].pNext); -#else vk::QueueFamilyCheckpointPropertiesNV const& checkpointProperties = queueFamilyProperties2[j].get(); -#endif std::cout << "\t\t" << "CheckPointPropertiesNV:\n"; -#if USE_WORKAROUND - std::cout << "\t\t\t" << "checkpointExecutionStageMask = " << vk::to_string(checkpointProperties->checkpointExecutionStageMask) << "\n"; -#else std::cout << "\t\t\t" << "checkpointExecutionStageMask = " << vk::to_string(checkpointProperties.checkpointExecutionStageMask) << "\n"; -#endif std::cout << "\n"; } } diff --git a/vulkan/vulkan.hpp b/vulkan/vulkan.hpp index 566a7a7..47bdffb 100644 --- a/vulkan/vulkan.hpp +++ b/vulkan/vulkan.hpp @@ -65829,7 +65829,16 @@ namespace VULKAN_HPP_NAMESPACE uint32_t queueFamilyPropertyCount; d.vkGetPhysicalDeviceQueueFamilyProperties2( m_physicalDevice, &queueFamilyPropertyCount, nullptr ); queueFamilyProperties.resize( queueFamilyPropertyCount ); - d.vkGetPhysicalDeviceQueueFamilyProperties2( m_physicalDevice, &queueFamilyPropertyCount, reinterpret_cast( queueFamilyProperties.data() ) ); + std::vector localVector( queueFamilyPropertyCount ); + for ( uint32_t i = 0; i < queueFamilyPropertyCount ; i++ ) + { + localVector[i].pNext = queueFamilyProperties[i].template get().pNext; + } + d.vkGetPhysicalDeviceQueueFamilyProperties2( m_physicalDevice, &queueFamilyPropertyCount, reinterpret_cast( localVector.data() ) ); + for ( uint32_t i = 0; i < queueFamilyPropertyCount ; i++ ) + { + queueFamilyProperties[i].template get() = localVector[i]; + } return queueFamilyProperties; } template @@ -65839,7 +65848,16 @@ namespace VULKAN_HPP_NAMESPACE uint32_t queueFamilyPropertyCount; d.vkGetPhysicalDeviceQueueFamilyProperties2( m_physicalDevice, &queueFamilyPropertyCount, nullptr ); queueFamilyProperties.resize( queueFamilyPropertyCount ); - d.vkGetPhysicalDeviceQueueFamilyProperties2( m_physicalDevice, &queueFamilyPropertyCount, reinterpret_cast( queueFamilyProperties.data() ) ); + std::vector localVector( queueFamilyPropertyCount ); + for ( uint32_t i = 0; i < queueFamilyPropertyCount ; i++ ) + { + localVector[i].pNext = queueFamilyProperties[i].template get().pNext; + } + d.vkGetPhysicalDeviceQueueFamilyProperties2( m_physicalDevice, &queueFamilyPropertyCount, reinterpret_cast( localVector.data() ) ); + for ( uint32_t i = 0; i < queueFamilyPropertyCount ; i++ ) + { + queueFamilyProperties[i].template get() = localVector[i]; + } return queueFamilyProperties; } #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/ @@ -65877,7 +65895,16 @@ namespace VULKAN_HPP_NAMESPACE uint32_t queueFamilyPropertyCount; d.vkGetPhysicalDeviceQueueFamilyProperties2KHR( m_physicalDevice, &queueFamilyPropertyCount, nullptr ); queueFamilyProperties.resize( queueFamilyPropertyCount ); - d.vkGetPhysicalDeviceQueueFamilyProperties2KHR( m_physicalDevice, &queueFamilyPropertyCount, reinterpret_cast( queueFamilyProperties.data() ) ); + std::vector localVector( queueFamilyPropertyCount ); + for ( uint32_t i = 0; i < queueFamilyPropertyCount ; i++ ) + { + localVector[i].pNext = queueFamilyProperties[i].template get().pNext; + } + d.vkGetPhysicalDeviceQueueFamilyProperties2KHR( m_physicalDevice, &queueFamilyPropertyCount, reinterpret_cast( localVector.data() ) ); + for ( uint32_t i = 0; i < queueFamilyPropertyCount ; i++ ) + { + queueFamilyProperties[i].template get() = localVector[i]; + } return queueFamilyProperties; } template @@ -65887,7 +65914,16 @@ namespace VULKAN_HPP_NAMESPACE uint32_t queueFamilyPropertyCount; d.vkGetPhysicalDeviceQueueFamilyProperties2KHR( m_physicalDevice, &queueFamilyPropertyCount, nullptr ); queueFamilyProperties.resize( queueFamilyPropertyCount ); - d.vkGetPhysicalDeviceQueueFamilyProperties2KHR( m_physicalDevice, &queueFamilyPropertyCount, reinterpret_cast( queueFamilyProperties.data() ) ); + std::vector localVector( queueFamilyPropertyCount ); + for ( uint32_t i = 0; i < queueFamilyPropertyCount ; i++ ) + { + localVector[i].pNext = queueFamilyProperties[i].template get().pNext; + } + d.vkGetPhysicalDeviceQueueFamilyProperties2KHR( m_physicalDevice, &queueFamilyPropertyCount, reinterpret_cast( localVector.data() ) ); + for ( uint32_t i = 0; i < queueFamilyPropertyCount ; i++ ) + { + queueFamilyProperties[i].template get() = localVector[i]; + } return queueFamilyProperties; } #endif /*VULKAN_HPP_DISABLE_ENHANCED_MODE*/