/src/qtbase/src/gui/rhi/qshaderdescription.h
Line | Count | Source |
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 | | // Qt-Security score:significant reason:default |
4 | | |
5 | | #ifndef QSHADERDESCRIPTION_H |
6 | | #define QSHADERDESCRIPTION_H |
7 | | |
8 | | // |
9 | | // W A R N I N G |
10 | | // ------------- |
11 | | // |
12 | | // This file is part of the RHI API, with limited compatibility guarantees. |
13 | | // Usage of this API may make your code source and binary incompatible with |
14 | | // future versions of Qt. |
15 | | // |
16 | | |
17 | | #include <QtGui/qtguiglobal.h> |
18 | | #include <QtCore/qstring.h> |
19 | | #include <QtCore/qlist.h> |
20 | | #include <array> |
21 | | |
22 | | QT_BEGIN_NAMESPACE |
23 | | |
24 | | struct QShaderDescriptionPrivate; |
25 | | class QDataStream; |
26 | | |
27 | | class Q_GUI_EXPORT QShaderDescription |
28 | | { |
29 | | public: |
30 | | QShaderDescription(); |
31 | | QShaderDescription(const QShaderDescription &other); |
32 | | QShaderDescription &operator=(const QShaderDescription &other); |
33 | | ~QShaderDescription(); |
34 | | void detach(); |
35 | | |
36 | | bool isValid() const; |
37 | | |
38 | | void serialize(QDataStream *stream, int version) const; |
39 | | QByteArray toJson() const; |
40 | | |
41 | | static QShaderDescription deserialize(QDataStream *stream, int version); |
42 | | |
43 | | enum VariableType { |
44 | | Unknown = 0, |
45 | | |
46 | | // do not reorder |
47 | | Float, |
48 | | Vec2, |
49 | | Vec3, |
50 | | Vec4, |
51 | | Mat2, |
52 | | Mat2x3, |
53 | | Mat2x4, |
54 | | Mat3, |
55 | | Mat3x2, |
56 | | Mat3x4, |
57 | | Mat4, |
58 | | Mat4x2, |
59 | | Mat4x3, |
60 | | |
61 | | Int, |
62 | | Int2, |
63 | | Int3, |
64 | | Int4, |
65 | | |
66 | | Uint, |
67 | | Uint2, |
68 | | Uint3, |
69 | | Uint4, |
70 | | |
71 | | Bool, |
72 | | Bool2, |
73 | | Bool3, |
74 | | Bool4, |
75 | | |
76 | | Double, |
77 | | Double2, |
78 | | Double3, |
79 | | Double4, |
80 | | DMat2, |
81 | | DMat2x3, |
82 | | DMat2x4, |
83 | | DMat3, |
84 | | DMat3x2, |
85 | | DMat3x4, |
86 | | DMat4, |
87 | | DMat4x2, |
88 | | DMat4x3, |
89 | | |
90 | | Sampler1D, |
91 | | Sampler2D, |
92 | | Sampler2DMS, |
93 | | Sampler3D, |
94 | | SamplerCube, |
95 | | Sampler1DArray, |
96 | | Sampler2DArray, |
97 | | Sampler2DMSArray, |
98 | | Sampler3DArray, |
99 | | SamplerCubeArray, |
100 | | SamplerRect, |
101 | | SamplerBuffer, |
102 | | SamplerExternalOES, |
103 | | Sampler, |
104 | | |
105 | | Image1D, |
106 | | Image2D, |
107 | | Image2DMS, |
108 | | Image3D, |
109 | | ImageCube, |
110 | | Image1DArray, |
111 | | Image2DArray, |
112 | | Image2DMSArray, |
113 | | Image3DArray, |
114 | | ImageCubeArray, |
115 | | ImageRect, |
116 | | ImageBuffer, |
117 | | |
118 | | Struct, |
119 | | |
120 | | Half, |
121 | | Half2, |
122 | | Half3, |
123 | | Half4 |
124 | | }; |
125 | | |
126 | | enum ImageFormat { |
127 | | // must match SPIR-V's ImageFormat |
128 | | ImageFormatUnknown = 0, |
129 | | ImageFormatRgba32f = 1, |
130 | | ImageFormatRgba16f = 2, |
131 | | ImageFormatR32f = 3, |
132 | | ImageFormatRgba8 = 4, |
133 | | ImageFormatRgba8Snorm = 5, |
134 | | ImageFormatRg32f = 6, |
135 | | ImageFormatRg16f = 7, |
136 | | ImageFormatR11fG11fB10f = 8, |
137 | | ImageFormatR16f = 9, |
138 | | ImageFormatRgba16 = 10, |
139 | | ImageFormatRgb10A2 = 11, |
140 | | ImageFormatRg16 = 12, |
141 | | ImageFormatRg8 = 13, |
142 | | ImageFormatR16 = 14, |
143 | | ImageFormatR8 = 15, |
144 | | ImageFormatRgba16Snorm = 16, |
145 | | ImageFormatRg16Snorm = 17, |
146 | | ImageFormatRg8Snorm = 18, |
147 | | ImageFormatR16Snorm = 19, |
148 | | ImageFormatR8Snorm = 20, |
149 | | ImageFormatRgba32i = 21, |
150 | | ImageFormatRgba16i = 22, |
151 | | ImageFormatRgba8i = 23, |
152 | | ImageFormatR32i = 24, |
153 | | ImageFormatRg32i = 25, |
154 | | ImageFormatRg16i = 26, |
155 | | ImageFormatRg8i = 27, |
156 | | ImageFormatR16i = 28, |
157 | | ImageFormatR8i = 29, |
158 | | ImageFormatRgba32ui = 30, |
159 | | ImageFormatRgba16ui = 31, |
160 | | ImageFormatRgba8ui = 32, |
161 | | ImageFormatR32ui = 33, |
162 | | ImageFormatRgb10a2ui = 34, |
163 | | ImageFormatRg32ui = 35, |
164 | | ImageFormatRg16ui = 36, |
165 | | ImageFormatRg8ui = 37, |
166 | | ImageFormatR16ui = 38, |
167 | | ImageFormatR8ui = 39 |
168 | | }; |
169 | | |
170 | | enum ImageFlag { |
171 | | ReadOnlyImage = 1 << 0, |
172 | | WriteOnlyImage = 1 << 1 |
173 | | }; |
174 | | Q_DECLARE_FLAGS(ImageFlags, ImageFlag) |
175 | | |
176 | | enum QualifierFlag { |
177 | | QualifierReadOnly = 1 << 0, |
178 | | QualifierWriteOnly = 1 << 1, |
179 | | QualifierCoherent = 1 << 2, |
180 | | QualifierVolatile = 1 << 3, |
181 | | QualifierRestrict = 1 << 4, |
182 | | }; |
183 | | Q_DECLARE_FLAGS(QualifierFlags, QualifierFlag) |
184 | | |
185 | | // Optional data (like decorations) usually default to an otherwise invalid value (-1 or 0). This is intentional. |
186 | | |
187 | | struct BlockVariable { |
188 | | QByteArray name; |
189 | | VariableType type = Unknown; |
190 | | int offset = 0; |
191 | | int size = 0; |
192 | | QList<int> arrayDims; |
193 | | int arrayStride = 0; |
194 | | int matrixStride = 0; |
195 | | bool matrixIsRowMajor = false; |
196 | | QList<BlockVariable> structMembers; |
197 | | }; |
198 | | |
199 | | struct InOutVariable { |
200 | | QByteArray name; |
201 | | VariableType type = Unknown; |
202 | | int location = -1; |
203 | | int binding = -1; |
204 | | int descriptorSet = -1; |
205 | | ImageFormat imageFormat = ImageFormatUnknown; |
206 | | ImageFlags imageFlags; |
207 | | QList<int> arrayDims; |
208 | | bool perPatch = false; |
209 | | QList<BlockVariable> structMembers; |
210 | | }; |
211 | | |
212 | | struct UniformBlock { |
213 | | QByteArray blockName; |
214 | | QByteArray structName; // instanceName |
215 | | int size = 0; |
216 | | int binding = -1; |
217 | | int descriptorSet = -1; |
218 | | QList<BlockVariable> members; |
219 | | }; |
220 | | |
221 | | struct PushConstantBlock { |
222 | | QByteArray name; |
223 | | int size = 0; |
224 | | QList<BlockVariable> members; |
225 | | }; |
226 | | |
227 | | struct StorageBlock { |
228 | | QByteArray blockName; |
229 | | QByteArray instanceName; |
230 | | int knownSize = 0; |
231 | | int binding = -1; |
232 | | int descriptorSet = -1; |
233 | | QList<BlockVariable> members; |
234 | | int runtimeArrayStride = 0; |
235 | | QualifierFlags qualifierFlags; |
236 | | }; |
237 | | |
238 | | QList<InOutVariable> inputVariables() const; |
239 | | QList<InOutVariable> outputVariables() const; |
240 | | QList<UniformBlock> uniformBlocks() const; |
241 | | QList<PushConstantBlock> pushConstantBlocks() const; |
242 | | QList<StorageBlock> storageBlocks() const; |
243 | | QList<InOutVariable> combinedImageSamplers() const; |
244 | | QList<InOutVariable> separateImages() const; |
245 | | QList<InOutVariable> separateSamplers() const; |
246 | | QList<InOutVariable> storageImages() const; |
247 | | |
248 | | enum BuiltinType { |
249 | | // must match SpvBuiltIn |
250 | | PositionBuiltin = 0, |
251 | | PointSizeBuiltin = 1, |
252 | | ClipDistanceBuiltin = 3, |
253 | | CullDistanceBuiltin = 4, |
254 | | VertexIdBuiltin = 5, |
255 | | InstanceIdBuiltin = 6, |
256 | | PrimitiveIdBuiltin = 7, |
257 | | InvocationIdBuiltin = 8, |
258 | | LayerBuiltin = 9, |
259 | | ViewportIndexBuiltin = 10, |
260 | | TessLevelOuterBuiltin = 11, |
261 | | TessLevelInnerBuiltin = 12, |
262 | | TessCoordBuiltin = 13, |
263 | | PatchVerticesBuiltin = 14, |
264 | | FragCoordBuiltin = 15, |
265 | | PointCoordBuiltin = 16, |
266 | | FrontFacingBuiltin = 17, |
267 | | SampleIdBuiltin = 18, |
268 | | SamplePositionBuiltin = 19, |
269 | | SampleMaskBuiltin = 20, |
270 | | FragDepthBuiltin = 22, |
271 | | NumWorkGroupsBuiltin = 24, |
272 | | WorkgroupSizeBuiltin = 25, |
273 | | WorkgroupIdBuiltin = 26, |
274 | | LocalInvocationIdBuiltin = 27, |
275 | | GlobalInvocationIdBuiltin = 28, |
276 | | LocalInvocationIndexBuiltin = 29, |
277 | | VertexIndexBuiltin = 42, |
278 | | InstanceIndexBuiltin = 43, |
279 | | ViewIndexBuiltin = 4440, |
280 | | }; |
281 | | |
282 | | struct BuiltinVariable { |
283 | | BuiltinType type; |
284 | | VariableType varType; |
285 | | QList<int> arrayDims; |
286 | | }; |
287 | | |
288 | | QList<BuiltinVariable> inputBuiltinVariables() const; |
289 | | QList<BuiltinVariable> outputBuiltinVariables() const; |
290 | | |
291 | | std::array<uint, 3> computeShaderLocalSize() const; |
292 | | |
293 | | uint tessellationOutputVertexCount() const; |
294 | | |
295 | | enum TessellationMode { |
296 | | UnknownTessellationMode, |
297 | | TrianglesTessellationMode, |
298 | | QuadTessellationMode, |
299 | | IsolineTessellationMode |
300 | | }; |
301 | | |
302 | | TessellationMode tessellationMode() const; |
303 | | |
304 | | enum TessellationWindingOrder { |
305 | | UnknownTessellationWindingOrder, |
306 | | CwTessellationWindingOrder, |
307 | | CcwTessellationWindingOrder |
308 | | }; |
309 | | |
310 | | TessellationWindingOrder tessellationWindingOrder() const; |
311 | | |
312 | | enum TessellationPartitioning { |
313 | | UnknownTessellationPartitioning, |
314 | | EqualTessellationPartitioning, |
315 | | FractionalEvenTessellationPartitioning, |
316 | | FractionalOddTessellationPartitioning |
317 | | }; |
318 | | |
319 | | TessellationPartitioning tessellationPartitioning() const; |
320 | | |
321 | | private: |
322 | | QShaderDescriptionPrivate *d; |
323 | | friend struct QShaderDescriptionPrivate; |
324 | | #ifndef QT_NO_DEBUG_STREAM |
325 | | friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QShaderDescription &); |
326 | | #endif |
327 | | friend Q_GUI_EXPORT bool operator==(const QShaderDescription &lhs, const QShaderDescription &rhs) noexcept; |
328 | | }; |
329 | | |
330 | 0 | Q_DECLARE_OPERATORS_FOR_FLAGS(QShaderDescription::ImageFlags) Unexecuted instantiation: operator|(QShaderDescription::ImageFlag, QShaderDescription::ImageFlag) Unexecuted instantiation: operator|(QShaderDescription::ImageFlag, QFlags<QShaderDescription::ImageFlag>) Unexecuted instantiation: operator&(QShaderDescription::ImageFlag, QShaderDescription::ImageFlag) Unexecuted instantiation: operator&(QShaderDescription::ImageFlag, QFlags<QShaderDescription::ImageFlag>) Unexecuted instantiation: operator^(QShaderDescription::ImageFlag, QShaderDescription::ImageFlag) Unexecuted instantiation: operator^(QShaderDescription::ImageFlag, QFlags<QShaderDescription::ImageFlag>) Unexecuted instantiation: operator|(QShaderDescription::ImageFlag, int) |
331 | 0 | Q_DECLARE_OPERATORS_FOR_FLAGS(QShaderDescription::QualifierFlags) Unexecuted instantiation: operator|(QShaderDescription::QualifierFlag, QShaderDescription::QualifierFlag) Unexecuted instantiation: operator|(QShaderDescription::QualifierFlag, QFlags<QShaderDescription::QualifierFlag>) Unexecuted instantiation: operator&(QShaderDescription::QualifierFlag, QShaderDescription::QualifierFlag) Unexecuted instantiation: operator&(QShaderDescription::QualifierFlag, QFlags<QShaderDescription::QualifierFlag>) Unexecuted instantiation: operator^(QShaderDescription::QualifierFlag, QShaderDescription::QualifierFlag) Unexecuted instantiation: operator^(QShaderDescription::QualifierFlag, QFlags<QShaderDescription::QualifierFlag>) Unexecuted instantiation: operator|(QShaderDescription::QualifierFlag, int) |
332 | 0 |
|
333 | 0 | #ifndef QT_NO_DEBUG_STREAM |
334 | 0 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QShaderDescription &); |
335 | 0 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QShaderDescription::InOutVariable &); |
336 | 0 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QShaderDescription::BlockVariable &); |
337 | 0 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QShaderDescription::UniformBlock &); |
338 | 0 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QShaderDescription::PushConstantBlock &); |
339 | 0 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QShaderDescription::StorageBlock &); |
340 | 0 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QShaderDescription::BuiltinVariable &); |
341 | 0 | #endif |
342 | 0 |
|
343 | 0 | Q_GUI_EXPORT bool operator==(const QShaderDescription &lhs, const QShaderDescription &rhs) noexcept; |
344 | 0 | Q_GUI_EXPORT bool operator==(const QShaderDescription::InOutVariable &lhs, const QShaderDescription::InOutVariable &rhs) noexcept; |
345 | 0 | Q_GUI_EXPORT bool operator==(const QShaderDescription::BlockVariable &lhs, const QShaderDescription::BlockVariable &rhs) noexcept; |
346 | 0 | Q_GUI_EXPORT bool operator==(const QShaderDescription::UniformBlock &lhs, const QShaderDescription::UniformBlock &rhs) noexcept; |
347 | 0 | Q_GUI_EXPORT bool operator==(const QShaderDescription::PushConstantBlock &lhs, const QShaderDescription::PushConstantBlock &rhs) noexcept; |
348 | 0 | Q_GUI_EXPORT bool operator==(const QShaderDescription::StorageBlock &lhs, const QShaderDescription::StorageBlock &rhs) noexcept; |
349 | 0 | Q_GUI_EXPORT bool operator==(const QShaderDescription::BuiltinVariable &lhs, const QShaderDescription::BuiltinVariable &rhs) noexcept; |
350 | 0 |
|
351 | 0 | inline bool operator!=(const QShaderDescription &lhs, const QShaderDescription &rhs) noexcept |
352 | 0 | { |
353 | 0 | return !(lhs == rhs); |
354 | 0 | } |
355 | | |
356 | | inline bool operator!=(const QShaderDescription::InOutVariable &lhs, const QShaderDescription::InOutVariable &rhs) noexcept |
357 | 0 | { |
358 | 0 | return !(lhs == rhs); |
359 | 0 | } |
360 | | |
361 | | inline bool operator!=(const QShaderDescription::BlockVariable &lhs, const QShaderDescription::BlockVariable &rhs) noexcept |
362 | 0 | { |
363 | 0 | return !(lhs == rhs); |
364 | 0 | } |
365 | | |
366 | | inline bool operator!=(const QShaderDescription::UniformBlock &lhs, const QShaderDescription::UniformBlock &rhs) noexcept |
367 | 0 | { |
368 | 0 | return !(lhs == rhs); |
369 | 0 | } |
370 | | |
371 | | inline bool operator!=(const QShaderDescription::PushConstantBlock &lhs, const QShaderDescription::PushConstantBlock &rhs) noexcept |
372 | 0 | { |
373 | 0 | return !(lhs == rhs); |
374 | 0 | } |
375 | | |
376 | | inline bool operator!=(const QShaderDescription::StorageBlock &lhs, const QShaderDescription::StorageBlock &rhs) noexcept |
377 | 0 | { |
378 | 0 | return !(lhs == rhs); |
379 | 0 | } |
380 | | |
381 | | inline bool operator!=(const QShaderDescription::BuiltinVariable &lhs, const QShaderDescription::BuiltinVariable &rhs) noexcept |
382 | 0 | { |
383 | 0 | return !(lhs == rhs); |
384 | 0 | } |
385 | | |
386 | | QT_END_NAMESPACE |
387 | | |
388 | | #endif |