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