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
qvulkanwindow.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 QVULKANWINDOW_H
6#define QVULKANWINDOW_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#include <QtGui/qvulkaninstance.h>
18#include <QtGui/qwindow.h>
19#include <QtGui/qimage.h>
20#include <QtGui/qmatrix4x4.h>
21#include <QtCore/qset.h>
22
23#ifdef Q_QDOC
24typedef void* VkQueue;
25typedef void* VkCommandPool;
26typedef void* VkRenderPass;
27typedef void* VkCommandBuffer;
28typedef void* VkFramebuffer;
29typedef int VkPhysicalDeviceProperties;
30typedef int VkFormat;
31typedef int VkQueueFamilyProperties;
32typedef int VkDeviceQueueCreateInfo;
33typedef int VkFormat;
34typedef int VkSampleCountFlagBits;
35#endif
36
37QT_BEGIN_NAMESPACE
38
39class QVulkanWindowPrivate;
40
41class Q_GUI_EXPORT QVulkanWindowRenderer
42{
43public:
44 virtual ~QVulkanWindowRenderer();
45
46 virtual void preInitResources();
47 virtual void initResources();
48 virtual void initSwapChainResources();
49 virtual void releaseSwapChainResources();
50 virtual void releaseResources();
51
52 virtual void startNextFrame() = 0;
53
54 virtual void physicalDeviceLost();
55 virtual void logicalDeviceLost();
56};
57
58#ifndef VK_VERSION_1_1
59typedef struct VkPhysicalDeviceFeatures2 {
60 VkStructureType sType;
61 void* pNext;
62 VkPhysicalDeviceFeatures features;
63} VkPhysicalDeviceFeatures2;
64#endif
65
66class Q_GUI_EXPORT QVulkanWindow : public QWindow
67{
68 Q_OBJECT
69 Q_DECLARE_PRIVATE(QVulkanWindow)
70
71public:
72 enum Flag {
73 PersistentResources = 0x01
74 };
75 Q_DECLARE_FLAGS(Flags, Flag)
76
77 explicit QVulkanWindow(QWindow *parent = nullptr);
78 ~QVulkanWindow();
79
80 void setFlags(Flags flags);
81 Flags flags() const;
82
83 QList<VkPhysicalDeviceProperties> availablePhysicalDevices();
84 void setPhysicalDeviceIndex(int idx);
85
86 QVulkanInfoVector<QVulkanExtension> supportedDeviceExtensions();
87 void setDeviceExtensions(const QByteArrayList &extensions);
88
89 typedef std::function<void(VkPhysicalDeviceFeatures &)> EnabledFeaturesModifier;
90 void setEnabledFeaturesModifier(const EnabledFeaturesModifier &modifier);
91 typedef std::function<void(VkPhysicalDeviceFeatures2 &)> EnabledFeatures2Modifier;
92 void setEnabledFeaturesModifier(EnabledFeatures2Modifier modifier);
93
94 void setPreferredColorFormats(const QList<VkFormat> &formats);
95
96 QList<int> supportedSampleCounts();
97 void setSampleCount(int sampleCount);
98
99 typedef std::function<void(const VkQueueFamilyProperties *, uint32_t,
100 QList<VkDeviceQueueCreateInfo> &)>
101 QueueCreateInfoModifier;
102 void setQueueCreateInfoModifier(const QueueCreateInfoModifier &modifier);
103
104 bool isValid() const;
105
106 virtual QVulkanWindowRenderer *createRenderer();
107 void frameReady();
108
109 VkPhysicalDevice physicalDevice() const;
110 const VkPhysicalDeviceProperties *physicalDeviceProperties() const;
111 VkDevice device() const;
112 VkQueue graphicsQueue() const;
113 uint32_t graphicsQueueFamilyIndex() const;
114 VkCommandPool graphicsCommandPool() const;
115 uint32_t hostVisibleMemoryIndex() const;
116 uint32_t deviceLocalMemoryIndex() const;
117 VkRenderPass defaultRenderPass() const;
118
119 VkFormat colorFormat() const;
120 VkFormat depthStencilFormat() const;
121 QSize swapChainImageSize() const;
122
123 VkCommandBuffer currentCommandBuffer() const;
124 VkFramebuffer currentFramebuffer() const;
125 int currentFrame() const;
126
127 static const int MAX_CONCURRENT_FRAME_COUNT = 3;
128 int concurrentFrameCount() const;
129
130 int swapChainImageCount() const;
131 int currentSwapChainImageIndex() const;
132 VkImage swapChainImage(int idx) const;
133 VkImageView swapChainImageView(int idx) const;
134 VkImage depthStencilImage() const;
135 VkImageView depthStencilImageView() const;
136
137 VkSampleCountFlagBits sampleCountFlagBits() const;
138 VkImage msaaColorImage(int idx) const;
139 VkImageView msaaColorImageView(int idx) const;
140
141 bool supportsGrab() const;
142 QImage grab();
143
144 QMatrix4x4 clipCorrectionMatrix();
145
146Q_SIGNALS:
147 void frameGrabbed(const QImage &image);
148
149protected:
150 void exposeEvent(QExposeEvent *) override;
151 void resizeEvent(QResizeEvent *) override;
152 bool event(QEvent *) override;
153
154private:
155 Q_DISABLE_COPY(QVulkanWindow)
156};
157
158Q_DECLARE_OPERATORS_FOR_FLAGS(QVulkanWindow::Flags)
159
160QT_END_NAMESPACE
161
162#endif // QT_CONFIG(vulkan)
163
164#endif