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 defined(Q_OS_MACOS) || defined(Q_OS_IOS) || defined(Q_QDOC) |
27 | Q_FORWARD_DECLARE_OBJC_CLASS(MTLDevice); |
28 | Q_FORWARD_DECLARE_OBJC_CLASS(MTLCommandQueue); |
29 | Q_FORWARD_DECLARE_OBJC_CLASS(MTLCommandBuffer); |
30 | Q_FORWARD_DECLARE_OBJC_CLASS(MTLRenderCommandEncoder); |
31 | #endif |
32 | |
33 | QT_BEGIN_NAMESPACE |
34 | |
35 | struct Q_GUI_EXPORT QRhiNullInitParams : public QRhiInitParams |
36 | { |
37 | }; |
38 | |
39 | struct Q_GUI_EXPORT QRhiNullNativeHandles : public QRhiNativeHandles |
40 | { |
41 | }; |
42 | |
43 | #if QT_CONFIG(opengl) || defined(Q_QDOC) |
44 | |
45 | class QOpenGLContext; |
46 | class QOffscreenSurface; |
47 | class QSurface; |
48 | class QWindow; |
49 | |
50 | struct 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 | |
62 | struct 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 | |
71 | struct 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 | |
81 | struct 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 | |
97 | struct Q_GUI_EXPORT QRhiVulkanCommandBufferNativeHandles : public QRhiNativeHandles |
98 | { |
99 | VkCommandBuffer commandBuffer = VK_NULL_HANDLE; |
100 | }; |
101 | |
102 | struct Q_GUI_EXPORT QRhiVulkanRenderPassNativeHandles : public QRhiNativeHandles |
103 | { |
104 | VkRenderPass renderPass = VK_NULL_HANDLE; |
105 | }; |
106 | |
107 | #endif // vulkan/qdoc |
108 | |
109 | #if defined(Q_OS_WIN) || defined(Q_QDOC) |
110 | |
111 | // no d3d includes here, to prevent precompiled header mess due to COM, hence the void pointers |
112 | |
113 | struct Q_GUI_EXPORT QRhiD3D11InitParams : public QRhiInitParams |
114 | { |
115 | bool enableDebugLayer = false; |
116 | }; |
117 | |
118 | struct Q_GUI_EXPORT QRhiD3D11NativeHandles : public QRhiNativeHandles |
119 | { |
120 | // to import a device and a context |
121 | void *dev = nullptr; |
122 | void *context = nullptr; |
123 | // alternatively, to specify the device feature level and/or the adapter to use |
124 | int featureLevel = 0; |
125 | quint32 adapterLuidLow = 0; |
126 | qint32 adapterLuidHigh = 0; |
127 | }; |
128 | |
129 | struct Q_GUI_EXPORT QRhiD3D12InitParams : public QRhiInitParams |
130 | { |
131 | bool enableDebugLayer = false; |
132 | }; |
133 | |
134 | struct Q_GUI_EXPORT QRhiD3D12NativeHandles : public QRhiNativeHandles |
135 | { |
136 | // to import a device |
137 | void *dev = nullptr; |
138 | int minimumFeatureLevel = 0; |
139 | // to just specify the adapter to use, set these and leave dev set to null |
140 | quint32 adapterLuidLow = 0; |
141 | qint32 adapterLuidHigh = 0; |
142 | // in addition, can specify the command queue to use |
143 | void *commandQueue = nullptr; |
144 | }; |
145 | |
146 | struct Q_GUI_EXPORT QRhiD3D12CommandBufferNativeHandles : public QRhiNativeHandles |
147 | { |
148 | void *commandList = nullptr; // ID3D12GraphicsCommandList |
149 | }; |
150 | |
151 | #endif // WIN/QDOC |
152 | |
153 | #if defined(Q_OS_MACOS) || defined(Q_OS_IOS) || defined(Q_QDOC) |
154 | |
155 | struct Q_GUI_EXPORT QRhiMetalInitParams : public QRhiInitParams |
156 | { |
157 | }; |
158 | |
159 | struct Q_GUI_EXPORT QRhiMetalNativeHandles : public QRhiNativeHandles |
160 | { |
161 | MTLDevice *dev = nullptr; |
162 | MTLCommandQueue *cmdQueue = nullptr; |
163 | }; |
164 | |
165 | struct Q_GUI_EXPORT QRhiMetalCommandBufferNativeHandles : public QRhiNativeHandles |
166 | { |
167 | MTLCommandBuffer *commandBuffer = nullptr; |
168 | MTLRenderCommandEncoder *encoder = nullptr; |
169 | }; |
170 | |
171 | #endif // MACOS/IOS/QDOC |
172 | |
173 | QT_END_NAMESPACE |
174 | |
175 | #endif |
176 | |