4#ifndef QVULKANINSTANCE_H
5#define QVULKANINSTANCE_H
7#include <QtGui/qtguiglobal.h>
10#pragma qt_no_master_include
11#pragma qt_sync_skip_header_check
14#if QT_CONFIG(vulkan) || defined(Q_QDOC)
16#ifndef VK_NO_PROTOTYPES
17#define VK_NO_PROTOTYPES
19#if !defined(Q_QDOC) && __has_include(<vulkan/vulkan.h>)
20#include <vulkan/vulkan.h>
28typedef void* PFN_vkVoidFunction;
30typedef quint64 VkSurfaceKHR;
31typedef quint64 VkImage;
32typedef quint64 VkImageView;
34typedef void* VkInstance;
35typedef void* VkPhysicalDevice;
36typedef void* VkDevice;
40typedef int VkImageLayout;
41typedef int VkDebugReportFlagsEXT;
42typedef int VkDebugReportObjectTypeEXT;
48#if __has_include(<vulkan/vulkan.h>) || defined(Q_QDOC)
50#include <QtCore/qbytearraylist.h>
51#include <QtCore/qhashfunctions.h>
52#include <QtCore/qlist.h>
53#include <QtCore/qscopedpointer.h>
54#include <QtCore/qversionnumber.h>
60class QVulkanInstancePrivate;
61class QPlatformVulkanInstance;
62class QVulkanFunctions;
63class QVulkanDeviceFunctions;
70 QVersionNumber specVersion;
71 QByteArray description;
73Q_DECLARE_TYPEINFO(QVulkanLayer, Q_RELOCATABLE_TYPE);
75inline bool operator==(
const QVulkanLayer &lhs,
const QVulkanLayer &rhs)
noexcept
77 return lhs.name == rhs.name && lhs.version == rhs.version && lhs.specVersion == rhs.specVersion;
79inline bool operator!=(
const QVulkanLayer &lhs,
const QVulkanLayer &rhs)
noexcept
80{
return !(lhs == rhs); }
82inline size_t qHash(
const QVulkanLayer &key, size_t seed = 0)
noexcept
84 QtPrivate::QHashCombine hash(seed);
85 seed = hash(seed, key.name);
86 seed = hash(seed, key.version);
87 seed = hash(seed, key.specVersion);
91struct QVulkanExtension
96Q_DECLARE_TYPEINFO(QVulkanExtension, Q_RELOCATABLE_TYPE);
98inline bool operator==(
const QVulkanExtension &lhs,
const QVulkanExtension &rhs)
noexcept
100 return lhs.name == rhs.name && lhs.version == rhs.version;
102inline bool operator!=(
const QVulkanExtension &lhs,
const QVulkanExtension &rhs)
noexcept
103{
return !(lhs == rhs); }
105inline size_t qHash(
const QVulkanExtension &key, size_t seed = 0)
noexcept
107 QtPrivate::QHashCombine hash(seed);
108 seed = hash(seed, key.name);
109 seed = hash(seed, key.version);
113#ifndef QT_NO_DEBUG_STREAM
114Q_GUI_EXPORT QDebug operator<<(QDebug,
const QVulkanLayer &);
115Q_GUI_EXPORT QDebug operator<<(QDebug,
const QVulkanExtension &);
119class QVulkanInfoVector :
public QList<T>
122 bool contains(
const QByteArray &name)
const {
123 return std::any_of(
this->cbegin(),
this->cend(), [&](
const T &entry) {
124 return entry.name == name; });
126 bool contains(
const QByteArray &name,
int minVersion)
const {
127 return std::any_of(
this->cbegin(),
this->cend(), [&](
const T &entry) {
128 return entry.name == name && entry.version >= minVersion; });
132class Q_GUI_EXPORT QVulkanInstance
139 NoDebugOutputRedirect = 0x01,
140 NoPortabilityDrivers = 0x02
142 Q_DECLARE_FLAGS(Flags, Flag)
145 QVulkanInfoVector<QVulkanLayer> supportedLayers();
146 inline QVulkanInfoVector<QVulkanLayer> supportedLayers()
const
147 {
return const_cast<QVulkanInstance*>(
this)->supportedLayers(); }
148 QVulkanInfoVector<QVulkanExtension> supportedExtensions();
149 inline QVulkanInfoVector<QVulkanExtension> supportedExtensions()
const
150 {
return const_cast<QVulkanInstance*>(
this)->supportedExtensions(); }
151 QVersionNumber supportedApiVersion()
const;
153 void setVkInstance(VkInstance existingVkInstance);
155 void setFlags(Flags flags);
156 void setLayers(
const QByteArrayList &layers);
157 void setExtensions(
const QByteArrayList &extensions);
158 void setApiVersion(
const QVersionNumber &vulkanVersion);
162 bool isValid()
const;
163 VkResult errorCode()
const;
165 VkInstance vkInstance()
const;
168 QByteArrayList layers()
const;
169 QByteArrayList extensions()
const;
170 QVersionNumber apiVersion()
const;
172 PFN_vkVoidFunction getInstanceProcAddr(
const char *name);
174 QPlatformVulkanInstance *handle()
const;
176 QVulkanFunctions *functions()
const;
177 QVulkanDeviceFunctions *deviceFunctions(VkDevice device);
178 void resetDeviceFunctions(VkDevice device);
180 static VkSurfaceKHR surfaceForWindow(QWindow *window);
182 bool supportsPresent(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, QWindow *window);
184 void presentAboutToBeQueued(QWindow *window);
185 void presentQueued(QWindow *window);
187 typedef bool (*DebugFilter)(VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objectType, uint64_t object,
188 size_t location, int32_t messageCode,
const char *pLayerPrefix,
const char *pMessage);
189 void installDebugOutputFilter(DebugFilter filter);
190 void removeDebugOutputFilter(DebugFilter filter);
192 enum DebugMessageSeverityFlag {
193 VerboseSeverity = 0x01,
195 WarningSeverity = 0x04,
198 Q_DECLARE_FLAGS(DebugMessageSeverityFlags, DebugMessageSeverityFlag)
200 enum DebugMessageTypeFlag {
201 GeneralMessage = 0x01,
202 ValidationMessage = 0x02,
203 PerformanceMessage = 0x04
205 Q_DECLARE_FLAGS(DebugMessageTypeFlags, DebugMessageTypeFlag)
207 using DebugUtilsFilter = std::function<
bool(DebugMessageSeverityFlags severity, DebugMessageTypeFlags type,
const void *message)>;
208 void installDebugOutputFilter(DebugUtilsFilter filter);
209 void clearDebugOutputFilters();
212 friend class QVulkanInstancePrivate;
213 QScopedPointer<QVulkanInstancePrivate> d_ptr;
214 Q_DISABLE_COPY(QVulkanInstance)
217Q_DECLARE_OPERATORS_FOR_FLAGS(QVulkanInstance::Flags)
218Q_DECLARE_OPERATORS_FOR_FLAGS(QVulkanInstance::DebugMessageTypeFlags)
219Q_DECLARE_OPERATORS_FOR_FLAGS(QVulkanInstance::DebugMessageSeverityFlags)
A collection of static helper functions for Vulkan support.