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
27#ifdef Q_OS_INTEGRITY
28 class QShaderVersion;
29 size_t qHash(const QShaderVersion &, size_t = 0) noexcept;
30#endif
31
32class Q_GUI_EXPORT QShaderVersion
33{
34public:
35 enum Flag {
36 GlslEs = 0x01
37 };
38 Q_DECLARE_FLAGS(Flags, Flag)
39
40 QShaderVersion() = default;
41 QShaderVersion(int v, Flags f = Flags());
42
43 int version() const { return m_version; }
44 void setVersion(int v) { m_version = v; }
45
46 Flags flags() const { return m_flags; }
47 void setFlags(Flags f) { m_flags = f; }
48
49private:
50 int m_version = 100;
51 Flags m_flags;
52};
53
54Q_DECLARE_OPERATORS_FOR_FLAGS(QShaderVersion::Flags)
55Q_DECLARE_TYPEINFO(QShaderVersion, Q_RELOCATABLE_TYPE);
56
57class QShaderCode;
58Q_GUI_EXPORT size_t qHash(const QShaderCode &, size_t = 0) noexcept;
59
60class Q_GUI_EXPORT QShaderCode
61{
62public:
63 QShaderCode() = default;
64 QShaderCode(const QByteArray &code, const QByteArray &entry = QByteArray());
65
66 QByteArray shader() const { return m_shader; }
67 void setShader(const QByteArray &code) { m_shader = code; }
68
69 QByteArray entryPoint() const { return m_entryPoint; }
70 void setEntryPoint(const QByteArray &entry) { m_entryPoint = entry; }
71
72private:
73 friend Q_GUI_EXPORT size_t qHash(const QShaderCode &, size_t) noexcept;
74
75 QByteArray m_shader;
76 QByteArray m_entryPoint;
77};
78
80
81class Q_GUI_EXPORT QShader
82{
83public:
84 enum Stage {
85 VertexStage = 0,
86 TessellationControlStage,
87 TessellationEvaluationStage,
88 GeometryStage,
89 FragmentStage,
90 ComputeStage
91 };
92
93 enum Source {
94 SpirvShader = 0,
95 GlslShader,
96 HlslShader,
97 DxbcShader, // fxc
98 MslShader,
99 DxilShader, // dxc
100 MetalLibShader, // xcrun metal + xcrun metallib
101 WgslShader
102 };
103
104 enum Variant {
105 StandardShader = 0,
106 BatchableVertexShader,
107 UInt16IndexedVertexAsComputeShader,
108 UInt32IndexedVertexAsComputeShader,
109 NonIndexedVertexAsComputeShader,
110 HdrCapableFragmentShader,
111 };
112
113 enum class SerializedFormatVersion {
114 Latest = 0,
115 Qt_6_5,
116 Qt_6_4
117 };
118
119 QShader();
120 QShader(const QShader &other);
121 QShader &operator=(const QShader &other);
122 QShader(QShader &&other) noexcept : d(std::exchange(other.d, nullptr)) {}
123 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QShader)
124 ~QShader();
125
126 void swap(QShader &other) noexcept { qt_ptr_swap(d, other.d); }
127 void detach();
128
129 bool isValid() const;
130
131 Stage stage() const;
132 void setStage(Stage stage);
133
134 QShaderDescription description() const;
135 void setDescription(const QShaderDescription &desc);
136
137 QList<QShaderKey> availableShaders() const;
138 QShaderCode shader(const QShaderKey &key) const;
139 void setShader(const QShaderKey &key, const QShaderCode &shader);
140 void removeShader(const QShaderKey &key);
141
142 QByteArray serialized(SerializedFormatVersion version = SerializedFormatVersion::Latest) const;
143 static QShader fromSerialized(const QByteArray &data);
144
145 using NativeResourceBindingMap = QMap<int, std::pair<int, int>>; // binding -> native_binding[, native_binding]
146 NativeResourceBindingMap nativeResourceBindingMap(const QShaderKey &key) const;
147 void setResourceBindingMap(const QShaderKey &key, const NativeResourceBindingMap &map);
148 void removeResourceBindingMap(const QShaderKey &key);
149
150 struct SeparateToCombinedImageSamplerMapping {
151 QByteArray combinedSamplerName;
152 int textureBinding;
153 int samplerBinding;
154 };
155 using SeparateToCombinedImageSamplerMappingList = QList<SeparateToCombinedImageSamplerMapping>;
156 SeparateToCombinedImageSamplerMappingList separateToCombinedImageSamplerMappingList(const QShaderKey &key) const;
157 void setSeparateToCombinedImageSamplerMappingList(const QShaderKey &key,
158 const SeparateToCombinedImageSamplerMappingList &list);
159 void removeSeparateToCombinedImageSamplerMappingList(const QShaderKey &key);
160
161 struct NativeShaderInfo {
162 int flags = 0;
163 QMap<int, int> extraBufferBindings;
164 };
165 NativeShaderInfo nativeShaderInfo(const QShaderKey &key) const;
166 void setNativeShaderInfo(const QShaderKey &key, const NativeShaderInfo &info);
167 void removeNativeShaderInfo(const QShaderKey &key);
168
169private:
170 QShaderPrivate *d;
171 friend struct QShaderPrivate;
172 friend Q_GUI_EXPORT bool operator==(const QShader &, const QShader &) noexcept;
173 friend Q_GUI_EXPORT size_t qHash(const QShader &, size_t) noexcept;
174#ifndef QT_NO_DEBUG_STREAM
175 friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QShader &);
176#endif
177};
178
180
181class Q_GUI_EXPORT QShaderKey
182{
183public:
184 QShaderKey() = default;
185 QShaderKey(QShader::Source s,
186 const QShaderVersion &sver,
187 QShader::Variant svar = QShader::StandardShader);
188
189 QShader::Source source() const { return m_source; }
190 void setSource(QShader::Source s) { m_source = s; }
191
192 QShaderVersion sourceVersion() const { return m_sourceVersion; }
193 void setSourceVersion(const QShaderVersion &sver) { m_sourceVersion = sver; }
194
195 QShader::Variant sourceVariant() const { return m_sourceVariant; }
196 void setSourceVariant(QShader::Variant svar) { m_sourceVariant = svar; }
197
198private:
199 QShader::Source m_source = QShader::SpirvShader;
200 QShaderVersion m_sourceVersion;
201 QShader::Variant m_sourceVariant = QShader::StandardShader;
202};
203
205
206Q_GUI_EXPORT bool operator==(const QShader &lhs, const QShader &rhs) noexcept;
207Q_GUI_EXPORT size_t qHash(const QShader &s, size_t seed = 0) noexcept;
208
209inline bool operator!=(const QShader &lhs, const QShader &rhs) noexcept
210{
211 return !(lhs == rhs);
212}
213
214Q_GUI_EXPORT bool operator==(const QShaderVersion &lhs, const QShaderVersion &rhs) noexcept;
215Q_GUI_EXPORT bool operator<(const QShaderVersion &lhs, const QShaderVersion &rhs) noexcept;
216Q_GUI_EXPORT bool operator==(const QShaderKey &lhs, const QShaderKey &rhs) noexcept;
217Q_GUI_EXPORT bool operator<(const QShaderKey &lhs, const QShaderKey &rhs) noexcept;
218Q_GUI_EXPORT bool operator==(const QShaderCode &lhs, const QShaderCode &rhs) noexcept;
219
220inline bool operator!=(const QShaderVersion &lhs, const QShaderVersion &rhs) noexcept
221{
222 return !(lhs == rhs);
223}
224
225inline bool operator!=(const QShaderKey &lhs, const QShaderKey &rhs) noexcept
226{
227 return !(lhs == rhs);
228}
229
230inline bool operator!=(const QShaderCode &lhs, const QShaderCode &rhs) noexcept
231{
232 return !(lhs == rhs);
233}
234
235Q_GUI_EXPORT size_t qHash(const QShaderKey &k, size_t seed = 0) noexcept;
236
237#ifndef QT_NO_DEBUG_STREAM
238Q_GUI_EXPORT QDebug operator<<(QDebug, const QShader &);
239Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QShaderKey &k);
240Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QShaderVersion &v);
241#endif
242
243QT_END_NAMESPACE
244
245#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:807
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:818
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1853
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:857
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:578
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:46
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1310
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:783
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1118
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1182
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1198
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1781
\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:1213
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1594
\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:1224
\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:1864
\inmodule QtGui
Definition qshader.h:61
\inmodule QtGui
Definition qshader.h:182
\inmodule QtGui
Definition qshader.h:33
\inmodule QtGui
Definition qshader.h:82
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:230
Q_GUI_EXPORT bool operator==(const QShaderCode &lhs, const QShaderCode &rhs) noexcept
bool operator!=(const QShaderKey &lhs, const QShaderKey &rhs) noexcept
Definition qshader.h:225
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:1812
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1860
\variable QRhiReadbackResult::completed
Definition qrhi.h:810
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1835
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1556
LuminanceBehavior
\value SceneReferred Indicates that the color value of 1.0 is interpreted as 80 nits.
Definition qrhi.h:1562
LimitsType limitsType
Definition qrhi.h:1567
float maxPotentialColorComponentValue
Definition qrhi.h:1575
LimitsType
\value LuminanceInNits Indicates that the \l limits union has its luminanceInNits struct set
Definition qrhi.h:1557
LuminanceBehavior luminanceBehavior
Definition qrhi.h:1578
float maxColorComponentValue
Definition qrhi.h:1574
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1589
void * reserved[2]
Definition qrhi.h:1590