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;
49#if __has_include(<vulkan/vulkan.h>) || defined(Q_QDOC)
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>
61class QVulkanInstancePrivate;
62class QPlatformVulkanInstance;
63class QVulkanFunctions;
64class QVulkanDeviceFunctions;
71 QVersionNumber specVersion;
72 QByteArray description;
74Q_DECLARE_TYPEINFO(QVulkanLayer, Q_RELOCATABLE_TYPE);
76inline bool operator==(
const QVulkanLayer &lhs,
const QVulkanLayer &rhs)
noexcept
78 return lhs.name == rhs.name && lhs.version == rhs.version && lhs.specVersion == rhs.specVersion;
80inline bool operator!=(
const QVulkanLayer &lhs,
const QVulkanLayer &rhs)
noexcept
81{
return !(lhs == rhs); }
83inline size_t qHash(
const QVulkanLayer &key, size_t seed = 0)
noexcept
85 QtPrivate::QHashCombine hash(seed);
86 seed = hash(seed, key.name);
87 seed = hash(seed, key.version);
88 seed = hash(seed, key.specVersion);
92struct QVulkanExtension
97Q_DECLARE_TYPEINFO(QVulkanExtension, Q_RELOCATABLE_TYPE);
99inline bool operator==(
const QVulkanExtension &lhs,
const QVulkanExtension &rhs)
noexcept
101 return lhs.name == rhs.name && lhs.version == rhs.version;
103inline bool operator!=(
const QVulkanExtension &lhs,
const QVulkanExtension &rhs)
noexcept
104{
return !(lhs == rhs); }
106inline size_t qHash(
const QVulkanExtension &key, size_t seed = 0)
noexcept
108 QtPrivate::QHashCombine hash(seed);
109 seed = hash(seed, key.name);
110 seed = hash(seed, key.version);
114#ifndef QT_NO_DEBUG_STREAM
115Q_GUI_EXPORT QDebug operator<<(QDebug,
const QVulkanLayer &);
116Q_GUI_EXPORT QDebug operator<<(QDebug,
const QVulkanExtension &);
120class QVulkanInfoVector :
public QList<T>
123 bool contains(
const QByteArray &name)
const {
124 return std::any_of(
this->cbegin(),
this->cend(), [&](
const T &entry) {
125 return entry.name == name; });
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; });
133class Q_GUI_EXPORT QVulkanInstance
140 NoDebugOutputRedirect = 0x01,
141 NoPortabilityDrivers = 0x02
143 Q_DECLARE_FLAGS(Flags, Flag)
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;
154 void setVkInstance(VkInstance existingVkInstance);
156 void setFlags(Flags flags);
157 void setLayers(
const QByteArrayList &layers);
158 void setExtensions(
const QByteArrayList &extensions);
159 void setApiVersion(
const QVersionNumber &vulkanVersion);
163 bool isValid()
const;
164 VkResult errorCode()
const;
166 VkInstance vkInstance()
const;
169 QByteArrayList layers()
const;
170 QByteArrayList extensions()
const;
171 QVersionNumber apiVersion()
const;
173 PFN_vkVoidFunction getInstanceProcAddr(
const char *name);
175 QPlatformVulkanInstance *handle()
const;
177 QVulkanFunctions *functions()
const;
178 QVulkanDeviceFunctions *deviceFunctions(VkDevice device);
179 void resetDeviceFunctions(VkDevice device);
181 static VkSurfaceKHR surfaceForWindow(QWindow *window);
183 bool supportsPresent(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, QWindow *window);
185 void presentAboutToBeQueued(QWindow *window);
186 void presentQueued(QWindow *window);
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);
193 enum DebugMessageSeverityFlag {
194 VerboseSeverity = 0x01,
196 WarningSeverity = 0x04,
199 Q_DECLARE_FLAGS(DebugMessageSeverityFlags, DebugMessageSeverityFlag)
201 enum DebugMessageTypeFlag {
202 GeneralMessage = 0x01,
203 ValidationMessage = 0x02,
204 PerformanceMessage = 0x04
206 Q_DECLARE_FLAGS(DebugMessageTypeFlags, DebugMessageTypeFlag)
208 using DebugUtilsFilter = std::function<
bool(DebugMessageSeverityFlags severity, DebugMessageTypeFlags type,
const void *message)>;
209 void installDebugOutputFilter(DebugUtilsFilter filter);
210 void clearDebugOutputFilters();
213 friend class QVulkanInstancePrivate;
214 QScopedPointer<QVulkanInstancePrivate> d_ptr;
215 Q_DISABLE_COPY(QVulkanInstance)
218Q_DECLARE_OPERATORS_FOR_FLAGS(QVulkanInstance::Flags)
219Q_DECLARE_OPERATORS_FOR_FLAGS(QVulkanInstance::DebugMessageTypeFlags)
220Q_DECLARE_OPERATORS_FOR_FLAGS(QVulkanInstance::DebugMessageSeverityFlags)
A collection of static helper functions for Vulkan support.
Combined button and popup list for selecting options.