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