fixed getting featureCount for Vk11/12/13 feature structs
This commit is contained in:
parent
b5b1f345bc
commit
d1407a839b
@ -1,5 +1,6 @@
|
||||
#include "vulkan_util.hpp"
|
||||
#include <bits/ranges_base.h>
|
||||
#include <gz-util/string/conversion.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#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
|
||||
|
||||
|
@ -176,15 +176,15 @@ namespace gz::vlk {
|
||||
template<typename 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 {
|
||||
std::vector<Vertex3D> vertices;
|
||||
std::vector<T> indices;
|
||||
std::vector<VertexT> vertices;
|
||||
std::vector<IndexT> indices;
|
||||
constexpr vk::IndexType getIndexType() const {
|
||||
if (std::same_as<T, uint16_t>) {
|
||||
if constexpr (std::same_as<IndexT, uint16_t>) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -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<uint64_t> handles;
|
||||
@ -308,16 +309,14 @@ namespace gz::vlk {
|
||||
*/
|
||||
virtual void updateHandles() override;
|
||||
private:
|
||||
/// 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() {}
|
||||
// Recursively call addHandles for every member of the pack
|
||||
/// Add reinterpret_cast<uint64_t>(static_cast<PHandle::NativeType>(handle)) to handles set
|
||||
template<PtrToVulkanHppHandle PHandle>
|
||||
void addHandles(const PHandle& pHandle);
|
||||
template<PtrToVulkanHppHandleRange PHandleRange>
|
||||
void addHandles(const PHandleRange& pHandleRange);
|
||||
template<PtrToVulkanHppHandle PHandle, PtrToVulkanHppHandleConvertible... PHandleConvertibles>
|
||||
void addHandles(const PHandle& pHandle, const PHandleConvertibles&&... pHandleConvertibles);
|
||||
template<PtrToVulkanHppHandleRange PHandleRange, PtrToVulkanHppHandleConvertible... PHandleConvertibles>
|
||||
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<T...> handlePack;
|
||||
@ -334,31 +333,26 @@ namespace gz::vlk {
|
||||
template<PtrToVulkanHppHandleConvertible... T>
|
||||
void ObjectUsingVulkan<T...>::updateHandles() {
|
||||
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(std::bind(&addHandles, this, std::placeholders::_1), handlePack); */
|
||||
}
|
||||
|
||||
template<PtrToVulkanHppHandleConvertible... T>
|
||||
template<PtrToVulkanHppHandleConvertible PHandleConvertible, PtrToVulkanHppHandleConvertible... PHandleConvertibles>
|
||||
void ObjectUsingVulkan<T...>::addHandlesProxy(const PHandleConvertible&& pHandleConvertible, const PHandleConvertibles&&... pHandleConvertibles) {
|
||||
addHandles(pHandleConvertible);
|
||||
addHandlesProxy(std::forward<const PHandleConvertibles>(pHandleConvertibles)...);
|
||||
}
|
||||
|
||||
template<PtrToVulkanHppHandleConvertible... T>
|
||||
template<PtrToVulkanHppHandle PHandle>
|
||||
void ObjectUsingVulkan<T...>::addHandles(const PHandle& pHandle) {
|
||||
template<PtrToVulkanHppHandle PHandle, PtrToVulkanHppHandleConvertible... PHandleConvertibles>
|
||||
void ObjectUsingVulkan<T...>::addHandles(const PHandle& pHandle, const PHandleConvertibles&&... pHandleConvertibles) {
|
||||
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<PtrToVulkanHppHandleRange PHandleRange>
|
||||
void ObjectUsingVulkan<T...>::addHandles(const PHandleRange& pHandleRange) {
|
||||
template<PtrToVulkanHppHandleRange PHandleRange, PtrToVulkanHppHandleConvertible... PHandleConvertibles>
|
||||
void ObjectUsingVulkan<T...>::addHandles(const PHandleRange& pHandleRange, const PHandleConvertibles&&... pHandleConvertibles) {
|
||||
for (auto it = pHandleRange->begin(); it != pHandleRange->end(); it++) {
|
||||
handles.insert(reinterpret_cast<uint64_t>(
|
||||
static_cast<typename std::ranges::range_value_t<std::remove_pointer_t<PHandleRange>>::NativeType>(*it)));
|
||||
}
|
||||
addHandles(std::forward<const PHandleConvertibles>(pHandleConvertibles)...);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user