17#include <QtGui/qtguiglobal.h>
18#include <QtCore/qsize.h>
19#include <QtCore/qlist.h>
20#include <QtCore/qvarlengtharray.h>
21#include <QtCore/qthread.h>
22#include <QtGui/qmatrix4x4.h>
23#include <QtGui/qcolor.h>
24#include <QtGui/qimage.h>
28#include <rhi/qshader.h>
34class QRhiImplementation;
36class QRhiRenderBuffer;
39class QRhiCommandBuffer;
40class QRhiResourceUpdateBatch;
43class QRhiShadingRateMap;
48 QRhiDepthStencilClearValue() =
default;
49 QRhiDepthStencilClearValue(
float d, quint32 s);
51 float depthClearValue()
const {
return m_d; }
52 void setDepthClearValue(
float d) { m_d = d; }
54 quint32 stencilClearValue()
const {
return m_s; }
55 void setStencilClearValue(quint32 s) { m_s = s; }
61 friend bool operator==(
const QRhiDepthStencilClearValue &a,
const QRhiDepthStencilClearValue &b)
noexcept
63 return a.m_d == b.m_d && a.m_s == b.m_s;
66 friend bool operator!=(
const QRhiDepthStencilClearValue &a,
const QRhiDepthStencilClearValue &b)
noexcept
71 friend size_t qHash(
const QRhiDepthStencilClearValue &v, size_t seed = 0)
noexcept
73 QtPrivate::QHashCombine hash(seed);
74 seed = hash(seed, v.m_d);
75 seed = hash(seed, v.m_s);
82#ifndef QT_NO_DEBUG_STREAM
83Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiDepthStencilClearValue &);
89 QRhiViewport() =
default;
90 QRhiViewport(
float x,
float y,
float w,
float h,
float minDepth = 0.0f,
float maxDepth = 1.0f);
92 std::array<
float, 4> viewport()
const {
return m_rect; }
93 void setViewport(
float x,
float y,
float w,
float h) {
94 m_rect[0] = x; m_rect[1] = y; m_rect[2] = w; m_rect[3] = h;
97 float minDepth()
const {
return m_minDepth; }
98 void setMinDepth(
float minDepth) { m_minDepth = minDepth; }
100 float maxDepth()
const {
return m_maxDepth; }
101 void setMaxDepth(
float maxDepth) { m_maxDepth = maxDepth; }
104 std::array<
float, 4> m_rect { { 0.0f, 0.0f, 0.0f, 0.0f } };
105 float m_minDepth = 0.0f;
106 float m_maxDepth = 1.0f;
108 friend bool operator==(
const QRhiViewport &a,
const QRhiViewport &b)
noexcept
110 return a.m_rect == b.m_rect
111 && a.m_minDepth == b.m_minDepth
112 && a.m_maxDepth == b.m_maxDepth;
115 friend bool operator!=(
const QRhiViewport &a,
const QRhiViewport &b)
noexcept
120 friend size_t qHash(
const QRhiViewport &v, size_t seed = 0)
noexcept
122 QtPrivate::QHashCombine hash(seed);
123 seed = hash(seed, v.m_rect[0]);
124 seed = hash(seed, v.m_rect[1]);
125 seed = hash(seed, v.m_rect[2]);
126 seed = hash(seed, v.m_rect[3]);
127 seed = hash(seed, v.m_minDepth);
128 seed = hash(seed, v.m_maxDepth);
135#ifndef QT_NO_DEBUG_STREAM
136Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiViewport &);
142 QRhiScissor() =
default;
143 QRhiScissor(
int x,
int y,
int w,
int h);
145 std::array<
int, 4> scissor()
const {
return m_rect; }
146 void setScissor(
int x,
int y,
int w,
int h) {
147 m_rect[0] = x; m_rect[1] = y; m_rect[2] = w; m_rect[3] = h;
151 std::array<
int, 4> m_rect { { 0, 0, 0, 0 } };
153 friend bool operator==(
const QRhiScissor &a,
const QRhiScissor &b)
noexcept
155 return a.m_rect == b.m_rect;
158 friend bool operator!=(
const QRhiScissor &a,
const QRhiScissor &b)
noexcept
163 friend size_t qHash(
const QRhiScissor &v, size_t seed = 0)
noexcept
165 QtPrivate::QHashCombine hash(seed);
166 seed = hash(seed, v.m_rect[0]);
167 seed = hash(seed, v.m_rect[1]);
168 seed = hash(seed, v.m_rect[2]);
169 seed = hash(seed, v.m_rect[3]);
176#ifndef QT_NO_DEBUG_STREAM
177Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiScissor &);
183 enum Classification {
188 QRhiVertexInputBinding() =
default;
189 QRhiVertexInputBinding(quint32 stride, Classification cls = PerVertex, quint32 stepRate = 1);
191 quint32 stride()
const {
return m_stride; }
192 void setStride(quint32 s) { m_stride = s; }
194 Classification classification()
const {
return m_classification; }
195 void setClassification(Classification c) { m_classification = c; }
197 quint32 instanceStepRate()
const {
return m_instanceStepRate; }
198 void setInstanceStepRate(quint32 rate) { m_instanceStepRate = rate; }
201 quint32 m_stride = 0;
202 Classification m_classification = PerVertex;
203 quint32 m_instanceStepRate = 1;
205 friend bool operator==(
const QRhiVertexInputBinding &a,
const QRhiVertexInputBinding &b)
noexcept
207 return a.m_stride == b.m_stride
208 && a.m_classification == b.m_classification
209 && a.m_instanceStepRate == b.m_instanceStepRate;
212 friend bool operator!=(
const QRhiVertexInputBinding &a,
const QRhiVertexInputBinding &b)
noexcept
217 friend size_t qHash(
const QRhiVertexInputBinding &v, size_t seed = 0)
noexcept
219 QtPrivate::QHashCombine hash(seed);
220 seed = hash(seed, v.m_stride);
221 seed = hash(seed, v.m_classification);
222 seed = hash(seed, v.m_instanceStepRate);
229#ifndef QT_NO_DEBUG_STREAM
230Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiVertexInputBinding &);
266 QRhiVertexInputAttribute() =
default;
267 QRhiVertexInputAttribute(
int binding,
int location, Format format, quint32 offset,
int matrixSlice = -1);
269 int binding()
const {
return m_binding; }
270 void setBinding(
int b) { m_binding = b; }
272 int location()
const {
return m_location; }
273 void setLocation(
int loc) { m_location = loc; }
275 Format format()
const {
return m_format; }
276 void setFormat(Format f) { m_format = f; }
278 quint32 offset()
const {
return m_offset; }
279 void setOffset(quint32 ofs) { m_offset = ofs; }
281 int matrixSlice()
const {
return m_matrixSlice; }
282 void setMatrixSlice(
int slice) { m_matrixSlice = slice; }
287 Format m_format = Float4;
288 quint32 m_offset = 0;
289 int m_matrixSlice = -1;
291 friend bool operator==(
const QRhiVertexInputAttribute &a,
const QRhiVertexInputAttribute &b)
noexcept
293 return a.m_binding == b.m_binding
294 && a.m_location == b.m_location
295 && a.m_format == b.m_format
296 && a.m_offset == b.m_offset;
300 friend bool operator!=(
const QRhiVertexInputAttribute &a,
const QRhiVertexInputAttribute &b)
noexcept
305 friend size_t qHash(
const QRhiVertexInputAttribute &v, size_t seed = 0)
noexcept
307 QtPrivate::QHashCombine hash(seed);
308 seed = hash(seed, v.m_binding);
309 seed = hash(seed, v.m_location);
310 seed = hash(seed, v.m_format);
311 seed = hash(seed, v.m_offset);
318#ifndef QT_NO_DEBUG_STREAM
319Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiVertexInputAttribute &);
325 QRhiVertexInputLayout() =
default;
327 void setBindings(std::initializer_list<QRhiVertexInputBinding> list) { m_bindings = list; }
328 template<
typename InputIterator>
329 void setBindings(InputIterator first, InputIterator last)
332 std::copy(first, last, std::back_inserter(m_bindings));
334 const QRhiVertexInputBinding *cbeginBindings()
const {
return m_bindings.cbegin(); }
335 const QRhiVertexInputBinding *cendBindings()
const {
return m_bindings.cend(); }
336 const QRhiVertexInputBinding *bindingAt(qsizetype index)
const {
return &m_bindings.at(index); }
337 qsizetype bindingCount()
const {
return m_bindings.count(); }
339 void setAttributes(std::initializer_list<QRhiVertexInputAttribute> list) { m_attributes = list; }
340 template<
typename InputIterator>
341 void setAttributes(InputIterator first, InputIterator last)
343 m_attributes.clear();
344 std::copy(first, last, std::back_inserter(m_attributes));
346 const QRhiVertexInputAttribute *cbeginAttributes()
const {
return m_attributes.cbegin(); }
347 const QRhiVertexInputAttribute *cendAttributes()
const {
return m_attributes.cend(); }
348 const QRhiVertexInputAttribute *attributeAt(qsizetype index)
const {
return &m_attributes.at(index); }
349 qsizetype attributeCount()
const {
return m_attributes.count(); }
352 QVarLengthArray<QRhiVertexInputBinding, 8> m_bindings;
353 QVarLengthArray<QRhiVertexInputAttribute, 8> m_attributes;
355 friend bool operator==(
const QRhiVertexInputLayout &a,
const QRhiVertexInputLayout &b)
noexcept
357 return a.m_bindings == b.m_bindings && a.m_attributes == b.m_attributes;
360 friend bool operator!=(
const QRhiVertexInputLayout &a,
const QRhiVertexInputLayout &b)
noexcept
365 friend size_t qHash(
const QRhiVertexInputLayout &v, size_t seed = 0)
noexcept
367 QtPrivate::QHashCombine hash(seed);
368 seed = hash(seed, v.m_bindings);
369 seed = hash(seed, v.m_attributes);
373 friend Q_GUI_EXPORT QDebug operator<<(QDebug,
const QRhiVertexInputLayout &);
376#ifndef QT_NO_DEBUG_STREAM
377Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiVertexInputLayout &);
386 TessellationEvaluation,
392 QRhiShaderStage() =
default;
393 QRhiShaderStage(Type type,
const QShader &shader,
394 QShader::Variant v = QShader::StandardShader);
396 Type type()
const {
return m_type; }
397 void setType(Type t) { m_type = t; }
399 QShader shader()
const {
return m_shader; }
400 void setShader(
const QShader &s) { m_shader = s; }
402 QShader::Variant shaderVariant()
const {
return m_shaderVariant; }
403 void setShaderVariant(QShader::Variant v) { m_shaderVariant = v; }
406 Type m_type = Vertex;
408 QShader::Variant m_shaderVariant = QShader::StandardShader;
410 friend bool operator==(
const QRhiShaderStage &a,
const QRhiShaderStage &b)
noexcept
412 return a.m_type == b.m_type
413 && a.m_shader == b.m_shader
414 && a.m_shaderVariant == b.m_shaderVariant;
417 friend bool operator!=(
const QRhiShaderStage &a,
const QRhiShaderStage &b)
noexcept
422 friend size_t qHash(
const QRhiShaderStage &v, size_t seed = 0)
noexcept
424 QtPrivate::QHashCombine hash(seed);
425 seed = hash(seed, v.m_type);
426 seed = hash(seed, v.m_shader);
427 seed = hash(seed, v.m_shaderVariant);
434#ifndef QT_NO_DEBUG_STREAM
435Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiShaderStage &);
438using QRhiGraphicsShaderStage = QRhiShaderStage;
457 VertexStage = 1 << 0,
458 TessellationControlStage = 1 << 1,
459 TessellationEvaluationStage = 1 << 2,
460 GeometryStage = 1 << 3,
461 FragmentStage = 1 << 4,
462 ComputeStage = 1 << 5
464 Q_DECLARE_FLAGS(StageFlags, StageFlag)
466 QRhiShaderResourceBinding() =
default;
468 bool isLayoutCompatible(
const QRhiShaderResourceBinding &other)
const;
470 static QRhiShaderResourceBinding uniformBuffer(
int binding, StageFlags stage, QRhiBuffer *buf);
471 static QRhiShaderResourceBinding uniformBuffer(
int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size);
472 static QRhiShaderResourceBinding uniformBufferWithDynamicOffset(
int binding, StageFlags stage, QRhiBuffer *buf, quint32 size);
474 static QRhiShaderResourceBinding sampledTexture(
int binding, StageFlags stage, QRhiTexture *tex, QRhiSampler *sampler);
476 struct TextureAndSampler {
478 QRhiSampler *sampler;
480 static QRhiShaderResourceBinding sampledTextures(
int binding, StageFlags stage,
int count,
const TextureAndSampler *texSamplers);
482 static QRhiShaderResourceBinding texture(
int binding, StageFlags stage, QRhiTexture *tex);
483 static QRhiShaderResourceBinding textures(
int binding, StageFlags stage,
int count, QRhiTexture **tex);
484 static QRhiShaderResourceBinding sampler(
int binding, StageFlags stage, QRhiSampler *sampler);
486 static QRhiShaderResourceBinding imageLoad(
int binding, StageFlags stage, QRhiTexture *tex,
int level);
487 static QRhiShaderResourceBinding imageStore(
int binding, StageFlags stage, QRhiTexture *tex,
int level);
488 static QRhiShaderResourceBinding imageLoadStore(
int binding, StageFlags stage, QRhiTexture *tex,
int level);
490 static QRhiShaderResourceBinding bufferLoad(
int binding, StageFlags stage, QRhiBuffer *buf);
491 static QRhiShaderResourceBinding bufferLoad(
int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size);
492 static QRhiShaderResourceBinding bufferStore(
int binding, StageFlags stage, QRhiBuffer *buf);
493 static QRhiShaderResourceBinding bufferStore(
int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size);
494 static QRhiShaderResourceBinding bufferLoadStore(
int binding, StageFlags stage, QRhiBuffer *buf);
495 static QRhiShaderResourceBinding bufferLoadStore(
int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size);
500 QRhiShaderResourceBinding::StageFlags stage;
501 QRhiShaderResourceBinding::Type type;
502 struct UniformBufferData {
506 bool hasDynamicOffset;
508 static constexpr int MAX_TEX_SAMPLER_ARRAY_SIZE = 16;
509 struct TextureAndOrSamplerData {
511 TextureAndSampler texSamplers[MAX_TEX_SAMPLER_ARRAY_SIZE];
513 struct StorageImageData {
517 struct StorageBufferData {
523 UniformBufferData ubuf;
524 TextureAndOrSamplerData stex;
525 StorageImageData simage;
526 StorageBufferData sbuf;
529 int arraySize()
const
531 return type == QRhiShaderResourceBinding::SampledTexture || type == QRhiShaderResourceBinding::Texture
536 template<
typename Output>
537 Output serialize(Output dst)
const
540 *dst++ = quint32(binding);
541 *dst++ = quint32(stage);
542 *dst++ = quint32(type);
543 *dst++ = quint32(arraySize());
548 static constexpr int LAYOUT_DESC_ENTRIES_PER_BINDING = 4;
550 template<
typename Output>
551 static void serializeLayoutDescription(
const QRhiShaderResourceBinding *first,
552 const QRhiShaderResourceBinding *last,
555 while (first != last) {
556 dst = first->d.serialize(dst);
563 friend class QRhiImplementation;
566Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiShaderResourceBinding::StageFlags)
568Q_DECLARE_TYPEINFO(QRhiShaderResourceBinding, Q_PRIMITIVE_TYPE);
570Q_GUI_EXPORT
bool operator==(
const QRhiShaderResourceBinding &a,
const QRhiShaderResourceBinding &b)
noexcept;
571Q_GUI_EXPORT
bool operator!=(
const QRhiShaderResourceBinding &a,
const QRhiShaderResourceBinding &b)
noexcept;
572Q_GUI_EXPORT size_t qHash(
const QRhiShaderResourceBinding &b, size_t seed = 0)
noexcept;
573#ifndef QT_NO_DEBUG_STREAM
574Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiShaderResourceBinding &);
580 QRhiColorAttachment() =
default;
581 QRhiColorAttachment(QRhiTexture *texture);
582 QRhiColorAttachment(QRhiRenderBuffer *renderBuffer);
584 QRhiTexture *texture()
const {
return m_texture; }
585 void setTexture(QRhiTexture *tex) { m_texture = tex; }
587 QRhiRenderBuffer *renderBuffer()
const {
return m_renderBuffer; }
588 void setRenderBuffer(QRhiRenderBuffer *rb) { m_renderBuffer = rb; }
590 int layer()
const {
return m_layer; }
591 void setLayer(
int layer) { m_layer = layer; }
593 int level()
const {
return m_level; }
594 void setLevel(
int level) { m_level = level; }
596 QRhiTexture *resolveTexture()
const {
return m_resolveTexture; }
597 void setResolveTexture(QRhiTexture *tex) { m_resolveTexture = tex; }
599 int resolveLayer()
const {
return m_resolveLayer; }
600 void setResolveLayer(
int layer) { m_resolveLayer = layer; }
602 int resolveLevel()
const {
return m_resolveLevel; }
603 void setResolveLevel(
int level) { m_resolveLevel = level; }
605 int multiViewCount()
const {
return m_multiViewCount; }
606 void setMultiViewCount(
int count) { m_multiViewCount = count; }
609 QRhiTexture *m_texture =
nullptr;
610 QRhiRenderBuffer *m_renderBuffer =
nullptr;
613 QRhiTexture *m_resolveTexture =
nullptr;
614 int m_resolveLayer = 0;
615 int m_resolveLevel = 0;
616 int m_multiViewCount = 0;
624 QRhiTextureRenderTargetDescription() =
default;
625 QRhiTextureRenderTargetDescription(
const QRhiColorAttachment &colorAttachment);
626 QRhiTextureRenderTargetDescription(
const QRhiColorAttachment &colorAttachment, QRhiRenderBuffer *depthStencilBuffer);
627 QRhiTextureRenderTargetDescription(
const QRhiColorAttachment &colorAttachment, QRhiTexture *depthTexture);
629 void setColorAttachments(std::initializer_list<QRhiColorAttachment> list) { m_colorAttachments = list; }
630 template<
typename InputIterator>
631 void setColorAttachments(InputIterator first, InputIterator last)
633 m_colorAttachments.clear();
634 std::copy(first, last, std::back_inserter(m_colorAttachments));
636 const QRhiColorAttachment *cbeginColorAttachments()
const {
return m_colorAttachments.cbegin(); }
637 const QRhiColorAttachment *cendColorAttachments()
const {
return m_colorAttachments.cend(); }
638 const QRhiColorAttachment *colorAttachmentAt(qsizetype index)
const {
return &m_colorAttachments.at(index); }
639 qsizetype colorAttachmentCount()
const {
return m_colorAttachments.count(); }
641 QRhiRenderBuffer *depthStencilBuffer()
const {
return m_depthStencilBuffer; }
642 void setDepthStencilBuffer(QRhiRenderBuffer *renderBuffer) { m_depthStencilBuffer = renderBuffer; }
644 QRhiTexture *depthTexture()
const {
return m_depthTexture; }
645 void setDepthTexture(QRhiTexture *texture) { m_depthTexture = texture; }
647 int depthLayer()
const {
return m_depthLayer; }
648 void setDepthLayer(
int depthLayer) { m_depthLayer = depthLayer; }
650 QRhiTexture *depthResolveTexture()
const {
return m_depthResolveTexture; }
651 void setDepthResolveTexture(QRhiTexture *tex) { m_depthResolveTexture = tex; }
653 QRhiShadingRateMap *shadingRateMap()
const {
return m_shadingRateMap; }
654 void setShadingRateMap(QRhiShadingRateMap *map) { m_shadingRateMap = map; }
657 QVarLengthArray<QRhiColorAttachment, 8> m_colorAttachments;
658 QRhiRenderBuffer *m_depthStencilBuffer =
nullptr;
659 QRhiTexture *m_depthTexture =
nullptr;
660 QRhiTexture *m_depthResolveTexture =
nullptr;
661 QRhiShadingRateMap *m_shadingRateMap =
nullptr;
662 int m_depthLayer = -1;
668 QRhiTextureSubresourceUploadDescription() =
default;
669 explicit QRhiTextureSubresourceUploadDescription(
const QImage &image);
670 QRhiTextureSubresourceUploadDescription(
const void *data, quint32 size);
671 explicit QRhiTextureSubresourceUploadDescription(
const QByteArray &data);
673 QImage image()
const {
return m_image; }
674 void setImage(
const QImage &image) { m_image = image; }
676 QByteArray data()
const {
return m_data; }
677 void setData(
const QByteArray &data) { m_data = data; }
679 quint32 dataStride()
const {
return m_dataStride; }
680 void setDataStride(quint32 stride) { m_dataStride = stride; }
682 QPoint destinationTopLeft()
const {
return m_destinationTopLeft; }
683 void setDestinationTopLeft(
const QPoint &p) { m_destinationTopLeft = p; }
685 QSize sourceSize()
const {
return m_sourceSize; }
686 void setSourceSize(
const QSize &size) { m_sourceSize = size; }
688 QPoint sourceTopLeft()
const {
return m_sourceTopLeft; }
689 void setSourceTopLeft(
const QPoint &p) { m_sourceTopLeft = p; }
694 quint32 m_dataStride = 0;
695 QPoint m_destinationTopLeft;
697 QPoint m_sourceTopLeft;
705 QRhiTextureUploadEntry() =
default;
706 QRhiTextureUploadEntry(
int layer,
int level,
const QRhiTextureSubresourceUploadDescription &desc);
708 int layer()
const {
return m_layer; }
709 void setLayer(
int layer) { m_layer = layer; }
711 int level()
const {
return m_level; }
712 void setLevel(
int level) { m_level = level; }
714 QRhiTextureSubresourceUploadDescription description()
const {
return m_desc; }
715 void setDescription(
const QRhiTextureSubresourceUploadDescription &desc) { m_desc = desc; }
720 QRhiTextureSubresourceUploadDescription m_desc;
728 QRhiTextureUploadDescription() =
default;
729 QRhiTextureUploadDescription(
const QRhiTextureUploadEntry &entry);
730 QRhiTextureUploadDescription(std::initializer_list<QRhiTextureUploadEntry> list);
732 void setEntries(std::initializer_list<QRhiTextureUploadEntry> list) { m_entries = list; }
733 template<
typename InputIterator>
734 void setEntries(InputIterator first, InputIterator last)
737 std::copy(first, last, std::back_inserter(m_entries));
739 const QRhiTextureUploadEntry *cbeginEntries()
const {
return m_entries.cbegin(); }
740 const QRhiTextureUploadEntry *cendEntries()
const {
return m_entries.cend(); }
741 const QRhiTextureUploadEntry *entryAt(qsizetype index)
const {
return &m_entries.at(index); }
742 qsizetype entryCount()
const {
return m_entries.count(); }
745 QVarLengthArray<QRhiTextureUploadEntry, 16> m_entries;
751 QRhiTextureCopyDescription() =
default;
753 QSize pixelSize()
const {
return m_pixelSize; }
754 void setPixelSize(
const QSize &sz) { m_pixelSize = sz; }
756 int sourceLayer()
const {
return m_sourceLayer; }
757 void setSourceLayer(
int layer) { m_sourceLayer = layer; }
759 int sourceLevel()
const {
return m_sourceLevel; }
760 void setSourceLevel(
int level) { m_sourceLevel = level; }
762 QPoint sourceTopLeft()
const {
return m_sourceTopLeft; }
763 void setSourceTopLeft(
const QPoint &p) { m_sourceTopLeft = p; }
765 int destinationLayer()
const {
return m_destinationLayer; }
766 void setDestinationLayer(
int layer) { m_destinationLayer = layer; }
768 int destinationLevel()
const {
return m_destinationLevel; }
769 void setDestinationLevel(
int level) { m_destinationLevel = level; }
771 QPoint destinationTopLeft()
const {
return m_destinationTopLeft; }
772 void setDestinationTopLeft(
const QPoint &p) { m_destinationTopLeft = p; }
776 int m_sourceLayer = 0;
777 int m_sourceLevel = 0;
778 QPoint m_sourceTopLeft;
779 int m_destinationLayer = 0;
780 int m_destinationLevel = 0;
781 QPoint m_destinationTopLeft;
789 QRhiReadbackDescription() =
default;
790 QRhiReadbackDescription(QRhiTexture *texture);
792 QRhiTexture *texture()
const {
return m_texture; }
793 void setTexture(QRhiTexture *tex) { m_texture = tex; }
795 int layer()
const {
return m_layer; }
796 void setLayer(
int layer) { m_layer = layer; }
798 int level()
const {
return m_level; }
799 void setLevel(
int level) { m_level = level; }
801 QRect rect()
const {
return m_rect; }
802 void setRect(
const QRect &rectangle) { m_rect = rectangle; }
805 QRhiTexture *m_texture =
nullptr;
825 RenderPassDescriptor,
826 SwapChainRenderTarget,
828 ShaderResourceBindings,
836 virtual ~QRhiResource();
838 virtual Type resourceType()
const = 0;
840 virtual void destroy() = 0;
844 QByteArray name()
const;
845 void setName(
const QByteArray &name);
847 quint64 globalResourceId()
const;
852 QRhiResource(QRhiImplementation *rhi);
853 Q_DISABLE_COPY(QRhiResource)
854 friend class QRhiImplementation;
855 QRhiImplementation *m_rhi =
nullptr;
857 QByteArray m_objectName;
870 VertexBuffer = 1 << 0,
871 IndexBuffer = 1 << 1,
872 UniformBuffer = 1 << 2,
873 StorageBuffer = 1 << 3,
874 IndirectBuffer = 1 << 4,
876 Q_DECLARE_FLAGS(UsageFlags, UsageFlag)
878 struct NativeBuffer {
879 const void *objects[3];
883 QRhiResource::Type resourceType()
const override;
885 Type type()
const {
return m_type; }
886 void setType(Type t) { m_type = t; }
888 UsageFlags usage()
const {
return m_usage; }
889 void setUsage(UsageFlags u) { m_usage = u; }
891 quint32 size()
const {
return m_size; }
892 void setSize(quint32 sz) { m_size = sz; }
894 virtual bool create() = 0;
896 virtual NativeBuffer nativeBuffer();
898 virtual char *beginFullDynamicBufferUpdateForCurrentFrame();
899 virtual void endFullDynamicBufferUpdateForCurrentFrame();
900 virtual void fullDynamicBufferUpdateForCurrentFrame(
const void *data, quint32 size = 0);
903 QRhiBuffer(QRhiImplementation *rhi, Type type_, UsageFlags usage_, quint32 size_);
909Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiBuffer::UsageFlags)
911class Q_GUI_EXPORT QRhiTexture :
public QRhiResource
915 RenderTarget = 1 << 0,
919 UsedAsTransferSource = 1 << 5,
920 UsedWithGenerateMips = 1 << 6,
921 UsedWithLoadStore = 1 << 7,
922 UsedAsCompressedAtlas = 1 << 8,
923 ExternalOES = 1 << 9,
924 ThreeDimensional = 1 << 10,
925 TextureRectangleGL = 1 << 11,
926 TextureArray = 1 << 12,
927 OneDimensional = 1 << 13,
928 UsedAsShadingRateMap = 1 << 14
930 Q_DECLARE_FLAGS(Flags, Flag)
994 struct NativeTexture {
999 QRhiResource::Type resourceType()
const override;
1001 Format format()
const {
return m_format; }
1002 void setFormat(Format fmt) { m_format = fmt; }
1004 QSize pixelSize()
const {
return m_pixelSize; }
1005 void setPixelSize(
const QSize &sz) { m_pixelSize = sz; }
1007 int depth()
const {
return m_depth; }
1008 void setDepth(
int depth) { m_depth = depth; }
1010 int arraySize()
const {
return m_arraySize; }
1011 void setArraySize(
int arraySize) { m_arraySize = arraySize; }
1013 int arrayRangeStart()
const {
return m_arrayRangeStart; }
1014 int arrayRangeLength()
const {
return m_arrayRangeLength; }
1015 void setArrayRange(
int startIndex,
int count)
1017 m_arrayRangeStart = startIndex;
1018 m_arrayRangeLength = count;
1021 Flags flags()
const {
return m_flags; }
1022 void setFlags(Flags f) { m_flags = f; }
1024 int sampleCount()
const {
return m_sampleCount; }
1025 void setSampleCount(
int s) { m_sampleCount = s; }
1028 QRhiTexture::Format format;
1031 ViewFormat readViewFormat()
const {
return m_readViewFormat; }
1032 void setReadViewFormat(
const ViewFormat &fmt) { m_readViewFormat = fmt; }
1033 ViewFormat writeViewFormat()
const {
return m_writeViewFormat; }
1034 void setWriteViewFormat(
const ViewFormat &fmt) { m_writeViewFormat = fmt; }
1036 virtual bool create() = 0;
1037 virtual NativeTexture nativeTexture();
1038 virtual bool createFrom(NativeTexture src);
1039 virtual void setNativeLayout(
int layout);
1042 QRhiTexture(QRhiImplementation *rhi, Format format_,
const QSize &pixelSize_,
int depth_,
1043 int arraySize_,
int sampleCount_, Flags flags_);
1050 int m_arrayRangeStart = -1;
1051 int m_arrayRangeLength = -1;
1052 ViewFormat m_readViewFormat = { UnknownFormat,
false };
1053 ViewFormat m_writeViewFormat = { UnknownFormat,
false };
1056Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiTexture::Flags)
1058class Q_GUI_EXPORT QRhiSampler :
public QRhiResource
1084 QRhiResource::Type resourceType()
const override;
1086 Filter magFilter()
const {
return m_magFilter; }
1087 void setMagFilter(Filter f) { m_magFilter = f; }
1089 Filter minFilter()
const {
return m_minFilter; }
1090 void setMinFilter(Filter f) { m_minFilter = f; }
1092 Filter mipmapMode()
const {
return m_mipmapMode; }
1093 void setMipmapMode(Filter f) { m_mipmapMode = f; }
1095 AddressMode addressU()
const {
return m_addressU; }
1096 void setAddressU(AddressMode mode) { m_addressU = mode; }
1098 AddressMode addressV()
const {
return m_addressV; }
1099 void setAddressV(AddressMode mode) { m_addressV = mode; }
1101 AddressMode addressW()
const {
return m_addressW; }
1102 void setAddressW(AddressMode mode) { m_addressW = mode; }
1104 CompareOp textureCompareOp()
const {
return m_compareOp; }
1105 void setTextureCompareOp(CompareOp op) { m_compareOp = op; }
1107 virtual bool create() = 0;
1110 QRhiSampler(QRhiImplementation *rhi,
1111 Filter magFilter_, Filter minFilter_, Filter mipmapMode_,
1112 AddressMode u_, AddressMode v_, AddressMode w_);
1115 Filter m_mipmapMode;
1116 AddressMode m_addressU;
1117 AddressMode m_addressV;
1118 AddressMode m_addressW;
1119 CompareOp m_compareOp;
1131 UsedWithSwapChainOnly = 1 << 0
1133 Q_DECLARE_FLAGS(Flags, Flag)
1135 struct NativeRenderBuffer {
1139 QRhiResource::Type resourceType()
const override;
1141 Type type()
const {
return m_type; }
1142 void setType(Type t) { m_type = t; }
1144 QSize pixelSize()
const {
return m_pixelSize; }
1145 void setPixelSize(
const QSize &sz) { m_pixelSize = sz; }
1147 int sampleCount()
const {
return m_sampleCount; }
1148 void setSampleCount(
int s) { m_sampleCount = s; }
1150 Flags flags()
const {
return m_flags; }
1151 void setFlags(Flags f) { m_flags = f; }
1153 virtual bool create() = 0;
1154 virtual bool createFrom(NativeRenderBuffer src);
1156 virtual QRhiTexture::Format backingFormat()
const = 0;
1159 QRhiRenderBuffer(QRhiImplementation *rhi, Type type_,
const QSize &pixelSize_,
1160 int sampleCount_, Flags flags_, QRhiTexture::Format backingFormatHint_);
1165 QRhiTexture::Format m_backingFormatHint;
1168Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiRenderBuffer::Flags)
1170class Q_GUI_EXPORT QRhiShadingRateMap :
public QRhiResource
1173 struct NativeShadingRateMap {
1177 QRhiResource::Type resourceType()
const override;
1179 virtual bool createFrom(NativeShadingRateMap src);
1180 virtual bool createFrom(QRhiTexture *src);
1183 QRhiShadingRateMap(QRhiImplementation *rhi);
1189 QRhiResource::Type resourceType()
const override;
1191 virtual bool isCompatible(
const QRhiRenderPassDescriptor *other)
const = 0;
1192 virtual const QRhiNativeHandles *nativeHandles();
1194 virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor()
const = 0;
1196 virtual QVector<quint32> serializedFormat()
const = 0;
1199 QRhiRenderPassDescriptor(QRhiImplementation *rhi);
1205 virtual QSize pixelSize()
const = 0;
1206 virtual float devicePixelRatio()
const = 0;
1207 virtual int sampleCount()
const = 0;
1209 QRhiRenderPassDescriptor *renderPassDescriptor()
const {
return m_renderPassDesc; }
1210 void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; }
1213 QRhiRenderTarget(QRhiImplementation *rhi);
1214 QRhiRenderPassDescriptor *m_renderPassDesc =
nullptr;
1220 QRhiResource::Type resourceType()
const override;
1221 QRhiSwapChain *swapChain()
const {
return m_swapchain; }
1224 QRhiSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain_);
1225 QRhiSwapChain *m_swapchain;
1232 PreserveColorContents = 1 << 0,
1233 PreserveDepthStencilContents = 1 << 1,
1234 DoNotStoreDepthStencilContents = 1 << 2
1236 Q_DECLARE_FLAGS(Flags, Flag)
1238 QRhiResource::Type resourceType()
const override;
1240 QRhiTextureRenderTargetDescription description()
const {
return m_desc; }
1241 void setDescription(
const QRhiTextureRenderTargetDescription &desc) { m_desc = desc; }
1243 Flags flags()
const {
return m_flags; }
1244 void setFlags(Flags f) { m_flags = f; }
1246 virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() = 0;
1248 virtual bool create() = 0;
1251 QRhiTextureRenderTarget(QRhiImplementation *rhi,
const QRhiTextureRenderTargetDescription &desc_, Flags flags_);
1252 QRhiTextureRenderTargetDescription m_desc;
1256Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiTextureRenderTarget::Flags)
1258class Q_GUI_EXPORT QRhiShaderResourceBindings :
public QRhiResource
1261 QRhiResource::Type resourceType()
const override;
1263 void setBindings(std::initializer_list<QRhiShaderResourceBinding> list) { m_bindings = list; }
1264 template<
typename InputIterator>
1265 void setBindings(InputIterator first, InputIterator last)
1268 std::copy(first, last, std::back_inserter(m_bindings));
1270 const QRhiShaderResourceBinding *cbeginBindings()
const {
return m_bindings.cbegin(); }
1271 const QRhiShaderResourceBinding *cendBindings()
const {
return m_bindings.cend(); }
1272 const QRhiShaderResourceBinding *bindingAt(qsizetype index)
const {
return &m_bindings.at(index); }
1273 qsizetype bindingCount()
const {
return m_bindings.count(); }
1275 bool isLayoutCompatible(
const QRhiShaderResourceBindings *other)
const;
1277 QVector<quint32> serializedLayoutDescription()
const {
return m_layoutDesc; }
1279 virtual bool create() = 0;
1282 BindingsAreSorted = 0x01
1284 Q_DECLARE_FLAGS(UpdateFlags, UpdateFlag)
1286 virtual void updateResources(UpdateFlags flags = {}) = 0;
1289 static constexpr int BINDING_PREALLOC = 12;
1290 QRhiShaderResourceBindings(QRhiImplementation *rhi);
1291 QVarLengthArray<QRhiShaderResourceBinding, BINDING_PREALLOC> m_bindings;
1292 size_t m_layoutDescHash = 0;
1296 QVector<quint32> m_layoutDesc;
1297 friend class QRhiImplementation;
1298#ifndef QT_NO_DEBUG_STREAM
1299 friend Q_GUI_EXPORT QDebug operator<<(QDebug,
const QRhiShaderResourceBindings &);
1303Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiShaderResourceBindings::UpdateFlags)
1305#ifndef QT_NO_DEBUG_STREAM
1306Q_GUI_EXPORT QDebug operator<<(QDebug,
const QRhiShaderResourceBindings &);
1312using QRhiShaderResourceBindingSet = QRhiShaderResourceBindings;
1318 UsesBlendConstants = 1 << 0,
1319 UsesStencilRef = 1 << 1,
1320 UsesScissor = 1 << 2,
1321 CompileShadersWithDebugInfo = 1 << 3,
1322 UsesShadingRate = 1 << 4,
1323 UsesIndirectDraws = 1 << 5
1325 Q_DECLARE_FLAGS(Flags, Flag)
1348 enum ColorMaskComponent {
1354 Q_DECLARE_FLAGS(ColorMask, ColorMaskComponent)
1368 OneMinusConstantColor,
1370 OneMinusConstantAlpha,
1386 struct TargetBlend {
1387 ColorMask colorWrite = ColorMask(0xF);
1388 bool enable =
false;
1389 BlendFactor srcColor = One;
1390 BlendFactor dstColor = OneMinusSrcAlpha;
1391 BlendOp opColor = Add;
1392 BlendFactor srcAlpha = One;
1393 BlendFactor dstAlpha = OneMinusSrcAlpha;
1394 BlendOp opAlpha = Add;
1419 struct StencilOpState {
1420 StencilOp failOp = Keep;
1421 StencilOp depthFailOp = Keep;
1422 StencilOp passOp = Keep;
1423 CompareOp compareOp = Always;
1431 QRhiResource::Type resourceType()
const override;
1433 Flags flags()
const {
return m_flags; }
1434 void setFlags(Flags f) { m_flags = f; }
1436 Topology topology()
const {
return m_topology; }
1437 void setTopology(Topology t) { m_topology = t; }
1439 CullMode cullMode()
const {
return m_cullMode; }
1440 void setCullMode(CullMode mode) { m_cullMode = mode; }
1442 FrontFace frontFace()
const {
return m_frontFace; }
1443 void setFrontFace(FrontFace f) { m_frontFace = f; }
1445 void setTargetBlends(std::initializer_list<TargetBlend> list) { m_targetBlends = list; }
1446 template<
typename InputIterator>
1447 void setTargetBlends(InputIterator first, InputIterator last)
1449 m_targetBlends.clear();
1450 std::copy(first, last, std::back_inserter(m_targetBlends));
1452 const TargetBlend *cbeginTargetBlends()
const {
return m_targetBlends.cbegin(); }
1453 const TargetBlend *cendTargetBlends()
const {
return m_targetBlends.cend(); }
1454 const TargetBlend *targetBlendAt(qsizetype index)
const {
return &m_targetBlends.at(index); }
1455 qsizetype targetBlendCount()
const {
return m_targetBlends.count(); }
1457 bool hasDepthTest()
const {
return m_depthTest; }
1458 void setDepthTest(
bool enable) { m_depthTest = enable; }
1460 bool hasDepthWrite()
const {
return m_depthWrite; }
1461 void setDepthWrite(
bool enable) { m_depthWrite = enable; }
1463 bool hasDepthClamp()
const {
return m_depthClamp; }
1464 void setDepthClamp(
bool enable) { m_depthClamp = enable; }
1466 CompareOp depthOp()
const {
return m_depthOp; }
1467 void setDepthOp(CompareOp op) { m_depthOp = op; }
1469 bool hasStencilTest()
const {
return m_stencilTest; }
1470 void setStencilTest(
bool enable) { m_stencilTest = enable; }
1472 StencilOpState stencilFront()
const {
return m_stencilFront; }
1473 void setStencilFront(
const StencilOpState &state) { m_stencilFront = state; }
1475 StencilOpState stencilBack()
const {
return m_stencilBack; }
1476 void setStencilBack(
const StencilOpState &state) { m_stencilBack = state; }
1478 quint32 stencilReadMask()
const {
return m_stencilReadMask; }
1479 void setStencilReadMask(quint32 mask) { m_stencilReadMask = mask; }
1481 quint32 stencilWriteMask()
const {
return m_stencilWriteMask; }
1482 void setStencilWriteMask(quint32 mask) { m_stencilWriteMask = mask; }
1484 int sampleCount()
const {
return m_sampleCount; }
1485 void setSampleCount(
int s) { m_sampleCount = s; }
1487 float lineWidth()
const {
return m_lineWidth; }
1488 void setLineWidth(
float width) { m_lineWidth = width; }
1490 int depthBias()
const {
return m_depthBias; }
1491 void setDepthBias(
int bias) { m_depthBias = bias; }
1493 float slopeScaledDepthBias()
const {
return m_slopeScaledDepthBias; }
1494 void setSlopeScaledDepthBias(
float bias) { m_slopeScaledDepthBias = bias; }
1496 void setShaderStages(std::initializer_list<QRhiShaderStage> list) { m_shaderStages = list; }
1497 template<
typename InputIterator>
1498 void setShaderStages(InputIterator first, InputIterator last)
1500 m_shaderStages.clear();
1501 std::copy(first, last, std::back_inserter(m_shaderStages));
1503 const QRhiShaderStage *cbeginShaderStages()
const {
return m_shaderStages.cbegin(); }
1504 const QRhiShaderStage *cendShaderStages()
const {
return m_shaderStages.cend(); }
1505 const QRhiShaderStage *shaderStageAt(qsizetype index)
const {
return &m_shaderStages.at(index); }
1506 qsizetype shaderStageCount()
const {
return m_shaderStages.count(); }
1508 QRhiVertexInputLayout vertexInputLayout()
const {
return m_vertexInputLayout; }
1509 void setVertexInputLayout(
const QRhiVertexInputLayout &layout) { m_vertexInputLayout = layout; }
1511 QRhiShaderResourceBindings *shaderResourceBindings()
const {
return m_shaderResourceBindings; }
1512 void setShaderResourceBindings(QRhiShaderResourceBindings *srb) { m_shaderResourceBindings = srb; }
1514 QRhiRenderPassDescriptor *renderPassDescriptor()
const {
return m_renderPassDesc; }
1515 void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; }
1517 int patchControlPointCount()
const {
return m_patchControlPointCount; }
1518 void setPatchControlPointCount(
int count) { m_patchControlPointCount = count; }
1520 PolygonMode polygonMode()
const {
return m_polygonMode; }
1521 void setPolygonMode(PolygonMode mode) {m_polygonMode = mode; }
1523 int multiViewCount()
const {
return m_multiViewCount; }
1524 void setMultiViewCount(
int count) { m_multiViewCount = count; }
1526 virtual bool create() = 0;
1529 QRhiGraphicsPipeline(QRhiImplementation *rhi);
1531 Topology m_topology = Triangles;
1532 CullMode m_cullMode = None;
1533 FrontFace m_frontFace = CCW;
1534 QVarLengthArray<TargetBlend, 8> m_targetBlends;
1535 bool m_depthTest =
false;
1536 bool m_depthWrite =
false;
1537 bool m_depthClamp =
false;
1538 CompareOp m_depthOp = Less;
1539 bool m_stencilTest =
false;
1540 StencilOpState m_stencilFront;
1541 StencilOpState m_stencilBack;
1542 quint32 m_stencilReadMask = 0xFF;
1543 quint32 m_stencilWriteMask = 0xFF;
1544 int m_sampleCount = 1;
1545 float m_lineWidth = 1.0f;
1546 int m_depthBias = 0;
1547 float m_slopeScaledDepthBias = 0.0f;
1548 int m_patchControlPointCount = 3;
1549 PolygonMode m_polygonMode = Fill;
1550 int m_multiViewCount = 0;
1551 QVarLengthArray<QRhiShaderStage, 4> m_shaderStages;
1552 QRhiVertexInputLayout m_vertexInputLayout;
1553 QRhiShaderResourceBindings *m_shaderResourceBindings =
nullptr;
1554 QRhiRenderPassDescriptor *m_renderPassDesc =
nullptr;
1557Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiGraphicsPipeline::Flags)
1558Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiGraphicsPipeline::ColorMask)
1559Q_DECLARE_TYPEINFO(QRhiGraphicsPipeline::TargetBlend, Q_RELOCATABLE_TYPE);
1582 } colorComponentValue;
1590#ifndef QT_NO_DEBUG_STREAM
1591Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiSwapChainHdrInfo &);
1603 SurfaceHasPreMulAlpha = 1 << 0,
1604 SurfaceHasNonPreMulAlpha = 1 << 1,
1606 UsedAsTransferSource = 1 << 3,
1608 MinimalBufferCount = 1 << 5
1610 Q_DECLARE_FLAGS(Flags, Flag)
1614 HDRExtendedSrgbLinear,
1616 HDRExtendedDisplayP3Linear
1619 enum StereoTargetBuffer {
1624 QRhiResource::Type resourceType()
const override;
1626 QWindow *window()
const {
return m_window; }
1627 void setWindow(QWindow *window) { m_window = window; }
1629 QRhiSwapChainProxyData proxyData()
const {
return m_proxyData; }
1630 void setProxyData(
const QRhiSwapChainProxyData &d) { m_proxyData = d; }
1632 Flags flags()
const {
return m_flags; }
1633 void setFlags(Flags f) { m_flags = f; }
1635 Format format()
const {
return m_format; }
1636 void setFormat(Format f) { m_format = f; }
1638 QRhiRenderBuffer *depthStencil()
const {
return m_depthStencil; }
1639 void setDepthStencil(QRhiRenderBuffer *ds) { m_depthStencil = ds; }
1641 int sampleCount()
const {
return m_sampleCount; }
1642 void setSampleCount(
int samples) { m_sampleCount = samples; }
1644 QRhiRenderPassDescriptor *renderPassDescriptor()
const {
return m_renderPassDesc; }
1645 void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; }
1647 QRhiShadingRateMap *shadingRateMap()
const {
return m_shadingRateMap; }
1648 void setShadingRateMap(QRhiShadingRateMap *map) { m_shadingRateMap = map; }
1650 QSize currentPixelSize()
const {
return m_currentPixelSize; }
1652 virtual QRhiCommandBuffer *currentFrameCommandBuffer() = 0;
1653 virtual QRhiRenderTarget *currentFrameRenderTarget() = 0;
1654 virtual QRhiRenderTarget *currentFrameRenderTarget(StereoTargetBuffer targetBuffer);
1655 virtual QSize surfacePixelSize() = 0;
1656 virtual bool isFormatSupported(Format f) = 0;
1657 virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() = 0;
1658 virtual bool createOrResize() = 0;
1659 virtual QRhiSwapChainHdrInfo hdrInfo();
1662 QRhiSwapChain(QRhiImplementation *rhi);
1663 QWindow *m_window =
nullptr;
1665 Format m_format = SDR;
1666 QRhiRenderBuffer *m_depthStencil =
nullptr;
1667 int m_sampleCount = 1;
1668 QRhiRenderPassDescriptor *m_renderPassDesc =
nullptr;
1669 QSize m_currentPixelSize;
1670 QRhiSwapChainProxyData m_proxyData;
1671 QRhiShadingRateMap *m_shadingRateMap =
nullptr;
1674Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiSwapChain::Flags)
1676class Q_GUI_EXPORT QRhiComputePipeline :
public QRhiResource
1680 CompileShadersWithDebugInfo = 1 << 0
1682 Q_DECLARE_FLAGS(Flags, Flag)
1684 QRhiResource::Type resourceType()
const override;
1685 virtual bool create() = 0;
1687 Flags flags()
const {
return m_flags; }
1688 void setFlags(Flags f) { m_flags = f; }
1690 QRhiShaderStage shaderStage()
const {
return m_shaderStage; }
1691 void setShaderStage(
const QRhiShaderStage &stage) { m_shaderStage = stage; }
1693 QRhiShaderResourceBindings *shaderResourceBindings()
const {
return m_shaderResourceBindings; }
1694 void setShaderResourceBindings(QRhiShaderResourceBindings *srb) { m_shaderResourceBindings = srb; }
1697 QRhiComputePipeline(QRhiImplementation *rhi);
1699 QRhiShaderStage m_shaderStage;
1700 QRhiShaderResourceBindings *m_shaderResourceBindings =
nullptr;
1703Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiComputePipeline::Flags)
1705struct QRhiIndirectDrawCommand
1707 quint32 vertexCount;
1708 quint32 instanceCount = 1;
1709 quint32 firstVertex = 0;
1710 quint32 firstInstance = 0;
1723static_assert(
sizeof(QRhiIndirectDrawCommand) == 16);
1734 enum BeginPassFlag {
1735 ExternalContent = 0x01,
1736 DoNotTrackResourcesForCompute = 0x02
1738 Q_DECLARE_FLAGS(BeginPassFlags, BeginPassFlag)
1740 QRhiResource::Type resourceType()
const override;
1742 void resourceUpdate(QRhiResourceUpdateBatch *resourceUpdates);
1744 void beginPass(QRhiRenderTarget *rt,
1745 const QColor &colorClearValue,
1746 const QRhiDepthStencilClearValue &depthStencilClearValue,
1747 QRhiResourceUpdateBatch *resourceUpdates =
nullptr,
1748 BeginPassFlags flags = {});
1749 void endPass(QRhiResourceUpdateBatch *resourceUpdates =
nullptr);
1751 void setGraphicsPipeline(QRhiGraphicsPipeline *ps);
1752 using DynamicOffset = std::pair<
int, quint32>;
1753 void setShaderResources(QRhiShaderResourceBindings *srb =
nullptr,
1754 int dynamicOffsetCount = 0,
1755 const DynamicOffset *dynamicOffsets =
nullptr);
1756 using VertexInput = std::pair<QRhiBuffer *, quint32>;
1757 void setVertexInput(
int startBinding,
int bindingCount,
const VertexInput *bindings,
1758 QRhiBuffer *indexBuf =
nullptr, quint32 indexOffset = 0,
1759 IndexFormat indexFormat = IndexUInt16);
1761 void setViewport(
const QRhiViewport &viewport);
1762 void setScissor(
const QRhiScissor &scissor);
1763 void setBlendConstants(
const QColor &c);
1764 void setStencilRef(quint32 refValue);
1765 void setShadingRate(
const QSize &coarsePixelSize);
1767 void draw(quint32 vertexCount,
1768 quint32 instanceCount = 1,
1769 quint32 firstVertex = 0,
1770 quint32 firstInstance = 0);
1772 void drawIndexed(quint32 indexCount,
1773 quint32 instanceCount = 1,
1774 quint32 firstIndex = 0,
1775 qint32 vertexOffset = 0,
1776 quint32 firstInstance = 0);
1778 void drawIndirect(QRhiBuffer *indirectBuffer,
1779 quint32 indirectBufferOffset,
1781 quint32 stride =
sizeof(QRhiIndirectDrawCommand));
1783 void drawIndexedIndirect(QRhiBuffer *indirectBuffer,
1784 quint32 indirectBufferOffset,
1786 quint32 stride =
sizeof(QRhiIndexedIndirectDrawCommand));
1788 void debugMarkBegin(
const QByteArray &name);
1789 void debugMarkEnd();
1790 void debugMarkMsg(
const QByteArray &msg);
1792 void beginComputePass(QRhiResourceUpdateBatch *resourceUpdates =
nullptr, BeginPassFlags flags = {});
1793 void endComputePass(QRhiResourceUpdateBatch *resourceUpdates =
nullptr);
1794 void setComputePipeline(QRhiComputePipeline *ps);
1795 void dispatch(
int x,
int y,
int z);
1797 const QRhiNativeHandles *nativeHandles();
1798 void beginExternal();
1801 double lastCompletedGpuTime();
1804 QRhiCommandBuffer(QRhiImplementation *rhi);
1807Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiCommandBuffer::BeginPassFlags)
1809struct Q_GUI_EXPORT QRhiReadbackResult
1811 std::function<
void()> completed =
nullptr;
1812 QRhiTexture::Format format;
1820 ~QRhiResourceUpdateBatch();
1824 void merge(QRhiResourceUpdateBatch *other);
1825 bool hasOptimalCapacity()
const;
1827 void updateDynamicBuffer(QRhiBuffer *buf, quint32 offset, quint32 size,
const void *data);
1828 void updateDynamicBuffer(QRhiBuffer *buf, quint32 offset, QByteArray data);
1829 void uploadStaticBuffer(QRhiBuffer *buf, quint32 offset, quint32 size,
const void *data);
1830 void uploadStaticBuffer(QRhiBuffer *buf, quint32 offset, QByteArray data);
1831 void uploadStaticBuffer(QRhiBuffer *buf,
const void *data);
1832 void uploadStaticBuffer(QRhiBuffer *buf, QByteArray data);
1833 void readBackBuffer(QRhiBuffer *buf, quint32 offset, quint32 size, QRhiReadbackResult *result);
1834 void uploadTexture(QRhiTexture *tex,
const QRhiTextureUploadDescription &desc);
1835 void uploadTexture(QRhiTexture *tex,
const QImage &image);
1836 void copyTexture(QRhiTexture *dst, QRhiTexture *src,
const QRhiTextureCopyDescription &desc = QRhiTextureCopyDescription());
1837 void readBackTexture(
const QRhiReadbackDescription &rb, QRhiReadbackResult *result);
1838 void generateMips(QRhiTexture *tex);
1841 QRhiResourceUpdateBatch(QRhiImplementation *rhi);
1842 Q_DISABLE_COPY(QRhiResourceUpdateBatch)
1843 QRhiResourceUpdateBatchPrivate *d;
1844 friend class QRhiResourceUpdateBatchPrivate;
1859 QByteArray deviceName;
1860 quint64 deviceId = 0;
1861 quint64 vendorId = 0;
1862 DeviceType deviceType = UnknownDevice;
1867#ifndef QT_NO_DEBUG_STREAM
1868Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiDriverInfo &);
1873 qint64 totalPipelineCreationTime = 0;
1875 quint32 blockCount = 0;
1876 quint32 allocCount = 0;
1877 quint64 usedBytes = 0;
1878 quint64 unusedBytes = 0;
1880 quint64 totalUsageBytes = 0;
1885#ifndef QT_NO_DEBUG_STREAM
1886Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiStats &);
1892 virtual ~QRhiAdapter();
1893 virtual QRhiDriverInfo info()
const = 0;
1903 enum Implementation {
1913 EnableDebugMarkers = 1 << 0,
1914 PreferSoftwareRenderer = 1 << 1,
1915 EnablePipelineCacheDataSave = 1 << 2,
1916 EnableTimestamps = 1 << 3,
1917 SuppressSmokeTestWarnings = 1 << 4
1919 Q_DECLARE_FLAGS(Flags, Flag)
1921 enum FrameOpResult {
1924 FrameOpSwapChainOutOfDate,
1929 MultisampleTexture = 1,
1930 MultisampleRenderBuffer,
1934 CustomInstanceStepRate,
1936 NonDynamicUniformBuffers,
1937 NonFourAlignedEffectiveIndexBufferOffset,
1943 VertexShaderPointSize,
1946 TriangleFanTopology,
1947 ReadBackNonUniformBuffer,
1948 ReadBackNonBaseMipLevel,
1950 RenderToNonBaseMipLevel,
1952 ScreenSpaceDerivatives,
1953 ReadBackAnyTextureFormat,
1954 PipelineCacheDataLoadSave,
1957 ThreeDimensionalTextures,
1958 RenderTo3DTextureSlice,
1964 OneDimensionalTextures,
1965 OneDimensionalTextureMipmaps,
1967 RenderToOneDimensionalTexture,
1968 ThreeDimensionalTextureMipmaps,
1971 ResolveDepthStencil,
1972 VariableRateShading,
1973 VariableRateShadingMap,
1974 VariableRateShadingMapWithTexture,
1975 PerRenderTargetBlending,
1977 InstanceIndexIncludesBaseInstance,
1981 ShaderDrawParameters,
1984 enum BeginFrameFlag {
1986 Q_DECLARE_FLAGS(BeginFrameFlags, BeginFrameFlag)
1989 SkipPresent = 1 << 0
1991 Q_DECLARE_FLAGS(EndFrameFlags, EndFrameFlag)
1993 enum ResourceLimit {
1996 MaxColorAttachments,
1998 MaxAsyncReadbackFrames,
1999 MaxThreadGroupsPerDimension,
2000 MaxThreadsPerThreadGroup,
2004 TextureArraySizeMax,
2005 MaxUniformBufferRange,
2008 ShadingRateImageTileSize
2013 static QRhi *create(Implementation impl,
2014 QRhiInitParams *params,
2016 QRhiNativeHandles *importDevice =
nullptr);
2017 static QRhi *create(Implementation impl,
2018 QRhiInitParams *params,
2020 QRhiNativeHandles *importDevice,
2021 QRhiAdapter *adapter);
2022 static bool probe(Implementation impl, QRhiInitParams *params);
2023 using AdapterList = QVector<QRhiAdapter *>;
2024 static AdapterList enumerateAdapters(Implementation impl,
2025 QRhiInitParams *params,
2026 QRhiNativeHandles *nativeHandles =
nullptr);
2028 Implementation backend()
const;
2029 const char *backendName()
const;
2030 static const char *backendName(Implementation impl);
2031 QRhiDriverInfo driverInfo()
const;
2032 QThread *thread()
const;
2034 using CleanupCallback = std::function<
void(QRhi *)>;
2035 void addCleanupCallback(
const CleanupCallback &callback);
2036 void addCleanupCallback(
const void *key,
const CleanupCallback &callback);
2037 void removeCleanupCallback(
const void *key);
2039 QRhiGraphicsPipeline *newGraphicsPipeline();
2040 QRhiComputePipeline *newComputePipeline();
2041 QRhiShaderResourceBindings *newShaderResourceBindings();
2043 QRhiBuffer *newBuffer(QRhiBuffer::Type type,
2044 QRhiBuffer::UsageFlags usage,
2047 QRhiRenderBuffer *newRenderBuffer(QRhiRenderBuffer::Type type,
2048 const QSize &pixelSize,
2049 int sampleCount = 1,
2050 QRhiRenderBuffer::Flags flags = {},
2051 QRhiTexture::Format backingFormatHint = QRhiTexture::UnknownFormat);
2053 QRhiTexture *newTexture(QRhiTexture::Format format,
2054 const QSize &pixelSize,
2055 int sampleCount = 1,
2056 QRhiTexture::Flags flags = {});
2058 QRhiTexture *newTexture(QRhiTexture::Format format,
2059 int width,
int height,
int depth,
2060 int sampleCount = 1,
2061 QRhiTexture::Flags flags = {});
2063 QRhiTexture *newTextureArray(QRhiTexture::Format format,
2065 const QSize &pixelSize,
2066 int sampleCount = 1,
2067 QRhiTexture::Flags flags = {});
2069 QRhiSampler *newSampler(QRhiSampler::Filter magFilter,
2070 QRhiSampler::Filter minFilter,
2071 QRhiSampler::Filter mipmapMode,
2072 QRhiSampler::AddressMode addressU,
2073 QRhiSampler::AddressMode addressV,
2074 QRhiSampler::AddressMode addressW = QRhiSampler::Repeat);
2076 QRhiShadingRateMap *newShadingRateMap();
2078 QRhiTextureRenderTarget *newTextureRenderTarget(
const QRhiTextureRenderTargetDescription &desc,
2079 QRhiTextureRenderTarget::Flags flags = {});
2081 QRhiSwapChain *newSwapChain();
2082 FrameOpResult beginFrame(QRhiSwapChain *swapChain, BeginFrameFlags flags = {});
2083 FrameOpResult endFrame(QRhiSwapChain *swapChain, EndFrameFlags flags = {});
2084 bool isRecordingFrame()
const;
2085 int currentFrameSlot()
const;
2087 FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb, BeginFrameFlags flags = {});
2088 FrameOpResult endOffscreenFrame(EndFrameFlags flags = {});
2090 QRhi::FrameOpResult finish();
2092 QRhiResourceUpdateBatch *nextResourceUpdateBatch();
2094 QList<
int> supportedSampleCounts()
const;
2096 int ubufAlignment()
const;
2097 int ubufAligned(
int v)
const;
2099 static int mipLevelsForSize(
const QSize &size);
2100 static QSize sizeForMipLevel(
int mipLevel,
const QSize &baseLevelSize);
2102 bool isYUpInFramebuffer()
const;
2103 bool isYUpInNDC()
const;
2104 bool isClipDepthZeroToOne()
const;
2106 QMatrix4x4 clipSpaceCorrMatrix()
const;
2108 bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags = {})
const;
2109 bool isFeatureSupported(QRhi::Feature feature)
const;
2110 int resourceLimit(ResourceLimit limit)
const;
2112 const QRhiNativeHandles *nativeHandles();
2113 bool makeThreadLocalNativeContextCurrent();
2114 void setQueueSubmitParams(QRhiNativeHandles *params);
2116 static constexpr int MAX_MIP_LEVELS = 16;
2118 void releaseCachedResources();
2120 bool isDeviceLost()
const;
2122 QByteArray pipelineCacheData();
2123 void setPipelineCacheData(
const QByteArray &data);
2125 QRhiStats statistics()
const;
2127 static QRhiSwapChainProxyData updateSwapChainProxyData(Implementation impl, QWindow *window);
2129 QList<QSize> supportedShadingRates(
int sampleCount)
const;
2135 Q_DISABLE_COPY(QRhi)
2136 QRhiImplementation *d =
nullptr;
2139Q_DECLARE_OPERATORS_FOR_FLAGS(QRhi::Flags)
2140Q_DECLARE_OPERATORS_FOR_FLAGS(QRhi::BeginFrameFlags)
2141Q_DECLARE_OPERATORS_FOR_FLAGS(QRhi::EndFrameFlags)
2145#include <rhi/qrhi_platform.h>
friend bool operator==(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
Returns true if lhs and rhs are equal, otherwise returns false.
friend bool operator!=(const QByteArray::FromBase64Result &lhs, const QByteArray::FromBase64Result &rhs) noexcept
Returns true if lhs and rhs are different, otherwise returns false.
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\variable QRhiIndexedIndirectDrawCommand::indexCount
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
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)
Q_DECLARE_TYPEINFO(QRhiSwapChainHdrInfo, Q_RELOCATABLE_TYPE)
int main(int argc, char *argv[])
[ctor_close]
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\variable QRhiIndirectDrawCommand::vertexCount
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\variable QRhiReadbackResult::completed
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h
LuminanceBehavior
\value SceneReferred Indicates that the color value of 1.0 is interpreted as 80 nits.
float maxPotentialColorComponentValue
LimitsType
\value LuminanceInNits Indicates that the \l limits union has its luminanceInNits struct set
LuminanceBehavior luminanceBehavior
float maxColorComponentValue
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h