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