diff --git a/src/utility/vulkan_util.cpp b/src/utility/vulkan_util.cpp index b2e412f..8244a82 100644 --- a/src/utility/vulkan_util.cpp +++ b/src/utility/vulkan_util.cpp @@ -1,5 +1,6 @@ #include "vulkan_util.hpp" #include +#include #include #define VULKAN_HPP_NO_CONSTRUCTORS @@ -23,8 +24,9 @@ namespace gz::vlk { /* static_assert(sizeof(VkPhysicalDeviceFeatures) != sizeof(vk::PhysicalDeviceFeatures), "Objects do not have same size"); */ bool PhysicalDeviceFeatures::requiredFeaturesAvailable(const PhysicalDeviceFeatures& requiredFeatures) const { // iterate over all the features in the structs - // VkPhysicalDeviceFeatures2 - size_t featureCount = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32); + // VkPhysicalDeviceFeatures2.features + // feature count is size/vkbool + size_t featureCount = 55; //sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32); // pointer to first feature const VkBool32* pFeature = &f.features.robustBufferAccess; const VkBool32* pRequiredFeature = &requiredFeatures.f.features.robustBufferAccess; @@ -35,9 +37,12 @@ namespace gz::vlk { } } + static_assert(sizeof(VkBool32) == alignof(VkBool32)); + // VkPhysicalDeviceVulkan11Features - // pointer to first feature: after sType and pNext - featureCount = (sizeof(VkPhysicalDeviceVulkan11Features) - sizeof(VkStructureType) - sizeof(void*)) / sizeof(VkBool32); + // number of VkBool32 members after sType and pNext + featureCount = 12; + // pointer to first feature pFeature = &f11.storageBuffer16BitAccess; pRequiredFeature = &requiredFeatures.f11.storageBuffer16BitAccess; for (size_t i = 0; i < featureCount; i++) { @@ -48,8 +53,9 @@ namespace gz::vlk { } // VkPhysicalDeviceVulkan12Features - // pointer to first feature: after sType and pNext - featureCount = (sizeof(VkPhysicalDeviceVulkan12Features) - sizeof(VkStructureType) - sizeof(void*)) / sizeof(VkBool32); + // number of VkBool32 members after sType and pNext + featureCount = 47; + // pointer to first feature pFeature = &f12.samplerMirrorClampToEdge; pRequiredFeature = &requiredFeatures.f12.samplerMirrorClampToEdge; for (size_t i = 0; i < featureCount; i++) { @@ -60,8 +66,9 @@ namespace gz::vlk { } // VkPhysicalDeviceVulkan13Features - // pointer to first feature: after sType and pNext - featureCount = (sizeof(VkPhysicalDeviceVulkan13Features) - sizeof(VkStructureType) - sizeof(void*)) / sizeof(VkBool32); + // number of VkBool32 members after sType and pNext + featureCount = 15; + // pointer to first feature pFeature = &f13.robustImageAccess; pRequiredFeature = &requiredFeatures.f13.robustImageAccess; for (size_t i = 0; i < featureCount; i++) { @@ -99,6 +106,11 @@ namespace gz::vlk { /* memReq = device.getImageMemoryRequirements2(imMemReq); */ /* } */ + std::string ObjectUsingVulkanBase::toString() const { + std::string s = "Handles of " + objectName + ": "; + s += gz::toHexString(handles); + return s; + } } // namespace gz::vlk diff --git a/src/utility/vulkan_util.hpp b/src/utility/vulkan_util.hpp index cc4bedd..78900e1 100644 --- a/src/utility/vulkan_util.hpp +++ b/src/utility/vulkan_util.hpp @@ -176,15 +176,15 @@ namespace gz::vlk { template concept SupportedIndexType = std::same_as or std::same_as; - template + template struct VerticesAndIndices { - std::vector vertices; - std::vector indices; + std::vector vertices; + std::vector indices; constexpr vk::IndexType getIndexType() const { - if (std::same_as) { + if constexpr (std::same_as) { return vk::IndexType::eUint16; } - else if (std::same_as) { + else if constexpr (std::same_as) { return vk::IndexType::eUint32; } } @@ -253,6 +253,7 @@ namespace gz::vlk { virtual void updateHandles() {}; bool contains(const uint64_t& handle) const { return handles.contains(handle); }; const std::string& getName() const { return objectName; }; + std::string toString() const; protected: std::string objectName; std::set handles; @@ -308,16 +309,14 @@ namespace gz::vlk { */ virtual void updateHandles() override; private: - /// Recursively call addHandles for every member of the pack - template - void addHandlesProxy(const PHandleConvertible&& pHandleConvertible, const PHandleConvertibles&&... pHandleConvertibles); - /// End of recursion - void addHandlesProxy() {} + // Recursively call addHandles for every member of the pack /// Add reinterpret_cast(static_cast(handle)) to handles set - template - void addHandles(const PHandle& pHandle); - template - void addHandles(const PHandleRange& pHandleRange); + template + void addHandles(const PHandle& pHandle, const PHandleConvertibles&&... pHandleConvertibles); + template + void addHandles(const PHandleRange& pHandleRange, const PHandleConvertibles&&... pHandleConvertibles); + /// End of recursion + void addHandles() {} /// Contains pointers to (vulkan.hpp handles or ranges of vulkan.hpp handles) std::tuple handlePack; @@ -334,31 +333,26 @@ namespace gz::vlk { template void ObjectUsingVulkan::updateHandles() { handles.clear(); - auto f = [this](auto... args){ this->addHandlesProxy(std::forward(args)...); }; + // cant std::apply pack directly on addHandles, since that takes a this ptr + auto f = [this](auto... args){ this->addHandles(std::forward(args)...); }; std::apply(f, handlePack); - /* std::apply(std::bind(&addHandles, this, std::placeholders::_1), handlePack); */ } template - template - void ObjectUsingVulkan::addHandlesProxy(const PHandleConvertible&& pHandleConvertible, const PHandleConvertibles&&... pHandleConvertibles) { - addHandles(pHandleConvertible); - addHandlesProxy(std::forward(pHandleConvertibles)...); - } - - template - template - void ObjectUsingVulkan::addHandles(const PHandle& pHandle) { + template + void ObjectUsingVulkan::addHandles(const PHandle& pHandle, const PHandleConvertibles&&... pHandleConvertibles) { handles.insert(reinterpret_cast(static_cast::NativeType>(*pHandle))); + addHandles(std::forward(pHandleConvertibles)...); } template - template - void ObjectUsingVulkan::addHandles(const PHandleRange& pHandleRange) { + template + void ObjectUsingVulkan::addHandles(const PHandleRange& pHandleRange, const PHandleConvertibles&&... pHandleConvertibles) { for (auto it = pHandleRange->begin(); it != pHandleRange->end(); it++) { handles.insert(reinterpret_cast( static_cast>::NativeType>(*it))); } + addHandles(std::forward(pHandleConvertibles)...); }