/src/qtbase/src/gui/rhi/qrhi.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 QRHI_H |
6 | | #define QRHI_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/qsize.h> |
19 | | #include <QtCore/qlist.h> |
20 | | #include <QtCore/qvarlengtharray.h> |
21 | | #include <QtCore/qthread.h> |
22 | | #include <QtGui/qmatrix4x4.h> |
23 | | #include <QtGui/qcolor.h> |
24 | | #include <QtGui/qimage.h> |
25 | | #include <functional> |
26 | | #include <array> |
27 | | |
28 | | #include <rhi/qshader.h> |
29 | | |
30 | | QT_BEGIN_NAMESPACE |
31 | | |
32 | | class QWindow; |
33 | | class QRhi; |
34 | | class QRhiImplementation; |
35 | | class QRhiBuffer; |
36 | | class QRhiRenderBuffer; |
37 | | class QRhiTexture; |
38 | | class QRhiSampler; |
39 | | class QRhiCommandBuffer; |
40 | | class QRhiResourceUpdateBatch; |
41 | | class QRhiResourceUpdateBatchPrivate; |
42 | | class QRhiSwapChain; |
43 | | class QRhiShadingRateMap; |
44 | | |
45 | | class Q_GUI_EXPORT QRhiDepthStencilClearValue |
46 | | { |
47 | | public: |
48 | | QRhiDepthStencilClearValue() = default; |
49 | | QRhiDepthStencilClearValue(float d, quint32 s); |
50 | | |
51 | 0 | float depthClearValue() const { return m_d; } |
52 | 0 | void setDepthClearValue(float d) { m_d = d; } |
53 | | |
54 | 0 | quint32 stencilClearValue() const { return m_s; } |
55 | 0 | void setStencilClearValue(quint32 s) { m_s = s; } |
56 | | |
57 | | private: |
58 | | float m_d = 1.0f; |
59 | | quint32 m_s = 0; |
60 | | |
61 | | friend bool operator==(const QRhiDepthStencilClearValue &a, const QRhiDepthStencilClearValue &b) noexcept |
62 | 0 | { |
63 | 0 | return a.m_d == b.m_d && a.m_s == b.m_s; |
64 | 0 | } |
65 | | |
66 | | friend bool operator!=(const QRhiDepthStencilClearValue &a, const QRhiDepthStencilClearValue &b) noexcept |
67 | 0 | { |
68 | 0 | return !(a == b); |
69 | 0 | } |
70 | | |
71 | | friend size_t qHash(const QRhiDepthStencilClearValue &v, size_t seed = 0) noexcept |
72 | 0 | { |
73 | 0 | QtPrivate::QHashCombine hash(seed); |
74 | 0 | seed = hash(seed, v.m_d); |
75 | 0 | seed = hash(seed, v.m_s); |
76 | 0 | return seed; |
77 | 0 | } |
78 | | }; |
79 | | |
80 | | Q_DECLARE_TYPEINFO(QRhiDepthStencilClearValue, Q_RELOCATABLE_TYPE); |
81 | | |
82 | | #ifndef QT_NO_DEBUG_STREAM |
83 | | Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiDepthStencilClearValue &); |
84 | | #endif |
85 | | |
86 | | class Q_GUI_EXPORT QRhiViewport |
87 | | { |
88 | | public: |
89 | | QRhiViewport() = default; |
90 | | QRhiViewport(float x, float y, float w, float h, float minDepth = 0.0f, float maxDepth = 1.0f); |
91 | | |
92 | 0 | std::array<float, 4> viewport() const { return m_rect; } |
93 | 0 | void setViewport(float x, float y, float w, float h) { |
94 | 0 | m_rect[0] = x; m_rect[1] = y; m_rect[2] = w; m_rect[3] = h; |
95 | 0 | } |
96 | | |
97 | 0 | float minDepth() const { return m_minDepth; } |
98 | 0 | void setMinDepth(float minDepth) { m_minDepth = minDepth; } |
99 | | |
100 | 0 | float maxDepth() const { return m_maxDepth; } |
101 | 0 | void setMaxDepth(float maxDepth) { m_maxDepth = maxDepth; } |
102 | | |
103 | | private: |
104 | | std::array<float, 4> m_rect { { 0.0f, 0.0f, 0.0f, 0.0f } }; |
105 | | float m_minDepth = 0.0f; |
106 | | float m_maxDepth = 1.0f; |
107 | | |
108 | | friend bool operator==(const QRhiViewport &a, const QRhiViewport &b) noexcept |
109 | 0 | { |
110 | 0 | return a.m_rect == b.m_rect |
111 | 0 | && a.m_minDepth == b.m_minDepth |
112 | 0 | && a.m_maxDepth == b.m_maxDepth; |
113 | 0 | } |
114 | | |
115 | | friend bool operator!=(const QRhiViewport &a, const QRhiViewport &b) noexcept |
116 | 0 | { |
117 | 0 | return !(a == b); |
118 | 0 | } |
119 | | |
120 | | friend size_t qHash(const QRhiViewport &v, size_t seed = 0) noexcept |
121 | 0 | { |
122 | 0 | QtPrivate::QHashCombine hash(seed); |
123 | 0 | seed = hash(seed, v.m_rect[0]); |
124 | 0 | seed = hash(seed, v.m_rect[1]); |
125 | 0 | seed = hash(seed, v.m_rect[2]); |
126 | 0 | seed = hash(seed, v.m_rect[3]); |
127 | 0 | seed = hash(seed, v.m_minDepth); |
128 | 0 | seed = hash(seed, v.m_maxDepth); |
129 | 0 | return seed; |
130 | 0 | } |
131 | | }; |
132 | | |
133 | | Q_DECLARE_TYPEINFO(QRhiViewport, Q_RELOCATABLE_TYPE); |
134 | | |
135 | | #ifndef QT_NO_DEBUG_STREAM |
136 | | Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiViewport &); |
137 | | #endif |
138 | | |
139 | | class Q_GUI_EXPORT QRhiScissor |
140 | | { |
141 | | public: |
142 | | QRhiScissor() = default; |
143 | | QRhiScissor(int x, int y, int w, int h); |
144 | | |
145 | 0 | std::array<int, 4> scissor() const { return m_rect; } |
146 | 0 | void setScissor(int x, int y, int w, int h) { |
147 | 0 | m_rect[0] = x; m_rect[1] = y; m_rect[2] = w; m_rect[3] = h; |
148 | 0 | } |
149 | | |
150 | | private: |
151 | | std::array<int, 4> m_rect { { 0, 0, 0, 0 } }; |
152 | | |
153 | | friend bool operator==(const QRhiScissor &a, const QRhiScissor &b) noexcept |
154 | 0 | { |
155 | 0 | return a.m_rect == b.m_rect; |
156 | 0 | } |
157 | | |
158 | | friend bool operator!=(const QRhiScissor &a, const QRhiScissor &b) noexcept |
159 | 0 | { |
160 | 0 | return !(a == b); |
161 | 0 | } |
162 | | |
163 | | friend size_t qHash(const QRhiScissor &v, size_t seed = 0) noexcept |
164 | 0 | { |
165 | 0 | QtPrivate::QHashCombine hash(seed); |
166 | 0 | seed = hash(seed, v.m_rect[0]); |
167 | 0 | seed = hash(seed, v.m_rect[1]); |
168 | 0 | seed = hash(seed, v.m_rect[2]); |
169 | 0 | seed = hash(seed, v.m_rect[3]); |
170 | 0 | return seed; |
171 | 0 | } |
172 | | }; |
173 | | |
174 | | Q_DECLARE_TYPEINFO(QRhiScissor, Q_RELOCATABLE_TYPE); |
175 | | |
176 | | #ifndef QT_NO_DEBUG_STREAM |
177 | | Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiScissor &); |
178 | | #endif |
179 | | |
180 | | class Q_GUI_EXPORT QRhiVertexInputBinding |
181 | | { |
182 | | public: |
183 | | enum Classification { |
184 | | PerVertex, |
185 | | PerInstance |
186 | | }; |
187 | | |
188 | | QRhiVertexInputBinding() = default; |
189 | | QRhiVertexInputBinding(quint32 stride, Classification cls = PerVertex, quint32 stepRate = 1); |
190 | | |
191 | 0 | quint32 stride() const { return m_stride; } |
192 | 0 | void setStride(quint32 s) { m_stride = s; } |
193 | | |
194 | 0 | Classification classification() const { return m_classification; } |
195 | 0 | void setClassification(Classification c) { m_classification = c; } |
196 | | |
197 | 0 | quint32 instanceStepRate() const { return m_instanceStepRate; } |
198 | 0 | void setInstanceStepRate(quint32 rate) { m_instanceStepRate = rate; } |
199 | | |
200 | | private: |
201 | | quint32 m_stride = 0; |
202 | | Classification m_classification = PerVertex; |
203 | | quint32 m_instanceStepRate = 1; |
204 | | |
205 | | friend bool operator==(const QRhiVertexInputBinding &a, const QRhiVertexInputBinding &b) noexcept |
206 | 0 | { |
207 | 0 | return a.m_stride == b.m_stride |
208 | 0 | && a.m_classification == b.m_classification |
209 | 0 | && a.m_instanceStepRate == b.m_instanceStepRate; |
210 | 0 | } |
211 | | |
212 | | friend bool operator!=(const QRhiVertexInputBinding &a, const QRhiVertexInputBinding &b) noexcept |
213 | 0 | { |
214 | 0 | return !(a == b); |
215 | 0 | } |
216 | | |
217 | | friend size_t qHash(const QRhiVertexInputBinding &v, size_t seed = 0) noexcept |
218 | 0 | { |
219 | 0 | QtPrivate::QHashCombine hash(seed); |
220 | 0 | seed = hash(seed, v.m_stride); |
221 | 0 | seed = hash(seed, v.m_classification); |
222 | 0 | seed = hash(seed, v.m_instanceStepRate); |
223 | 0 | return seed; |
224 | 0 | } |
225 | | }; |
226 | | |
227 | | Q_DECLARE_TYPEINFO(QRhiVertexInputBinding, Q_RELOCATABLE_TYPE); |
228 | | |
229 | | #ifndef QT_NO_DEBUG_STREAM |
230 | | Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiVertexInputBinding &); |
231 | | #endif |
232 | | |
233 | | class Q_GUI_EXPORT QRhiVertexInputAttribute |
234 | | { |
235 | | public: |
236 | | enum Format { |
237 | | Float4, |
238 | | Float3, |
239 | | Float2, |
240 | | Float, |
241 | | UNormByte4, |
242 | | UNormByte2, |
243 | | UNormByte, |
244 | | UInt4, |
245 | | UInt3, |
246 | | UInt2, |
247 | | UInt, |
248 | | SInt4, |
249 | | SInt3, |
250 | | SInt2, |
251 | | SInt, |
252 | | Half4, |
253 | | Half3, |
254 | | Half2, |
255 | | Half, |
256 | | UShort4, |
257 | | UShort3, |
258 | | UShort2, |
259 | | UShort, |
260 | | SShort4, |
261 | | SShort3, |
262 | | SShort2, |
263 | | SShort, |
264 | | }; |
265 | | |
266 | | QRhiVertexInputAttribute() = default; |
267 | | QRhiVertexInputAttribute(int binding, int location, Format format, quint32 offset, int matrixSlice = -1); |
268 | | |
269 | 0 | int binding() const { return m_binding; } |
270 | 0 | void setBinding(int b) { m_binding = b; } |
271 | | |
272 | 0 | int location() const { return m_location; } |
273 | 0 | void setLocation(int loc) { m_location = loc; } |
274 | | |
275 | 0 | Format format() const { return m_format; } |
276 | 0 | void setFormat(Format f) { m_format = f; } |
277 | | |
278 | 0 | quint32 offset() const { return m_offset; } |
279 | 0 | void setOffset(quint32 ofs) { m_offset = ofs; } |
280 | | |
281 | 0 | int matrixSlice() const { return m_matrixSlice; } |
282 | 0 | void setMatrixSlice(int slice) { m_matrixSlice = slice; } |
283 | | |
284 | | private: |
285 | | int m_binding = 0; |
286 | | int m_location = 0; |
287 | | Format m_format = Float4; |
288 | | quint32 m_offset = 0; |
289 | | int m_matrixSlice = -1; |
290 | | |
291 | | friend bool operator==(const QRhiVertexInputAttribute &a, const QRhiVertexInputAttribute &b) noexcept |
292 | 0 | { |
293 | 0 | return a.m_binding == b.m_binding |
294 | 0 | && a.m_location == b.m_location |
295 | 0 | && a.m_format == b.m_format |
296 | 0 | && a.m_offset == b.m_offset; |
297 | 0 | // matrixSlice excluded intentionally |
298 | 0 | } |
299 | | |
300 | | friend bool operator!=(const QRhiVertexInputAttribute &a, const QRhiVertexInputAttribute &b) noexcept |
301 | 0 | { |
302 | 0 | return !(a == b); |
303 | 0 | } |
304 | | |
305 | | friend size_t qHash(const QRhiVertexInputAttribute &v, size_t seed = 0) noexcept |
306 | 0 | { |
307 | 0 | QtPrivate::QHashCombine hash(seed); |
308 | 0 | seed = hash(seed, v.m_binding); |
309 | 0 | seed = hash(seed, v.m_location); |
310 | 0 | seed = hash(seed, v.m_format); |
311 | 0 | seed = hash(seed, v.m_offset); |
312 | 0 | return seed; |
313 | 0 | } |
314 | | }; |
315 | | |
316 | | Q_DECLARE_TYPEINFO(QRhiVertexInputAttribute, Q_RELOCATABLE_TYPE); |
317 | | |
318 | | #ifndef QT_NO_DEBUG_STREAM |
319 | | Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiVertexInputAttribute &); |
320 | | #endif |
321 | | |
322 | | class Q_GUI_EXPORT QRhiVertexInputLayout |
323 | | { |
324 | | public: |
325 | 0 | QRhiVertexInputLayout() = default; |
326 | | |
327 | 0 | void setBindings(std::initializer_list<QRhiVertexInputBinding> list) { m_bindings = list; } |
328 | | template<typename InputIterator> |
329 | | void setBindings(InputIterator first, InputIterator last) |
330 | | { |
331 | | m_bindings.clear(); |
332 | | std::copy(first, last, std::back_inserter(m_bindings)); |
333 | | } |
334 | 0 | const QRhiVertexInputBinding *cbeginBindings() const { return m_bindings.cbegin(); } |
335 | 0 | const QRhiVertexInputBinding *cendBindings() const { return m_bindings.cend(); } |
336 | 0 | const QRhiVertexInputBinding *bindingAt(qsizetype index) const { return &m_bindings.at(index); } |
337 | 0 | qsizetype bindingCount() const { return m_bindings.count(); } |
338 | | |
339 | 0 | void setAttributes(std::initializer_list<QRhiVertexInputAttribute> list) { m_attributes = list; } |
340 | | template<typename InputIterator> |
341 | | void setAttributes(InputIterator first, InputIterator last) |
342 | | { |
343 | | m_attributes.clear(); |
344 | | std::copy(first, last, std::back_inserter(m_attributes)); |
345 | | } |
346 | 0 | const QRhiVertexInputAttribute *cbeginAttributes() const { return m_attributes.cbegin(); } |
347 | 0 | const QRhiVertexInputAttribute *cendAttributes() const { return m_attributes.cend(); } |
348 | 0 | const QRhiVertexInputAttribute *attributeAt(qsizetype index) const { return &m_attributes.at(index); } |
349 | 0 | qsizetype attributeCount() const { return m_attributes.count(); } |
350 | | |
351 | | private: |
352 | | QVarLengthArray<QRhiVertexInputBinding, 8> m_bindings; |
353 | | QVarLengthArray<QRhiVertexInputAttribute, 8> m_attributes; |
354 | | |
355 | | friend bool operator==(const QRhiVertexInputLayout &a, const QRhiVertexInputLayout &b) noexcept |
356 | 0 | { |
357 | 0 | return a.m_bindings == b.m_bindings && a.m_attributes == b.m_attributes; |
358 | 0 | } |
359 | | |
360 | | friend bool operator!=(const QRhiVertexInputLayout &a, const QRhiVertexInputLayout &b) noexcept |
361 | 0 | { |
362 | 0 | return !(a == b); |
363 | 0 | } |
364 | | |
365 | | friend size_t qHash(const QRhiVertexInputLayout &v, size_t seed = 0) noexcept |
366 | 0 | { |
367 | 0 | QtPrivate::QHashCombine hash(seed); |
368 | 0 | seed = hash(seed, v.m_bindings); |
369 | 0 | seed = hash(seed, v.m_attributes); |
370 | 0 | return seed; |
371 | 0 | } |
372 | | |
373 | | friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiVertexInputLayout &); |
374 | | }; |
375 | | |
376 | | #ifndef QT_NO_DEBUG_STREAM |
377 | | Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiVertexInputLayout &); |
378 | | #endif |
379 | | |
380 | | class Q_GUI_EXPORT QRhiShaderStage |
381 | | { |
382 | | public: |
383 | | enum Type { |
384 | | Vertex, |
385 | | TessellationControl, |
386 | | TessellationEvaluation, |
387 | | Geometry, |
388 | | Fragment, |
389 | | Compute |
390 | | }; |
391 | | |
392 | 0 | QRhiShaderStage() = default; |
393 | | QRhiShaderStage(Type type, const QShader &shader, |
394 | | QShader::Variant v = QShader::StandardShader); |
395 | | |
396 | 0 | Type type() const { return m_type; } |
397 | 0 | void setType(Type t) { m_type = t; } |
398 | | |
399 | 0 | QShader shader() const { return m_shader; } |
400 | 0 | void setShader(const QShader &s) { m_shader = s; } |
401 | | |
402 | 0 | QShader::Variant shaderVariant() const { return m_shaderVariant; } |
403 | 0 | void setShaderVariant(QShader::Variant v) { m_shaderVariant = v; } |
404 | | |
405 | | private: |
406 | | Type m_type = Vertex; |
407 | | QShader m_shader; |
408 | | QShader::Variant m_shaderVariant = QShader::StandardShader; |
409 | | |
410 | | friend bool operator==(const QRhiShaderStage &a, const QRhiShaderStage &b) noexcept |
411 | 0 | { |
412 | 0 | return a.m_type == b.m_type |
413 | 0 | && a.m_shader == b.m_shader |
414 | 0 | && a.m_shaderVariant == b.m_shaderVariant; |
415 | 0 | } |
416 | | |
417 | | friend bool operator!=(const QRhiShaderStage &a, const QRhiShaderStage &b) noexcept |
418 | 0 | { |
419 | 0 | return !(a == b); |
420 | 0 | } |
421 | | |
422 | | friend size_t qHash(const QRhiShaderStage &v, size_t seed = 0) noexcept |
423 | 0 | { |
424 | 0 | QtPrivate::QHashCombine hash(seed); |
425 | 0 | seed = hash(seed, v.m_type); |
426 | 0 | seed = hash(seed, v.m_shader); |
427 | 0 | seed = hash(seed, v.m_shaderVariant); |
428 | 0 | return seed; |
429 | 0 | } |
430 | | }; |
431 | | |
432 | | Q_DECLARE_TYPEINFO(QRhiShaderStage, Q_RELOCATABLE_TYPE); |
433 | | |
434 | | #ifndef QT_NO_DEBUG_STREAM |
435 | | Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiShaderStage &); |
436 | | #endif |
437 | | |
438 | | using QRhiGraphicsShaderStage = QRhiShaderStage; |
439 | | |
440 | | class Q_GUI_EXPORT QRhiShaderResourceBinding |
441 | | { |
442 | | public: |
443 | | enum Type { |
444 | | UniformBuffer, |
445 | | SampledTexture, |
446 | | Texture, |
447 | | Sampler, |
448 | | ImageLoad, |
449 | | ImageStore, |
450 | | ImageLoadStore, |
451 | | BufferLoad, |
452 | | BufferStore, |
453 | | BufferLoadStore |
454 | | }; |
455 | | |
456 | | enum StageFlag { |
457 | | VertexStage = 1 << 0, |
458 | | TessellationControlStage = 1 << 1, |
459 | | TessellationEvaluationStage = 1 << 2, |
460 | | GeometryStage = 1 << 3, |
461 | | FragmentStage = 1 << 4, |
462 | | ComputeStage = 1 << 5 |
463 | | }; |
464 | | Q_DECLARE_FLAGS(StageFlags, StageFlag) |
465 | | |
466 | 0 | QRhiShaderResourceBinding() = default; |
467 | | |
468 | | bool isLayoutCompatible(const QRhiShaderResourceBinding &other) const; |
469 | | |
470 | | static QRhiShaderResourceBinding uniformBuffer(int binding, StageFlags stage, QRhiBuffer *buf); |
471 | | static QRhiShaderResourceBinding uniformBuffer(int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size); |
472 | | static QRhiShaderResourceBinding uniformBufferWithDynamicOffset(int binding, StageFlags stage, QRhiBuffer *buf, quint32 size); |
473 | | |
474 | | static QRhiShaderResourceBinding sampledTexture(int binding, StageFlags stage, QRhiTexture *tex, QRhiSampler *sampler); |
475 | | |
476 | | struct TextureAndSampler { |
477 | | QRhiTexture *tex; |
478 | | QRhiSampler *sampler; |
479 | | }; |
480 | | static QRhiShaderResourceBinding sampledTextures(int binding, StageFlags stage, int count, const TextureAndSampler *texSamplers); |
481 | | |
482 | | static QRhiShaderResourceBinding texture(int binding, StageFlags stage, QRhiTexture *tex); |
483 | | static QRhiShaderResourceBinding textures(int binding, StageFlags stage, int count, QRhiTexture **tex); |
484 | | static QRhiShaderResourceBinding sampler(int binding, StageFlags stage, QRhiSampler *sampler); |
485 | | |
486 | | static QRhiShaderResourceBinding imageLoad(int binding, StageFlags stage, QRhiTexture *tex, int level); |
487 | | static QRhiShaderResourceBinding imageStore(int binding, StageFlags stage, QRhiTexture *tex, int level); |
488 | | static QRhiShaderResourceBinding imageLoadStore(int binding, StageFlags stage, QRhiTexture *tex, int level); |
489 | | |
490 | | static QRhiShaderResourceBinding bufferLoad(int binding, StageFlags stage, QRhiBuffer *buf); |
491 | | static QRhiShaderResourceBinding bufferLoad(int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size); |
492 | | static QRhiShaderResourceBinding bufferStore(int binding, StageFlags stage, QRhiBuffer *buf); |
493 | | static QRhiShaderResourceBinding bufferStore(int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size); |
494 | | static QRhiShaderResourceBinding bufferLoadStore(int binding, StageFlags stage, QRhiBuffer *buf); |
495 | | static QRhiShaderResourceBinding bufferLoadStore(int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size); |
496 | | |
497 | | struct Data |
498 | | { |
499 | | int binding; |
500 | | QRhiShaderResourceBinding::StageFlags stage; |
501 | | QRhiShaderResourceBinding::Type type; |
502 | | struct UniformBufferData { |
503 | | QRhiBuffer *buf; |
504 | | quint32 offset; |
505 | | quint32 maybeSize; |
506 | | bool hasDynamicOffset; |
507 | | }; |
508 | | static constexpr int MAX_TEX_SAMPLER_ARRAY_SIZE = 16; |
509 | | struct TextureAndOrSamplerData { |
510 | | int count; |
511 | | TextureAndSampler texSamplers[MAX_TEX_SAMPLER_ARRAY_SIZE]; |
512 | | }; |
513 | | struct StorageImageData { |
514 | | QRhiTexture *tex; |
515 | | int level; |
516 | | }; |
517 | | struct StorageBufferData { |
518 | | QRhiBuffer *buf; |
519 | | quint32 offset; |
520 | | quint32 maybeSize; |
521 | | }; |
522 | | union { |
523 | | UniformBufferData ubuf; |
524 | | TextureAndOrSamplerData stex; |
525 | | StorageImageData simage; |
526 | | StorageBufferData sbuf; |
527 | | } u; |
528 | | |
529 | | int arraySize() const |
530 | 0 | { |
531 | 0 | return type == QRhiShaderResourceBinding::SampledTexture || type == QRhiShaderResourceBinding::Texture |
532 | 0 | ? u.stex.count |
533 | 0 | : 1; |
534 | 0 | } |
535 | | |
536 | | template<typename Output> |
537 | | Output serialize(Output dst) const |
538 | 0 | { |
539 | | // must write out exactly LAYOUT_DESC_ENTRIES_PER_BINDING elements here |
540 | 0 | *dst++ = quint32(binding); |
541 | 0 | *dst++ = quint32(stage); |
542 | 0 | *dst++ = quint32(type); |
543 | 0 | *dst++ = quint32(arraySize()); |
544 | 0 | return dst; |
545 | 0 | } |
546 | | }; |
547 | | |
548 | | static constexpr int LAYOUT_DESC_ENTRIES_PER_BINDING = 4; |
549 | | |
550 | | template<typename Output> |
551 | | static void serializeLayoutDescription(const QRhiShaderResourceBinding *first, |
552 | | const QRhiShaderResourceBinding *last, |
553 | | Output dst) |
554 | | { |
555 | | while (first != last) { |
556 | | dst = first->d.serialize(dst); |
557 | | ++first; |
558 | | } |
559 | | } |
560 | | |
561 | | private: |
562 | | Data d; |
563 | | friend class QRhiImplementation; |
564 | | }; |
565 | | |
566 | 0 | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiShaderResourceBinding::StageFlags) Unexecuted instantiation: operator|(QRhiShaderResourceBinding::StageFlag, QRhiShaderResourceBinding::StageFlag) Unexecuted instantiation: operator|(QRhiShaderResourceBinding::StageFlag, QFlags<QRhiShaderResourceBinding::StageFlag>) Unexecuted instantiation: operator&(QRhiShaderResourceBinding::StageFlag, QRhiShaderResourceBinding::StageFlag) Unexecuted instantiation: operator&(QRhiShaderResourceBinding::StageFlag, QFlags<QRhiShaderResourceBinding::StageFlag>) Unexecuted instantiation: operator^(QRhiShaderResourceBinding::StageFlag, QRhiShaderResourceBinding::StageFlag) Unexecuted instantiation: operator^(QRhiShaderResourceBinding::StageFlag, QFlags<QRhiShaderResourceBinding::StageFlag>) Unexecuted instantiation: operator|(QRhiShaderResourceBinding::StageFlag, int) |
567 | 0 |
|
568 | 0 | Q_DECLARE_TYPEINFO(QRhiShaderResourceBinding, Q_PRIMITIVE_TYPE); |
569 | 0 |
|
570 | 0 | Q_GUI_EXPORT bool operator==(const QRhiShaderResourceBinding &a, const QRhiShaderResourceBinding &b) noexcept; |
571 | 0 | Q_GUI_EXPORT bool operator!=(const QRhiShaderResourceBinding &a, const QRhiShaderResourceBinding &b) noexcept; |
572 | 0 | Q_GUI_EXPORT size_t qHash(const QRhiShaderResourceBinding &b, size_t seed = 0) noexcept; |
573 | 0 | #ifndef QT_NO_DEBUG_STREAM |
574 | 0 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiShaderResourceBinding &); |
575 | 0 | #endif |
576 | 0 |
|
577 | 0 | class Q_GUI_EXPORT QRhiColorAttachment |
578 | 0 | { |
579 | 0 | public: |
580 | 0 | QRhiColorAttachment() = default; |
581 | 0 | QRhiColorAttachment(QRhiTexture *texture); |
582 | 0 | QRhiColorAttachment(QRhiRenderBuffer *renderBuffer); |
583 | 0 |
|
584 | 0 | QRhiTexture *texture() const { return m_texture; } |
585 | 0 | void setTexture(QRhiTexture *tex) { m_texture = tex; } |
586 | | |
587 | 0 | QRhiRenderBuffer *renderBuffer() const { return m_renderBuffer; } |
588 | 0 | void setRenderBuffer(QRhiRenderBuffer *rb) { m_renderBuffer = rb; } |
589 | | |
590 | 0 | int layer() const { return m_layer; } |
591 | 0 | void setLayer(int layer) { m_layer = layer; } |
592 | | |
593 | 0 | int level() const { return m_level; } |
594 | 0 | void setLevel(int level) { m_level = level; } |
595 | | |
596 | 0 | QRhiTexture *resolveTexture() const { return m_resolveTexture; } |
597 | 0 | void setResolveTexture(QRhiTexture *tex) { m_resolveTexture = tex; } |
598 | | |
599 | 0 | int resolveLayer() const { return m_resolveLayer; } |
600 | 0 | void setResolveLayer(int layer) { m_resolveLayer = layer; } |
601 | | |
602 | 0 | int resolveLevel() const { return m_resolveLevel; } |
603 | 0 | void setResolveLevel(int level) { m_resolveLevel = level; } |
604 | | |
605 | 0 | int multiViewCount() const { return m_multiViewCount; } |
606 | 0 | void setMultiViewCount(int count) { m_multiViewCount = count; } |
607 | | |
608 | | private: |
609 | | QRhiTexture *m_texture = nullptr; |
610 | | QRhiRenderBuffer *m_renderBuffer = nullptr; |
611 | | int m_layer = 0; |
612 | | int m_level = 0; |
613 | | QRhiTexture *m_resolveTexture = nullptr; |
614 | | int m_resolveLayer = 0; |
615 | | int m_resolveLevel = 0; |
616 | | int m_multiViewCount = 0; |
617 | | }; |
618 | | |
619 | | Q_DECLARE_TYPEINFO(QRhiColorAttachment, Q_RELOCATABLE_TYPE); |
620 | | |
621 | | class Q_GUI_EXPORT QRhiTextureRenderTargetDescription |
622 | | { |
623 | | public: |
624 | | QRhiTextureRenderTargetDescription() = default; |
625 | | QRhiTextureRenderTargetDescription(const QRhiColorAttachment &colorAttachment); |
626 | | QRhiTextureRenderTargetDescription(const QRhiColorAttachment &colorAttachment, QRhiRenderBuffer *depthStencilBuffer); |
627 | | QRhiTextureRenderTargetDescription(const QRhiColorAttachment &colorAttachment, QRhiTexture *depthTexture); |
628 | | |
629 | 0 | void setColorAttachments(std::initializer_list<QRhiColorAttachment> list) { m_colorAttachments = list; } |
630 | | template<typename InputIterator> |
631 | | void setColorAttachments(InputIterator first, InputIterator last) |
632 | | { |
633 | | m_colorAttachments.clear(); |
634 | | std::copy(first, last, std::back_inserter(m_colorAttachments)); |
635 | | } |
636 | 0 | const QRhiColorAttachment *cbeginColorAttachments() const { return m_colorAttachments.cbegin(); } |
637 | 0 | const QRhiColorAttachment *cendColorAttachments() const { return m_colorAttachments.cend(); } |
638 | 0 | const QRhiColorAttachment *colorAttachmentAt(qsizetype index) const { return &m_colorAttachments.at(index); } |
639 | 0 | qsizetype colorAttachmentCount() const { return m_colorAttachments.count(); } |
640 | | |
641 | 0 | QRhiRenderBuffer *depthStencilBuffer() const { return m_depthStencilBuffer; } |
642 | 0 | void setDepthStencilBuffer(QRhiRenderBuffer *renderBuffer) { m_depthStencilBuffer = renderBuffer; } |
643 | | |
644 | 0 | QRhiTexture *depthTexture() const { return m_depthTexture; } |
645 | 0 | void setDepthTexture(QRhiTexture *texture) { m_depthTexture = texture; } |
646 | | |
647 | 0 | int depthLayer() const { return m_depthLayer; } |
648 | 0 | void setDepthLayer(int depthLayer) { m_depthLayer = depthLayer; } |
649 | | |
650 | 0 | QRhiTexture *depthResolveTexture() const { return m_depthResolveTexture; } |
651 | 0 | void setDepthResolveTexture(QRhiTexture *tex) { m_depthResolveTexture = tex; } |
652 | | |
653 | 0 | QRhiShadingRateMap *shadingRateMap() const { return m_shadingRateMap; } |
654 | 0 | void setShadingRateMap(QRhiShadingRateMap *map) { m_shadingRateMap = map; } |
655 | | |
656 | | private: |
657 | | QVarLengthArray<QRhiColorAttachment, 8> m_colorAttachments; |
658 | | QRhiRenderBuffer *m_depthStencilBuffer = nullptr; |
659 | | QRhiTexture *m_depthTexture = nullptr; |
660 | | QRhiTexture *m_depthResolveTexture = nullptr; |
661 | | QRhiShadingRateMap *m_shadingRateMap = nullptr; |
662 | | int m_depthLayer = -1; |
663 | | }; |
664 | | |
665 | | class Q_GUI_EXPORT QRhiTextureSubresourceUploadDescription |
666 | | { |
667 | | public: |
668 | | QRhiTextureSubresourceUploadDescription() = default; |
669 | | explicit QRhiTextureSubresourceUploadDescription(const QImage &image); |
670 | | QRhiTextureSubresourceUploadDescription(const void *data, quint32 size); |
671 | | explicit QRhiTextureSubresourceUploadDescription(const QByteArray &data); |
672 | | |
673 | 0 | QImage image() const { return m_image; } |
674 | 0 | void setImage(const QImage &image) { m_image = image; } |
675 | | |
676 | 0 | QByteArray data() const { return m_data; } |
677 | 0 | void setData(const QByteArray &data) { m_data = data; } |
678 | | |
679 | 0 | quint32 dataStride() const { return m_dataStride; } |
680 | 0 | void setDataStride(quint32 stride) { m_dataStride = stride; } |
681 | | |
682 | 0 | QPoint destinationTopLeft() const { return m_destinationTopLeft; } |
683 | 0 | void setDestinationTopLeft(const QPoint &p) { m_destinationTopLeft = p; } |
684 | | |
685 | 0 | QSize sourceSize() const { return m_sourceSize; } |
686 | 0 | void setSourceSize(const QSize &size) { m_sourceSize = size; } |
687 | | |
688 | 0 | QPoint sourceTopLeft() const { return m_sourceTopLeft; } |
689 | 0 | void setSourceTopLeft(const QPoint &p) { m_sourceTopLeft = p; } |
690 | | |
691 | | private: |
692 | | QImage m_image; |
693 | | QByteArray m_data; |
694 | | quint32 m_dataStride = 0; |
695 | | QPoint m_destinationTopLeft; |
696 | | QSize m_sourceSize; |
697 | | QPoint m_sourceTopLeft; |
698 | | }; |
699 | | |
700 | | Q_DECLARE_TYPEINFO(QRhiTextureSubresourceUploadDescription, Q_RELOCATABLE_TYPE); |
701 | | |
702 | | class Q_GUI_EXPORT QRhiTextureUploadEntry |
703 | | { |
704 | | public: |
705 | | QRhiTextureUploadEntry() = default; |
706 | | QRhiTextureUploadEntry(int layer, int level, const QRhiTextureSubresourceUploadDescription &desc); |
707 | | |
708 | 0 | int layer() const { return m_layer; } |
709 | 0 | void setLayer(int layer) { m_layer = layer; } |
710 | | |
711 | 0 | int level() const { return m_level; } |
712 | 0 | void setLevel(int level) { m_level = level; } |
713 | | |
714 | 0 | QRhiTextureSubresourceUploadDescription description() const { return m_desc; } |
715 | 0 | void setDescription(const QRhiTextureSubresourceUploadDescription &desc) { m_desc = desc; } |
716 | | |
717 | | private: |
718 | | int m_layer = 0; |
719 | | int m_level = 0; |
720 | | QRhiTextureSubresourceUploadDescription m_desc; |
721 | | }; |
722 | | |
723 | | Q_DECLARE_TYPEINFO(QRhiTextureUploadEntry, Q_RELOCATABLE_TYPE); |
724 | | |
725 | | class Q_GUI_EXPORT QRhiTextureUploadDescription |
726 | | { |
727 | | public: |
728 | | QRhiTextureUploadDescription() = default; |
729 | | QRhiTextureUploadDescription(const QRhiTextureUploadEntry &entry); |
730 | | QRhiTextureUploadDescription(std::initializer_list<QRhiTextureUploadEntry> list); |
731 | | |
732 | 0 | void setEntries(std::initializer_list<QRhiTextureUploadEntry> list) { m_entries = list; } |
733 | | template<typename InputIterator> |
734 | | void setEntries(InputIterator first, InputIterator last) |
735 | | { |
736 | | m_entries.clear(); |
737 | | std::copy(first, last, std::back_inserter(m_entries)); |
738 | | } |
739 | 0 | const QRhiTextureUploadEntry *cbeginEntries() const { return m_entries.cbegin(); } |
740 | 0 | const QRhiTextureUploadEntry *cendEntries() const { return m_entries.cend(); } |
741 | 0 | const QRhiTextureUploadEntry *entryAt(qsizetype index) const { return &m_entries.at(index); } |
742 | 0 | qsizetype entryCount() const { return m_entries.count(); } |
743 | | |
744 | | private: |
745 | | QVarLengthArray<QRhiTextureUploadEntry, 16> m_entries; |
746 | | }; |
747 | | |
748 | | class Q_GUI_EXPORT QRhiTextureCopyDescription |
749 | | { |
750 | | public: |
751 | 0 | QRhiTextureCopyDescription() = default; |
752 | | |
753 | 0 | QSize pixelSize() const { return m_pixelSize; } |
754 | 0 | void setPixelSize(const QSize &sz) { m_pixelSize = sz; } |
755 | | |
756 | 0 | int sourceLayer() const { return m_sourceLayer; } |
757 | 0 | void setSourceLayer(int layer) { m_sourceLayer = layer; } |
758 | | |
759 | 0 | int sourceLevel() const { return m_sourceLevel; } |
760 | 0 | void setSourceLevel(int level) { m_sourceLevel = level; } |
761 | | |
762 | 0 | QPoint sourceTopLeft() const { return m_sourceTopLeft; } |
763 | 0 | void setSourceTopLeft(const QPoint &p) { m_sourceTopLeft = p; } |
764 | | |
765 | 0 | int destinationLayer() const { return m_destinationLayer; } |
766 | 0 | void setDestinationLayer(int layer) { m_destinationLayer = layer; } |
767 | | |
768 | 0 | int destinationLevel() const { return m_destinationLevel; } |
769 | 0 | void setDestinationLevel(int level) { m_destinationLevel = level; } |
770 | | |
771 | 0 | QPoint destinationTopLeft() const { return m_destinationTopLeft; } |
772 | 0 | void setDestinationTopLeft(const QPoint &p) { m_destinationTopLeft = p; } |
773 | | |
774 | | private: |
775 | | QSize m_pixelSize; |
776 | | int m_sourceLayer = 0; |
777 | | int m_sourceLevel = 0; |
778 | | QPoint m_sourceTopLeft; |
779 | | int m_destinationLayer = 0; |
780 | | int m_destinationLevel = 0; |
781 | | QPoint m_destinationTopLeft; |
782 | | }; |
783 | | |
784 | | Q_DECLARE_TYPEINFO(QRhiTextureCopyDescription, Q_RELOCATABLE_TYPE); |
785 | | |
786 | | class Q_GUI_EXPORT QRhiReadbackDescription |
787 | | { |
788 | | public: |
789 | 0 | QRhiReadbackDescription() = default; |
790 | | QRhiReadbackDescription(QRhiTexture *texture); |
791 | | |
792 | 0 | QRhiTexture *texture() const { return m_texture; } |
793 | 0 | void setTexture(QRhiTexture *tex) { m_texture = tex; } |
794 | | |
795 | 0 | int layer() const { return m_layer; } |
796 | 0 | void setLayer(int layer) { m_layer = layer; } |
797 | | |
798 | 0 | int level() const { return m_level; } |
799 | 0 | void setLevel(int level) { m_level = level; } |
800 | | |
801 | 0 | QRect rect() const { return m_rect; } |
802 | 0 | void setRect(const QRect &rectangle) { m_rect = rectangle; } |
803 | | |
804 | | private: |
805 | | QRhiTexture *m_texture = nullptr; |
806 | | int m_layer = 0; |
807 | | int m_level = 0; |
808 | | QRect m_rect; |
809 | | }; |
810 | | |
811 | | Q_DECLARE_TYPEINFO(QRhiReadbackDescription, Q_RELOCATABLE_TYPE); |
812 | | |
813 | | struct Q_GUI_EXPORT QRhiNativeHandles |
814 | | { |
815 | | }; |
816 | | |
817 | | class Q_GUI_EXPORT QRhiResource |
818 | | { |
819 | | public: |
820 | | enum Type { |
821 | | Buffer, |
822 | | Texture, |
823 | | Sampler, |
824 | | RenderBuffer, |
825 | | RenderPassDescriptor, |
826 | | SwapChainRenderTarget, |
827 | | TextureRenderTarget, |
828 | | ShaderResourceBindings, |
829 | | GraphicsPipeline, |
830 | | SwapChain, |
831 | | ComputePipeline, |
832 | | CommandBuffer, |
833 | | ShadingRateMap |
834 | | }; |
835 | | |
836 | | virtual ~QRhiResource(); |
837 | | |
838 | | virtual Type resourceType() const = 0; |
839 | | |
840 | | virtual void destroy() = 0; |
841 | | |
842 | | void deleteLater(); |
843 | | |
844 | | QByteArray name() const; |
845 | | void setName(const QByteArray &name); |
846 | | |
847 | | quint64 globalResourceId() const; |
848 | | |
849 | | QRhi *rhi() const; |
850 | | |
851 | | protected: |
852 | | QRhiResource(QRhiImplementation *rhi); |
853 | | Q_DISABLE_COPY(QRhiResource) |
854 | | friend class QRhiImplementation; |
855 | | QRhiImplementation *m_rhi = nullptr; |
856 | | quint64 m_id; |
857 | | QByteArray m_objectName; |
858 | | }; |
859 | | |
860 | | class Q_GUI_EXPORT QRhiBuffer : public QRhiResource |
861 | | { |
862 | | public: |
863 | | enum Type { |
864 | | Immutable, |
865 | | Static, |
866 | | Dynamic |
867 | | }; |
868 | | |
869 | | enum UsageFlag { |
870 | | VertexBuffer = 1 << 0, |
871 | | IndexBuffer = 1 << 1, |
872 | | UniformBuffer = 1 << 2, |
873 | | StorageBuffer = 1 << 3, |
874 | | IndirectBuffer = 1 << 4, |
875 | | }; |
876 | | Q_DECLARE_FLAGS(UsageFlags, UsageFlag) |
877 | | |
878 | | struct NativeBuffer { |
879 | | const void *objects[3]; |
880 | | int slotCount; |
881 | | }; |
882 | | |
883 | | QRhiResource::Type resourceType() const override; |
884 | | |
885 | 0 | Type type() const { return m_type; } |
886 | 0 | void setType(Type t) { m_type = t; } |
887 | | |
888 | 0 | UsageFlags usage() const { return m_usage; } |
889 | 0 | void setUsage(UsageFlags u) { m_usage = u; } |
890 | | |
891 | 0 | quint32 size() const { return m_size; } |
892 | 0 | void setSize(quint32 sz) { m_size = sz; } |
893 | | |
894 | | virtual bool create() = 0; |
895 | | |
896 | | virtual NativeBuffer nativeBuffer(); |
897 | | |
898 | | virtual char *beginFullDynamicBufferUpdateForCurrentFrame(); |
899 | | virtual void endFullDynamicBufferUpdateForCurrentFrame(); |
900 | | virtual void fullDynamicBufferUpdateForCurrentFrame(const void *data, quint32 size = 0); |
901 | | |
902 | | protected: |
903 | | QRhiBuffer(QRhiImplementation *rhi, Type type_, UsageFlags usage_, quint32 size_); |
904 | | Type m_type; |
905 | | UsageFlags m_usage; |
906 | | quint32 m_size; |
907 | | }; |
908 | | |
909 | 0 | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiBuffer::UsageFlags) Unexecuted instantiation: operator|(QRhiBuffer::UsageFlag, QRhiBuffer::UsageFlag) Unexecuted instantiation: operator|(QRhiBuffer::UsageFlag, QFlags<QRhiBuffer::UsageFlag>) Unexecuted instantiation: operator&(QRhiBuffer::UsageFlag, QRhiBuffer::UsageFlag) Unexecuted instantiation: operator&(QRhiBuffer::UsageFlag, QFlags<QRhiBuffer::UsageFlag>) Unexecuted instantiation: operator^(QRhiBuffer::UsageFlag, QRhiBuffer::UsageFlag) Unexecuted instantiation: operator^(QRhiBuffer::UsageFlag, QFlags<QRhiBuffer::UsageFlag>) Unexecuted instantiation: operator|(QRhiBuffer::UsageFlag, int) |
910 | 0 |
|
911 | 0 | class Q_GUI_EXPORT QRhiTexture : public QRhiResource |
912 | 0 | { |
913 | 0 | public: |
914 | 0 | enum Flag { |
915 | 0 | RenderTarget = 1 << 0, |
916 | 0 | CubeMap = 1 << 2, |
917 | 0 | MipMapped = 1 << 3, |
918 | 0 | sRGB = 1 << 4, |
919 | 0 | UsedAsTransferSource = 1 << 5, |
920 | 0 | UsedWithGenerateMips = 1 << 6, |
921 | 0 | UsedWithLoadStore = 1 << 7, |
922 | 0 | UsedAsCompressedAtlas = 1 << 8, |
923 | 0 | ExternalOES = 1 << 9, |
924 | 0 | ThreeDimensional = 1 << 10, |
925 | 0 | TextureRectangleGL = 1 << 11, |
926 | 0 | TextureArray = 1 << 12, |
927 | 0 | OneDimensional = 1 << 13, |
928 | 0 | UsedAsShadingRateMap = 1 << 14 |
929 | 0 | }; |
930 | 0 | Q_DECLARE_FLAGS(Flags, Flag) |
931 | 0 |
|
932 | 0 | enum Format { |
933 | 0 | UnknownFormat, |
934 | 0 |
|
935 | 0 | RGBA8, |
936 | 0 | BGRA8, |
937 | 0 | R8, |
938 | 0 | RG8, |
939 | 0 | R16, |
940 | 0 | RG16, |
941 | 0 | RED_OR_ALPHA8, |
942 | 0 |
|
943 | 0 | RGBA16F, |
944 | 0 | RGBA32F, |
945 | 0 | R16F, |
946 | 0 | R32F, |
947 | 0 |
|
948 | 0 | RGB10A2, |
949 | 0 |
|
950 | 0 | R8SI, |
951 | 0 | R32SI, |
952 | 0 | RG32SI, |
953 | 0 | RGBA32SI, |
954 | 0 |
|
955 | 0 | R8UI, |
956 | 0 | R32UI, |
957 | 0 | RG32UI, |
958 | 0 | RGBA32UI, |
959 | 0 |
|
960 | 0 | D16, |
961 | 0 | D24, |
962 | 0 | D24S8, |
963 | 0 | D32F, |
964 | 0 | D32FS8, |
965 | 0 |
|
966 | 0 | BC1, |
967 | 0 | BC2, |
968 | 0 | BC3, |
969 | 0 | BC4, |
970 | 0 | BC5, |
971 | 0 | BC6H, |
972 | 0 | BC7, |
973 | 0 |
|
974 | 0 | ETC2_RGB8, |
975 | 0 | ETC2_RGB8A1, |
976 | 0 | ETC2_RGBA8, |
977 | 0 |
|
978 | 0 | ASTC_4x4, |
979 | 0 | ASTC_5x4, |
980 | 0 | ASTC_5x5, |
981 | 0 | ASTC_6x5, |
982 | 0 | ASTC_6x6, |
983 | 0 | ASTC_8x5, |
984 | 0 | ASTC_8x6, |
985 | 0 | ASTC_8x8, |
986 | 0 | ASTC_10x5, |
987 | 0 | ASTC_10x6, |
988 | 0 | ASTC_10x8, |
989 | 0 | ASTC_10x10, |
990 | 0 | ASTC_12x10, |
991 | 0 | ASTC_12x12 |
992 | 0 | }; |
993 | 0 |
|
994 | 0 | struct NativeTexture { |
995 | 0 | quint64 object; |
996 | 0 | int layout; // or state |
997 | 0 | }; |
998 | 0 |
|
999 | 0 | QRhiResource::Type resourceType() const override; |
1000 | 0 |
|
1001 | 0 | Format format() const { return m_format; } |
1002 | 0 | void setFormat(Format fmt) { m_format = fmt; } |
1003 | | |
1004 | 0 | QSize pixelSize() const { return m_pixelSize; } |
1005 | 0 | void setPixelSize(const QSize &sz) { m_pixelSize = sz; } |
1006 | | |
1007 | 0 | int depth() const { return m_depth; } |
1008 | 0 | void setDepth(int depth) { m_depth = depth; } |
1009 | | |
1010 | 0 | int arraySize() const { return m_arraySize; } |
1011 | 0 | void setArraySize(int arraySize) { m_arraySize = arraySize; } |
1012 | | |
1013 | 0 | int arrayRangeStart() const { return m_arrayRangeStart; } |
1014 | 0 | int arrayRangeLength() const { return m_arrayRangeLength; } |
1015 | | void setArrayRange(int startIndex, int count) |
1016 | 0 | { |
1017 | 0 | m_arrayRangeStart = startIndex; |
1018 | 0 | m_arrayRangeLength = count; |
1019 | 0 | } |
1020 | | |
1021 | 0 | Flags flags() const { return m_flags; } |
1022 | 0 | void setFlags(Flags f) { m_flags = f; } |
1023 | | |
1024 | 0 | int sampleCount() const { return m_sampleCount; } |
1025 | 0 | void setSampleCount(int s) { m_sampleCount = s; } |
1026 | | |
1027 | | struct ViewFormat { |
1028 | | QRhiTexture::Format format; |
1029 | | bool srgb; |
1030 | | }; |
1031 | 0 | ViewFormat readViewFormat() const { return m_readViewFormat; } |
1032 | 0 | void setReadViewFormat(const ViewFormat &fmt) { m_readViewFormat = fmt; } |
1033 | 0 | ViewFormat writeViewFormat() const { return m_writeViewFormat; } |
1034 | 0 | void setWriteViewFormat(const ViewFormat &fmt) { m_writeViewFormat = fmt; } |
1035 | | |
1036 | | virtual bool create() = 0; |
1037 | | virtual NativeTexture nativeTexture(); |
1038 | | virtual bool createFrom(NativeTexture src); |
1039 | | virtual void setNativeLayout(int layout); |
1040 | | |
1041 | | protected: |
1042 | | QRhiTexture(QRhiImplementation *rhi, Format format_, const QSize &pixelSize_, int depth_, |
1043 | | int arraySize_, int sampleCount_, Flags flags_); |
1044 | | Format m_format; |
1045 | | QSize m_pixelSize; |
1046 | | int m_depth; |
1047 | | int m_arraySize; |
1048 | | int m_sampleCount; |
1049 | | Flags m_flags; |
1050 | | int m_arrayRangeStart = -1; |
1051 | | int m_arrayRangeLength = -1; |
1052 | | ViewFormat m_readViewFormat = { UnknownFormat, false }; |
1053 | | ViewFormat m_writeViewFormat = { UnknownFormat, false }; |
1054 | | }; |
1055 | | |
1056 | 0 | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiTexture::Flags) Unexecuted instantiation: operator|(QRhiTexture::Flag, QRhiTexture::Flag) Unexecuted instantiation: operator|(QRhiTexture::Flag, QFlags<QRhiTexture::Flag>) Unexecuted instantiation: operator&(QRhiTexture::Flag, QRhiTexture::Flag) Unexecuted instantiation: operator&(QRhiTexture::Flag, QFlags<QRhiTexture::Flag>) Unexecuted instantiation: operator^(QRhiTexture::Flag, QRhiTexture::Flag) Unexecuted instantiation: operator^(QRhiTexture::Flag, QFlags<QRhiTexture::Flag>) Unexecuted instantiation: operator|(QRhiTexture::Flag, int) |
1057 | 0 |
|
1058 | 0 | class Q_GUI_EXPORT QRhiSampler : public QRhiResource |
1059 | 0 | { |
1060 | 0 | public: |
1061 | 0 | enum Filter { |
1062 | 0 | None, |
1063 | 0 | Nearest, |
1064 | 0 | Linear |
1065 | 0 | }; |
1066 | 0 |
|
1067 | 0 | enum AddressMode { |
1068 | 0 | Repeat, |
1069 | 0 | ClampToEdge, |
1070 | 0 | Mirror, |
1071 | 0 | }; |
1072 | 0 |
|
1073 | 0 | enum CompareOp { |
1074 | 0 | Never, |
1075 | 0 | Less, |
1076 | 0 | Equal, |
1077 | 0 | LessOrEqual, |
1078 | 0 | Greater, |
1079 | 0 | NotEqual, |
1080 | 0 | GreaterOrEqual, |
1081 | 0 | Always |
1082 | 0 | }; |
1083 | 0 |
|
1084 | 0 | QRhiResource::Type resourceType() const override; |
1085 | 0 |
|
1086 | 0 | Filter magFilter() const { return m_magFilter; } |
1087 | 0 | void setMagFilter(Filter f) { m_magFilter = f; } |
1088 | | |
1089 | 0 | Filter minFilter() const { return m_minFilter; } |
1090 | 0 | void setMinFilter(Filter f) { m_minFilter = f; } |
1091 | | |
1092 | 0 | Filter mipmapMode() const { return m_mipmapMode; } |
1093 | 0 | void setMipmapMode(Filter f) { m_mipmapMode = f; } |
1094 | | |
1095 | 0 | AddressMode addressU() const { return m_addressU; } |
1096 | 0 | void setAddressU(AddressMode mode) { m_addressU = mode; } |
1097 | | |
1098 | 0 | AddressMode addressV() const { return m_addressV; } |
1099 | 0 | void setAddressV(AddressMode mode) { m_addressV = mode; } |
1100 | | |
1101 | 0 | AddressMode addressW() const { return m_addressW; } |
1102 | 0 | void setAddressW(AddressMode mode) { m_addressW = mode; } |
1103 | | |
1104 | 0 | CompareOp textureCompareOp() const { return m_compareOp; } |
1105 | 0 | void setTextureCompareOp(CompareOp op) { m_compareOp = op; } |
1106 | | |
1107 | | virtual bool create() = 0; |
1108 | | |
1109 | | protected: |
1110 | | QRhiSampler(QRhiImplementation *rhi, |
1111 | | Filter magFilter_, Filter minFilter_, Filter mipmapMode_, |
1112 | | AddressMode u_, AddressMode v_, AddressMode w_); |
1113 | | Filter m_magFilter; |
1114 | | Filter m_minFilter; |
1115 | | Filter m_mipmapMode; |
1116 | | AddressMode m_addressU; |
1117 | | AddressMode m_addressV; |
1118 | | AddressMode m_addressW; |
1119 | | CompareOp m_compareOp; |
1120 | | }; |
1121 | | |
1122 | | class Q_GUI_EXPORT QRhiRenderBuffer : public QRhiResource |
1123 | | { |
1124 | | public: |
1125 | | enum Type { |
1126 | | DepthStencil, |
1127 | | Color |
1128 | | }; |
1129 | | |
1130 | | enum Flag { |
1131 | | UsedWithSwapChainOnly = 1 << 0 |
1132 | | }; |
1133 | | Q_DECLARE_FLAGS(Flags, Flag) |
1134 | | |
1135 | | struct NativeRenderBuffer { |
1136 | | quint64 object; |
1137 | | }; |
1138 | | |
1139 | | QRhiResource::Type resourceType() const override; |
1140 | | |
1141 | 0 | Type type() const { return m_type; } |
1142 | 0 | void setType(Type t) { m_type = t; } |
1143 | | |
1144 | 0 | QSize pixelSize() const { return m_pixelSize; } |
1145 | 0 | void setPixelSize(const QSize &sz) { m_pixelSize = sz; } |
1146 | | |
1147 | 0 | int sampleCount() const { return m_sampleCount; } |
1148 | 0 | void setSampleCount(int s) { m_sampleCount = s; } |
1149 | | |
1150 | 0 | Flags flags() const { return m_flags; } |
1151 | 0 | void setFlags(Flags f) { m_flags = f; } |
1152 | | |
1153 | | virtual bool create() = 0; |
1154 | | virtual bool createFrom(NativeRenderBuffer src); |
1155 | | |
1156 | | virtual QRhiTexture::Format backingFormat() const = 0; |
1157 | | |
1158 | | protected: |
1159 | | QRhiRenderBuffer(QRhiImplementation *rhi, Type type_, const QSize &pixelSize_, |
1160 | | int sampleCount_, Flags flags_, QRhiTexture::Format backingFormatHint_); |
1161 | | Type m_type; |
1162 | | QSize m_pixelSize; |
1163 | | int m_sampleCount; |
1164 | | Flags m_flags; |
1165 | | QRhiTexture::Format m_backingFormatHint; |
1166 | | }; |
1167 | | |
1168 | 0 | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiRenderBuffer::Flags) Unexecuted instantiation: operator|(QRhiRenderBuffer::Flag, QRhiRenderBuffer::Flag) Unexecuted instantiation: operator|(QRhiRenderBuffer::Flag, QFlags<QRhiRenderBuffer::Flag>) Unexecuted instantiation: operator&(QRhiRenderBuffer::Flag, QRhiRenderBuffer::Flag) Unexecuted instantiation: operator&(QRhiRenderBuffer::Flag, QFlags<QRhiRenderBuffer::Flag>) Unexecuted instantiation: operator^(QRhiRenderBuffer::Flag, QRhiRenderBuffer::Flag) Unexecuted instantiation: operator^(QRhiRenderBuffer::Flag, QFlags<QRhiRenderBuffer::Flag>) Unexecuted instantiation: operator|(QRhiRenderBuffer::Flag, int) |
1169 | 0 |
|
1170 | 0 | class Q_GUI_EXPORT QRhiShadingRateMap : public QRhiResource |
1171 | 0 | { |
1172 | 0 | public: |
1173 | 0 | struct NativeShadingRateMap { |
1174 | 0 | quint64 object; |
1175 | 0 | }; |
1176 | 0 |
|
1177 | 0 | QRhiResource::Type resourceType() const override; |
1178 | 0 |
|
1179 | 0 | virtual bool createFrom(NativeShadingRateMap src); |
1180 | 0 | virtual bool createFrom(QRhiTexture *src); |
1181 | 0 |
|
1182 | 0 | protected: |
1183 | 0 | QRhiShadingRateMap(QRhiImplementation *rhi); |
1184 | 0 | }; |
1185 | 0 |
|
1186 | 0 | class Q_GUI_EXPORT QRhiRenderPassDescriptor : public QRhiResource |
1187 | 0 | { |
1188 | 0 | public: |
1189 | 0 | QRhiResource::Type resourceType() const override; |
1190 | 0 |
|
1191 | 0 | virtual bool isCompatible(const QRhiRenderPassDescriptor *other) const = 0; |
1192 | 0 | virtual const QRhiNativeHandles *nativeHandles(); |
1193 | 0 |
|
1194 | 0 | virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() const = 0; |
1195 | 0 |
|
1196 | 0 | virtual QVector<quint32> serializedFormat() const = 0; |
1197 | 0 |
|
1198 | 0 | protected: |
1199 | 0 | QRhiRenderPassDescriptor(QRhiImplementation *rhi); |
1200 | 0 | }; |
1201 | 0 |
|
1202 | 0 | class Q_GUI_EXPORT QRhiRenderTarget : public QRhiResource |
1203 | 0 | { |
1204 | 0 | public: |
1205 | 0 | virtual QSize pixelSize() const = 0; |
1206 | 0 | virtual float devicePixelRatio() const = 0; |
1207 | 0 | virtual int sampleCount() const = 0; |
1208 | 0 |
|
1209 | 0 | QRhiRenderPassDescriptor *renderPassDescriptor() const { return m_renderPassDesc; } |
1210 | 0 | void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; } |
1211 | | |
1212 | | protected: |
1213 | | QRhiRenderTarget(QRhiImplementation *rhi); |
1214 | | QRhiRenderPassDescriptor *m_renderPassDesc = nullptr; |
1215 | | }; |
1216 | | |
1217 | | class Q_GUI_EXPORT QRhiSwapChainRenderTarget : public QRhiRenderTarget |
1218 | | { |
1219 | | public: |
1220 | | QRhiResource::Type resourceType() const override; |
1221 | 0 | QRhiSwapChain *swapChain() const { return m_swapchain; } |
1222 | | |
1223 | | protected: |
1224 | | QRhiSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain_); |
1225 | | QRhiSwapChain *m_swapchain; |
1226 | | }; |
1227 | | |
1228 | | class Q_GUI_EXPORT QRhiTextureRenderTarget : public QRhiRenderTarget |
1229 | | { |
1230 | | public: |
1231 | | enum Flag { |
1232 | | PreserveColorContents = 1 << 0, |
1233 | | PreserveDepthStencilContents = 1 << 1, |
1234 | | DoNotStoreDepthStencilContents = 1 << 2 |
1235 | | }; |
1236 | | Q_DECLARE_FLAGS(Flags, Flag) |
1237 | | |
1238 | | QRhiResource::Type resourceType() const override; |
1239 | | |
1240 | 0 | QRhiTextureRenderTargetDescription description() const { return m_desc; } |
1241 | 0 | void setDescription(const QRhiTextureRenderTargetDescription &desc) { m_desc = desc; } |
1242 | | |
1243 | 0 | Flags flags() const { return m_flags; } |
1244 | 0 | void setFlags(Flags f) { m_flags = f; } |
1245 | | |
1246 | | virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() = 0; |
1247 | | |
1248 | | virtual bool create() = 0; |
1249 | | |
1250 | | protected: |
1251 | | QRhiTextureRenderTarget(QRhiImplementation *rhi, const QRhiTextureRenderTargetDescription &desc_, Flags flags_); |
1252 | | QRhiTextureRenderTargetDescription m_desc; |
1253 | | Flags m_flags; |
1254 | | }; |
1255 | | |
1256 | 0 | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiTextureRenderTarget::Flags) Unexecuted instantiation: operator|(QRhiTextureRenderTarget::Flag, QRhiTextureRenderTarget::Flag) Unexecuted instantiation: operator|(QRhiTextureRenderTarget::Flag, QFlags<QRhiTextureRenderTarget::Flag>) Unexecuted instantiation: operator&(QRhiTextureRenderTarget::Flag, QRhiTextureRenderTarget::Flag) Unexecuted instantiation: operator&(QRhiTextureRenderTarget::Flag, QFlags<QRhiTextureRenderTarget::Flag>) Unexecuted instantiation: operator^(QRhiTextureRenderTarget::Flag, QRhiTextureRenderTarget::Flag) Unexecuted instantiation: operator^(QRhiTextureRenderTarget::Flag, QFlags<QRhiTextureRenderTarget::Flag>) Unexecuted instantiation: operator|(QRhiTextureRenderTarget::Flag, int) |
1257 | 0 |
|
1258 | 0 | class Q_GUI_EXPORT QRhiShaderResourceBindings : public QRhiResource |
1259 | 0 | { |
1260 | 0 | public: |
1261 | 0 | QRhiResource::Type resourceType() const override; |
1262 | 0 |
|
1263 | 0 | void setBindings(std::initializer_list<QRhiShaderResourceBinding> list) { m_bindings = list; } |
1264 | | template<typename InputIterator> |
1265 | | void setBindings(InputIterator first, InputIterator last) |
1266 | | { |
1267 | | m_bindings.clear(); |
1268 | | std::copy(first, last, std::back_inserter(m_bindings)); |
1269 | | } |
1270 | 0 | const QRhiShaderResourceBinding *cbeginBindings() const { return m_bindings.cbegin(); } |
1271 | 0 | const QRhiShaderResourceBinding *cendBindings() const { return m_bindings.cend(); } |
1272 | 0 | const QRhiShaderResourceBinding *bindingAt(qsizetype index) const { return &m_bindings.at(index); } |
1273 | 0 | qsizetype bindingCount() const { return m_bindings.count(); } |
1274 | | |
1275 | | bool isLayoutCompatible(const QRhiShaderResourceBindings *other) const; |
1276 | | |
1277 | 0 | QVector<quint32> serializedLayoutDescription() const { return m_layoutDesc; } |
1278 | | |
1279 | | virtual bool create() = 0; |
1280 | | |
1281 | | enum UpdateFlag { |
1282 | | BindingsAreSorted = 0x01 |
1283 | | }; |
1284 | | Q_DECLARE_FLAGS(UpdateFlags, UpdateFlag) |
1285 | | |
1286 | | virtual void updateResources(UpdateFlags flags = {}) = 0; |
1287 | | |
1288 | | protected: |
1289 | | static constexpr int BINDING_PREALLOC = 12; |
1290 | | QRhiShaderResourceBindings(QRhiImplementation *rhi); |
1291 | | QVarLengthArray<QRhiShaderResourceBinding, BINDING_PREALLOC> m_bindings; |
1292 | | size_t m_layoutDescHash = 0; |
1293 | | // Intentionally not using QVLA for m_layoutDesc: clients like Qt Quick are much |
1294 | | // better served with an implicitly shared container here, because they will likely |
1295 | | // throw this directly into structs serving as cache keys. |
1296 | | QVector<quint32> m_layoutDesc; |
1297 | | friend class QRhiImplementation; |
1298 | | #ifndef QT_NO_DEBUG_STREAM |
1299 | | friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiShaderResourceBindings &); |
1300 | | #endif |
1301 | | }; |
1302 | | |
1303 | 0 | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiShaderResourceBindings::UpdateFlags) Unexecuted instantiation: operator|(QRhiShaderResourceBindings::UpdateFlag, QRhiShaderResourceBindings::UpdateFlag) Unexecuted instantiation: operator|(QRhiShaderResourceBindings::UpdateFlag, QFlags<QRhiShaderResourceBindings::UpdateFlag>) Unexecuted instantiation: operator&(QRhiShaderResourceBindings::UpdateFlag, QRhiShaderResourceBindings::UpdateFlag) Unexecuted instantiation: operator&(QRhiShaderResourceBindings::UpdateFlag, QFlags<QRhiShaderResourceBindings::UpdateFlag>) Unexecuted instantiation: operator^(QRhiShaderResourceBindings::UpdateFlag, QRhiShaderResourceBindings::UpdateFlag) Unexecuted instantiation: operator^(QRhiShaderResourceBindings::UpdateFlag, QFlags<QRhiShaderResourceBindings::UpdateFlag>) Unexecuted instantiation: operator|(QRhiShaderResourceBindings::UpdateFlag, int) |
1304 | 0 |
|
1305 | 0 | #ifndef QT_NO_DEBUG_STREAM |
1306 | 0 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiShaderResourceBindings &); |
1307 | 0 | #endif |
1308 | 0 |
|
1309 | 0 | // The proper name. Until it gets rolled out universally, have the better name |
1310 | 0 | // as a typedef. Eventually it should be reversed (the old name being a typedef |
1311 | 0 | // to the new one). |
1312 | 0 | using QRhiShaderResourceBindingSet = QRhiShaderResourceBindings; |
1313 | 0 |
|
1314 | 0 | class Q_GUI_EXPORT QRhiGraphicsPipeline : public QRhiResource |
1315 | 0 | { |
1316 | 0 | public: |
1317 | 0 | enum Flag { |
1318 | 0 | UsesBlendConstants = 1 << 0, |
1319 | 0 | UsesStencilRef = 1 << 1, |
1320 | 0 | UsesScissor = 1 << 2, |
1321 | 0 | CompileShadersWithDebugInfo = 1 << 3, |
1322 | 0 | UsesShadingRate = 1 << 4, |
1323 | 0 | UsesIndirectDraws = 1 << 5 |
1324 | 0 | }; |
1325 | 0 | Q_DECLARE_FLAGS(Flags, Flag) |
1326 | 0 |
|
1327 | 0 | enum Topology { |
1328 | 0 | Triangles, |
1329 | 0 | TriangleStrip, |
1330 | 0 | TriangleFan, |
1331 | 0 | Lines, |
1332 | 0 | LineStrip, |
1333 | 0 | Points, |
1334 | 0 | Patches |
1335 | 0 | }; |
1336 | 0 |
|
1337 | 0 | enum CullMode { |
1338 | 0 | None, |
1339 | 0 | Front, |
1340 | 0 | Back |
1341 | 0 | }; |
1342 | 0 |
|
1343 | 0 | enum FrontFace { |
1344 | 0 | CCW, |
1345 | 0 | CW |
1346 | 0 | }; |
1347 | 0 |
|
1348 | 0 | enum ColorMaskComponent { |
1349 | 0 | R = 1 << 0, |
1350 | 0 | G = 1 << 1, |
1351 | 0 | B = 1 << 2, |
1352 | 0 | A = 1 << 3 |
1353 | 0 | }; |
1354 | 0 | Q_DECLARE_FLAGS(ColorMask, ColorMaskComponent) |
1355 | 0 |
|
1356 | 0 | enum BlendFactor { |
1357 | 0 | Zero, |
1358 | 0 | One, |
1359 | 0 | SrcColor, |
1360 | 0 | OneMinusSrcColor, |
1361 | 0 | DstColor, |
1362 | 0 | OneMinusDstColor, |
1363 | 0 | SrcAlpha, |
1364 | 0 | OneMinusSrcAlpha, |
1365 | 0 | DstAlpha, |
1366 | 0 | OneMinusDstAlpha, |
1367 | 0 | ConstantColor, |
1368 | 0 | OneMinusConstantColor, |
1369 | 0 | ConstantAlpha, |
1370 | 0 | OneMinusConstantAlpha, |
1371 | 0 | SrcAlphaSaturate, |
1372 | 0 | Src1Color, |
1373 | 0 | OneMinusSrc1Color, |
1374 | 0 | Src1Alpha, |
1375 | 0 | OneMinusSrc1Alpha |
1376 | 0 | }; |
1377 | 0 |
|
1378 | 0 | enum BlendOp { |
1379 | 0 | Add, |
1380 | 0 | Subtract, |
1381 | 0 | ReverseSubtract, |
1382 | 0 | Min, |
1383 | 0 | Max |
1384 | 0 | }; |
1385 | 0 |
|
1386 | 0 | struct TargetBlend { |
1387 | 0 | ColorMask colorWrite = ColorMask(0xF); // R | G | B | A |
1388 | 0 | bool enable = false; |
1389 | 0 | BlendFactor srcColor = One; |
1390 | 0 | BlendFactor dstColor = OneMinusSrcAlpha; |
1391 | 0 | BlendOp opColor = Add; |
1392 | 0 | BlendFactor srcAlpha = One; |
1393 | 0 | BlendFactor dstAlpha = OneMinusSrcAlpha; |
1394 | 0 | BlendOp opAlpha = Add; |
1395 | 0 | }; |
1396 | 0 |
|
1397 | 0 | enum CompareOp { |
1398 | 0 | Never, |
1399 | 0 | Less, |
1400 | 0 | Equal, |
1401 | 0 | LessOrEqual, |
1402 | 0 | Greater, |
1403 | 0 | NotEqual, |
1404 | 0 | GreaterOrEqual, |
1405 | 0 | Always |
1406 | 0 | }; |
1407 | 0 |
|
1408 | 0 | enum StencilOp { |
1409 | 0 | StencilZero, |
1410 | 0 | Keep, |
1411 | 0 | Replace, |
1412 | 0 | IncrementAndClamp, |
1413 | 0 | DecrementAndClamp, |
1414 | 0 | Invert, |
1415 | 0 | IncrementAndWrap, |
1416 | 0 | DecrementAndWrap |
1417 | 0 | }; |
1418 | 0 |
|
1419 | 0 | struct StencilOpState { |
1420 | 0 | StencilOp failOp = Keep; |
1421 | 0 | StencilOp depthFailOp = Keep; |
1422 | 0 | StencilOp passOp = Keep; |
1423 | 0 | CompareOp compareOp = Always; |
1424 | 0 | }; |
1425 | 0 |
|
1426 | 0 | enum PolygonMode { |
1427 | 0 | Fill, |
1428 | 0 | Line |
1429 | 0 | }; |
1430 | 0 |
|
1431 | 0 | QRhiResource::Type resourceType() const override; |
1432 | 0 |
|
1433 | 0 | Flags flags() const { return m_flags; } |
1434 | 0 | void setFlags(Flags f) { m_flags = f; } |
1435 | | |
1436 | 0 | Topology topology() const { return m_topology; } |
1437 | 0 | void setTopology(Topology t) { m_topology = t; } |
1438 | | |
1439 | 0 | CullMode cullMode() const { return m_cullMode; } |
1440 | 0 | void setCullMode(CullMode mode) { m_cullMode = mode; } |
1441 | | |
1442 | 0 | FrontFace frontFace() const { return m_frontFace; } |
1443 | 0 | void setFrontFace(FrontFace f) { m_frontFace = f; } |
1444 | | |
1445 | 0 | void setTargetBlends(std::initializer_list<TargetBlend> list) { m_targetBlends = list; } |
1446 | | template<typename InputIterator> |
1447 | | void setTargetBlends(InputIterator first, InputIterator last) |
1448 | | { |
1449 | | m_targetBlends.clear(); |
1450 | | std::copy(first, last, std::back_inserter(m_targetBlends)); |
1451 | | } |
1452 | 0 | const TargetBlend *cbeginTargetBlends() const { return m_targetBlends.cbegin(); } |
1453 | 0 | const TargetBlend *cendTargetBlends() const { return m_targetBlends.cend(); } |
1454 | 0 | const TargetBlend *targetBlendAt(qsizetype index) const { return &m_targetBlends.at(index); } |
1455 | 0 | qsizetype targetBlendCount() const { return m_targetBlends.count(); } |
1456 | | |
1457 | 0 | bool hasDepthTest() const { return m_depthTest; } |
1458 | 0 | void setDepthTest(bool enable) { m_depthTest = enable; } |
1459 | | |
1460 | 0 | bool hasDepthWrite() const { return m_depthWrite; } |
1461 | 0 | void setDepthWrite(bool enable) { m_depthWrite = enable; } |
1462 | | |
1463 | 0 | bool hasDepthClamp() const { return m_depthClamp; } |
1464 | 0 | void setDepthClamp(bool enable) { m_depthClamp = enable; } |
1465 | | |
1466 | 0 | CompareOp depthOp() const { return m_depthOp; } |
1467 | 0 | void setDepthOp(CompareOp op) { m_depthOp = op; } |
1468 | | |
1469 | 0 | bool hasStencilTest() const { return m_stencilTest; } |
1470 | 0 | void setStencilTest(bool enable) { m_stencilTest = enable; } |
1471 | | |
1472 | 0 | StencilOpState stencilFront() const { return m_stencilFront; } |
1473 | 0 | void setStencilFront(const StencilOpState &state) { m_stencilFront = state; } |
1474 | | |
1475 | 0 | StencilOpState stencilBack() const { return m_stencilBack; } |
1476 | 0 | void setStencilBack(const StencilOpState &state) { m_stencilBack = state; } |
1477 | | |
1478 | 0 | quint32 stencilReadMask() const { return m_stencilReadMask; } |
1479 | 0 | void setStencilReadMask(quint32 mask) { m_stencilReadMask = mask; } |
1480 | | |
1481 | 0 | quint32 stencilWriteMask() const { return m_stencilWriteMask; } |
1482 | 0 | void setStencilWriteMask(quint32 mask) { m_stencilWriteMask = mask; } |
1483 | | |
1484 | 0 | int sampleCount() const { return m_sampleCount; } |
1485 | 0 | void setSampleCount(int s) { m_sampleCount = s; } |
1486 | | |
1487 | 0 | float lineWidth() const { return m_lineWidth; } |
1488 | 0 | void setLineWidth(float width) { m_lineWidth = width; } |
1489 | | |
1490 | 0 | int depthBias() const { return m_depthBias; } |
1491 | 0 | void setDepthBias(int bias) { m_depthBias = bias; } |
1492 | | |
1493 | 0 | float slopeScaledDepthBias() const { return m_slopeScaledDepthBias; } |
1494 | 0 | void setSlopeScaledDepthBias(float bias) { m_slopeScaledDepthBias = bias; } |
1495 | | |
1496 | 0 | void setShaderStages(std::initializer_list<QRhiShaderStage> list) { m_shaderStages = list; } |
1497 | | template<typename InputIterator> |
1498 | | void setShaderStages(InputIterator first, InputIterator last) |
1499 | | { |
1500 | | m_shaderStages.clear(); |
1501 | | std::copy(first, last, std::back_inserter(m_shaderStages)); |
1502 | | } |
1503 | 0 | const QRhiShaderStage *cbeginShaderStages() const { return m_shaderStages.cbegin(); } |
1504 | 0 | const QRhiShaderStage *cendShaderStages() const { return m_shaderStages.cend(); } |
1505 | 0 | const QRhiShaderStage *shaderStageAt(qsizetype index) const { return &m_shaderStages.at(index); } |
1506 | 0 | qsizetype shaderStageCount() const { return m_shaderStages.count(); } |
1507 | | |
1508 | 0 | QRhiVertexInputLayout vertexInputLayout() const { return m_vertexInputLayout; } |
1509 | 0 | void setVertexInputLayout(const QRhiVertexInputLayout &layout) { m_vertexInputLayout = layout; } |
1510 | | |
1511 | 0 | QRhiShaderResourceBindings *shaderResourceBindings() const { return m_shaderResourceBindings; } |
1512 | 0 | void setShaderResourceBindings(QRhiShaderResourceBindings *srb) { m_shaderResourceBindings = srb; } |
1513 | | |
1514 | 0 | QRhiRenderPassDescriptor *renderPassDescriptor() const { return m_renderPassDesc; } |
1515 | 0 | void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; } |
1516 | | |
1517 | 0 | int patchControlPointCount() const { return m_patchControlPointCount; } |
1518 | 0 | void setPatchControlPointCount(int count) { m_patchControlPointCount = count; } |
1519 | | |
1520 | 0 | PolygonMode polygonMode() const {return m_polygonMode; } |
1521 | 0 | void setPolygonMode(PolygonMode mode) {m_polygonMode = mode; } |
1522 | | |
1523 | 0 | int multiViewCount() const { return m_multiViewCount; } |
1524 | 0 | void setMultiViewCount(int count) { m_multiViewCount = count; } |
1525 | | |
1526 | | virtual bool create() = 0; |
1527 | | |
1528 | | protected: |
1529 | | QRhiGraphicsPipeline(QRhiImplementation *rhi); |
1530 | | Flags m_flags; |
1531 | | Topology m_topology = Triangles; |
1532 | | CullMode m_cullMode = None; |
1533 | | FrontFace m_frontFace = CCW; |
1534 | | QVarLengthArray<TargetBlend, 8> m_targetBlends; |
1535 | | bool m_depthTest = false; |
1536 | | bool m_depthWrite = false; |
1537 | | bool m_depthClamp = false; |
1538 | | CompareOp m_depthOp = Less; |
1539 | | bool m_stencilTest = false; |
1540 | | StencilOpState m_stencilFront; |
1541 | | StencilOpState m_stencilBack; |
1542 | | quint32 m_stencilReadMask = 0xFF; |
1543 | | quint32 m_stencilWriteMask = 0xFF; |
1544 | | int m_sampleCount = 1; |
1545 | | float m_lineWidth = 1.0f; |
1546 | | int m_depthBias = 0; |
1547 | | float m_slopeScaledDepthBias = 0.0f; |
1548 | | int m_patchControlPointCount = 3; |
1549 | | PolygonMode m_polygonMode = Fill; |
1550 | | int m_multiViewCount = 0; |
1551 | | QVarLengthArray<QRhiShaderStage, 4> m_shaderStages; |
1552 | | QRhiVertexInputLayout m_vertexInputLayout; |
1553 | | QRhiShaderResourceBindings *m_shaderResourceBindings = nullptr; |
1554 | | QRhiRenderPassDescriptor *m_renderPassDesc = nullptr; |
1555 | | }; |
1556 | | |
1557 | 0 | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiGraphicsPipeline::Flags) Unexecuted instantiation: operator|(QRhiGraphicsPipeline::Flag, QRhiGraphicsPipeline::Flag) Unexecuted instantiation: operator|(QRhiGraphicsPipeline::Flag, QFlags<QRhiGraphicsPipeline::Flag>) Unexecuted instantiation: operator&(QRhiGraphicsPipeline::Flag, QRhiGraphicsPipeline::Flag) Unexecuted instantiation: operator&(QRhiGraphicsPipeline::Flag, QFlags<QRhiGraphicsPipeline::Flag>) Unexecuted instantiation: operator^(QRhiGraphicsPipeline::Flag, QRhiGraphicsPipeline::Flag) Unexecuted instantiation: operator^(QRhiGraphicsPipeline::Flag, QFlags<QRhiGraphicsPipeline::Flag>) Unexecuted instantiation: operator|(QRhiGraphicsPipeline::Flag, int) |
1558 | 0 | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiGraphicsPipeline::ColorMask) Unexecuted instantiation: operator|(QRhiGraphicsPipeline::ColorMaskComponent, QRhiGraphicsPipeline::ColorMaskComponent) Unexecuted instantiation: operator|(QRhiGraphicsPipeline::ColorMaskComponent, QFlags<QRhiGraphicsPipeline::ColorMaskComponent>) Unexecuted instantiation: operator&(QRhiGraphicsPipeline::ColorMaskComponent, QRhiGraphicsPipeline::ColorMaskComponent) Unexecuted instantiation: operator&(QRhiGraphicsPipeline::ColorMaskComponent, QFlags<QRhiGraphicsPipeline::ColorMaskComponent>) Unexecuted instantiation: operator^(QRhiGraphicsPipeline::ColorMaskComponent, QRhiGraphicsPipeline::ColorMaskComponent) Unexecuted instantiation: operator^(QRhiGraphicsPipeline::ColorMaskComponent, QFlags<QRhiGraphicsPipeline::ColorMaskComponent>) Unexecuted instantiation: operator|(QRhiGraphicsPipeline::ColorMaskComponent, int) |
1559 | 0 | Q_DECLARE_TYPEINFO(QRhiGraphicsPipeline::TargetBlend, Q_RELOCATABLE_TYPE); |
1560 | 0 |
|
1561 | 0 | struct QRhiSwapChainHdrInfo |
1562 | 0 | { |
1563 | 0 | enum LimitsType { |
1564 | 0 | LuminanceInNits, |
1565 | 0 | ColorComponentValue |
1566 | 0 | }; |
1567 | 0 |
|
1568 | 0 | enum LuminanceBehavior { |
1569 | 0 | SceneReferred, |
1570 | 0 | DisplayReferred |
1571 | 0 | }; |
1572 | 0 |
|
1573 | 0 | LimitsType limitsType; |
1574 | 0 | union { |
1575 | 0 | struct { |
1576 | 0 | float minLuminance; |
1577 | 0 | float maxLuminance; |
1578 | 0 | } luminanceInNits; |
1579 | 0 | struct { |
1580 | 0 | float maxColorComponentValue; |
1581 | 0 | float maxPotentialColorComponentValue; |
1582 | 0 | } colorComponentValue; |
1583 | 0 | } limits; |
1584 | 0 | LuminanceBehavior luminanceBehavior; |
1585 | 0 | float sdrWhiteLevel; |
1586 | 0 | }; |
1587 | 0 |
|
1588 | 0 | Q_DECLARE_TYPEINFO(QRhiSwapChainHdrInfo, Q_RELOCATABLE_TYPE); |
1589 | 0 |
|
1590 | 0 | #ifndef QT_NO_DEBUG_STREAM |
1591 | 0 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiSwapChainHdrInfo &); |
1592 | 0 | #endif |
1593 | 0 |
|
1594 | 0 | struct QRhiSwapChainProxyData |
1595 | 0 | { |
1596 | 0 | void *reserved[2] = {}; |
1597 | 0 | }; |
1598 | 0 |
|
1599 | 0 | class Q_GUI_EXPORT QRhiSwapChain : public QRhiResource |
1600 | 0 | { |
1601 | 0 | public: |
1602 | 0 | enum Flag { |
1603 | 0 | SurfaceHasPreMulAlpha = 1 << 0, |
1604 | 0 | SurfaceHasNonPreMulAlpha = 1 << 1, |
1605 | 0 | sRGB = 1 << 2, |
1606 | 0 | UsedAsTransferSource = 1 << 3, |
1607 | 0 | NoVSync = 1 << 4, |
1608 | 0 | MinimalBufferCount = 1 << 5 |
1609 | 0 | }; |
1610 | 0 | Q_DECLARE_FLAGS(Flags, Flag) |
1611 | 0 |
|
1612 | 0 | enum Format { |
1613 | 0 | SDR, |
1614 | 0 | HDRExtendedSrgbLinear, |
1615 | 0 | HDR10, |
1616 | 0 | HDRExtendedDisplayP3Linear |
1617 | 0 | }; |
1618 | 0 |
|
1619 | 0 | enum StereoTargetBuffer { |
1620 | 0 | LeftBuffer, |
1621 | 0 | RightBuffer |
1622 | 0 | }; |
1623 | 0 |
|
1624 | 0 | QRhiResource::Type resourceType() const override; |
1625 | 0 |
|
1626 | 0 | QWindow *window() const { return m_window; } |
1627 | 0 | void setWindow(QWindow *window) { m_window = window; } |
1628 | | |
1629 | 0 | QRhiSwapChainProxyData proxyData() const { return m_proxyData; } |
1630 | 0 | void setProxyData(const QRhiSwapChainProxyData &d) { m_proxyData = d; } |
1631 | | |
1632 | 0 | Flags flags() const { return m_flags; } |
1633 | 0 | void setFlags(Flags f) { m_flags = f; } |
1634 | | |
1635 | 0 | Format format() const { return m_format; } |
1636 | 0 | void setFormat(Format f) { m_format = f; } |
1637 | | |
1638 | 0 | QRhiRenderBuffer *depthStencil() const { return m_depthStencil; } |
1639 | 0 | void setDepthStencil(QRhiRenderBuffer *ds) { m_depthStencil = ds; } |
1640 | | |
1641 | 0 | int sampleCount() const { return m_sampleCount; } |
1642 | 0 | void setSampleCount(int samples) { m_sampleCount = samples; } |
1643 | | |
1644 | 0 | QRhiRenderPassDescriptor *renderPassDescriptor() const { return m_renderPassDesc; } |
1645 | 0 | void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; } |
1646 | | |
1647 | 0 | QRhiShadingRateMap *shadingRateMap() const { return m_shadingRateMap; } |
1648 | 0 | void setShadingRateMap(QRhiShadingRateMap *map) { m_shadingRateMap = map; } |
1649 | | |
1650 | 0 | QSize currentPixelSize() const { return m_currentPixelSize; } |
1651 | | |
1652 | | virtual QRhiCommandBuffer *currentFrameCommandBuffer() = 0; |
1653 | | virtual QRhiRenderTarget *currentFrameRenderTarget() = 0; |
1654 | | virtual QRhiRenderTarget *currentFrameRenderTarget(StereoTargetBuffer targetBuffer); |
1655 | | virtual QSize surfacePixelSize() = 0; |
1656 | | virtual bool isFormatSupported(Format f) = 0; |
1657 | | virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() = 0; |
1658 | | virtual bool createOrResize() = 0; |
1659 | | virtual QRhiSwapChainHdrInfo hdrInfo(); |
1660 | | |
1661 | | protected: |
1662 | | QRhiSwapChain(QRhiImplementation *rhi); |
1663 | | QWindow *m_window = nullptr; |
1664 | | Flags m_flags; |
1665 | | Format m_format = SDR; |
1666 | | QRhiRenderBuffer *m_depthStencil = nullptr; |
1667 | | int m_sampleCount = 1; |
1668 | | QRhiRenderPassDescriptor *m_renderPassDesc = nullptr; |
1669 | | QSize m_currentPixelSize; |
1670 | | QRhiSwapChainProxyData m_proxyData; |
1671 | | QRhiShadingRateMap *m_shadingRateMap = nullptr; |
1672 | | }; |
1673 | | |
1674 | 0 | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiSwapChain::Flags) Unexecuted instantiation: operator|(QRhiSwapChain::Flag, QRhiSwapChain::Flag) Unexecuted instantiation: operator|(QRhiSwapChain::Flag, QFlags<QRhiSwapChain::Flag>) Unexecuted instantiation: operator&(QRhiSwapChain::Flag, QRhiSwapChain::Flag) Unexecuted instantiation: operator&(QRhiSwapChain::Flag, QFlags<QRhiSwapChain::Flag>) Unexecuted instantiation: operator^(QRhiSwapChain::Flag, QRhiSwapChain::Flag) Unexecuted instantiation: operator^(QRhiSwapChain::Flag, QFlags<QRhiSwapChain::Flag>) Unexecuted instantiation: operator|(QRhiSwapChain::Flag, int) |
1675 | 0 |
|
1676 | 0 | class Q_GUI_EXPORT QRhiComputePipeline : public QRhiResource |
1677 | 0 | { |
1678 | 0 | public: |
1679 | 0 | enum Flag { |
1680 | 0 | CompileShadersWithDebugInfo = 1 << 0 |
1681 | 0 | }; |
1682 | 0 | Q_DECLARE_FLAGS(Flags, Flag) |
1683 | 0 |
|
1684 | 0 | QRhiResource::Type resourceType() const override; |
1685 | 0 | virtual bool create() = 0; |
1686 | 0 |
|
1687 | 0 | Flags flags() const { return m_flags; } |
1688 | 0 | void setFlags(Flags f) { m_flags = f; } |
1689 | | |
1690 | 0 | QRhiShaderStage shaderStage() const { return m_shaderStage; } |
1691 | 0 | void setShaderStage(const QRhiShaderStage &stage) { m_shaderStage = stage; } |
1692 | | |
1693 | 0 | QRhiShaderResourceBindings *shaderResourceBindings() const { return m_shaderResourceBindings; } |
1694 | 0 | void setShaderResourceBindings(QRhiShaderResourceBindings *srb) { m_shaderResourceBindings = srb; } |
1695 | | |
1696 | | protected: |
1697 | | QRhiComputePipeline(QRhiImplementation *rhi); |
1698 | | Flags m_flags; |
1699 | | QRhiShaderStage m_shaderStage; |
1700 | | QRhiShaderResourceBindings *m_shaderResourceBindings = nullptr; |
1701 | | }; |
1702 | | |
1703 | 0 | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiComputePipeline::Flags) Unexecuted instantiation: operator|(QRhiComputePipeline::Flag, QRhiComputePipeline::Flag) Unexecuted instantiation: operator|(QRhiComputePipeline::Flag, QFlags<QRhiComputePipeline::Flag>) Unexecuted instantiation: operator&(QRhiComputePipeline::Flag, QRhiComputePipeline::Flag) Unexecuted instantiation: operator&(QRhiComputePipeline::Flag, QFlags<QRhiComputePipeline::Flag>) Unexecuted instantiation: operator^(QRhiComputePipeline::Flag, QRhiComputePipeline::Flag) Unexecuted instantiation: operator^(QRhiComputePipeline::Flag, QFlags<QRhiComputePipeline::Flag>) Unexecuted instantiation: operator|(QRhiComputePipeline::Flag, int) |
1704 | 0 |
|
1705 | 0 | struct QRhiIndirectDrawCommand |
1706 | 0 | { |
1707 | 0 | quint32 vertexCount; |
1708 | 0 | quint32 instanceCount = 1; |
1709 | 0 | quint32 firstVertex = 0; |
1710 | 0 | quint32 firstInstance = 0; |
1711 | 0 | }; |
1712 | 0 |
|
1713 | 0 | struct QRhiIndexedIndirectDrawCommand |
1714 | 0 | { |
1715 | 0 | quint32 indexCount; |
1716 | 0 | quint32 instanceCount = 1; |
1717 | 0 | quint32 firstIndex = 0; |
1718 | 0 | qint32 vertexOffset = 0; |
1719 | 0 | quint32 firstInstance = 0; |
1720 | 0 | }; |
1721 | 0 |
|
1722 | 0 | // Check that the compiler isn't doing anything nasty. |
1723 | 0 | static_assert(sizeof(QRhiIndirectDrawCommand) == 16); |
1724 | 0 | static_assert(sizeof(QRhiIndexedIndirectDrawCommand) == 20); |
1725 | 0 |
|
1726 | 0 | class Q_GUI_EXPORT QRhiCommandBuffer : public QRhiResource |
1727 | 0 | { |
1728 | 0 | public: |
1729 | 0 | enum IndexFormat { |
1730 | 0 | IndexUInt16, |
1731 | 0 | IndexUInt32 |
1732 | 0 | }; |
1733 | 0 |
|
1734 | 0 | enum BeginPassFlag { |
1735 | 0 | ExternalContent = 0x01, |
1736 | 0 | DoNotTrackResourcesForCompute = 0x02 |
1737 | 0 | }; |
1738 | 0 | Q_DECLARE_FLAGS(BeginPassFlags, BeginPassFlag) |
1739 | 0 |
|
1740 | 0 | QRhiResource::Type resourceType() const override; |
1741 | 0 |
|
1742 | 0 | void resourceUpdate(QRhiResourceUpdateBatch *resourceUpdates); |
1743 | 0 |
|
1744 | 0 | void beginPass(QRhiRenderTarget *rt, |
1745 | 0 | const QColor &colorClearValue, |
1746 | 0 | const QRhiDepthStencilClearValue &depthStencilClearValue, |
1747 | 0 | QRhiResourceUpdateBatch *resourceUpdates = nullptr, |
1748 | 0 | BeginPassFlags flags = {}); |
1749 | 0 | void endPass(QRhiResourceUpdateBatch *resourceUpdates = nullptr); |
1750 | 0 |
|
1751 | 0 | void setGraphicsPipeline(QRhiGraphicsPipeline *ps); |
1752 | 0 | using DynamicOffset = std::pair<int, quint32>; // binding, offset |
1753 | 0 | void setShaderResources(QRhiShaderResourceBindings *srb = nullptr, |
1754 | 0 | int dynamicOffsetCount = 0, |
1755 | 0 | const DynamicOffset *dynamicOffsets = nullptr); |
1756 | 0 | using VertexInput = std::pair<QRhiBuffer *, quint32>; // buffer, offset |
1757 | 0 | void setVertexInput(int startBinding, int bindingCount, const VertexInput *bindings, |
1758 | 0 | QRhiBuffer *indexBuf = nullptr, quint32 indexOffset = 0, |
1759 | 0 | IndexFormat indexFormat = IndexUInt16); |
1760 | 0 |
|
1761 | 0 | void setViewport(const QRhiViewport &viewport); |
1762 | 0 | void setScissor(const QRhiScissor &scissor); |
1763 | 0 | void setBlendConstants(const QColor &c); |
1764 | 0 | void setStencilRef(quint32 refValue); |
1765 | 0 | void setShadingRate(const QSize &coarsePixelSize); |
1766 | 0 |
|
1767 | 0 | void draw(quint32 vertexCount, |
1768 | 0 | quint32 instanceCount = 1, |
1769 | 0 | quint32 firstVertex = 0, |
1770 | 0 | quint32 firstInstance = 0); |
1771 | 0 |
|
1772 | 0 | void drawIndexed(quint32 indexCount, |
1773 | 0 | quint32 instanceCount = 1, |
1774 | 0 | quint32 firstIndex = 0, |
1775 | 0 | qint32 vertexOffset = 0, |
1776 | 0 | quint32 firstInstance = 0); |
1777 | 0 |
|
1778 | 0 | void drawIndirect(QRhiBuffer *indirectBuffer, |
1779 | 0 | quint32 indirectBufferOffset, |
1780 | 0 | quint32 drawCount, |
1781 | 0 | quint32 stride = sizeof(QRhiIndirectDrawCommand)); |
1782 | 0 |
|
1783 | 0 | void drawIndexedIndirect(QRhiBuffer *indirectBuffer, |
1784 | 0 | quint32 indirectBufferOffset, |
1785 | 0 | quint32 drawCount, |
1786 | 0 | quint32 stride = sizeof(QRhiIndexedIndirectDrawCommand)); |
1787 | 0 |
|
1788 | 0 | void debugMarkBegin(const QByteArray &name); |
1789 | 0 | void debugMarkEnd(); |
1790 | 0 | void debugMarkMsg(const QByteArray &msg); |
1791 | 0 |
|
1792 | 0 | void beginComputePass(QRhiResourceUpdateBatch *resourceUpdates = nullptr, BeginPassFlags flags = {}); |
1793 | 0 | void endComputePass(QRhiResourceUpdateBatch *resourceUpdates = nullptr); |
1794 | 0 | void setComputePipeline(QRhiComputePipeline *ps); |
1795 | 0 | void dispatch(int x, int y, int z); |
1796 | 0 |
|
1797 | 0 | const QRhiNativeHandles *nativeHandles(); |
1798 | 0 | void beginExternal(); |
1799 | 0 | void endExternal(); |
1800 | 0 |
|
1801 | 0 | double lastCompletedGpuTime(); |
1802 | 0 |
|
1803 | 0 | protected: |
1804 | 0 | QRhiCommandBuffer(QRhiImplementation *rhi); |
1805 | 0 | }; |
1806 | 0 |
|
1807 | 0 | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiCommandBuffer::BeginPassFlags) Unexecuted instantiation: operator|(QRhiCommandBuffer::BeginPassFlag, QRhiCommandBuffer::BeginPassFlag) Unexecuted instantiation: operator|(QRhiCommandBuffer::BeginPassFlag, QFlags<QRhiCommandBuffer::BeginPassFlag>) Unexecuted instantiation: operator&(QRhiCommandBuffer::BeginPassFlag, QRhiCommandBuffer::BeginPassFlag) Unexecuted instantiation: operator&(QRhiCommandBuffer::BeginPassFlag, QFlags<QRhiCommandBuffer::BeginPassFlag>) Unexecuted instantiation: operator^(QRhiCommandBuffer::BeginPassFlag, QRhiCommandBuffer::BeginPassFlag) Unexecuted instantiation: operator^(QRhiCommandBuffer::BeginPassFlag, QFlags<QRhiCommandBuffer::BeginPassFlag>) Unexecuted instantiation: operator|(QRhiCommandBuffer::BeginPassFlag, int) |
1808 | 0 |
|
1809 | 0 | struct Q_GUI_EXPORT QRhiReadbackResult |
1810 | 0 | { |
1811 | 0 | std::function<void()> completed = nullptr; |
1812 | 0 | QRhiTexture::Format format; |
1813 | 0 | QSize pixelSize; |
1814 | 0 | QByteArray data; |
1815 | 0 | }; |
1816 | 0 |
|
1817 | 0 | class Q_GUI_EXPORT QRhiResourceUpdateBatch |
1818 | 0 | { |
1819 | 0 | public: |
1820 | 0 | ~QRhiResourceUpdateBatch(); |
1821 | 0 |
|
1822 | 0 | void release(); |
1823 | 0 |
|
1824 | 0 | void merge(QRhiResourceUpdateBatch *other); |
1825 | 0 | bool hasOptimalCapacity() const; |
1826 | 0 |
|
1827 | 0 | void updateDynamicBuffer(QRhiBuffer *buf, quint32 offset, quint32 size, const void *data); |
1828 | 0 | void updateDynamicBuffer(QRhiBuffer *buf, quint32 offset, QByteArray data); |
1829 | 0 | void uploadStaticBuffer(QRhiBuffer *buf, quint32 offset, quint32 size, const void *data); |
1830 | 0 | void uploadStaticBuffer(QRhiBuffer *buf, quint32 offset, QByteArray data); |
1831 | 0 | void uploadStaticBuffer(QRhiBuffer *buf, const void *data); |
1832 | 0 | void uploadStaticBuffer(QRhiBuffer *buf, QByteArray data); |
1833 | 0 | void readBackBuffer(QRhiBuffer *buf, quint32 offset, quint32 size, QRhiReadbackResult *result); |
1834 | 0 | void uploadTexture(QRhiTexture *tex, const QRhiTextureUploadDescription &desc); |
1835 | 0 | void uploadTexture(QRhiTexture *tex, const QImage &image); |
1836 | 0 | void copyTexture(QRhiTexture *dst, QRhiTexture *src, const QRhiTextureCopyDescription &desc = QRhiTextureCopyDescription()); |
1837 | 0 | void readBackTexture(const QRhiReadbackDescription &rb, QRhiReadbackResult *result); |
1838 | 0 | void generateMips(QRhiTexture *tex); |
1839 | 0 |
|
1840 | 0 | private: |
1841 | 0 | QRhiResourceUpdateBatch(QRhiImplementation *rhi); |
1842 | 0 | Q_DISABLE_COPY(QRhiResourceUpdateBatch) |
1843 | 0 | QRhiResourceUpdateBatchPrivate *d; |
1844 | 0 | friend class QRhiResourceUpdateBatchPrivate; |
1845 | 0 | friend class QRhi; |
1846 | 0 | }; |
1847 | 0 |
|
1848 | 0 | struct Q_GUI_EXPORT QRhiDriverInfo |
1849 | 0 | { |
1850 | 0 | enum DeviceType { |
1851 | 0 | UnknownDevice, |
1852 | 0 | IntegratedDevice, |
1853 | 0 | DiscreteDevice, |
1854 | 0 | ExternalDevice, |
1855 | 0 | VirtualDevice, |
1856 | 0 | CpuDevice |
1857 | 0 | }; |
1858 | 0 |
|
1859 | 0 | QByteArray deviceName; |
1860 | 0 | quint64 deviceId = 0; |
1861 | 0 | quint64 vendorId = 0; |
1862 | 0 | DeviceType deviceType = UnknownDevice; |
1863 | 0 | }; |
1864 | 0 |
|
1865 | 0 | Q_DECLARE_TYPEINFO(QRhiDriverInfo, Q_RELOCATABLE_TYPE); |
1866 | 0 |
|
1867 | 0 | #ifndef QT_NO_DEBUG_STREAM |
1868 | 0 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiDriverInfo &); |
1869 | 0 | #endif |
1870 | 0 |
|
1871 | 0 | struct Q_GUI_EXPORT QRhiStats |
1872 | 0 | { |
1873 | 0 | qint64 totalPipelineCreationTime = 0; |
1874 | 0 | // Vulkan or D3D12 memory allocator statistics |
1875 | 0 | quint32 blockCount = 0; |
1876 | 0 | quint32 allocCount = 0; |
1877 | 0 | quint64 usedBytes = 0; |
1878 | 0 | quint64 unusedBytes = 0; |
1879 | 0 | // D3D12 only, from IDXGIAdapter3::QueryVideoMemoryInfo(), incl. all resources |
1880 | 0 | quint64 totalUsageBytes = 0; |
1881 | 0 | }; |
1882 | 0 |
|
1883 | 0 | Q_DECLARE_TYPEINFO(QRhiStats, Q_RELOCATABLE_TYPE); |
1884 | 0 |
|
1885 | 0 | #ifndef QT_NO_DEBUG_STREAM |
1886 | 0 | Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiStats &); |
1887 | 0 | #endif |
1888 | 0 |
|
1889 | 0 | class Q_GUI_EXPORT QRhiAdapter |
1890 | 0 | { |
1891 | 0 | public: |
1892 | 0 | virtual ~QRhiAdapter(); |
1893 | 0 | virtual QRhiDriverInfo info() const = 0; |
1894 | 0 | }; |
1895 | 0 |
|
1896 | 0 | struct Q_GUI_EXPORT QRhiInitParams |
1897 | 0 | { |
1898 | 0 | }; |
1899 | 0 |
|
1900 | 0 | class Q_GUI_EXPORT QRhi |
1901 | 0 | { |
1902 | 0 | public: |
1903 | 0 | enum Implementation { |
1904 | 0 | Null, |
1905 | 0 | Vulkan, |
1906 | 0 | OpenGLES2, |
1907 | 0 | D3D11, |
1908 | 0 | Metal, |
1909 | 0 | D3D12 |
1910 | 0 | }; |
1911 | 0 |
|
1912 | 0 | enum Flag { |
1913 | 0 | EnableDebugMarkers = 1 << 0, |
1914 | 0 | PreferSoftwareRenderer = 1 << 1, |
1915 | 0 | EnablePipelineCacheDataSave = 1 << 2, |
1916 | 0 | EnableTimestamps = 1 << 3, |
1917 | 0 | SuppressSmokeTestWarnings = 1 << 4 |
1918 | 0 | }; |
1919 | 0 | Q_DECLARE_FLAGS(Flags, Flag) |
1920 | 0 |
|
1921 | 0 | enum FrameOpResult { |
1922 | 0 | FrameOpSuccess = 0, |
1923 | 0 | FrameOpError, |
1924 | 0 | FrameOpSwapChainOutOfDate, |
1925 | 0 | FrameOpDeviceLost |
1926 | 0 | }; |
1927 | 0 |
|
1928 | 0 | enum Feature { |
1929 | 0 | MultisampleTexture = 1, |
1930 | 0 | MultisampleRenderBuffer, |
1931 | 0 | DebugMarkers, |
1932 | 0 | Timestamps, |
1933 | 0 | Instancing, |
1934 | 0 | CustomInstanceStepRate, |
1935 | 0 | PrimitiveRestart, |
1936 | 0 | NonDynamicUniformBuffers, |
1937 | 0 | NonFourAlignedEffectiveIndexBufferOffset, |
1938 | 0 | NPOTTextureRepeat, |
1939 | 0 | RedOrAlpha8IsRed, |
1940 | 0 | ElementIndexUint, |
1941 | 0 | Compute, |
1942 | 0 | WideLines, |
1943 | 0 | VertexShaderPointSize, |
1944 | 0 | BaseVertex, |
1945 | 0 | BaseInstance, |
1946 | 0 | TriangleFanTopology, |
1947 | 0 | ReadBackNonUniformBuffer, |
1948 | 0 | ReadBackNonBaseMipLevel, |
1949 | 0 | TexelFetch, |
1950 | 0 | RenderToNonBaseMipLevel, |
1951 | 0 | IntAttributes, |
1952 | 0 | ScreenSpaceDerivatives, |
1953 | 0 | ReadBackAnyTextureFormat, |
1954 | 0 | PipelineCacheDataLoadSave, |
1955 | 0 | ImageDataStride, |
1956 | 0 | RenderBufferImport, |
1957 | 0 | ThreeDimensionalTextures, |
1958 | 0 | RenderTo3DTextureSlice, |
1959 | 0 | TextureArrays, |
1960 | 0 | Tessellation, |
1961 | 0 | GeometryShader, |
1962 | 0 | TextureArrayRange, |
1963 | 0 | NonFillPolygonMode, |
1964 | 0 | OneDimensionalTextures, |
1965 | 0 | OneDimensionalTextureMipmaps, |
1966 | 0 | HalfAttributes, |
1967 | 0 | RenderToOneDimensionalTexture, |
1968 | 0 | ThreeDimensionalTextureMipmaps, |
1969 | 0 | MultiView, |
1970 | 0 | TextureViewFormat, |
1971 | 0 | ResolveDepthStencil, |
1972 | 0 | VariableRateShading, |
1973 | 0 | VariableRateShadingMap, |
1974 | 0 | VariableRateShadingMapWithTexture, |
1975 | 0 | PerRenderTargetBlending, |
1976 | 0 | SampleVariables, |
1977 | 0 | InstanceIndexIncludesBaseInstance, |
1978 | 0 | DepthClamp, |
1979 | 0 | DrawIndirect, |
1980 | 0 | DrawIndirectMulti, |
1981 | 0 | ShaderDrawParameters, |
1982 | 0 | }; |
1983 | 0 |
|
1984 | 0 | enum BeginFrameFlag { |
1985 | 0 | }; |
1986 | 0 | Q_DECLARE_FLAGS(BeginFrameFlags, BeginFrameFlag) |
1987 | 0 |
|
1988 | 0 | enum EndFrameFlag { |
1989 | 0 | SkipPresent = 1 << 0 |
1990 | 0 | }; |
1991 | 0 | Q_DECLARE_FLAGS(EndFrameFlags, EndFrameFlag) |
1992 | 0 |
|
1993 | 0 | enum ResourceLimit { |
1994 | 0 | TextureSizeMin = 1, |
1995 | 0 | TextureSizeMax, |
1996 | 0 | MaxColorAttachments, |
1997 | 0 | FramesInFlight, |
1998 | 0 | MaxAsyncReadbackFrames, |
1999 | 0 | MaxThreadGroupsPerDimension, |
2000 | 0 | MaxThreadsPerThreadGroup, |
2001 | 0 | MaxThreadGroupX, |
2002 | 0 | MaxThreadGroupY, |
2003 | 0 | MaxThreadGroupZ, |
2004 | 0 | TextureArraySizeMax, |
2005 | 0 | MaxUniformBufferRange, |
2006 | 0 | MaxVertexInputs, |
2007 | 0 | MaxVertexOutputs, |
2008 | 0 | ShadingRateImageTileSize |
2009 | 0 | }; |
2010 | 0 |
|
2011 | 0 | ~QRhi(); |
2012 | 0 |
|
2013 | 0 | static QRhi *create(Implementation impl, |
2014 | 0 | QRhiInitParams *params, |
2015 | 0 | Flags flags = {}, |
2016 | 0 | QRhiNativeHandles *importDevice = nullptr); |
2017 | 0 | static QRhi *create(Implementation impl, |
2018 | 0 | QRhiInitParams *params, |
2019 | 0 | Flags flags, |
2020 | 0 | QRhiNativeHandles *importDevice, |
2021 | 0 | QRhiAdapter *adapter); |
2022 | 0 | static bool probe(Implementation impl, QRhiInitParams *params); |
2023 | 0 | using AdapterList = QVector<QRhiAdapter *>; |
2024 | 0 | static AdapterList enumerateAdapters(Implementation impl, |
2025 | 0 | QRhiInitParams *params, |
2026 | 0 | QRhiNativeHandles *nativeHandles = nullptr); |
2027 | 0 |
|
2028 | 0 | Implementation backend() const; |
2029 | 0 | const char *backendName() const; |
2030 | 0 | static const char *backendName(Implementation impl); |
2031 | 0 | QRhiDriverInfo driverInfo() const; |
2032 | 0 | QThread *thread() const; |
2033 | 0 |
|
2034 | 0 | using CleanupCallback = std::function<void(QRhi *)>; |
2035 | 0 | void addCleanupCallback(const CleanupCallback &callback); |
2036 | 0 | void addCleanupCallback(const void *key, const CleanupCallback &callback); |
2037 | 0 | void removeCleanupCallback(const void *key); |
2038 | 0 |
|
2039 | 0 | QRhiGraphicsPipeline *newGraphicsPipeline(); |
2040 | 0 | QRhiComputePipeline *newComputePipeline(); |
2041 | 0 | QRhiShaderResourceBindings *newShaderResourceBindings(); |
2042 | 0 |
|
2043 | 0 | QRhiBuffer *newBuffer(QRhiBuffer::Type type, |
2044 | 0 | QRhiBuffer::UsageFlags usage, |
2045 | 0 | quint32 size); |
2046 | 0 |
|
2047 | 0 | QRhiRenderBuffer *newRenderBuffer(QRhiRenderBuffer::Type type, |
2048 | 0 | const QSize &pixelSize, |
2049 | 0 | int sampleCount = 1, |
2050 | 0 | QRhiRenderBuffer::Flags flags = {}, |
2051 | 0 | QRhiTexture::Format backingFormatHint = QRhiTexture::UnknownFormat); |
2052 | 0 |
|
2053 | 0 | QRhiTexture *newTexture(QRhiTexture::Format format, |
2054 | 0 | const QSize &pixelSize, |
2055 | 0 | int sampleCount = 1, |
2056 | 0 | QRhiTexture::Flags flags = {}); |
2057 | 0 |
|
2058 | 0 | QRhiTexture *newTexture(QRhiTexture::Format format, |
2059 | 0 | int width, int height, int depth, |
2060 | 0 | int sampleCount = 1, |
2061 | 0 | QRhiTexture::Flags flags = {}); |
2062 | 0 |
|
2063 | 0 | QRhiTexture *newTextureArray(QRhiTexture::Format format, |
2064 | 0 | int arraySize, |
2065 | 0 | const QSize &pixelSize, |
2066 | 0 | int sampleCount = 1, |
2067 | 0 | QRhiTexture::Flags flags = {}); |
2068 | 0 |
|
2069 | 0 | QRhiSampler *newSampler(QRhiSampler::Filter magFilter, |
2070 | 0 | QRhiSampler::Filter minFilter, |
2071 | 0 | QRhiSampler::Filter mipmapMode, |
2072 | 0 | QRhiSampler::AddressMode addressU, |
2073 | 0 | QRhiSampler::AddressMode addressV, |
2074 | 0 | QRhiSampler::AddressMode addressW = QRhiSampler::Repeat); |
2075 | 0 |
|
2076 | 0 | QRhiShadingRateMap *newShadingRateMap(); |
2077 | 0 |
|
2078 | 0 | QRhiTextureRenderTarget *newTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc, |
2079 | 0 | QRhiTextureRenderTarget::Flags flags = {}); |
2080 | 0 |
|
2081 | 0 | QRhiSwapChain *newSwapChain(); |
2082 | 0 | FrameOpResult beginFrame(QRhiSwapChain *swapChain, BeginFrameFlags flags = {}); |
2083 | 0 | FrameOpResult endFrame(QRhiSwapChain *swapChain, EndFrameFlags flags = {}); |
2084 | 0 | bool isRecordingFrame() const; |
2085 | 0 | int currentFrameSlot() const; |
2086 | 0 |
|
2087 | 0 | FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb, BeginFrameFlags flags = {}); |
2088 | 0 | FrameOpResult endOffscreenFrame(EndFrameFlags flags = {}); |
2089 | 0 |
|
2090 | 0 | QRhi::FrameOpResult finish(); |
2091 | 0 |
|
2092 | 0 | QRhiResourceUpdateBatch *nextResourceUpdateBatch(); |
2093 | 0 |
|
2094 | 0 | QList<int> supportedSampleCounts() const; |
2095 | 0 |
|
2096 | 0 | int ubufAlignment() const; |
2097 | 0 | int ubufAligned(int v) const; |
2098 | 0 |
|
2099 | 0 | static int mipLevelsForSize(const QSize &size); |
2100 | 0 | static QSize sizeForMipLevel(int mipLevel, const QSize &baseLevelSize); |
2101 | 0 |
|
2102 | 0 | bool isYUpInFramebuffer() const; |
2103 | 0 | bool isYUpInNDC() const; |
2104 | 0 | bool isClipDepthZeroToOne() const; |
2105 | 0 |
|
2106 | 0 | QMatrix4x4 clipSpaceCorrMatrix() const; |
2107 | 0 |
|
2108 | 0 | bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags = {}) const; |
2109 | 0 | bool isFeatureSupported(QRhi::Feature feature) const; |
2110 | 0 | int resourceLimit(ResourceLimit limit) const; |
2111 | 0 |
|
2112 | 0 | const QRhiNativeHandles *nativeHandles(); |
2113 | 0 | bool makeThreadLocalNativeContextCurrent(); |
2114 | 0 | void setQueueSubmitParams(QRhiNativeHandles *params); |
2115 | 0 |
|
2116 | 0 | static constexpr int MAX_MIP_LEVELS = 16; // -> max width or height is 65536 |
2117 | 0 |
|
2118 | 0 | void releaseCachedResources(); |
2119 | 0 |
|
2120 | 0 | bool isDeviceLost() const; |
2121 | 0 |
|
2122 | 0 | QByteArray pipelineCacheData(); |
2123 | 0 | void setPipelineCacheData(const QByteArray &data); |
2124 | 0 |
|
2125 | 0 | QRhiStats statistics() const; |
2126 | 0 |
|
2127 | 0 | static QRhiSwapChainProxyData updateSwapChainProxyData(Implementation impl, QWindow *window); |
2128 | 0 |
|
2129 | 0 | QList<QSize> supportedShadingRates(int sampleCount) const; |
2130 | 0 |
|
2131 | 0 | protected: |
2132 | 0 | QRhi(); |
2133 | 0 |
|
2134 | 0 | private: |
2135 | 0 | Q_DISABLE_COPY(QRhi) |
2136 | 0 | QRhiImplementation *d = nullptr; |
2137 | 0 | }; |
2138 | 0 |
|
2139 | 0 | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhi::Flags) Unexecuted instantiation: operator|(QRhi::Flag, QRhi::Flag) Unexecuted instantiation: operator|(QRhi::Flag, QFlags<QRhi::Flag>) Unexecuted instantiation: operator&(QRhi::Flag, QRhi::Flag) Unexecuted instantiation: operator&(QRhi::Flag, QFlags<QRhi::Flag>) Unexecuted instantiation: operator^(QRhi::Flag, QRhi::Flag) Unexecuted instantiation: operator^(QRhi::Flag, QFlags<QRhi::Flag>) Unexecuted instantiation: operator|(QRhi::Flag, int) |
2140 | 0 | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhi::BeginFrameFlags) Unexecuted instantiation: operator|(QRhi::BeginFrameFlag, QRhi::BeginFrameFlag) Unexecuted instantiation: operator|(QRhi::BeginFrameFlag, QFlags<QRhi::BeginFrameFlag>) Unexecuted instantiation: operator&(QRhi::BeginFrameFlag, QRhi::BeginFrameFlag) Unexecuted instantiation: operator&(QRhi::BeginFrameFlag, QFlags<QRhi::BeginFrameFlag>) Unexecuted instantiation: operator^(QRhi::BeginFrameFlag, QRhi::BeginFrameFlag) Unexecuted instantiation: operator^(QRhi::BeginFrameFlag, QFlags<QRhi::BeginFrameFlag>) Unexecuted instantiation: operator|(QRhi::BeginFrameFlag, int) |
2141 | | Q_DECLARE_OPERATORS_FOR_FLAGS(QRhi::EndFrameFlags) Unexecuted instantiation: operator|(QRhi::EndFrameFlag, QRhi::EndFrameFlag) Unexecuted instantiation: operator|(QRhi::EndFrameFlag, QFlags<QRhi::EndFrameFlag>) Unexecuted instantiation: operator&(QRhi::EndFrameFlag, QRhi::EndFrameFlag) Unexecuted instantiation: operator&(QRhi::EndFrameFlag, QFlags<QRhi::EndFrameFlag>) Unexecuted instantiation: operator^(QRhi::EndFrameFlag, QRhi::EndFrameFlag) Unexecuted instantiation: operator^(QRhi::EndFrameFlag, QFlags<QRhi::EndFrameFlag>) Unexecuted instantiation: operator|(QRhi::EndFrameFlag, int) |
2142 | | |
2143 | | QT_END_NAMESPACE |
2144 | | |
2145 | | #include <rhi/qrhi_platform.h> |
2146 | | |
2147 | | #endif |