5#ifndef QVULKANINSTANCE_H
6#define QVULKANINSTANCE_H
8#include <QtGui/qtguiglobal.h>
11#pragma qt_no_master_include
12#pragma qt_sync_skip_header_check
15#if QT_CONFIG(vulkan) || defined(Q_QDOC)
17#ifndef VK_NO_PROTOTYPES
18#define VK_NO_PROTOTYPES
20#if !defined(Q_QDOC) && __has_include(<vulkan/vulkan.h>)
21#include <vulkan/vulkan.h>
29typedef void* PFN_vkVoidFunction;
31typedef quint64 VkSurfaceKHR;
32typedef quint64 VkImage;
33typedef quint64 VkImageView;
35typedef void* VkInstance;
36typedef void* VkPhysicalDevice;
37typedef void* VkDevice;
41typedef int VkImageLayout;
42typedef int VkDebugReportFlagsEXT;
43typedef int VkDebugReportObjectTypeEXT;
44typedef int VkDeviceQueueCreateFlags;
50#if __has_include(<vulkan/vulkan.h>) || defined(Q_QDOC)
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>
62class QVulkanInstancePrivate;
63class QPlatformVulkanInstance;
64class QVulkanFunctions;
65class QVulkanDeviceFunctions;
72 QVersionNumber specVersion;
73 QByteArray description;
75Q_DECLARE_TYPEINFO(QVulkanLayer, Q_RELOCATABLE_TYPE);
77inline bool operator==(
const QVulkanLayer &lhs,
const QVulkanLayer &rhs)
noexcept
79 return lhs.name == rhs.name && lhs.version == rhs.version && lhs.specVersion == rhs.specVersion;
81inline bool operator!=(
const QVulkanLayer &lhs,
const QVulkanLayer &rhs)
noexcept
82{
return !(lhs == rhs); }
84inline size_t qHash(
const QVulkanLayer &key, size_t seed = 0)
noexcept
86 QtPrivate::QHashCombine hash(seed);
87 seed = hash(seed, key.name);
88 seed = hash(seed, key.version);
89 seed = hash(seed, key.specVersion);
93struct QVulkanExtension
98Q_DECLARE_TYPEINFO(QVulkanExtension, Q_RELOCATABLE_TYPE);
100inline bool operator==(
const QVulkanExtension &lhs,
const QVulkanExtension &rhs)
noexcept
102 return lhs.name == rhs.name && lhs.version == rhs.version;
104inline bool operator!=(
const QVulkanExtension &lhs,
const QVulkanExtension &rhs)
noexcept
105{
return !(lhs == rhs); }
107inline size_t qHash(
const QVulkanExtension &key, size_t seed = 0)
noexcept
109 QtPrivate::QHashCombine hash(seed);
110 seed = hash(seed, key.name);
111 seed = hash(seed, key.version);
115#ifndef QT_NO_DEBUG_STREAM
116Q_GUI_EXPORT QDebug operator<<(QDebug,
const QVulkanLayer &);
117Q_GUI_EXPORT QDebug operator<<(QDebug,
const QVulkanExtension &);
121class QVulkanInfoVector :
public QList<T>
124 bool contains(
const QByteArray &name)
const {
125 return std::any_of(
this->cbegin(),
this->cend(), [&](
const T &entry) {
126 return entry.name == name; });
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; });
134class Q_GUI_EXPORT QVulkanInstance
141 NoDebugOutputRedirect = 0x01,
142 NoPortabilityDrivers = 0x02
144 Q_DECLARE_FLAGS(Flags, Flag)
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;
155 void setVkInstance(VkInstance existingVkInstance);
157 void setFlags(Flags flags);
158 void setLayers(
const QByteArrayList &layers);
159 void setExtensions(
const QByteArrayList &extensions);
160 void setApiVersion(
const QVersionNumber &vulkanVersion);
164 bool isValid()
const;
165 VkResult errorCode()
const;
167 VkInstance vkInstance()
const;
170 QByteArrayList layers()
const;
171 QByteArrayList extensions()
const;
172 QVersionNumber apiVersion()
const;
174 PFN_vkVoidFunction getInstanceProcAddr(
const char *name);
176 QPlatformVulkanInstance *handle()
const;
178 QVulkanFunctions *functions()
const;
179 QVulkanDeviceFunctions *deviceFunctions(VkDevice device);
180 void resetDeviceFunctions(VkDevice device);
182 static VkSurfaceKHR surfaceForWindow(QWindow *window);
184 bool supportsPresent(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, QWindow *window);
186 void presentAboutToBeQueued(QWindow *window);
187 void presentQueued(QWindow *window);
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);
194 enum DebugMessageSeverityFlag {
195 VerboseSeverity = 0x01,
197 WarningSeverity = 0x04,
200 Q_DECLARE_FLAGS(DebugMessageSeverityFlags, DebugMessageSeverityFlag)
202 enum DebugMessageTypeFlag {
203 GeneralMessage = 0x01,
204 ValidationMessage = 0x02,
205 PerformanceMessage = 0x04
207 Q_DECLARE_FLAGS(DebugMessageTypeFlags, DebugMessageTypeFlag)
209 using DebugUtilsFilter = std::function<
bool(DebugMessageSeverityFlags severity, DebugMessageTypeFlags type,
const void *message)>;
210 void installDebugOutputFilter(DebugUtilsFilter filter);
211 void clearDebugOutputFilters();
214 friend class QVulkanInstancePrivate;
215 QScopedPointer<QVulkanInstancePrivate> d_ptr;
216 Q_DISABLE_COPY(QVulkanInstance)
219Q_DECLARE_OPERATORS_FOR_FLAGS(QVulkanInstance::Flags)
220Q_DECLARE_OPERATORS_FOR_FLAGS(QVulkanInstance::DebugMessageTypeFlags)
221Q_DECLARE_OPERATORS_FOR_FLAGS(QVulkanInstance::DebugMessageSeverityFlags)
A collection of static helper functions for Vulkan support.
Combined button and popup list for selecting options.