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