1/****************************************************************************
2**
3** Copyright (C) 2019 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the Qt Gui module
7**
8** $QT_BEGIN_LICENSE:LGPL3$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPLv3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or later as published by the Free
28** Software Foundation and appearing in the file LICENSE.GPL included in
29** the packaging of this file. Please review the following information to
30** ensure the GNU General Public License version 2.0 requirements will be
31** met: http://www.gnu.org/licenses/gpl-2.0.html.
32**
33** $QT_END_LICENSE$
34**
35****************************************************************************/
36
37#ifndef QSHADERDESCRIPTION_H
38#define QSHADERDESCRIPTION_H
39
40//
41// W A R N I N G
42// -------------
43//
44// This file is not part of the Qt API. It exists for the convenience
45// of a number of Qt sources files. This header file may change from
46// version to version without notice, or even be removed.
47//
48// We mean it.
49//
50
51#include <QtGui/qtguiglobal.h>
52#include <QtCore/QString>
53#include <QtCore/QVector>
54#include <array>
55
56QT_BEGIN_NAMESPACE
57
58struct QShaderDescriptionPrivate;
59
60class Q_GUI_EXPORT QShaderDescription
61{
62public:
63 QShaderDescription();
64 QShaderDescription(const QShaderDescription &other);
65 QShaderDescription &operator=(const QShaderDescription &other);
66 ~QShaderDescription();
67 void detach();
68
69 bool isValid() const;
70
71 QByteArray toBinaryJson() const;
72 QByteArray toJson() const;
73
74 static QShaderDescription fromBinaryJson(const QByteArray &data);
75
76 enum VariableType {
77 Unknown = 0,
78
79 // do not reorder
80 Float,
81 Vec2,
82 Vec3,
83 Vec4,
84 Mat2,
85 Mat2x3,
86 Mat2x4,
87 Mat3,
88 Mat3x2,
89 Mat3x4,
90 Mat4,
91 Mat4x2,
92 Mat4x3,
93
94 Int,
95 Int2,
96 Int3,
97 Int4,
98
99 Uint,
100 Uint2,
101 Uint3,
102 Uint4,
103
104 Bool,
105 Bool2,
106 Bool3,
107 Bool4,
108
109 Double,
110 Double2,
111 Double3,
112 Double4,
113 DMat2,
114 DMat2x3,
115 DMat2x4,
116 DMat3,
117 DMat3x2,
118 DMat3x4,
119 DMat4,
120 DMat4x2,
121 DMat4x3,
122
123 Sampler1D,
124 Sampler2D,
125 Sampler2DMS,
126 Sampler3D,
127 SamplerCube,
128 Sampler1DArray,
129 Sampler2DArray,
130 Sampler2DMSArray,
131 Sampler3DArray,
132 SamplerCubeArray,
133 SamplerRect,
134 SamplerBuffer,
135
136 Image1D,
137 Image2D,
138 Image2DMS,
139 Image3D,
140 ImageCube,
141 Image1DArray,
142 Image2DArray,
143 Image2DMSArray,
144 Image3DArray,
145 ImageCubeArray,
146 ImageRect,
147 ImageBuffer,
148
149 Struct
150 };
151
152 enum ImageFormat {
153 // must match SPIR-V's ImageFormat
154 ImageFormatUnknown = 0,
155 ImageFormatRgba32f = 1,
156 ImageFormatRgba16f = 2,
157 ImageFormatR32f = 3,
158 ImageFormatRgba8 = 4,
159 ImageFormatRgba8Snorm = 5,
160 ImageFormatRg32f = 6,
161 ImageFormatRg16f = 7,
162 ImageFormatR11fG11fB10f = 8,
163 ImageFormatR16f = 9,
164 ImageFormatRgba16 = 10,
165 ImageFormatRgb10A2 = 11,
166 ImageFormatRg16 = 12,
167 ImageFormatRg8 = 13,
168 ImageFormatR16 = 14,
169 ImageFormatR8 = 15,
170 ImageFormatRgba16Snorm = 16,
171 ImageFormatRg16Snorm = 17,
172 ImageFormatRg8Snorm = 18,
173 ImageFormatR16Snorm = 19,
174 ImageFormatR8Snorm = 20,
175 ImageFormatRgba32i = 21,
176 ImageFormatRgba16i = 22,
177 ImageFormatRgba8i = 23,
178 ImageFormatR32i = 24,
179 ImageFormatRg32i = 25,
180 ImageFormatRg16i = 26,
181 ImageFormatRg8i = 27,
182 ImageFormatR16i = 28,
183 ImageFormatR8i = 29,
184 ImageFormatRgba32ui = 30,
185 ImageFormatRgba16ui = 31,
186 ImageFormatRgba8ui = 32,
187 ImageFormatR32ui = 33,
188 ImageFormatRgb10a2ui = 34,
189 ImageFormatRg32ui = 35,
190 ImageFormatRg16ui = 36,
191 ImageFormatRg8ui = 37,
192 ImageFormatR16ui = 38,
193 ImageFormatR8ui = 39
194 };
195
196 enum ImageFlag {
197 ReadOnlyImage = 1 << 0,
198 WriteOnlyImage = 1 << 1
199 };
200 Q_DECLARE_FLAGS(ImageFlags, ImageFlag)
201
202 // Optional data (like decorations) usually default to an otherwise invalid value (-1 or 0). This is intentional.
203
204 struct InOutVariable {
205 QString name;
206 VariableType type = Unknown;
207 int location = -1;
208 int binding = -1;
209 int descriptorSet = -1;
210 ImageFormat imageFormat = ImageFormatUnknown;
211 ImageFlags imageFlags;
212 };
213
214 struct BlockVariable {
215 QString name;
216 VariableType type = Unknown;
217 int offset = 0;
218 int size = 0;
219 QVector<int> arrayDims;
220 int arrayStride = 0;
221 int matrixStride = 0;
222 bool matrixIsRowMajor = false;
223 QVector<BlockVariable> structMembers;
224 };
225
226 struct UniformBlock {
227 QString blockName;
228 QString structName; // instanceName
229 int size = 0;
230 int binding = -1;
231 int descriptorSet = -1;
232 QVector<BlockVariable> members;
233 };
234
235 struct PushConstantBlock {
236 QString name;
237 int size = 0;
238 QVector<BlockVariable> members;
239 };
240
241 struct StorageBlock {
242 QString blockName;
243 QString instanceName;
244 int knownSize = 0;
245 int binding = -1;
246 int descriptorSet = -1;
247 QVector<BlockVariable> members;
248 };
249
250 QVector<InOutVariable> inputVariables() const;
251 QVector<InOutVariable> outputVariables() const;
252 QVector<UniformBlock> uniformBlocks() const;
253 QVector<PushConstantBlock> pushConstantBlocks() const;
254 QVector<StorageBlock> storageBlocks() const;
255 QVector<InOutVariable> combinedImageSamplers() const;
256 QVector<InOutVariable> storageImages() const;
257
258 std::array<uint, 3> computeShaderLocalSize() const;
259
260private:
261 QShaderDescriptionPrivate *d;
262 friend struct QShaderDescriptionPrivate;
263#ifndef QT_NO_DEBUG_STREAM
264 friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QShaderDescription &);
265#endif
266};
267
268Q_DECLARE_OPERATORS_FOR_FLAGS(QShaderDescription::ImageFlags)
269
270#ifndef QT_NO_DEBUG_STREAM
271Q_GUI_EXPORT QDebug operator<<(QDebug, const QShaderDescription &);
272Q_GUI_EXPORT QDebug operator<<(QDebug, const QShaderDescription::InOutVariable &);
273Q_GUI_EXPORT QDebug operator<<(QDebug, const QShaderDescription::BlockVariable &);
274Q_GUI_EXPORT QDebug operator<<(QDebug, const QShaderDescription::UniformBlock &);
275Q_GUI_EXPORT QDebug operator<<(QDebug, const QShaderDescription::PushConstantBlock &);
276Q_GUI_EXPORT QDebug operator<<(QDebug, const QShaderDescription::StorageBlock &);
277#endif
278
279QT_END_NAMESPACE
280
281#endif
282