Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qvulkaninstance.h
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QVULKANINSTANCE_H
6#define QVULKANINSTANCE_H
7
8#include <QtGui/qtguiglobal.h>
9
10#if 0
11#pragma qt_no_master_include
12#pragma qt_sync_skip_header_check
13#endif
14
15#if QT_CONFIG(vulkan) || defined(Q_QDOC)
16
17#ifndef VK_NO_PROTOTYPES
18#define VK_NO_PROTOTYPES
19#endif
20#if !defined(Q_QDOC) && __has_include(<vulkan/vulkan.h>)
21#include <vulkan/vulkan.h>
22#else
23// QT_CONFIG(vulkan) implies vulkan.h being available at Qt build time, but it
24// does not guarantee vulkan.h is available at *application* build time. Both
25// for qdoc and for apps built on systems without Vulkan SDK we provide a set
26// of typedefs to keep things compiling since this header may be included from
27// Qt Quick and elsewhere just to get types like VkImage and friends defined.
28
29typedef void* PFN_vkVoidFunction;
30// non-dispatchable handles (64-bit regardless of arch)
31typedef quint64 VkSurfaceKHR;
32typedef quint64 VkImage;
33typedef quint64 VkImageView;
34// dispatchable handles (32 or 64-bit depending on arch)
35typedef void* VkInstance;
36typedef void* VkPhysicalDevice;
37typedef void* VkDevice;
38// enums
39typedef int VkResult;
40typedef int VkFormat;
41typedef int VkImageLayout;
42typedef int VkDebugReportFlagsEXT;
43typedef int VkDebugReportObjectTypeEXT;
44typedef int VkDeviceQueueCreateFlags;
45#endif
46
47// QVulkanInstance itself is only applicable if vulkan.h is available, or if
48// it's qdoc. An application that is built on a vulkan.h-less system against a
49// Vulkan-enabled Qt gets the dummy typedefs but not QVulkan*.
50#if __has_include(<vulkan/vulkan.h>) || defined(Q_QDOC)
51
52#include <QtCore/qbytearraylist.h>
53#include <QtCore/qhashfunctions.h>
54#include <QtCore/qlist.h>
55#include <QtCore/qscopedpointer.h>
56#include <QtCore/qversionnumber.h>
57
58QT_BEGIN_NAMESPACE
59
60class QDebug;
61
62class QVulkanInstancePrivate;
63class QPlatformVulkanInstance;
64class QVulkanFunctions;
65class QVulkanDeviceFunctions;
66class QWindow;
67
68struct QVulkanLayer
69{
70 QByteArray name;
71 uint32_t version;
72 QVersionNumber specVersion;
73 QByteArray description;
74};
75Q_DECLARE_TYPEINFO(QVulkanLayer, Q_RELOCATABLE_TYPE);
76
77inline bool operator==(const QVulkanLayer &lhs, const QVulkanLayer &rhs) noexcept
78{
79 return lhs.name == rhs.name && lhs.version == rhs.version && lhs.specVersion == rhs.specVersion;
80}
81inline bool operator!=(const QVulkanLayer &lhs, const QVulkanLayer &rhs) noexcept
82{ return !(lhs == rhs); }
83
84inline size_t qHash(const QVulkanLayer &key, size_t seed = 0) noexcept
85{
86 QtPrivate::QHashCombine hash(seed);
87 seed = hash(seed, key.name);
88 seed = hash(seed, key.version);
89 seed = hash(seed, key.specVersion);
90 return seed;
91}
92
93struct QVulkanExtension
94{
95 QByteArray name;
96 uint32_t version;
97};
98Q_DECLARE_TYPEINFO(QVulkanExtension, Q_RELOCATABLE_TYPE);
99
100inline bool operator==(const QVulkanExtension &lhs, const QVulkanExtension &rhs) noexcept
101{
102 return lhs.name == rhs.name && lhs.version == rhs.version;
103}
104inline bool operator!=(const QVulkanExtension &lhs, const QVulkanExtension &rhs) noexcept
105{ return !(lhs == rhs); }
106
107inline size_t qHash(const QVulkanExtension &key, size_t seed = 0) noexcept
108{
109 QtPrivate::QHashCombine hash(seed);
110 seed = hash(seed, key.name);
111 seed = hash(seed, key.version);
112 return seed;
113}
114
115#ifndef QT_NO_DEBUG_STREAM
116Q_GUI_EXPORT QDebug operator<<(QDebug, const QVulkanLayer &);
117Q_GUI_EXPORT QDebug operator<<(QDebug, const QVulkanExtension &);
118#endif
119
120template<typename T>
121class QVulkanInfoVector : public QList<T>
122{
123public:
124 bool contains(const QByteArray &name) const {
125 return std::any_of(this->cbegin(), this->cend(), [&](const T &entry) {
126 return entry.name == name; });
127 }
128 bool contains(const QByteArray &name, int minVersion) const {
129 return std::any_of(this->cbegin(), this->cend(), [&](const T &entry) {
130 return entry.name == name && entry.version >= minVersion; });
131 }
132};
133
134class Q_GUI_EXPORT QVulkanInstance
135{
136public:
137 QVulkanInstance();
138 ~QVulkanInstance();
139
140 enum Flag {
141 NoDebugOutputRedirect = 0x01,
142 NoPortabilityDrivers = 0x02
143 };
144 Q_DECLARE_FLAGS(Flags, Flag)
145
146 // ### Qt 7: remove non-const overloads
147 QVulkanInfoVector<QVulkanLayer> supportedLayers();
148 inline QVulkanInfoVector<QVulkanLayer> supportedLayers() const
149 { return const_cast<QVulkanInstance*>(this)->supportedLayers(); }
150 QVulkanInfoVector<QVulkanExtension> supportedExtensions();
151 inline QVulkanInfoVector<QVulkanExtension> supportedExtensions() const
152 { return const_cast<QVulkanInstance*>(this)->supportedExtensions(); }
153 QVersionNumber supportedApiVersion() const;
154
155 void setVkInstance(VkInstance existingVkInstance);
156
157 void setFlags(Flags flags);
158 void setLayers(const QByteArrayList &layers);
159 void setExtensions(const QByteArrayList &extensions);
160 void setApiVersion(const QVersionNumber &vulkanVersion);
161
162 bool create();
163 void destroy();
164 bool isValid() const;
165 VkResult errorCode() const;
166
167 VkInstance vkInstance() const;
168
169 Flags flags() const;
170 QByteArrayList layers() const;
171 QByteArrayList extensions() const;
172 QVersionNumber apiVersion() const;
173
174 PFN_vkVoidFunction getInstanceProcAddr(const char *name);
175
176 QPlatformVulkanInstance *handle() const;
177
178 QVulkanFunctions *functions() const;
179 QVulkanDeviceFunctions *deviceFunctions(VkDevice device);
180 void resetDeviceFunctions(VkDevice device);
181
182 static VkSurfaceKHR surfaceForWindow(QWindow *window);
183
184 bool supportsPresent(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, QWindow *window);
185
186 void presentAboutToBeQueued(QWindow *window);
187 void presentQueued(QWindow *window);
188
189 typedef bool (*DebugFilter)(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objectType, uint64_t object,
190 size_t location, int32_t messageCode, const char *pLayerPrefix, const char *pMessage);
191 void installDebugOutputFilter(DebugFilter filter);
192 void removeDebugOutputFilter(DebugFilter filter);
193
194 enum DebugMessageSeverityFlag {
195 VerboseSeverity = 0x01,
196 InfoSeverity = 0x02,
197 WarningSeverity = 0x04,
198 ErrorSeverity = 0x08
199 };
200 Q_DECLARE_FLAGS(DebugMessageSeverityFlags, DebugMessageSeverityFlag)
201
202 enum DebugMessageTypeFlag {
203 GeneralMessage = 0x01,
204 ValidationMessage = 0x02,
205 PerformanceMessage = 0x04
206 };
207 Q_DECLARE_FLAGS(DebugMessageTypeFlags, DebugMessageTypeFlag)
208
209 using DebugUtilsFilter = std::function<bool(DebugMessageSeverityFlags severity, DebugMessageTypeFlags type, const void *message)>;
210 void installDebugOutputFilter(DebugUtilsFilter filter);
211 void clearDebugOutputFilters();
212
213private:
214 friend class QVulkanInstancePrivate;
215 QScopedPointer<QVulkanInstancePrivate> d_ptr;
216 Q_DISABLE_COPY(QVulkanInstance)
217};
218
219Q_DECLARE_OPERATORS_FOR_FLAGS(QVulkanInstance::Flags)
220Q_DECLARE_OPERATORS_FOR_FLAGS(QVulkanInstance::DebugMessageTypeFlags)
221Q_DECLARE_OPERATORS_FOR_FLAGS(QVulkanInstance::DebugMessageSeverityFlags)
222
223QT_END_NAMESPACE
224
225#endif // __has_include(<vulkan/vulkan.h>) || defined(Q_QDOC)
226
227#endif // QT_CONFIG(vulkan) || defined(Q_QDOC)
228
229#endif // QVULKANINSTANCE_H
A collection of static helper functions for Vulkan support.
Combined button and popup list for selecting options.