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