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
4#ifndef QVULKANWINDOW_P_H
5#define QVULKANWINDOW_P_H
6
7#include <QtGui/private/qtguiglobal_p.h>
8
9#if QT_CONFIG(vulkan) || defined(Q_QDOC)
10
11#include "qvulkanwindow.h"
12#include <QtCore/QHash>
13#include <private/qwindow_p.h>
14
15//
16// W A R N I N G
17// -------------
18//
19// This file is not part of the Qt API. It exists for the convenience
20// of a number of Qt sources files. This header file may change from
21// version to version without notice, or even be removed.
22//
23// We mean it.
24//
25
26QT_BEGIN_NAMESPACE
27
28class Q_GUI_EXPORT QVulkanWindowPrivate : public QWindowPrivate
29{
30 Q_DECLARE_PUBLIC(QVulkanWindow)
31
32public:
33 ~QVulkanWindowPrivate();
34
35 void ensureStarted();
36 void init();
37 void reset();
38 bool createDefaultRenderPass();
39 void recreateSwapChain();
40 uint32_t chooseTransientImageMemType(VkImage img, uint32_t startIndex);
41 bool createTransientImage(VkFormat format, VkImageUsageFlags usage, VkImageAspectFlags aspectMask,
42 VkImage *images, VkDeviceMemory *mem, VkImageView *views, int count);
43 void releaseSwapChain();
44 void beginFrame();
45 void endFrame();
46 bool checkDeviceLost(VkResult err);
47 void addReadback();
48 void finishBlockingReadback();
49
50 enum Status {
51 StatusUninitialized,
52 StatusFail,
53 StatusFailRetry,
54 StatusDeviceReady,
55 StatusReady
56 };
57 Status status = StatusUninitialized;
58 QVulkanWindowRenderer *renderer = nullptr;
59 QVulkanInstance *inst = nullptr;
60 VkSurfaceKHR surface = VK_NULL_HANDLE;
61 int physDevIndex = 0;
62 QList<VkPhysicalDevice> physDevs;
63 QList<VkPhysicalDeviceProperties> physDevProps;
64 QVulkanWindow::Flags flags;
65 QByteArrayList requestedDevExtensions;
66 QHash<VkPhysicalDevice, QVulkanInfoVector<QVulkanExtension> > supportedDevExtensions;
67 QList<VkFormat> requestedColorFormats;
68 VkSampleCountFlagBits sampleCount = VK_SAMPLE_COUNT_1_BIT;
69 QVulkanWindow::QueueCreateInfoModifier queueCreateInfoModifier;
70 QVulkanWindow::EnabledFeaturesModifier enabledFeaturesModifier;
71
72 VkDevice dev = VK_NULL_HANDLE;
73 QVulkanDeviceFunctions *devFuncs;
74 uint32_t gfxQueueFamilyIdx;
75 uint32_t presQueueFamilyIdx;
76 VkQueue gfxQueue;
77 VkQueue presQueue;
78 VkCommandPool cmdPool = VK_NULL_HANDLE;
79 VkCommandPool presCmdPool = VK_NULL_HANDLE;
80 uint32_t hostVisibleMemIndex;
81 uint32_t deviceLocalMemIndex;
82 VkFormat colorFormat;
83 VkColorSpaceKHR colorSpace;
84 VkFormat dsFormat = VK_FORMAT_D24_UNORM_S8_UINT;
85
86 PFN_vkCreateSwapchainKHR vkCreateSwapchainKHR = nullptr;
87 PFN_vkDestroySwapchainKHR vkDestroySwapchainKHR;
88 PFN_vkGetSwapchainImagesKHR vkGetSwapchainImagesKHR;
89 PFN_vkAcquireNextImageKHR vkAcquireNextImageKHR;
90 PFN_vkQueuePresentKHR vkQueuePresentKHR;
91 PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR vkGetPhysicalDeviceSurfaceCapabilitiesKHR = nullptr;
92 PFN_vkGetPhysicalDeviceSurfaceFormatsKHR vkGetPhysicalDeviceSurfaceFormatsKHR;
93
94 static const int MAX_SWAPCHAIN_BUFFER_COUNT = 4;
95 static const int MAX_FRAME_LAG = QVulkanWindow::MAX_CONCURRENT_FRAME_COUNT;
96 // QVulkanWindow only supports the always available FIFO mode. The
97 // rendering thread will get throttled to the presentation rate (vsync).
98 // This is in effect Example 5 from the VK_KHR_swapchain spec.
99 VkPresentModeKHR presentMode = VK_PRESENT_MODE_FIFO_KHR;
100 int swapChainBufferCount = 0;
101 int frameLag = 2;
102
103 QSize swapChainImageSize;
104 VkSwapchainKHR swapChain = VK_NULL_HANDLE;
105 bool swapChainSupportsReadBack = false;
106
107 struct ImageResources {
108 VkImage image = VK_NULL_HANDLE;
109 VkImageView imageView = VK_NULL_HANDLE;
110 VkCommandBuffer cmdBuf = VK_NULL_HANDLE;
111 VkFence cmdFence = VK_NULL_HANDLE;
112 bool cmdFenceWaitable = false;
113 VkFramebuffer fb = VK_NULL_HANDLE;
114 VkCommandBuffer presTransCmdBuf = VK_NULL_HANDLE;
115 VkImage msaaImage = VK_NULL_HANDLE;
116 VkImageView msaaImageView = VK_NULL_HANDLE;
117 } imageRes[MAX_SWAPCHAIN_BUFFER_COUNT];
118
119 VkDeviceMemory msaaImageMem = VK_NULL_HANDLE;
120
121 uint32_t currentImage;
122
123 struct FrameResources {
124 VkFence fence = VK_NULL_HANDLE;
125 bool fenceWaitable = false;
126 VkSemaphore imageSem = VK_NULL_HANDLE;
127 VkSemaphore drawSem = VK_NULL_HANDLE;
128 VkSemaphore presTransSem = VK_NULL_HANDLE;
129 bool imageAcquired = false;
130 bool imageSemWaitable = false;
131 } frameRes[MAX_FRAME_LAG];
132
133 uint32_t currentFrame;
134
135 VkRenderPass defaultRenderPass = VK_NULL_HANDLE;
136
137 VkDeviceMemory dsMem = VK_NULL_HANDLE;
138 VkImage dsImage = VK_NULL_HANDLE;
139 VkImageView dsView = VK_NULL_HANDLE;
140
141 bool framePending = false;
142 bool frameGrabbing = false;
143 QImage frameGrabTargetImage;
144 VkImage frameGrabImage = VK_NULL_HANDLE;
145 VkDeviceMemory frameGrabImageMem = VK_NULL_HANDLE;
146
147 QMatrix4x4 m_clipCorrect;
148};
149
150QT_END_NAMESPACE
151
152#endif // QT_CONFIG(vulkan)
153
154#endif
155

source code of qtbase/src/gui/vulkan/qvulkanwindow_p.h