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