Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qshader.h
Go to the documentation of this file.
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 QSHADER_H
6#define QSHADER_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/qhash.h>
19#include <QtCore/qmap.h>
20#include <rhi/qshaderdescription.h>
21
23
24struct QShaderPrivate;
25class QShaderKey;
26
27class Q_GUI_EXPORT QShaderVersion
28{
29public:
30 enum Flag {
31 GlslEs = 0x01
32 };
33 Q_DECLARE_FLAGS(Flags, Flag)
34
35 QShaderVersion() = default;
36 QShaderVersion(int v, Flags f = Flags());
37
38 int version() const { return m_version; }
39 void setVersion(int v) { m_version = v; }
40
41 Flags flags() const { return m_flags; }
42 void setFlags(Flags f) { m_flags = f; }
43
44private:
45 Q_GUI_EXPORT friend size_t qHash(QShaderVersion key, size_t seed) noexcept;
46 friend size_t qHash(QShaderVersion key) noexcept { return qHash(key, size_t{0}); }
47 #define QSHADERVERSION_IS_HASHABLE
48
49 int m_version = 100;
50 Flags m_flags;
51};
52
53Q_DECLARE_OPERATORS_FOR_FLAGS(QShaderVersion::Flags)
54Q_DECLARE_TYPEINFO(QShaderVersion, Q_RELOCATABLE_TYPE);
55
56class QShaderCode;
57Q_GUI_EXPORT size_t qHash(const QShaderCode &, size_t = 0) noexcept;
58
59class Q_GUI_EXPORT QShaderCode
60{
61public:
62 QShaderCode() = default;
63 QShaderCode(const QByteArray &code, const QByteArray &entry = QByteArray());
64
65 QByteArray shader() const { return m_shader; }
66 void setShader(const QByteArray &code) { m_shader = code; }
67
68 QByteArray entryPoint() const { return m_entryPoint; }
69 void setEntryPoint(const QByteArray &entry) { m_entryPoint = entry; }
70
71private:
72 friend Q_GUI_EXPORT size_t qHash(const QShaderCode &, size_t) noexcept;
73
74 QByteArray m_shader;
75 QByteArray m_entryPoint;
76};
77
79
80class Q_GUI_EXPORT QShader
81{
82public:
83 enum Stage {
84 VertexStage = 0,
85 TessellationControlStage,
86 TessellationEvaluationStage,
87 GeometryStage,
88 FragmentStage,
89 ComputeStage
90 };
91
92 enum Source {
93 SpirvShader = 0,
94 GlslShader,
95 HlslShader,
96 DxbcShader, // fxc
97 MslShader,
98 DxilShader, // dxc
99 MetalLibShader, // xcrun metal + xcrun metallib
100 WgslShader
101 };
102
103 enum Variant {
104 StandardShader = 0,
105 BatchableVertexShader,
106 UInt16IndexedVertexAsComputeShader,
107 UInt32IndexedVertexAsComputeShader,
108 NonIndexedVertexAsComputeShader,
109 HdrCapableFragmentShader,
110 };
111
112 enum class SerializedFormatVersion {
113 Latest = 0,
114 Qt_6_5,
115 Qt_6_4
116 };
117
118 QShader();
119 QShader(const QShader &other);
120 QShader &operator=(const QShader &other);
121 QShader(QShader &&other) noexcept : d(std::exchange(other.d, nullptr)) {}
122 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QShader)
123 ~QShader();
124
125 void swap(QShader &other) noexcept { qt_ptr_swap(d, other.d); }
126 void detach();
127
128 bool isValid() const;
129
130 Stage stage() const;
131 void setStage(Stage stage);
132
133 QShaderDescription description() const;
134 void setDescription(const QShaderDescription &desc);
135
136 QList<QShaderKey> availableShaders() const;
137 QShaderCode shader(const QShaderKey &key) const;
138 void setShader(const QShaderKey &key, const QShaderCode &shader);
139 void removeShader(const QShaderKey &key);
140
141 QByteArray serialized(SerializedFormatVersion version = SerializedFormatVersion::Latest) const;
142 static QShader fromSerialized(const QByteArray &data);
143
144 using NativeResourceBindingMap = QMap<int, std::pair<int, int>>; // binding -> native_binding[, native_binding]
145 NativeResourceBindingMap nativeResourceBindingMap(const QShaderKey &key) const;
146 void setResourceBindingMap(const QShaderKey &key, const NativeResourceBindingMap &map);
147 void removeResourceBindingMap(const QShaderKey &key);
148
149 struct SeparateToCombinedImageSamplerMapping {
150 QByteArray combinedSamplerName;
151 int textureBinding;
152 int samplerBinding;
153 };
154 using SeparateToCombinedImageSamplerMappingList = QList<SeparateToCombinedImageSamplerMapping>;
155 SeparateToCombinedImageSamplerMappingList separateToCombinedImageSamplerMappingList(const QShaderKey &key) const;
156 void setSeparateToCombinedImageSamplerMappingList(const QShaderKey &key,
157 const SeparateToCombinedImageSamplerMappingList &list);
158 void removeSeparateToCombinedImageSamplerMappingList(const QShaderKey &key);
159
160 struct NativeShaderInfo {
161 int flags = 0;
162 QMap<int, int> extraBufferBindings;
163 };
164 NativeShaderInfo nativeShaderInfo(const QShaderKey &key) const;
165 void setNativeShaderInfo(const QShaderKey &key, const NativeShaderInfo &info);
166 void removeNativeShaderInfo(const QShaderKey &key);
167
168private:
169 QShaderPrivate *d;
170 friend struct QShaderPrivate;
171 friend Q_GUI_EXPORT bool operator==(const QShader &, const QShader &) noexcept;
172 friend Q_GUI_EXPORT size_t qHash(const QShader &, size_t) noexcept;
173#ifndef QT_NO_DEBUG_STREAM
174 friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QShader &);
175#endif
176};
177
179
180class Q_GUI_EXPORT QShaderKey
181{
182public:
183 QShaderKey() = default;
184 QShaderKey(QShader::Source s,
185 const QShaderVersion &sver,
186 QShader::Variant svar = QShader::StandardShader);
187
188 QShader::Source source() const { return m_source; }
189 void setSource(QShader::Source s) { m_source = s; }
190
191 QShaderVersion sourceVersion() const { return m_sourceVersion; }
192 void setSourceVersion(const QShaderVersion &sver) { m_sourceVersion = sver; }
193
194 QShader::Variant sourceVariant() const { return m_sourceVariant; }
195 void setSourceVariant(QShader::Variant svar) { m_sourceVariant = svar; }
196
197private:
198 QShader::Source m_source = QShader::SpirvShader;
199 QShaderVersion m_sourceVersion;
200 QShader::Variant m_sourceVariant = QShader::StandardShader;
201};
202
204
205Q_GUI_EXPORT bool operator==(const QShader &lhs, const QShader &rhs) noexcept;
206Q_GUI_EXPORT size_t qHash(const QShader &s, size_t seed = 0) noexcept;
207
208inline bool operator!=(const QShader &lhs, const QShader &rhs) noexcept
209{
210 return !(lhs == rhs);
211}
212
213Q_GUI_EXPORT bool operator==(const QShaderVersion &lhs, const QShaderVersion &rhs) noexcept;
214Q_GUI_EXPORT bool operator<(const QShaderVersion &lhs, const QShaderVersion &rhs) noexcept;
215Q_GUI_EXPORT bool operator==(const QShaderKey &lhs, const QShaderKey &rhs) noexcept;
216Q_GUI_EXPORT bool operator<(const QShaderKey &lhs, const QShaderKey &rhs) noexcept;
217Q_GUI_EXPORT bool operator==(const QShaderCode &lhs, const QShaderCode &rhs) noexcept;
218
219inline bool operator!=(const QShaderVersion &lhs, const QShaderVersion &rhs) noexcept
220{
221 return !(lhs == rhs);
222}
223
224inline bool operator!=(const QShaderKey &lhs, const QShaderKey &rhs) noexcept
225{
226 return !(lhs == rhs);
227}
228
229inline bool operator!=(const QShaderCode &lhs, const QShaderCode &rhs) noexcept
230{
231 return !(lhs == rhs);
232}
233
234Q_GUI_EXPORT size_t qHash(const QShaderKey &k, size_t seed = 0) noexcept;
235
236#ifndef QT_NO_DEBUG_STREAM
237Q_GUI_EXPORT QDebug operator<<(QDebug, const QShader &);
238Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QShaderKey &k);
239Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QShaderVersion &v);
240#endif
241
242QT_END_NAMESPACE
243
244#endif
friend bool operator==(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
Returns true if lhs and rhs are equal, otherwise returns false.
Definition qbytearray.h:803
friend bool operator!=(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
Returns true if lhs and rhs are different, otherwise returns false.
Definition qbytearray.h:814
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1886
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:857
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:578
\variable QRhiIndexedIndirectDrawCommand::indexCount
Definition qrhi.h:1723
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:46
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1311
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:783
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1119
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1183
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1199
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1814
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:814
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:140
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:441
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:381
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1214
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1596
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:745
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:622
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1225
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:662
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:722
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:699
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:234
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:181
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:323
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:87
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1897
\inmodule QtGui
Definition qshader.h:60
\inmodule QtGui
Definition qshader.h:181
\inmodule QtGui
Definition qshader.h:28
\inmodule QtGui
Definition qshader.h:81
Combined button and popup list for selecting options.
Q_DECLARE_TYPEINFO(QByteArrayView, Q_PRIMITIVE_TYPE)
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2582
bool operator<(const QElapsedTimer &lhs, const QElapsedTimer &rhs) noexcept
Q_DECLARE_TYPEINFO(QRhiSwapChainHdrInfo, Q_RELOCATABLE_TYPE)
Q_DECLARE_TYPEINFO(QShaderKey, Q_RELOCATABLE_TYPE)
Q_DECLARE_TYPEINFO(QShaderCode, Q_RELOCATABLE_TYPE)
Q_GUI_EXPORT bool operator==(const QShaderKey &lhs, const QShaderKey &rhs) noexcept
bool operator!=(const QShaderCode &lhs, const QShaderCode &rhs) noexcept
Definition qshader.h:229
Q_GUI_EXPORT bool operator==(const QShaderCode &lhs, const QShaderCode &rhs) noexcept
bool operator!=(const QShaderKey &lhs, const QShaderKey &rhs) noexcept
Definition qshader.h:224
Q_GUI_EXPORT bool operator<(const QShaderKey &lhs, const QShaderKey &rhs) noexcept
int main(int argc, char *argv[])
[ctor_close]
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1845
\variable QRhiIndirectDrawCommand::vertexCount
Definition qrhi.h:1710
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1893
\variable QRhiReadbackResult::completed
Definition qrhi.h:810
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1868
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1558
LuminanceBehavior
\value SceneReferred Indicates that the color value of 1.0 is interpreted as 80 nits.
Definition qrhi.h:1564
LimitsType limitsType
Definition qrhi.h:1569
float maxPotentialColorComponentValue
Definition qrhi.h:1577
LimitsType
\value LuminanceInNits Indicates that the \l limits union has its luminanceInNits struct set
Definition qrhi.h:1559
LuminanceBehavior luminanceBehavior
Definition qrhi.h:1580
float maxColorComponentValue
Definition qrhi.h:1576
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1591
void * reserved[2]
Definition qrhi.h:1592