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;
44#endif
45
46// QVulkanInstance itself is only applicable if vulkan.h is available, or if
47// it's qdoc. An application that is built on a vulkan.h-less system against a
48// Vulkan-enabled Qt gets the dummy typedefs but not QVulkan*.
49#if __has_include(<vulkan/vulkan.h>) || defined(Q_QDOC)
50
51#include <QtCore/qbytearraylist.h>
52#include <QtCore/qhashfunctions.h>
53#include <QtCore/qlist.h>
54#include <QtCore/qscopedpointer.h>
55#include <QtCore/qversionnumber.h>
56
57QT_BEGIN_NAMESPACE
58
59class QDebug;
60
61class QVulkanInstancePrivate;
62class QPlatformVulkanInstance;
63class QVulkanFunctions;
64class QVulkanDeviceFunctions;
65class QWindow;
66
67struct QVulkanLayer
68{
69 QByteArray name;
70 uint32_t version;
71 QVersionNumber specVersion;
72 QByteArray description;
73};
74Q_DECLARE_TYPEINFO(QVulkanLayer, Q_RELOCATABLE_TYPE);
75
76inline bool operator==(const QVulkanLayer &lhs, const QVulkanLayer &rhs) noexcept
77{
78 return lhs.name == rhs.name && lhs.version == rhs.version && lhs.specVersion == rhs.specVersion;
79}
80inline bool operator!=(const QVulkanLayer &lhs, const QVulkanLayer &rhs) noexcept
81{ return !(lhs == rhs); }
82
83inline size_t qHash(const QVulkanLayer &key, size_t seed = 0) noexcept
84{
85 QtPrivate::QHashCombine hash(seed);
86 seed = hash(seed, key.name);
87 seed = hash(seed, key.version);
88 seed = hash(seed, key.specVersion);
89 return seed;
90}
91
92struct QVulkanExtension
93{
94 QByteArray name;
95 uint32_t version;
96};
97Q_DECLARE_TYPEINFO(QVulkanExtension, Q_RELOCATABLE_TYPE);
98
99inline bool operator==(const QVulkanExtension &lhs, const QVulkanExtension &rhs) noexcept
100{
101 return lhs.name == rhs.name && lhs.version == rhs.version;
102}
103inline bool operator!=(const QVulkanExtension &lhs, const QVulkanExtension &rhs) noexcept
104{ return !(lhs == rhs); }
105
106inline size_t qHash(const QVulkanExtension &key, size_t seed = 0) noexcept
107{
108 QtPrivate::QHashCombine hash(seed);
109 seed = hash(seed, key.name);
110 seed = hash(seed, key.version);
111 return seed;
112}
113
114#ifndef QT_NO_DEBUG_STREAM
115Q_GUI_EXPORT QDebug operator<<(QDebug, const QVulkanLayer &);
116Q_GUI_EXPORT QDebug operator<<(QDebug, const QVulkanExtension &);
117#endif
118
119template<typename T>
120class QVulkanInfoVector : public QList<T>
121{
122public:
123 bool contains(const QByteArray &name) const {
124 return std::any_of(this->cbegin(), this->cend(), [&](const T &entry) {
125 return entry.name == name; });
126 }
127 bool contains(const QByteArray &name, int minVersion) const {
128 return std::any_of(this->cbegin(), this->cend(), [&](const T &entry) {
129 return entry.name == name && entry.version >= minVersion; });
130 }
131};
132
133class Q_GUI_EXPORT QVulkanInstance
134{
135public:
136 QVulkanInstance();
137 ~QVulkanInstance();
138
139 enum Flag {
140 NoDebugOutputRedirect = 0x01,
141 NoPortabilityDrivers = 0x02
142 };
143 Q_DECLARE_FLAGS(Flags, Flag)
144
145 // ### Qt 7: remove non-const overloads
146 QVulkanInfoVector<QVulkanLayer> supportedLayers();
147 inline QVulkanInfoVector<QVulkanLayer> supportedLayers() const
148 { return const_cast<QVulkanInstance*>(this)->supportedLayers(); }
149 QVulkanInfoVector<QVulkanExtension> supportedExtensions();
150 inline QVulkanInfoVector<QVulkanExtension> supportedExtensions() const
151 { return const_cast<QVulkanInstance*>(this)->supportedExtensions(); }
152 QVersionNumber supportedApiVersion() const;
153
154 void setVkInstance(VkInstance existingVkInstance);
155
156 void setFlags(Flags flags);
157 void setLayers(const QByteArrayList &layers);
158 void setExtensions(const QByteArrayList &extensions);
159 void setApiVersion(const QVersionNumber &vulkanVersion);
160
161 bool create();
162 void destroy();
163 bool isValid() const;
164 VkResult errorCode() const;
165
166 VkInstance vkInstance() const;
167
168 Flags flags() const;
169 QByteArrayList layers() const;
170 QByteArrayList extensions() const;
171 QVersionNumber apiVersion() const;
172
173 PFN_vkVoidFunction getInstanceProcAddr(const char *name);
174
175 QPlatformVulkanInstance *handle() const;
176
177 QVulkanFunctions *functions() const;
178 QVulkanDeviceFunctions *deviceFunctions(VkDevice device);
179 void resetDeviceFunctions(VkDevice device);
180
181 static VkSurfaceKHR surfaceForWindow(QWindow *window);
182
183 bool supportsPresent(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, QWindow *window);
184
185 void presentAboutToBeQueued(QWindow *window);
186 void presentQueued(QWindow *window);
187
188 typedef bool (*DebugFilter)(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objectType, uint64_t object,
189 size_t location, int32_t messageCode, const char *pLayerPrefix, const char *pMessage);
190 void installDebugOutputFilter(DebugFilter filter);
191 void removeDebugOutputFilter(DebugFilter filter);
192
193 enum DebugMessageSeverityFlag {
194 VerboseSeverity = 0x01,
195 InfoSeverity = 0x02,
196 WarningSeverity = 0x04,
197 ErrorSeverity = 0x08
198 };
199 Q_DECLARE_FLAGS(DebugMessageSeverityFlags, DebugMessageSeverityFlag)
200
201 enum DebugMessageTypeFlag {
202 GeneralMessage = 0x01,
203 ValidationMessage = 0x02,
204 PerformanceMessage = 0x04
205 };
206 Q_DECLARE_FLAGS(DebugMessageTypeFlags, DebugMessageTypeFlag)
207
208 using DebugUtilsFilter = std::function<bool(DebugMessageSeverityFlags severity, DebugMessageTypeFlags type, const void *message)>;
209 void installDebugOutputFilter(DebugUtilsFilter filter);
210 void clearDebugOutputFilters();
211
212private:
213 friend class QVulkanInstancePrivate;
214 QScopedPointer<QVulkanInstancePrivate> d_ptr;
215 Q_DISABLE_COPY(QVulkanInstance)
216};
217
218Q_DECLARE_OPERATORS_FOR_FLAGS(QVulkanInstance::Flags)
219Q_DECLARE_OPERATORS_FOR_FLAGS(QVulkanInstance::DebugMessageTypeFlags)
220Q_DECLARE_OPERATORS_FOR_FLAGS(QVulkanInstance::DebugMessageSeverityFlags)
221
222QT_END_NAMESPACE
223
224#endif // __has_include(<vulkan/vulkan.h>) || defined(Q_QDOC)
225
226#endif // QT_CONFIG(vulkan) || defined(Q_QDOC)
227
228#endif // QVULKANINSTANCE_H
A collection of static helper functions for Vulkan support.
Combined button and popup list for selecting options.