Skip to content

Commit

Permalink
Guard vulkan.h inclusion with __has_include
Browse files Browse the repository at this point in the history
...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 <[email protected]>
Reviewed-by: Andy Nichols <[email protected]>
  • Loading branch information
alpqr committed Oct 16, 2020
1 parent ada6e4f commit 696d94b
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/gui/vulkan/qvulkaninstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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

0 comments on commit 696d94b

Please sign in to comment.