Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
4#ifndef QSHADER_H
5#define QSHADER_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 <QtGui/qtguiglobal.h>
17#include <QtCore/qhash.h>
18#include <QtCore/qmap.h>
20
22
23struct QShaderPrivate;
24class QShaderKey;
25
26#ifdef Q_OS_INTEGRITY
27 class QShaderVersion;
28 size_t qHash(const QShaderVersion &, size_t = 0) noexcept;
29#endif
30
31class Q_GUI_EXPORT QShaderVersion
32{
33public:
34 enum Flag {
35 GlslEs = 0x01
36 };
38
39 QShaderVersion() = default;
40 QShaderVersion(int v, Flags f = Flags());
41
42 int version() const { return m_version; }
43 void setVersion(int v) { m_version = v; }
44
45 Flags flags() const { return m_flags; }
46 void setFlags(Flags f) { m_flags = f; }
47
48private:
49 int m_version = 100;
50 Flags m_flags;
51};
52
53Q_DECLARE_OPERATORS_FOR_FLAGS(QShaderVersion::Flags)
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:
91
92 enum Source {
93 SpirvShader = 0,
96 DxbcShader, // fxc
98 DxilShader, // dxc
99 MetalLibShader, // xcrun metal + xcrun metallib
100 WgslShader
101 };
102
110
112 Latest = 0,
113 Qt_6_5,
114 Qt_6_4
115 };
116
117 QShader();
118 QShader(const QShader &other);
119 QShader &operator=(const QShader &other);
120 QShader(QShader &&other) noexcept : d(std::exchange(other.d, nullptr)) {}
121 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QShader)
122 ~QShader();
123
124 void swap(QShader &other) noexcept { qt_ptr_swap(d, other.d); }
125 void detach();
126
127 bool isValid() const;
128
129 Stage stage() const;
130 void setStage(Stage stage);
131
132 QShaderDescription description() const;
133 void setDescription(const QShaderDescription &desc);
134
135 QList<QShaderKey> availableShaders() const;
136 QShaderCode shader(const QShaderKey &key) const;
137 void setShader(const QShaderKey &key, const QShaderCode &shader);
138 void removeShader(const QShaderKey &key);
139
140 QByteArray serialized(SerializedFormatVersion version = SerializedFormatVersion::Latest) const;
141 static QShader fromSerialized(const QByteArray &data);
142
143 using NativeResourceBindingMap = QMap<int, QPair<int, int> >; // binding -> native_binding[, native_binding]
144 NativeResourceBindingMap nativeResourceBindingMap(const QShaderKey &key) const;
145 void setResourceBindingMap(const QShaderKey &key, const NativeResourceBindingMap &map);
146 void removeResourceBindingMap(const QShaderKey &key);
147
153 using SeparateToCombinedImageSamplerMappingList = QList<SeparateToCombinedImageSamplerMapping>;
154 SeparateToCombinedImageSamplerMappingList separateToCombinedImageSamplerMappingList(const QShaderKey &key) const;
155 void setSeparateToCombinedImageSamplerMappingList(const QShaderKey &key,
157 void removeSeparateToCombinedImageSamplerMappingList(const QShaderKey &key);
158
160 int flags = 0;
161 QMap<int, int> extraBufferBindings;
162 };
163 NativeShaderInfo nativeShaderInfo(const QShaderKey &key) const;
164 void setNativeShaderInfo(const QShaderKey &key, const NativeShaderInfo &info);
165 void removeNativeShaderInfo(const QShaderKey &key);
166
167private:
169 friend struct QShaderPrivate;
170 friend Q_GUI_EXPORT bool operator==(const QShader &, const QShader &) noexcept;
171 friend Q_GUI_EXPORT size_t qHash(const QShader &, size_t) noexcept;
172#ifndef QT_NO_DEBUG_STREAM
173 friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QShader &);
174#endif
175};
176
177class Q_GUI_EXPORT QShaderKey
178{
179public:
180 QShaderKey() = default;
182 const QShaderVersion &sver,
184
185 QShader::Source source() const { return m_source; }
186 void setSource(QShader::Source s) { m_source = s; }
187
188 QShaderVersion sourceVersion() const { return m_sourceVersion; }
189 void setSourceVersion(const QShaderVersion &sver) { m_sourceVersion = sver; }
190
191 QShader::Variant sourceVariant() const { return m_sourceVariant; }
192 void setSourceVariant(QShader::Variant svar) { m_sourceVariant = svar; }
193
194private:
196 QShaderVersion m_sourceVersion;
198};
199
201
202Q_GUI_EXPORT bool operator==(const QShader &lhs, const QShader &rhs) noexcept;
203Q_GUI_EXPORT size_t qHash(const QShader &s, size_t seed = 0) noexcept;
204
205inline bool operator!=(const QShader &lhs, const QShader &rhs) noexcept
206{
207 return !(lhs == rhs);
208}
209
210Q_GUI_EXPORT bool operator==(const QShaderVersion &lhs, const QShaderVersion &rhs) noexcept;
211Q_GUI_EXPORT bool operator<(const QShaderVersion &lhs, const QShaderVersion &rhs) noexcept;
212Q_GUI_EXPORT bool operator==(const QShaderKey &lhs, const QShaderKey &rhs) noexcept;
213Q_GUI_EXPORT bool operator<(const QShaderKey &lhs, const QShaderKey &rhs) noexcept;
214Q_GUI_EXPORT bool operator==(const QShaderCode &lhs, const QShaderCode &rhs) noexcept;
215
216inline bool operator!=(const QShaderVersion &lhs, const QShaderVersion &rhs) noexcept
217{
218 return !(lhs == rhs);
219}
220
221inline bool operator!=(const QShaderKey &lhs, const QShaderKey &rhs) noexcept
222{
223 return !(lhs == rhs);
224}
225
226inline bool operator!=(const QShaderCode &lhs, const QShaderCode &rhs) noexcept
227{
228 return !(lhs == rhs);
229}
230
231Q_GUI_EXPORT size_t qHash(const QShaderKey &k, size_t seed = 0) noexcept;
232
233#ifndef QT_NO_DEBUG_STREAM
234Q_GUI_EXPORT QDebug operator<<(QDebug, const QShader &);
235Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QShaderKey &k);
236Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QShaderVersion &v);
237#endif
238
240
241#endif
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
Definition qlist.h:75
\inmodule QtGui
Definition qshader.h:60
QShaderCode()=default
QByteArray shader() const
Definition qshader.h:65
void setShader(const QByteArray &code)
Sets the shader source or byte code.
Definition qshader.h:66
QByteArray entryPoint() const
Definition qshader.h:68
void setEntryPoint(const QByteArray &entry)
Sets the entry point name.
Definition qshader.h:69
\inmodule QtGui
Definition qshader.h:178
void setSource(QShader::Source s)
Sets the shader type s.
Definition qshader.h:186
void setSourceVariant(QShader::Variant svar)
Sets the type of variant to use to svar.
Definition qshader.h:192
void setSourceVersion(const QShaderVersion &sver)
Sets the shading language version sver.
Definition qshader.h:189
QShader::Source source() const
Definition qshader.h:185
QShaderVersion sourceVersion() const
Definition qshader.h:188
QShader::Variant sourceVariant() const
Definition qshader.h:191
QShaderKey()=default
\inmodule QtGui
Definition qshader.h:32
void setVersion(int v)
Sets the shading language version to v.
Definition qshader.h:43
Flag
Describes the flags that can be set.
Definition qshader.h:34
void setFlags(Flags f)
Sets the flags f.
Definition qshader.h:46
Flags flags() const
Definition qshader.h:45
\inmodule QtGui
Definition qshader.h:81
SerializedFormatVersion
Describes the desired output format when serializing the QShader.
Definition qshader.h:111
void swap(QShader &other) noexcept
Definition qshader.h:124
Variant
Describes what kind of shader code an entry contains.
Definition qshader.h:103
@ BatchableVertexShader
Definition qshader.h:105
@ UInt32IndexedVertexAsComputeShader
Definition qshader.h:107
@ UInt16IndexedVertexAsComputeShader
Definition qshader.h:106
@ StandardShader
Definition qshader.h:104
QShader(QShader &&other) noexcept
Definition qshader.h:120
Source
Describes what kind of shader code an entry contains.
Definition qshader.h:92
@ SpirvShader
Definition qshader.h:93
@ GlslShader
Definition qshader.h:94
@ DxilShader
Definition qshader.h:98
@ HlslShader
Definition qshader.h:95
@ DxbcShader
Definition qshader.h:96
@ MetalLibShader
Definition qshader.h:99
@ MslShader
Definition qshader.h:97
Stage
Describes the stage of the graphics pipeline the shader is suitable for.
Definition qshader.h:83
@ GeometryStage
Definition qshader.h:87
@ TessellationEvaluationStage
Definition qshader.h:86
@ FragmentStage
Definition qshader.h:88
@ TessellationControlStage
Definition qshader.h:85
QMap< QString, QString > map
[6]
Combined button and popup list for selecting options.
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
size_t qHash(const QFileSystemWatcherPathKey &key, size_t seed=0)
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition qflags.h:194
Flags
GLsizei const GLfloat * v
[13]
GLuint64 key
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLfloat GLfloat f
GLbitfield flags
GLdouble s
[6]
Definition qopenglext.h:235
GLuint entry
GLuint shader
Definition qopenglext.h:665
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
Definition qrandom.cpp:196
bool operator==(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
Definition qrandom.cpp:1220
Q_GUI_EXPORT bool operator<(const QShaderVersion &lhs, const QShaderVersion &rhs) noexcept
Q_GUI_EXPORT bool operator==(const QShader &lhs, const QShader &rhs) noexcept
bool operator!=(const QShader &lhs, const QShader &rhs) noexcept
Definition qshader.h:205
Q_GUI_EXPORT size_t qHash(const QShaderCode &, size_t=0) noexcept
Q_GUI_EXPORT QDebug operator<<(QDebug, const QShader &)
Definition qshader.cpp:949
constexpr void qt_ptr_swap(T *&lhs, T *&rhs) noexcept
Definition qswap.h:29
@ Q_RELOCATABLE_TYPE
Definition qtypeinfo.h:158
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:180
QList< int > list
[14]
QDataStream & operator<<(QDataStream &out, const MyClass &myObj)
[4]
QSharedPointer< T > other(t)
[5]
QHostInfo info
[0]
\inmodule QtGui
Definition qshader.h:159
QMap< int, int > extraBufferBindings
Definition qshader.h:161