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#include <QtGui/qvulkaninstance.h>
18#include <QtGui/qwindow.h>
19#include <QtGui/qimage.h>
20#include <QtGui/qmatrix4x4.h>
21#include <QtCore/qset.h>
25typedef void* VkCommandPool;
26typedef void* VkRenderPass;
27typedef void* VkCommandBuffer;
28typedef void* VkFramebuffer;
29typedef int VkPhysicalDeviceProperties;
31typedef int VkQueueFamilyProperties;
32typedef int VkDeviceQueueCreateInfo;
34typedef int VkSampleCountFlagBits;
39class QVulkanWindowPrivate;
41class Q_GUI_EXPORT QVulkanWindowRenderer
44 virtual ~QVulkanWindowRenderer();
46 virtual void preInitResources();
47 virtual void initResources();
48 virtual void initSwapChainResources();
49 virtual void releaseSwapChainResources();
50 virtual void releaseResources();
52 virtual void startNextFrame() = 0;
54 virtual void physicalDeviceLost();
55 virtual void logicalDeviceLost();
59typedef struct VkPhysicalDeviceFeatures2 {
60 VkStructureType sType;
62 VkPhysicalDeviceFeatures features;
63} VkPhysicalDeviceFeatures2;
66class Q_GUI_EXPORT QVulkanWindow :
public QWindow
69 Q_DECLARE_PRIVATE(QVulkanWindow)
73 PersistentResources = 0x01
75 Q_DECLARE_FLAGS(Flags, Flag)
77 explicit QVulkanWindow(QWindow *parent =
nullptr);
80 void setFlags(Flags flags);
83 QList<VkPhysicalDeviceProperties> availablePhysicalDevices();
84 void setPhysicalDeviceIndex(
int idx);
86 QVulkanInfoVector<QVulkanExtension> supportedDeviceExtensions();
87 void setDeviceExtensions(
const QByteArrayList &extensions);
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);
94 void setPreferredColorFormats(
const QList<VkFormat> &formats);
96 QList<
int> supportedSampleCounts();
97 void setSampleCount(
int sampleCount);
99 typedef std::function<
void(
const VkQueueFamilyProperties *, uint32_t,
100 QList<VkDeviceQueueCreateInfo> &)>
101 QueueCreateInfoModifier;
102 void setQueueCreateInfoModifier(
const QueueCreateInfoModifier &modifier);
104 bool isValid()
const;
106 virtual QVulkanWindowRenderer *createRenderer();
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;
119 VkFormat colorFormat()
const;
120 VkFormat depthStencilFormat()
const;
121 QSize swapChainImageSize()
const;
123 VkCommandBuffer currentCommandBuffer()
const;
124 VkFramebuffer currentFramebuffer()
const;
125 int currentFrame()
const;
127 static const int MAX_CONCURRENT_FRAME_COUNT = 3;
128 int concurrentFrameCount()
const;
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;
137 VkSampleCountFlagBits sampleCountFlagBits()
const;
138 VkImage msaaColorImage(
int idx)
const;
139 VkImageView msaaColorImageView(
int idx)
const;
141 bool supportsGrab()
const;
144 QMatrix4x4 clipCorrectionMatrix();
147 void frameGrabbed(
const QImage &image);
150 void exposeEvent(QExposeEvent *) override;
151 void resizeEvent(QResizeEvent *) override;
152 bool event(QEvent *) override;
155 Q_DISABLE_COPY(QVulkanWindow)
158Q_DECLARE_OPERATORS_FOR_FLAGS(QVulkanWindow::Flags)