fixed getting featureCount for Vk11/12/13 feature structs

This commit is contained in:
matthias@arch 2022-11-10 16:57:46 +01:00
parent b5b1f345bc
commit d1407a839b
2 changed files with 41 additions and 35 deletions

View File

@ -1,5 +1,6 @@
#include "vulkan_util.hpp" #include "vulkan_util.hpp"
#include <bits/ranges_base.h> #include <bits/ranges_base.h>
#include <gz-util/string/conversion.hpp>
#include <iostream> #include <iostream>
#define VULKAN_HPP_NO_CONSTRUCTORS #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"); */ /* static_assert(sizeof(VkPhysicalDeviceFeatures) != sizeof(vk::PhysicalDeviceFeatures), "Objects do not have same size"); */
bool PhysicalDeviceFeatures::requiredFeaturesAvailable(const PhysicalDeviceFeatures& requiredFeatures) const { bool PhysicalDeviceFeatures::requiredFeaturesAvailable(const PhysicalDeviceFeatures& requiredFeatures) const {
// iterate over all the features in the structs // iterate over all the features in the structs
// VkPhysicalDeviceFeatures2 // VkPhysicalDeviceFeatures2.features
size_t featureCount = sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32); // feature count is size/vkbool
size_t featureCount = 55; //sizeof(VkPhysicalDeviceFeatures) / sizeof(VkBool32);
// pointer to first feature // pointer to first feature
const VkBool32* pFeature = &f.features.robustBufferAccess; const VkBool32* pFeature = &f.features.robustBufferAccess;
const VkBool32* pRequiredFeature = &requiredFeatures.f.features.robustBufferAccess; const VkBool32* pRequiredFeature = &requiredFeatures.f.features.robustBufferAccess;
@ -35,9 +37,12 @@ namespace gz::vlk {
} }
} }
static_assert(sizeof(VkBool32) == alignof(VkBool32));
// VkPhysicalDeviceVulkan11Features // VkPhysicalDeviceVulkan11Features
// pointer to first feature: after sType and pNext // number of VkBool32 members after sType and pNext
featureCount = (sizeof(VkPhysicalDeviceVulkan11Features) - sizeof(VkStructureType) - sizeof(void*)) / sizeof(VkBool32); featureCount = 12;
// pointer to first feature
pFeature = &f11.storageBuffer16BitAccess; pFeature = &f11.storageBuffer16BitAccess;
pRequiredFeature = &requiredFeatures.f11.storageBuffer16BitAccess; pRequiredFeature = &requiredFeatures.f11.storageBuffer16BitAccess;
for (size_t i = 0; i < featureCount; i++) { for (size_t i = 0; i < featureCount; i++) {
@ -48,8 +53,9 @@ namespace gz::vlk {
} }
// VkPhysicalDeviceVulkan12Features // VkPhysicalDeviceVulkan12Features
// pointer to first feature: after sType and pNext // number of VkBool32 members after sType and pNext
featureCount = (sizeof(VkPhysicalDeviceVulkan12Features) - sizeof(VkStructureType) - sizeof(void*)) / sizeof(VkBool32); featureCount = 47;
// pointer to first feature
pFeature = &f12.samplerMirrorClampToEdge; pFeature = &f12.samplerMirrorClampToEdge;
pRequiredFeature = &requiredFeatures.f12.samplerMirrorClampToEdge; pRequiredFeature = &requiredFeatures.f12.samplerMirrorClampToEdge;
for (size_t i = 0; i < featureCount; i++) { for (size_t i = 0; i < featureCount; i++) {
@ -60,8 +66,9 @@ namespace gz::vlk {
} }
// VkPhysicalDeviceVulkan13Features // VkPhysicalDeviceVulkan13Features
// pointer to first feature: after sType and pNext // number of VkBool32 members after sType and pNext
featureCount = (sizeof(VkPhysicalDeviceVulkan13Features) - sizeof(VkStructureType) - sizeof(void*)) / sizeof(VkBool32); featureCount = 15;
// pointer to first feature
pFeature = &f13.robustImageAccess; pFeature = &f13.robustImageAccess;
pRequiredFeature = &requiredFeatures.f13.robustImageAccess; pRequiredFeature = &requiredFeatures.f13.robustImageAccess;
for (size_t i = 0; i < featureCount; i++) { for (size_t i = 0; i < featureCount; i++) {
@ -99,6 +106,11 @@ namespace gz::vlk {
/* memReq = device.getImageMemoryRequirements2(imMemReq); */ /* memReq = device.getImageMemoryRequirements2(imMemReq); */
/* } */ /* } */
std::string ObjectUsingVulkanBase::toString() const {
std::string s = "Handles of " + objectName + ": ";
s += gz::toHexString(handles);
return s;
}
} // namespace gz::vlk } // namespace gz::vlk

View File

@ -176,15 +176,15 @@ namespace gz::vlk {
template<typename T> template<typename T>
concept SupportedIndexType = std::same_as<T, uint16_t> or std::same_as<T, uint32_t>; concept SupportedIndexType = std::same_as<T, uint16_t> or std::same_as<T, uint32_t>;
template<SupportedIndexType T> template<VertexType VertexT = Vertex3D, SupportedIndexType IndexT = uint32_t>
struct VerticesAndIndices { struct VerticesAndIndices {
std::vector<Vertex3D> vertices; std::vector<VertexT> vertices;
std::vector<T> indices; std::vector<IndexT> indices;
constexpr vk::IndexType getIndexType() const { constexpr vk::IndexType getIndexType() const {
if (std::same_as<T, uint16_t>) { if constexpr (std::same_as<IndexT, uint16_t>) {
return vk::IndexType::eUint16; return vk::IndexType::eUint16;
} }
else if (std::same_as<T, uint32_t>) { else if constexpr (std::same_as<IndexT, uint32_t>) {
return vk::IndexType::eUint32; return vk::IndexType::eUint32;
} }
} }
@ -253,6 +253,7 @@ namespace gz::vlk {
virtual void updateHandles() {}; virtual void updateHandles() {};
bool contains(const uint64_t& handle) const { return handles.contains(handle); }; bool contains(const uint64_t& handle) const { return handles.contains(handle); };
const std::string& getName() const { return objectName; }; const std::string& getName() const { return objectName; };
std::string toString() const;
protected: protected:
std::string objectName; std::string objectName;
std::set<uint64_t> handles; std::set<uint64_t> handles;
@ -308,16 +309,14 @@ namespace gz::vlk {
*/ */
virtual void updateHandles() override; virtual void updateHandles() override;
private: private:
/// Recursively call addHandles for every member of the pack // Recursively call addHandles for every member of the pack
template<PtrToVulkanHppHandleConvertible PHandleConvertible, PtrToVulkanHppHandleConvertible... PHandleConvertibles>
void addHandlesProxy(const PHandleConvertible&& pHandleConvertible, const PHandleConvertibles&&... pHandleConvertibles);
/// End of recursion
void addHandlesProxy() {}
/// Add reinterpret_cast<uint64_t>(static_cast<PHandle::NativeType>(handle)) to handles set /// Add reinterpret_cast<uint64_t>(static_cast<PHandle::NativeType>(handle)) to handles set
template<PtrToVulkanHppHandle PHandle> template<PtrToVulkanHppHandle PHandle, PtrToVulkanHppHandleConvertible... PHandleConvertibles>
void addHandles(const PHandle& pHandle); void addHandles(const PHandle& pHandle, const PHandleConvertibles&&... pHandleConvertibles);
template<PtrToVulkanHppHandleRange PHandleRange> template<PtrToVulkanHppHandleRange PHandleRange, PtrToVulkanHppHandleConvertible... PHandleConvertibles>
void addHandles(const PHandleRange& pHandleRange); 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) /// Contains pointers to (vulkan.hpp handles or ranges of vulkan.hpp handles)
std::tuple<T...> handlePack; std::tuple<T...> handlePack;
@ -334,31 +333,26 @@ namespace gz::vlk {
template<PtrToVulkanHppHandleConvertible... T> template<PtrToVulkanHppHandleConvertible... T>
void ObjectUsingVulkan<T...>::updateHandles() { void ObjectUsingVulkan<T...>::updateHandles() {
handles.clear(); handles.clear();
auto f = [this](auto... args){ this->addHandlesProxy(std::forward<decltype(args)>(args)...); }; // cant std::apply pack directly on addHandles, since that takes a this ptr
auto f = [this](auto... args){ this->addHandles(std::forward<decltype(args)>(args)...); };
std::apply(f, handlePack); std::apply(f, handlePack);
/* std::apply(std::bind(&addHandles, this, std::placeholders::_1), handlePack); */
} }
template<PtrToVulkanHppHandleConvertible... T> template<PtrToVulkanHppHandleConvertible... T>
template<PtrToVulkanHppHandleConvertible PHandleConvertible, PtrToVulkanHppHandleConvertible... PHandleConvertibles> template<PtrToVulkanHppHandle PHandle, PtrToVulkanHppHandleConvertible... PHandleConvertibles>
void ObjectUsingVulkan<T...>::addHandlesProxy(const PHandleConvertible&& pHandleConvertible, const PHandleConvertibles&&... pHandleConvertibles) { void ObjectUsingVulkan<T...>::addHandles(const PHandle& pHandle, const PHandleConvertibles&&... pHandleConvertibles) {
addHandles(pHandleConvertible);
addHandlesProxy(std::forward<const PHandleConvertibles>(pHandleConvertibles)...);
}
template<PtrToVulkanHppHandleConvertible... T>
template<PtrToVulkanHppHandle PHandle>
void ObjectUsingVulkan<T...>::addHandles(const PHandle& pHandle) {
handles.insert(reinterpret_cast<uint64_t>(static_cast<typename std::remove_pointer_t<PHandle>::NativeType>(*pHandle))); handles.insert(reinterpret_cast<uint64_t>(static_cast<typename std::remove_pointer_t<PHandle>::NativeType>(*pHandle)));
addHandles(std::forward<const PHandleConvertibles>(pHandleConvertibles)...);
} }
template<PtrToVulkanHppHandleConvertible... T> template<PtrToVulkanHppHandleConvertible... T>
template<PtrToVulkanHppHandleRange PHandleRange> template<PtrToVulkanHppHandleRange PHandleRange, PtrToVulkanHppHandleConvertible... PHandleConvertibles>
void ObjectUsingVulkan<T...>::addHandles(const PHandleRange& pHandleRange) { void ObjectUsingVulkan<T...>::addHandles(const PHandleRange& pHandleRange, const PHandleConvertibles&&... pHandleConvertibles) {
for (auto it = pHandleRange->begin(); it != pHandleRange->end(); it++) { for (auto it = pHandleRange->begin(); it != pHandleRange->end(); it++) {
handles.insert(reinterpret_cast<uint64_t>( handles.insert(reinterpret_cast<uint64_t>(
static_cast<typename std::ranges::range_value_t<std::remove_pointer_t<PHandleRange>>::NativeType>(*it))); static_cast<typename std::ranges::range_value_t<std::remove_pointer_t<PHandleRange>>::NativeType>(*it)));
} }
addHandles(std::forward<const PHandleConvertibles>(pHandleConvertibles)...);
} }