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

Provided by KDAB

Privacy Policy
Learn Advanced QML with KDAB
Find out more

source code of qtbase/src/gui/rhi/qrhi.h