summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2020-10-13 13:23:32 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2020-10-16 09:48:09 +0200
commit696d94b132b2f352b5e6b889ad91c2437417fae8 (patch)
treee41e5160f3e4414014250f7594522714e4b14128 /src
parentada6e4fbe9f363a33d4f9341bbc468d22c0c1442 (diff)
Guard vulkan.h inclusion with __has_include
...and provide our dummy typedefs when vulkan.h is not available. Originally this was there for qdoc, but from the qtdeclarative API review it becomes clear that we need this also when an application - that includes Qt Quick headers which in turn want to use VkImage and co. for type safety - is built on a system without vulkan.h against a Vulkan-enabled Qt build. Also fix some of the typedefs which were technically incorrect. (not that it matters much since the dummy typedefs still do not allow calling exported Qt functions that use the real Vk* types since the function signatures like won't match in some cases (would need to replicate too much hocus pocus from vulkan.h for that), but that's fine since our goal here is to keep application compilation going when it encounters a Vk* type in a Qt header, not about enabling actually calling those functions) Task-number: QTBUG-87450 Change-Id: I855b4478c8707587b28db2408e282145129a0194 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/gui/vulkan/qvulkaninstance.h26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/gui/vulkan/qvulkaninstance.h b/src/gui/vulkan/qvulkaninstance.h
index 698285d12e..618f8a9e40 100644
--- a/src/gui/vulkan/qvulkaninstance.h
+++ b/src/gui/vulkan/qvulkaninstance.h
@@ -52,22 +52,36 @@
#ifndef VK_NO_PROTOTYPES
#define VK_NO_PROTOTYPES
#endif
-#ifndef Q_CLANG_QDOC
+#if !defined(Q_CLANG_QDOC) && __has_include(<vulkan/vulkan.h>)
#include <vulkan/vulkan.h>
#else
+// QT_CONFIG(vulkan) implies vulkan.h being available at Qt build time, but it
+// does not guarantee vulkan.h is available at *application* build time. Both
+// for qdoc and for apps built on systems without Vulkan SDK we provide a set
+// of typedefs to keep things compiling since this header may be included from
+// Qt Quick and elsewhere just to get types like VkImage and friends defined.
+
typedef void* PFN_vkVoidFunction;
-typedef unsigned long VkSurfaceKHR;
-typedef unsigned long VkImage;
-typedef unsigned long VkImageView;
+// non-dispatchable handles (64-bit regardless of arch)
+typedef quint64 VkSurfaceKHR;
+typedef quint64 VkImage;
+typedef quint64 VkImageView;
+// dispatchable handles (32 or 64-bit depending on arch)
typedef void* VkInstance;
typedef void* VkPhysicalDevice;
typedef void* VkDevice;
+// enums
typedef int VkResult;
typedef int VkImageLayout;
typedef int VkDebugReportFlagsEXT;
typedef int VkDebugReportObjectTypeEXT;
#endif
+// QVulkanInstance itself is only applicable if vulkan.h is available, or if
+// it's qdoc. An application that is built on a vulkan.h-less system against a
+// Vulkan-enabled Qt gets the dummy typedefs but not QVulkan*.
+#if __has_include(<vulkan/vulkan.h>) || defined(Q_CLANG_QDOC)
+
#include <QtCore/qbytearraylist.h>
#include <QtCore/qdebug.h>
#include <QtCore/qhashfunctions.h>
@@ -211,6 +225,8 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QVulkanInstance::Flags)
QT_END_NAMESPACE
-#endif // QT_CONFIG(vulkan)
+#endif // __has_include(<vulkan/vulkan.h>) || defined(Q_CLANG_QDOC)
+
+#endif // QT_CONFIG(vulkan) || defined(Q_CLANG_QDOC)
#endif // QVULKANINSTANCE_H