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 };
871 Q_DECLARE_FLAGS(UsageFlags, UsageFlag)
872
873 struct NativeBuffer {
874 const void *objects[3];
875 int slotCount;
876 };
877
878 QRhiResource::Type resourceType() const override;
879
880 Type type() const { return m_type; }
881 void setType(Type t) { m_type = t; }
882
883 UsageFlags usage() const { return m_usage; }
884 void setUsage(UsageFlags u) { m_usage = u; }
885
886 quint32 size() const { return m_size; }
887 void setSize(quint32 sz) { m_size = sz; }
888
889 virtual bool create() = 0;
890
891 virtual NativeBuffer nativeBuffer();
892
893 virtual char *beginFullDynamicBufferUpdateForCurrentFrame();
894 virtual void endFullDynamicBufferUpdateForCurrentFrame();
895 virtual void fullDynamicBufferUpdateForCurrentFrame(const void *data, quint32 size = 0);
896
897protected:
898 QRhiBuffer(QRhiImplementation *rhi, Type type_, UsageFlags usage_, quint32 size_);
899 Type m_type;
900 UsageFlags m_usage;
901 quint32 m_size;
902};
903
904Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiBuffer::UsageFlags)
905
906class Q_GUI_EXPORT QRhiTexture : public QRhiResource
907{
908public:
909 enum Flag {
910 RenderTarget = 1 << 0,
911 CubeMap = 1 << 2,
912 MipMapped = 1 << 3,
913 sRGB = 1 << 4,
914 UsedAsTransferSource = 1 << 5,
915 UsedWithGenerateMips = 1 << 6,
916 UsedWithLoadStore = 1 << 7,
917 UsedAsCompressedAtlas = 1 << 8,
918 ExternalOES = 1 << 9,
919 ThreeDimensional = 1 << 10,
920 TextureRectangleGL = 1 << 11,
921 TextureArray = 1 << 12,
922 OneDimensional = 1 << 13,
923 UsedAsShadingRateMap = 1 << 14
924 };
925 Q_DECLARE_FLAGS(Flags, Flag)
926
927 enum Format {
928 UnknownFormat,
929
930 RGBA8,
931 BGRA8,
932 R8,
933 RG8,
934 R16,
935 RG16,
936 RED_OR_ALPHA8,
937
938 RGBA16F,
939 RGBA32F,
940 R16F,
941 R32F,
942
943 RGB10A2,
944
945 R8SI,
946 R32SI,
947 RG32SI,
948 RGBA32SI,
949
950 R8UI,
951 R32UI,
952 RG32UI,
953 RGBA32UI,
954
955 D16,
956 D24,
957 D24S8,
958 D32F,
959 D32FS8,
960
961 BC1,
962 BC2,
963 BC3,
964 BC4,
965 BC5,
966 BC6H,
967 BC7,
968
969 ETC2_RGB8,
970 ETC2_RGB8A1,
971 ETC2_RGBA8,
972
973 ASTC_4x4,
974 ASTC_5x4,
975 ASTC_5x5,
976 ASTC_6x5,
977 ASTC_6x6,
978 ASTC_8x5,
979 ASTC_8x6,
980 ASTC_8x8,
981 ASTC_10x5,
982 ASTC_10x6,
983 ASTC_10x8,
984 ASTC_10x10,
985 ASTC_12x10,
986 ASTC_12x12
987 };
988
989 struct NativeTexture {
990 quint64 object;
991 int layout; // or state
992 };
993
994 QRhiResource::Type resourceType() const override;
995
996 Format format() const { return m_format; }
997 void setFormat(Format fmt) { m_format = fmt; }
998
999 QSize pixelSize() const { return m_pixelSize; }
1000 void setPixelSize(const QSize &sz) { m_pixelSize = sz; }
1001
1002 int depth() const { return m_depth; }
1003 void setDepth(int depth) { m_depth = depth; }
1004
1005 int arraySize() const { return m_arraySize; }
1006 void setArraySize(int arraySize) { m_arraySize = arraySize; }
1007
1008 int arrayRangeStart() const { return m_arrayRangeStart; }
1009 int arrayRangeLength() const { return m_arrayRangeLength; }
1010 void setArrayRange(int startIndex, int count)
1011 {
1012 m_arrayRangeStart = startIndex;
1013 m_arrayRangeLength = count;
1014 }
1015
1016 Flags flags() const { return m_flags; }
1017 void setFlags(Flags f) { m_flags = f; }
1018
1019 int sampleCount() const { return m_sampleCount; }
1020 void setSampleCount(int s) { m_sampleCount = s; }
1021
1022 struct ViewFormat {
1023 QRhiTexture::Format format;
1024 bool srgb;
1025 };
1026 ViewFormat readViewFormat() const { return m_readViewFormat; }
1027 void setReadViewFormat(const ViewFormat &fmt) { m_readViewFormat = fmt; }
1028 ViewFormat writeViewFormat() const { return m_writeViewFormat; }
1029 void setWriteViewFormat(const ViewFormat &fmt) { m_writeViewFormat = fmt; }
1030
1031 virtual bool create() = 0;
1032 virtual NativeTexture nativeTexture();
1033 virtual bool createFrom(NativeTexture src);
1034 virtual void setNativeLayout(int layout);
1035
1036protected:
1037 QRhiTexture(QRhiImplementation *rhi, Format format_, const QSize &pixelSize_, int depth_,
1038 int arraySize_, int sampleCount_, Flags flags_);
1039 Format m_format;
1040 QSize m_pixelSize;
1041 int m_depth;
1042 int m_arraySize;
1043 int m_sampleCount;
1044 Flags m_flags;
1045 int m_arrayRangeStart = -1;
1046 int m_arrayRangeLength = -1;
1047 ViewFormat m_readViewFormat = { UnknownFormat, false };
1048 ViewFormat m_writeViewFormat = { UnknownFormat, false };
1049};
1050
1051Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiTexture::Flags)
1052
1053class Q_GUI_EXPORT QRhiSampler : public QRhiResource
1054{
1055public:
1056 enum Filter {
1057 None,
1058 Nearest,
1059 Linear
1060 };
1061
1062 enum AddressMode {
1063 Repeat,
1064 ClampToEdge,
1065 Mirror,
1066 };
1067
1068 enum CompareOp {
1069 Never,
1070 Less,
1071 Equal,
1072 LessOrEqual,
1073 Greater,
1074 NotEqual,
1075 GreaterOrEqual,
1076 Always
1077 };
1078
1079 QRhiResource::Type resourceType() const override;
1080
1081 Filter magFilter() const { return m_magFilter; }
1082 void setMagFilter(Filter f) { m_magFilter = f; }
1083
1084 Filter minFilter() const { return m_minFilter; }
1085 void setMinFilter(Filter f) { m_minFilter = f; }
1086
1087 Filter mipmapMode() const { return m_mipmapMode; }
1088 void setMipmapMode(Filter f) { m_mipmapMode = f; }
1089
1090 AddressMode addressU() const { return m_addressU; }
1091 void setAddressU(AddressMode mode) { m_addressU = mode; }
1092
1093 AddressMode addressV() const { return m_addressV; }
1094 void setAddressV(AddressMode mode) { m_addressV = mode; }
1095
1096 AddressMode addressW() const { return m_addressW; }
1097 void setAddressW(AddressMode mode) { m_addressW = mode; }
1098
1099 CompareOp textureCompareOp() const { return m_compareOp; }
1100 void setTextureCompareOp(CompareOp op) { m_compareOp = op; }
1101
1102 virtual bool create() = 0;
1103
1104protected:
1105 QRhiSampler(QRhiImplementation *rhi,
1106 Filter magFilter_, Filter minFilter_, Filter mipmapMode_,
1107 AddressMode u_, AddressMode v_, AddressMode w_);
1108 Filter m_magFilter;
1109 Filter m_minFilter;
1110 Filter m_mipmapMode;
1111 AddressMode m_addressU;
1112 AddressMode m_addressV;
1113 AddressMode m_addressW;
1114 CompareOp m_compareOp;
1115};
1116
1117class Q_GUI_EXPORT QRhiRenderBuffer : public QRhiResource
1118{
1119public:
1120 enum Type {
1121 DepthStencil,
1122 Color
1123 };
1124
1125 enum Flag {
1126 UsedWithSwapChainOnly = 1 << 0
1127 };
1128 Q_DECLARE_FLAGS(Flags, Flag)
1129
1130 struct NativeRenderBuffer {
1131 quint64 object;
1132 };
1133
1134 QRhiResource::Type resourceType() const override;
1135
1136 Type type() const { return m_type; }
1137 void setType(Type t) { m_type = t; }
1138
1139 QSize pixelSize() const { return m_pixelSize; }
1140 void setPixelSize(const QSize &sz) { m_pixelSize = sz; }
1141
1142 int sampleCount() const { return m_sampleCount; }
1143 void setSampleCount(int s) { m_sampleCount = s; }
1144
1145 Flags flags() const { return m_flags; }
1146 void setFlags(Flags f) { m_flags = f; }
1147
1148 virtual bool create() = 0;
1149 virtual bool createFrom(NativeRenderBuffer src);
1150
1151 virtual QRhiTexture::Format backingFormat() const = 0;
1152
1153protected:
1154 QRhiRenderBuffer(QRhiImplementation *rhi, Type type_, const QSize &pixelSize_,
1155 int sampleCount_, Flags flags_, QRhiTexture::Format backingFormatHint_);
1156 Type m_type;
1157 QSize m_pixelSize;
1158 int m_sampleCount;
1159 Flags m_flags;
1160 QRhiTexture::Format m_backingFormatHint;
1161};
1162
1163Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiRenderBuffer::Flags)
1164
1165class Q_GUI_EXPORT QRhiShadingRateMap : public QRhiResource
1166{
1167public:
1168 struct NativeShadingRateMap {
1169 quint64 object;
1170 };
1171
1172 QRhiResource::Type resourceType() const override;
1173
1174 virtual bool createFrom(NativeShadingRateMap src);
1175 virtual bool createFrom(QRhiTexture *src);
1176
1177protected:
1178 QRhiShadingRateMap(QRhiImplementation *rhi);
1179};
1180
1181class Q_GUI_EXPORT QRhiRenderPassDescriptor : public QRhiResource
1182{
1183public:
1184 QRhiResource::Type resourceType() const override;
1185
1186 virtual bool isCompatible(const QRhiRenderPassDescriptor *other) const = 0;
1187 virtual const QRhiNativeHandles *nativeHandles();
1188
1189 virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() const = 0;
1190
1191 virtual QVector<quint32> serializedFormat() const = 0;
1192
1193protected:
1194 QRhiRenderPassDescriptor(QRhiImplementation *rhi);
1195};
1196
1197class Q_GUI_EXPORT QRhiRenderTarget : public QRhiResource
1198{
1199public:
1200 virtual QSize pixelSize() const = 0;
1201 virtual float devicePixelRatio() const = 0;
1202 virtual int sampleCount() const = 0;
1203
1204 QRhiRenderPassDescriptor *renderPassDescriptor() const { return m_renderPassDesc; }
1205 void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; }
1206
1207protected:
1208 QRhiRenderTarget(QRhiImplementation *rhi);
1209 QRhiRenderPassDescriptor *m_renderPassDesc = nullptr;
1210};
1211
1212class Q_GUI_EXPORT QRhiSwapChainRenderTarget : public QRhiRenderTarget
1213{
1214public:
1215 QRhiResource::Type resourceType() const override;
1216 QRhiSwapChain *swapChain() const { return m_swapchain; }
1217
1218protected:
1219 QRhiSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain_);
1220 QRhiSwapChain *m_swapchain;
1221};
1222
1223class Q_GUI_EXPORT QRhiTextureRenderTarget : public QRhiRenderTarget
1224{
1225public:
1226 enum Flag {
1227 PreserveColorContents = 1 << 0,
1228 PreserveDepthStencilContents = 1 << 1,
1229 DoNotStoreDepthStencilContents = 1 << 2
1230 };
1231 Q_DECLARE_FLAGS(Flags, Flag)
1232
1233 QRhiResource::Type resourceType() const override;
1234
1235 QRhiTextureRenderTargetDescription description() const { return m_desc; }
1236 void setDescription(const QRhiTextureRenderTargetDescription &desc) { m_desc = desc; }
1237
1238 Flags flags() const { return m_flags; }
1239 void setFlags(Flags f) { m_flags = f; }
1240
1241 virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() = 0;
1242
1243 virtual bool create() = 0;
1244
1245protected:
1246 QRhiTextureRenderTarget(QRhiImplementation *rhi, const QRhiTextureRenderTargetDescription &desc_, Flags flags_);
1247 QRhiTextureRenderTargetDescription m_desc;
1248 Flags m_flags;
1249};
1250
1251Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiTextureRenderTarget::Flags)
1252
1253class Q_GUI_EXPORT QRhiShaderResourceBindings : public QRhiResource
1254{
1255public:
1256 QRhiResource::Type resourceType() const override;
1257
1258 void setBindings(std::initializer_list<QRhiShaderResourceBinding> list) { m_bindings = list; }
1259 template<typename InputIterator>
1260 void setBindings(InputIterator first, InputIterator last)
1261 {
1262 m_bindings.clear();
1263 std::copy(first, last, std::back_inserter(m_bindings));
1264 }
1265 const QRhiShaderResourceBinding *cbeginBindings() const { return m_bindings.cbegin(); }
1266 const QRhiShaderResourceBinding *cendBindings() const { return m_bindings.cend(); }
1267 const QRhiShaderResourceBinding *bindingAt(qsizetype index) const { return &m_bindings.at(index); }
1268 qsizetype bindingCount() const { return m_bindings.count(); }
1269
1270 bool isLayoutCompatible(const QRhiShaderResourceBindings *other) const;
1271
1272 QVector<quint32> serializedLayoutDescription() const { return m_layoutDesc; }
1273
1274 virtual bool create() = 0;
1275
1276 enum UpdateFlag {
1277 BindingsAreSorted = 0x01
1278 };
1279 Q_DECLARE_FLAGS(UpdateFlags, UpdateFlag)
1280
1281 virtual void updateResources(UpdateFlags flags = {}) = 0;
1282
1283protected:
1284 static constexpr int BINDING_PREALLOC = 12;
1285 QRhiShaderResourceBindings(QRhiImplementation *rhi);
1286 QVarLengthArray<QRhiShaderResourceBinding, BINDING_PREALLOC> m_bindings;
1287 size_t m_layoutDescHash = 0;
1288 // Intentionally not using QVLA for m_layoutDesc: clients like Qt Quick are much
1289 // better served with an implicitly shared container here, because they will likely
1290 // throw this directly into structs serving as cache keys.
1291 QVector<quint32> m_layoutDesc;
1292 friend class QRhiImplementation;
1293#ifndef QT_NO_DEBUG_STREAM
1294 friend Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiShaderResourceBindings &);
1295#endif
1296};
1297
1298Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiShaderResourceBindings::UpdateFlags)
1299
1300#ifndef QT_NO_DEBUG_STREAM
1301Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiShaderResourceBindings &);
1302#endif
1303
1304// The proper name. Until it gets rolled out universally, have the better name
1305// as a typedef. Eventually it should be reversed (the old name being a typedef
1306// to the new one).
1307using QRhiShaderResourceBindingSet = QRhiShaderResourceBindings;
1308
1309class Q_GUI_EXPORT QRhiGraphicsPipeline : public QRhiResource
1310{
1311public:
1312 enum Flag {
1313 UsesBlendConstants = 1 << 0,
1314 UsesStencilRef = 1 << 1,
1315 UsesScissor = 1 << 2,
1316 CompileShadersWithDebugInfo = 1 << 3,
1317 UsesShadingRate = 1 << 4
1318 };
1319 Q_DECLARE_FLAGS(Flags, Flag)
1320
1321 enum Topology {
1322 Triangles,
1323 TriangleStrip,
1324 TriangleFan,
1325 Lines,
1326 LineStrip,
1327 Points,
1328 Patches
1329 };
1330
1331 enum CullMode {
1332 None,
1333 Front,
1334 Back
1335 };
1336
1337 enum FrontFace {
1338 CCW,
1340 };
1341
1342 enum ColorMaskComponent {
1343 R = 1 << 0,
1344 G = 1 << 1,
1345 B = 1 << 2,
1346 A = 1 << 3
1347 };
1348 Q_DECLARE_FLAGS(ColorMask, ColorMaskComponent)
1349
1350 enum BlendFactor {
1351 Zero,
1352 One,
1353 SrcColor,
1354 OneMinusSrcColor,
1355 DstColor,
1356 OneMinusDstColor,
1357 SrcAlpha,
1358 OneMinusSrcAlpha,
1359 DstAlpha,
1360 OneMinusDstAlpha,
1361 ConstantColor,
1362 OneMinusConstantColor,
1363 ConstantAlpha,
1364 OneMinusConstantAlpha,
1365 SrcAlphaSaturate,
1366 Src1Color,
1367 OneMinusSrc1Color,
1368 Src1Alpha,
1369 OneMinusSrc1Alpha
1370 };
1371
1372 enum BlendOp {
1373 Add,
1374 Subtract,
1375 ReverseSubtract,
1376 Min,
1377 Max
1378 };
1379
1380 struct TargetBlend {
1381 ColorMask colorWrite = ColorMask(0xF); // R | G | B | A
1382 bool enable = false;
1383 BlendFactor srcColor = One;
1384 BlendFactor dstColor = OneMinusSrcAlpha;
1385 BlendOp opColor = Add;
1386 BlendFactor srcAlpha = One;
1387 BlendFactor dstAlpha = OneMinusSrcAlpha;
1388 BlendOp opAlpha = Add;
1389 };
1390
1391 enum CompareOp {
1392 Never,
1393 Less,
1394 Equal,
1395 LessOrEqual,
1396 Greater,
1397 NotEqual,
1398 GreaterOrEqual,
1399 Always
1400 };
1401
1402 enum StencilOp {
1403 StencilZero,
1404 Keep,
1405 Replace,
1406 IncrementAndClamp,
1407 DecrementAndClamp,
1408 Invert,
1409 IncrementAndWrap,
1410 DecrementAndWrap
1411 };
1412
1413 struct StencilOpState {
1414 StencilOp failOp = Keep;
1415 StencilOp depthFailOp = Keep;
1416 StencilOp passOp = Keep;
1417 CompareOp compareOp = Always;
1418 };
1419
1420 enum PolygonMode {
1421 Fill,
1422 Line
1423 };
1424
1425 QRhiResource::Type resourceType() const override;
1426
1427 Flags flags() const { return m_flags; }
1428 void setFlags(Flags f) { m_flags = f; }
1429
1430 Topology topology() const { return m_topology; }
1431 void setTopology(Topology t) { m_topology = t; }
1432
1433 CullMode cullMode() const { return m_cullMode; }
1434 void setCullMode(CullMode mode) { m_cullMode = mode; }
1435
1436 FrontFace frontFace() const { return m_frontFace; }
1437 void setFrontFace(FrontFace f) { m_frontFace = f; }
1438
1439 void setTargetBlends(std::initializer_list<TargetBlend> list) { m_targetBlends = list; }
1440 template<typename InputIterator>
1441 void setTargetBlends(InputIterator first, InputIterator last)
1442 {
1443 m_targetBlends.clear();
1444 std::copy(first, last, std::back_inserter(m_targetBlends));
1445 }
1446 const TargetBlend *cbeginTargetBlends() const { return m_targetBlends.cbegin(); }
1447 const TargetBlend *cendTargetBlends() const { return m_targetBlends.cend(); }
1448 const TargetBlend *targetBlendAt(qsizetype index) const { return &m_targetBlends.at(index); }
1449 qsizetype targetBlendCount() const { return m_targetBlends.count(); }
1450
1451 bool hasDepthTest() const { return m_depthTest; }
1452 void setDepthTest(bool enable) { m_depthTest = enable; }
1453
1454 bool hasDepthWrite() const { return m_depthWrite; }
1455 void setDepthWrite(bool enable) { m_depthWrite = enable; }
1456
1457 bool hasDepthClamp() const { return m_depthClamp; }
1458 void setDepthClamp(bool enable) { m_depthClamp = enable; }
1459
1460 CompareOp depthOp() const { return m_depthOp; }
1461 void setDepthOp(CompareOp op) { m_depthOp = op; }
1462
1463 bool hasStencilTest() const { return m_stencilTest; }
1464 void setStencilTest(bool enable) { m_stencilTest = enable; }
1465
1466 StencilOpState stencilFront() const { return m_stencilFront; }
1467 void setStencilFront(const StencilOpState &state) { m_stencilFront = state; }
1468
1469 StencilOpState stencilBack() const { return m_stencilBack; }
1470 void setStencilBack(const StencilOpState &state) { m_stencilBack = state; }
1471
1472 quint32 stencilReadMask() const { return m_stencilReadMask; }
1473 void setStencilReadMask(quint32 mask) { m_stencilReadMask = mask; }
1474
1475 quint32 stencilWriteMask() const { return m_stencilWriteMask; }
1476 void setStencilWriteMask(quint32 mask) { m_stencilWriteMask = mask; }
1477
1478 int sampleCount() const { return m_sampleCount; }
1479 void setSampleCount(int s) { m_sampleCount = s; }
1480
1481 float lineWidth() const { return m_lineWidth; }
1482 void setLineWidth(float width) { m_lineWidth = width; }
1483
1484 int depthBias() const { return m_depthBias; }
1485 void setDepthBias(int bias) { m_depthBias = bias; }
1486
1487 float slopeScaledDepthBias() const { return m_slopeScaledDepthBias; }
1488 void setSlopeScaledDepthBias(float bias) { m_slopeScaledDepthBias = bias; }
1489
1490 void setShaderStages(std::initializer_list<QRhiShaderStage> list) { m_shaderStages = list; }
1491 template<typename InputIterator>
1492 void setShaderStages(InputIterator first, InputIterator last)
1493 {
1494 m_shaderStages.clear();
1495 std::copy(first, last, std::back_inserter(m_shaderStages));
1496 }
1497 const QRhiShaderStage *cbeginShaderStages() const { return m_shaderStages.cbegin(); }
1498 const QRhiShaderStage *cendShaderStages() const { return m_shaderStages.cend(); }
1499 const QRhiShaderStage *shaderStageAt(qsizetype index) const { return &m_shaderStages.at(index); }
1500 qsizetype shaderStageCount() const { return m_shaderStages.count(); }
1501
1502 QRhiVertexInputLayout vertexInputLayout() const { return m_vertexInputLayout; }
1503 void setVertexInputLayout(const QRhiVertexInputLayout &layout) { m_vertexInputLayout = layout; }
1504
1505 QRhiShaderResourceBindings *shaderResourceBindings() const { return m_shaderResourceBindings; }
1506 void setShaderResourceBindings(QRhiShaderResourceBindings *srb) { m_shaderResourceBindings = srb; }
1507
1508 QRhiRenderPassDescriptor *renderPassDescriptor() const { return m_renderPassDesc; }
1509 void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; }
1510
1511 int patchControlPointCount() const { return m_patchControlPointCount; }
1512 void setPatchControlPointCount(int count) { m_patchControlPointCount = count; }
1513
1514 PolygonMode polygonMode() const {return m_polygonMode; }
1515 void setPolygonMode(PolygonMode mode) {m_polygonMode = mode; }
1516
1517 int multiViewCount() const { return m_multiViewCount; }
1518 void setMultiViewCount(int count) { m_multiViewCount = count; }
1519
1520 virtual bool create() = 0;
1521
1522protected:
1523 QRhiGraphicsPipeline(QRhiImplementation *rhi);
1524 Flags m_flags;
1525 Topology m_topology = Triangles;
1526 CullMode m_cullMode = None;
1527 FrontFace m_frontFace = CCW;
1528 QVarLengthArray<TargetBlend, 8> m_targetBlends;
1529 bool m_depthTest = false;
1530 bool m_depthWrite = false;
1531 bool m_depthClamp = false;
1532 CompareOp m_depthOp = Less;
1533 bool m_stencilTest = false;
1534 StencilOpState m_stencilFront;
1535 StencilOpState m_stencilBack;
1536 quint32 m_stencilReadMask = 0xFF;
1537 quint32 m_stencilWriteMask = 0xFF;
1538 int m_sampleCount = 1;
1539 float m_lineWidth = 1.0f;
1540 int m_depthBias = 0;
1541 float m_slopeScaledDepthBias = 0.0f;
1542 int m_patchControlPointCount = 3;
1543 PolygonMode m_polygonMode = Fill;
1544 int m_multiViewCount = 0;
1545 QVarLengthArray<QRhiShaderStage, 4> m_shaderStages;
1546 QRhiVertexInputLayout m_vertexInputLayout;
1547 QRhiShaderResourceBindings *m_shaderResourceBindings = nullptr;
1548 QRhiRenderPassDescriptor *m_renderPassDesc = nullptr;
1549};
1550
1551Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiGraphicsPipeline::Flags)
1552Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiGraphicsPipeline::ColorMask)
1553Q_DECLARE_TYPEINFO(QRhiGraphicsPipeline::TargetBlend, Q_RELOCATABLE_TYPE);
1554
1581
1583
1584#ifndef QT_NO_DEBUG_STREAM
1585Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiSwapChainHdrInfo &);
1586#endif
1587
1589{
1590 void *reserved[2] = {};
1591};
1592
1593class Q_GUI_EXPORT QRhiSwapChain : public QRhiResource
1594{
1595public:
1596 enum Flag {
1597 SurfaceHasPreMulAlpha = 1 << 0,
1598 SurfaceHasNonPreMulAlpha = 1 << 1,
1599 sRGB = 1 << 2,
1600 UsedAsTransferSource = 1 << 3,
1601 NoVSync = 1 << 4,
1602 MinimalBufferCount = 1 << 5
1603 };
1604 Q_DECLARE_FLAGS(Flags, Flag)
1605
1606 enum Format {
1607 SDR,
1608 HDRExtendedSrgbLinear,
1609 HDR10,
1610 HDRExtendedDisplayP3Linear
1611 };
1612
1613 enum StereoTargetBuffer {
1614 LeftBuffer,
1615 RightBuffer
1616 };
1617
1618 QRhiResource::Type resourceType() const override;
1619
1620 QWindow *window() const { return m_window; }
1621 void setWindow(QWindow *window) { m_window = window; }
1622
1623 QRhiSwapChainProxyData proxyData() const { return m_proxyData; }
1624 void setProxyData(const QRhiSwapChainProxyData &d) { m_proxyData = d; }
1625
1626 Flags flags() const { return m_flags; }
1627 void setFlags(Flags f) { m_flags = f; }
1628
1629 Format format() const { return m_format; }
1630 void setFormat(Format f) { m_format = f; }
1631
1632 QRhiRenderBuffer *depthStencil() const { return m_depthStencil; }
1633 void setDepthStencil(QRhiRenderBuffer *ds) { m_depthStencil = ds; }
1634
1635 int sampleCount() const { return m_sampleCount; }
1636 void setSampleCount(int samples) { m_sampleCount = samples; }
1637
1638 QRhiRenderPassDescriptor *renderPassDescriptor() const { return m_renderPassDesc; }
1639 void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; }
1640
1641 QRhiShadingRateMap *shadingRateMap() const { return m_shadingRateMap; }
1642 void setShadingRateMap(QRhiShadingRateMap *map) { m_shadingRateMap = map; }
1643
1644 QSize currentPixelSize() const { return m_currentPixelSize; }
1645
1646 virtual QRhiCommandBuffer *currentFrameCommandBuffer() = 0;
1647 virtual QRhiRenderTarget *currentFrameRenderTarget() = 0;
1648 virtual QRhiRenderTarget *currentFrameRenderTarget(StereoTargetBuffer targetBuffer);
1649 virtual QSize surfacePixelSize() = 0;
1650 virtual bool isFormatSupported(Format f) = 0;
1651 virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() = 0;
1652 virtual bool createOrResize() = 0;
1653 virtual QRhiSwapChainHdrInfo hdrInfo();
1654
1655protected:
1656 QRhiSwapChain(QRhiImplementation *rhi);
1657 QWindow *m_window = nullptr;
1658 Flags m_flags;
1659 Format m_format = SDR;
1660 QRhiRenderBuffer *m_depthStencil = nullptr;
1661 int m_sampleCount = 1;
1662 QRhiRenderPassDescriptor *m_renderPassDesc = nullptr;
1663 QSize m_currentPixelSize;
1664 QRhiSwapChainProxyData m_proxyData;
1665 QRhiShadingRateMap *m_shadingRateMap = nullptr;
1666};
1667
1668Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiSwapChain::Flags)
1669
1670class Q_GUI_EXPORT QRhiComputePipeline : public QRhiResource
1671{
1672public:
1673 enum Flag {
1674 CompileShadersWithDebugInfo = 1 << 0
1675 };
1676 Q_DECLARE_FLAGS(Flags, Flag)
1677
1678 QRhiResource::Type resourceType() const override;
1679 virtual bool create() = 0;
1680
1681 Flags flags() const { return m_flags; }
1682 void setFlags(Flags f) { m_flags = f; }
1683
1684 QRhiShaderStage shaderStage() const { return m_shaderStage; }
1685 void setShaderStage(const QRhiShaderStage &stage) { m_shaderStage = stage; }
1686
1687 QRhiShaderResourceBindings *shaderResourceBindings() const { return m_shaderResourceBindings; }
1688 void setShaderResourceBindings(QRhiShaderResourceBindings *srb) { m_shaderResourceBindings = srb; }
1689
1690protected:
1691 QRhiComputePipeline(QRhiImplementation *rhi);
1692 Flags m_flags;
1693 QRhiShaderStage m_shaderStage;
1694 QRhiShaderResourceBindings *m_shaderResourceBindings = nullptr;
1695};
1696
1697Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiComputePipeline::Flags)
1698
1699class Q_GUI_EXPORT QRhiCommandBuffer : public QRhiResource
1700{
1701public:
1702 enum IndexFormat {
1703 IndexUInt16,
1704 IndexUInt32
1705 };
1706
1707 enum BeginPassFlag {
1708 ExternalContent = 0x01,
1709 DoNotTrackResourcesForCompute = 0x02
1710 };
1711 Q_DECLARE_FLAGS(BeginPassFlags, BeginPassFlag)
1712
1713 QRhiResource::Type resourceType() const override;
1714
1715 void resourceUpdate(QRhiResourceUpdateBatch *resourceUpdates);
1716
1717 void beginPass(QRhiRenderTarget *rt,
1718 const QColor &colorClearValue,
1719 const QRhiDepthStencilClearValue &depthStencilClearValue,
1720 QRhiResourceUpdateBatch *resourceUpdates = nullptr,
1721 BeginPassFlags flags = {});
1722 void endPass(QRhiResourceUpdateBatch *resourceUpdates = nullptr);
1723
1724 void setGraphicsPipeline(QRhiGraphicsPipeline *ps);
1725 using DynamicOffset = std::pair<int, quint32>; // binding, offset
1726 void setShaderResources(QRhiShaderResourceBindings *srb = nullptr,
1727 int dynamicOffsetCount = 0,
1728 const DynamicOffset *dynamicOffsets = nullptr);
1729 using VertexInput = std::pair<QRhiBuffer *, quint32>; // buffer, offset
1730 void setVertexInput(int startBinding, int bindingCount, const VertexInput *bindings,
1731 QRhiBuffer *indexBuf = nullptr, quint32 indexOffset = 0,
1732 IndexFormat indexFormat = IndexUInt16);
1733
1734 void setViewport(const QRhiViewport &viewport);
1735 void setScissor(const QRhiScissor &scissor);
1736 void setBlendConstants(const QColor &c);
1737 void setStencilRef(quint32 refValue);
1738 void setShadingRate(const QSize &coarsePixelSize);
1739
1740 void draw(quint32 vertexCount,
1741 quint32 instanceCount = 1,
1742 quint32 firstVertex = 0,
1743 quint32 firstInstance = 0);
1744
1745 void drawIndexed(quint32 indexCount,
1746 quint32 instanceCount = 1,
1747 quint32 firstIndex = 0,
1748 qint32 vertexOffset = 0,
1749 quint32 firstInstance = 0);
1750
1751 void debugMarkBegin(const QByteArray &name);
1752 void debugMarkEnd();
1753 void debugMarkMsg(const QByteArray &msg);
1754
1755 void beginComputePass(QRhiResourceUpdateBatch *resourceUpdates = nullptr, BeginPassFlags flags = {});
1756 void endComputePass(QRhiResourceUpdateBatch *resourceUpdates = nullptr);
1757 void setComputePipeline(QRhiComputePipeline *ps);
1758 void dispatch(int x, int y, int z);
1759
1760 const QRhiNativeHandles *nativeHandles();
1761 void beginExternal();
1762 void endExternal();
1763
1764 double lastCompletedGpuTime();
1765
1766protected:
1767 QRhiCommandBuffer(QRhiImplementation *rhi);
1768};
1769
1770Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiCommandBuffer::BeginPassFlags)
1771
1772struct Q_GUI_EXPORT QRhiReadbackResult
1773{
1774 std::function<void()> completed = nullptr;
1775 QRhiTexture::Format format;
1776 QSize pixelSize;
1777 QByteArray data;
1778};
1779
1780class Q_GUI_EXPORT QRhiResourceUpdateBatch
1781{
1782public:
1783 ~QRhiResourceUpdateBatch();
1784
1785 void release();
1786
1787 void merge(QRhiResourceUpdateBatch *other);
1788 bool hasOptimalCapacity() const;
1789
1790 void updateDynamicBuffer(QRhiBuffer *buf, quint32 offset, quint32 size, const void *data);
1791 void updateDynamicBuffer(QRhiBuffer *buf, quint32 offset, QByteArray data);
1792 void uploadStaticBuffer(QRhiBuffer *buf, quint32 offset, quint32 size, const void *data);
1793 void uploadStaticBuffer(QRhiBuffer *buf, quint32 offset, QByteArray data);
1794 void uploadStaticBuffer(QRhiBuffer *buf, const void *data);
1795 void uploadStaticBuffer(QRhiBuffer *buf, QByteArray data);
1796 void readBackBuffer(QRhiBuffer *buf, quint32 offset, quint32 size, QRhiReadbackResult *result);
1797 void uploadTexture(QRhiTexture *tex, const QRhiTextureUploadDescription &desc);
1798 void uploadTexture(QRhiTexture *tex, const QImage &image);
1799 void copyTexture(QRhiTexture *dst, QRhiTexture *src, const QRhiTextureCopyDescription &desc = QRhiTextureCopyDescription());
1800 void readBackTexture(const QRhiReadbackDescription &rb, QRhiReadbackResult *result);
1801 void generateMips(QRhiTexture *tex);
1802
1803private:
1804 QRhiResourceUpdateBatch(QRhiImplementation *rhi);
1805 Q_DISABLE_COPY(QRhiResourceUpdateBatch)
1806 QRhiResourceUpdateBatchPrivate *d;
1807 friend class QRhiResourceUpdateBatchPrivate;
1808 friend class QRhi;
1809};
1810
1811struct Q_GUI_EXPORT QRhiDriverInfo
1812{
1813 enum DeviceType {
1814 UnknownDevice,
1815 IntegratedDevice,
1816 DiscreteDevice,
1817 ExternalDevice,
1818 VirtualDevice,
1819 CpuDevice
1820 };
1821
1822 QByteArray deviceName;
1823 quint64 deviceId = 0;
1824 quint64 vendorId = 0;
1825 DeviceType deviceType = UnknownDevice;
1826};
1827
1828Q_DECLARE_TYPEINFO(QRhiDriverInfo, Q_RELOCATABLE_TYPE);
1829
1830#ifndef QT_NO_DEBUG_STREAM
1831Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiDriverInfo &);
1832#endif
1833
1834struct Q_GUI_EXPORT QRhiStats
1835{
1836 qint64 totalPipelineCreationTime = 0;
1837 // Vulkan or D3D12 memory allocator statistics
1838 quint32 blockCount = 0;
1839 quint32 allocCount = 0;
1840 quint64 usedBytes = 0;
1841 quint64 unusedBytes = 0;
1842 // D3D12 only, from IDXGIAdapter3::QueryVideoMemoryInfo(), incl. all resources
1843 quint64 totalUsageBytes = 0;
1844};
1845
1846Q_DECLARE_TYPEINFO(QRhiStats, Q_RELOCATABLE_TYPE);
1847
1848#ifndef QT_NO_DEBUG_STREAM
1849Q_GUI_EXPORT QDebug operator<<(QDebug, const QRhiStats &);
1850#endif
1851
1852class Q_GUI_EXPORT QRhiAdapter
1853{
1854public:
1855 virtual ~QRhiAdapter();
1856 virtual QRhiDriverInfo info() const = 0;
1857};
1858
1859struct Q_GUI_EXPORT QRhiInitParams
1860{
1861};
1862
1863class Q_GUI_EXPORT QRhi
1864{
1865public:
1866 enum Implementation {
1867 Null,
1868 Vulkan,
1869 OpenGLES2,
1870 D3D11,
1871 Metal,
1872 D3D12
1873 };
1874
1875 enum Flag {
1876 EnableDebugMarkers = 1 << 0,
1877 PreferSoftwareRenderer = 1 << 1,
1878 EnablePipelineCacheDataSave = 1 << 2,
1879 EnableTimestamps = 1 << 3,
1880 SuppressSmokeTestWarnings = 1 << 4
1881 };
1882 Q_DECLARE_FLAGS(Flags, Flag)
1883
1884 enum FrameOpResult {
1885 FrameOpSuccess = 0,
1886 FrameOpError,
1887 FrameOpSwapChainOutOfDate,
1888 FrameOpDeviceLost
1889 };
1890
1891 enum Feature {
1892 MultisampleTexture = 1,
1893 MultisampleRenderBuffer,
1894 DebugMarkers,
1895 Timestamps,
1896 Instancing,
1897 CustomInstanceStepRate,
1898 PrimitiveRestart,
1899 NonDynamicUniformBuffers,
1900 NonFourAlignedEffectiveIndexBufferOffset,
1901 NPOTTextureRepeat,
1902 RedOrAlpha8IsRed,
1903 ElementIndexUint,
1904 Compute,
1905 WideLines,
1906 VertexShaderPointSize,
1907 BaseVertex,
1908 BaseInstance,
1909 TriangleFanTopology,
1910 ReadBackNonUniformBuffer,
1911 ReadBackNonBaseMipLevel,
1912 TexelFetch,
1913 RenderToNonBaseMipLevel,
1914 IntAttributes,
1915 ScreenSpaceDerivatives,
1916 ReadBackAnyTextureFormat,
1917 PipelineCacheDataLoadSave,
1918 ImageDataStride,
1919 RenderBufferImport,
1920 ThreeDimensionalTextures,
1921 RenderTo3DTextureSlice,
1922 TextureArrays,
1923 Tessellation,
1924 GeometryShader,
1925 TextureArrayRange,
1926 NonFillPolygonMode,
1927 OneDimensionalTextures,
1928 OneDimensionalTextureMipmaps,
1929 HalfAttributes,
1930 RenderToOneDimensionalTexture,
1931 ThreeDimensionalTextureMipmaps,
1932 MultiView,
1933 TextureViewFormat,
1934 ResolveDepthStencil,
1935 VariableRateShading,
1936 VariableRateShadingMap,
1937 VariableRateShadingMapWithTexture,
1938 PerRenderTargetBlending,
1939 SampleVariables,
1940 InstanceIndexIncludesBaseInstance,
1941 DepthClamp
1942 };
1943
1944 enum BeginFrameFlag {
1945 };
1946 Q_DECLARE_FLAGS(BeginFrameFlags, BeginFrameFlag)
1947
1948 enum EndFrameFlag {
1949 SkipPresent = 1 << 0
1950 };
1951 Q_DECLARE_FLAGS(EndFrameFlags, EndFrameFlag)
1952
1953 enum ResourceLimit {
1954 TextureSizeMin = 1,
1955 TextureSizeMax,
1956 MaxColorAttachments,
1957 FramesInFlight,
1958 MaxAsyncReadbackFrames,
1959 MaxThreadGroupsPerDimension,
1960 MaxThreadsPerThreadGroup,
1961 MaxThreadGroupX,
1962 MaxThreadGroupY,
1963 MaxThreadGroupZ,
1964 TextureArraySizeMax,
1965 MaxUniformBufferRange,
1966 MaxVertexInputs,
1967 MaxVertexOutputs,
1968 ShadingRateImageTileSize
1969 };
1970
1971 ~QRhi();
1972
1973 static QRhi *create(Implementation impl,
1974 QRhiInitParams *params,
1975 Flags flags = {},
1976 QRhiNativeHandles *importDevice = nullptr);
1977 static QRhi *create(Implementation impl,
1978 QRhiInitParams *params,
1979 Flags flags,
1980 QRhiNativeHandles *importDevice,
1981 QRhiAdapter *adapter);
1982 static bool probe(Implementation impl, QRhiInitParams *params);
1983 using AdapterList = QVector<QRhiAdapter *>;
1984 static AdapterList enumerateAdapters(Implementation impl,
1985 QRhiInitParams *params,
1986 QRhiNativeHandles *nativeHandles = nullptr);
1987
1988 Implementation backend() const;
1989 const char *backendName() const;
1990 static const char *backendName(Implementation impl);
1991 QRhiDriverInfo driverInfo() const;
1992 QThread *thread() const;
1993
1994 using CleanupCallback = std::function<void(QRhi *)>;
1995 void addCleanupCallback(const CleanupCallback &callback);
1996 void addCleanupCallback(const void *key, const CleanupCallback &callback);
1997 void removeCleanupCallback(const void *key);
1998
1999 QRhiGraphicsPipeline *newGraphicsPipeline();
2000 QRhiComputePipeline *newComputePipeline();
2001 QRhiShaderResourceBindings *newShaderResourceBindings();
2002
2003 QRhiBuffer *newBuffer(QRhiBuffer::Type type,
2004 QRhiBuffer::UsageFlags usage,
2005 quint32 size);
2006
2007 QRhiRenderBuffer *newRenderBuffer(QRhiRenderBuffer::Type type,
2008 const QSize &pixelSize,
2009 int sampleCount = 1,
2010 QRhiRenderBuffer::Flags flags = {},
2011 QRhiTexture::Format backingFormatHint = QRhiTexture::UnknownFormat);
2012
2013 QRhiTexture *newTexture(QRhiTexture::Format format,
2014 const QSize &pixelSize,
2015 int sampleCount = 1,
2016 QRhiTexture::Flags flags = {});
2017
2018 QRhiTexture *newTexture(QRhiTexture::Format format,
2019 int width, int height, int depth,
2020 int sampleCount = 1,
2021 QRhiTexture::Flags flags = {});
2022
2023 QRhiTexture *newTextureArray(QRhiTexture::Format format,
2024 int arraySize,
2025 const QSize &pixelSize,
2026 int sampleCount = 1,
2027 QRhiTexture::Flags flags = {});
2028
2029 QRhiSampler *newSampler(QRhiSampler::Filter magFilter,
2030 QRhiSampler::Filter minFilter,
2031 QRhiSampler::Filter mipmapMode,
2032 QRhiSampler::AddressMode addressU,
2033 QRhiSampler::AddressMode addressV,
2034 QRhiSampler::AddressMode addressW = QRhiSampler::Repeat);
2035
2036 QRhiShadingRateMap *newShadingRateMap();
2037
2038 QRhiTextureRenderTarget *newTextureRenderTarget(const QRhiTextureRenderTargetDescription &desc,
2039 QRhiTextureRenderTarget::Flags flags = {});
2040
2041 QRhiSwapChain *newSwapChain();
2042 FrameOpResult beginFrame(QRhiSwapChain *swapChain, BeginFrameFlags flags = {});
2043 FrameOpResult endFrame(QRhiSwapChain *swapChain, EndFrameFlags flags = {});
2044 bool isRecordingFrame() const;
2045 int currentFrameSlot() const;
2046
2047 FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb, BeginFrameFlags flags = {});
2048 FrameOpResult endOffscreenFrame(EndFrameFlags flags = {});
2049
2050 QRhi::FrameOpResult finish();
2051
2052 QRhiResourceUpdateBatch *nextResourceUpdateBatch();
2053
2054 QList<int> supportedSampleCounts() const;
2055
2056 int ubufAlignment() const;
2057 int ubufAligned(int v) const;
2058
2059 static int mipLevelsForSize(const QSize &size);
2060 static QSize sizeForMipLevel(int mipLevel, const QSize &baseLevelSize);
2061
2062 bool isYUpInFramebuffer() const;
2063 bool isYUpInNDC() const;
2064 bool isClipDepthZeroToOne() const;
2065
2066 QMatrix4x4 clipSpaceCorrMatrix() const;
2067
2068 bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags = {}) const;
2069 bool isFeatureSupported(QRhi::Feature feature) const;
2070 int resourceLimit(ResourceLimit limit) const;
2071
2072 const QRhiNativeHandles *nativeHandles();
2073 bool makeThreadLocalNativeContextCurrent();
2074 void setQueueSubmitParams(QRhiNativeHandles *params);
2075
2076 static constexpr int MAX_MIP_LEVELS = 16; // -> max width or height is 65536
2077
2078 void releaseCachedResources();
2079
2080 bool isDeviceLost() const;
2081
2082 QByteArray pipelineCacheData();
2083 void setPipelineCacheData(const QByteArray &data);
2084
2085 QRhiStats statistics() const;
2086
2087 static QRhiSwapChainProxyData updateSwapChainProxyData(Implementation impl, QWindow *window);
2088
2089 QList<QSize> supportedShadingRates(int sampleCount) const;
2090
2091protected:
2092 QRhi();
2093
2094private:
2095 Q_DISABLE_COPY(QRhi)
2096 QRhiImplementation *d = nullptr;
2097};
2098
2099Q_DECLARE_OPERATORS_FOR_FLAGS(QRhi::Flags)
2100Q_DECLARE_OPERATORS_FOR_FLAGS(QRhi::BeginFrameFlags)
2101Q_DECLARE_OPERATORS_FOR_FLAGS(QRhi::EndFrameFlags)
2102
2103QT_END_NAMESPACE
2104
2105#include <rhi/qrhi_platform.h>
2106
2107#endif
friend bool operator==(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
Returns true if lhs and rhs are equal, otherwise returns false.
Definition qbytearray.h:807
friend bool operator!=(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
Returns true if lhs and rhs are different, otherwise returns false.
Definition qbytearray.h:818
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1853
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:857
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:578
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:46
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1310
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:783
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1118
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1182
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1198
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1781
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:814
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:140
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:441
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:381
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1213
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1594
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:745
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:622
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1224
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:662
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:722
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:699
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:234
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:181
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:323
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:87
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1864
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:1812
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1860
\variable QRhiReadbackResult::completed
Definition qrhi.h:810
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1835
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1556
LuminanceBehavior
\value SceneReferred Indicates that the color value of 1.0 is interpreted as 80 nits.
Definition qrhi.h:1562
LimitsType limitsType
Definition qrhi.h:1567
float maxPotentialColorComponentValue
Definition qrhi.h:1575
LimitsType
\value LuminanceInNits Indicates that the \l limits union has its luminanceInNits struct set
Definition qrhi.h:1557
LuminanceBehavior luminanceBehavior
Definition qrhi.h:1578
float maxColorComponentValue
Definition qrhi.h:1574
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
Definition qrhi.h:1589
void * reserved[2]
Definition qrhi.h:1590