1// Copyright (C) 2023 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 QRHIPLATFORM_H
5#define QRHIPLATFORM_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is part of the RHI API, with limited compatibility guarantees.
12// Usage of this API may make your code source and binary incompatible with
13// future versions of Qt.
14//
15
16#include <rhi/qrhi.h>
17
18#if QT_CONFIG(opengl)
19#include <QtGui/qsurfaceformat.h>
20#endif
21
22#if QT_CONFIG(vulkan)
23#include <QtGui/qvulkaninstance.h>
24#endif
25
26#if QT_CONFIG(metal) || defined(Q_QDOC)
27Q_FORWARD_DECLARE_OBJC_CLASS(MTLDevice);
28Q_FORWARD_DECLARE_OBJC_CLASS(MTLCommandQueue);
29Q_FORWARD_DECLARE_OBJC_CLASS(MTLCommandBuffer);
30Q_FORWARD_DECLARE_OBJC_CLASS(MTLRenderCommandEncoder);
31#endif
32
33QT_BEGIN_NAMESPACE
34
35struct Q_GUI_EXPORT QRhiNullInitParams : public QRhiInitParams
36{
37};
38
39struct Q_GUI_EXPORT QRhiNullNativeHandles : public QRhiNativeHandles
40{
41};
42
43#if QT_CONFIG(opengl) || defined(Q_QDOC)
44
45class QOpenGLContext;
46class QOffscreenSurface;
47class QSurface;
48class QWindow;
49
50struct Q_GUI_EXPORT QRhiGles2InitParams : public QRhiInitParams
51{
52 QRhiGles2InitParams();
53
54 QSurfaceFormat format;
55 QSurface *fallbackSurface = nullptr;
56 QWindow *window = nullptr;
57 QOpenGLContext *shareContext = nullptr;
58
59 static QOffscreenSurface *newFallbackSurface(const QSurfaceFormat &format = QSurfaceFormat::defaultFormat());
60};
61
62struct Q_GUI_EXPORT QRhiGles2NativeHandles : public QRhiNativeHandles
63{
64 QOpenGLContext *context = nullptr;
65};
66
67#endif // opengl/qdoc
68
69#if (QT_CONFIG(vulkan) && __has_include(<vulkan/vulkan.h>)) || defined(Q_QDOC)
70
71struct Q_GUI_EXPORT QRhiVulkanInitParams : public QRhiInitParams
72{
73 QVulkanInstance *inst = nullptr;
74 QWindow *window = nullptr;
75 QByteArrayList deviceExtensions;
76
77 static QByteArrayList preferredInstanceExtensions();
78 static QByteArrayList preferredExtensionsForImportedDevice();
79};
80
81struct Q_GUI_EXPORT QRhiVulkanNativeHandles : public QRhiNativeHandles
82{
83 // to import a physical device (always required)
84 VkPhysicalDevice physDev = VK_NULL_HANDLE;
85 // to import a device and queue
86 VkDevice dev = VK_NULL_HANDLE;
87 quint32 gfxQueueFamilyIdx = 0;
88 quint32 gfxQueueIdx = 0;
89 // and optionally, the mem allocator
90 void *vmemAllocator = nullptr;
91
92 // only for querying (rhi->nativeHandles())
93 VkQueue gfxQueue = VK_NULL_HANDLE;
94 QVulkanInstance *inst = nullptr;
95};
96
97struct Q_GUI_EXPORT QRhiVulkanCommandBufferNativeHandles : public QRhiNativeHandles
98{
99 VkCommandBuffer commandBuffer = VK_NULL_HANDLE;
100};
101
102struct Q_GUI_EXPORT QRhiVulkanRenderPassNativeHandles : public QRhiNativeHandles
103{
104 VkRenderPass renderPass = VK_NULL_HANDLE;
105};
106
107struct Q_GUI_EXPORT QRhiVulkanQueueSubmitParams : public QRhiNativeHandles
108{
109 uint32_t waitSemaphoreCount;
110 VkSemaphore *waitSemaphores;
111 uint32_t signalSemaphoreCount;
112 VkSemaphore *signalSemaphores;
113 uint32_t presentWaitSemaphoreCount;
114 VkSemaphore *presentWaitSemaphores;
115};
116
117#endif // vulkan/qdoc
118
119#if defined(Q_OS_WIN) || defined(Q_QDOC)
120
121// no d3d includes here, to prevent precompiled header mess due to COM, hence the void pointers
122
123struct Q_GUI_EXPORT QRhiD3D11InitParams : public QRhiInitParams
124{
125 bool enableDebugLayer = false;
126};
127
128struct Q_GUI_EXPORT QRhiD3D11NativeHandles : public QRhiNativeHandles
129{
130 // to import a device and a context
131 void *dev = nullptr;
132 void *context = nullptr;
133 // alternatively, to specify the device feature level and/or the adapter to use
134 int featureLevel = 0;
135 quint32 adapterLuidLow = 0;
136 qint32 adapterLuidHigh = 0;
137};
138
139struct Q_GUI_EXPORT QRhiD3D12InitParams : public QRhiInitParams
140{
141 bool enableDebugLayer = false;
142};
143
144struct Q_GUI_EXPORT QRhiD3D12NativeHandles : public QRhiNativeHandles
145{
146 // to import a device
147 void *dev = nullptr;
148 int minimumFeatureLevel = 0;
149 // to just specify the adapter to use, set these and leave dev set to null
150 quint32 adapterLuidLow = 0;
151 qint32 adapterLuidHigh = 0;
152 // in addition, can specify the command queue to use
153 void *commandQueue = nullptr;
154};
155
156struct Q_GUI_EXPORT QRhiD3D12CommandBufferNativeHandles : public QRhiNativeHandles
157{
158 void *commandList = nullptr; // ID3D12GraphicsCommandList1
159};
160
161#endif // WIN/QDOC
162
163#if QT_CONFIG(metal) || defined(Q_QDOC)
164
165struct Q_GUI_EXPORT QRhiMetalInitParams : public QRhiInitParams
166{
167};
168
169struct Q_GUI_EXPORT QRhiMetalNativeHandles : public QRhiNativeHandles
170{
171 MTLDevice *dev = nullptr;
172 MTLCommandQueue *cmdQueue = nullptr;
173};
174
175struct Q_GUI_EXPORT QRhiMetalCommandBufferNativeHandles : public QRhiNativeHandles
176{
177 MTLCommandBuffer *commandBuffer = nullptr;
178 MTLRenderCommandEncoder *encoder = nullptr;
179};
180
181#endif // MACOS/IOS/QDOC
182
183QT_END_NAMESPACE
184
185#endif
186

source code of qtbase/src/gui/rhi/qrhi_platform.h