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>
27#include <rhi/qshader.h>
33class QRhiImplementation;
35class QRhiRenderBuffer;
38class QRhiCommandBuffer;
39class QRhiResourceUpdateBatch;
42class QRhiShadingRateMap;
47 QRhiDepthStencilClearValue() =
default;
48 QRhiDepthStencilClearValue(
float d, quint32 s);
50 float depthClearValue()
const {
return m_d; }
51 void setDepthClearValue(
float d) { m_d = d; }
53 quint32 stencilClearValue()
const {
return m_s; }
54 void setStencilClearValue(quint32 s) { m_s = s; }
60 friend bool operator==(
const QRhiDepthStencilClearValue &a,
const QRhiDepthStencilClearValue &b)
noexcept
62 return a.m_d == b.m_d && a.m_s == b.m_s;
65 friend bool operator!=(
const QRhiDepthStencilClearValue &a,
const QRhiDepthStencilClearValue &b)
noexcept
70 friend size_t qHash(
const QRhiDepthStencilClearValue &v, size_t seed = 0)
noexcept
72 QtPrivate::QHashCombine hash(seed);
73 seed = hash(seed, v.m_d);
74 seed = hash(seed, v.m_s);
81#ifndef QT_NO_DEBUG_STREAM
82Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiDepthStencilClearValue &);
88 QRhiViewport() =
default;
89 QRhiViewport(
float x,
float y,
float w,
float h,
float minDepth = 0.0f,
float maxDepth = 1.0f);
91 std::array<
float, 4> viewport()
const {
return m_rect; }
92 void setViewport(
float x,
float y,
float w,
float h) {
93 m_rect[0] = x; m_rect[1] = y; m_rect[2] = w; m_rect[3] = h;
96 float minDepth()
const {
return m_minDepth; }
97 void setMinDepth(
float minDepth) { m_minDepth = minDepth; }
99 float maxDepth()
const {
return m_maxDepth; }
100 void setMaxDepth(
float maxDepth) { m_maxDepth = maxDepth; }
103 std::array<
float, 4> m_rect { { 0.0f, 0.0f, 0.0f, 0.0f } };
104 float m_minDepth = 0.0f;
105 float m_maxDepth = 1.0f;
107 friend bool operator==(
const QRhiViewport &a,
const QRhiViewport &b)
noexcept
109 return a.m_rect == b.m_rect
110 && a.m_minDepth == b.m_minDepth
111 && a.m_maxDepth == b.m_maxDepth;
114 friend bool operator!=(
const QRhiViewport &a,
const QRhiViewport &b)
noexcept
119 friend size_t qHash(
const QRhiViewport &v, size_t seed = 0)
noexcept
121 QtPrivate::QHashCombine hash(seed);
122 seed = hash(seed, v.m_rect[0]);
123 seed = hash(seed, v.m_rect[1]);
124 seed = hash(seed, v.m_rect[2]);
125 seed = hash(seed, v.m_rect[3]);
126 seed = hash(seed, v.m_minDepth);
127 seed = hash(seed, v.m_maxDepth);
134#ifndef QT_NO_DEBUG_STREAM
135Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiViewport &);
141 QRhiScissor() =
default;
142 QRhiScissor(
int x,
int y,
int w,
int h);
144 std::array<
int, 4> scissor()
const {
return m_rect; }
145 void setScissor(
int x,
int y,
int w,
int h) {
146 m_rect[0] = x; m_rect[1] = y; m_rect[2] = w; m_rect[3] = h;
150 std::array<
int, 4> m_rect { { 0, 0, 0, 0 } };
152 friend bool operator==(
const QRhiScissor &a,
const QRhiScissor &b)
noexcept
154 return a.m_rect == b.m_rect;
157 friend bool operator!=(
const QRhiScissor &a,
const QRhiScissor &b)
noexcept
162 friend size_t qHash(
const QRhiScissor &v, size_t seed = 0)
noexcept
164 QtPrivate::QHashCombine hash(seed);
165 seed = hash(seed, v.m_rect[0]);
166 seed = hash(seed, v.m_rect[1]);
167 seed = hash(seed, v.m_rect[2]);
168 seed = hash(seed, v.m_rect[3]);
175#ifndef QT_NO_DEBUG_STREAM
176Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiScissor &);
182 enum Classification {
187 QRhiVertexInputBinding() =
default;
188 QRhiVertexInputBinding(quint32 stride, Classification cls = PerVertex, quint32 stepRate = 1);
190 quint32 stride()
const {
return m_stride; }
191 void setStride(quint32 s) { m_stride = s; }
193 Classification classification()
const {
return m_classification; }
194 void setClassification(Classification c) { m_classification = c; }
196 quint32 instanceStepRate()
const {
return m_instanceStepRate; }
197 void setInstanceStepRate(quint32 rate) { m_instanceStepRate = rate; }
200 quint32 m_stride = 0;
201 Classification m_classification = PerVertex;
202 quint32 m_instanceStepRate = 1;
204 friend bool operator==(
const QRhiVertexInputBinding &a,
const QRhiVertexInputBinding &b)
noexcept
206 return a.m_stride == b.m_stride
207 && a.m_classification == b.m_classification
208 && a.m_instanceStepRate == b.m_instanceStepRate;
211 friend bool operator!=(
const QRhiVertexInputBinding &a,
const QRhiVertexInputBinding &b)
noexcept
216 friend size_t qHash(
const QRhiVertexInputBinding &v, size_t seed = 0)
noexcept
218 QtPrivate::QHashCombine hash(seed);
219 seed = hash(seed, v.m_stride);
220 seed = hash(seed, v.m_classification);
221 seed = hash(seed, v.m_instanceStepRate);
228#ifndef QT_NO_DEBUG_STREAM
229Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiVertexInputBinding &);
265 QRhiVertexInputAttribute() =
default;
266 QRhiVertexInputAttribute(
int binding,
int location, Format format, quint32 offset,
int matrixSlice = -1);
268 int binding()
const {
return m_binding; }
269 void setBinding(
int b) { m_binding = b; }
271 int location()
const {
return m_location; }
272 void setLocation(
int loc) { m_location = loc; }
274 Format format()
const {
return m_format; }
275 void setFormat(Format f) { m_format = f; }
277 quint32 offset()
const {
return m_offset; }
278 void setOffset(quint32 ofs) { m_offset = ofs; }
280 int matrixSlice()
const {
return m_matrixSlice; }
281 void setMatrixSlice(
int slice) { m_matrixSlice = slice; }
286 Format m_format = Float4;
287 quint32 m_offset = 0;
288 int m_matrixSlice = -1;
290 friend bool operator==(
const QRhiVertexInputAttribute &a,
const QRhiVertexInputAttribute &b)
noexcept
292 return a.m_binding == b.m_binding
293 && a.m_location == b.m_location
294 && a.m_format == b.m_format
295 && a.m_offset == b.m_offset;
299 friend bool operator!=(
const QRhiVertexInputAttribute &a,
const QRhiVertexInputAttribute &b)
noexcept
304 friend size_t qHash(
const QRhiVertexInputAttribute &v, size_t seed = 0)
noexcept
306 QtPrivate::QHashCombine hash(seed);
307 seed = hash(seed, v.m_binding);
308 seed = hash(seed, v.m_location);
309 seed = hash(seed, v.m_format);
310 seed = hash(seed, v.m_offset);
317#ifndef QT_NO_DEBUG_STREAM
318Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiVertexInputAttribute &);
324 QRhiVertexInputLayout() =
default;
326 void setBindings(std::initializer_list<QRhiVertexInputBinding> list) { m_bindings = list; }
327 template<
typename InputIterator>
328 void setBindings(InputIterator first, InputIterator last)
331 std::copy(first, last, std::back_inserter(m_bindings));
333 const QRhiVertexInputBinding *cbeginBindings()
const {
return m_bindings.cbegin(); }
334 const QRhiVertexInputBinding *cendBindings()
const {
return m_bindings.cend(); }
335 const QRhiVertexInputBinding *bindingAt(qsizetype index)
const {
return &m_bindings.at(index); }
336 qsizetype bindingCount()
const {
return m_bindings.count(); }
338 void setAttributes(std::initializer_list<QRhiVertexInputAttribute> list) { m_attributes = list; }
339 template<
typename InputIterator>
340 void setAttributes(InputIterator first, InputIterator last)
342 m_attributes.clear();
343 std::copy(first, last, std::back_inserter(m_attributes));
345 const QRhiVertexInputAttribute *cbeginAttributes()
const {
return m_attributes.cbegin(); }
346 const QRhiVertexInputAttribute *cendAttributes()
const {
return m_attributes.cend(); }
347 const QRhiVertexInputAttribute *attributeAt(qsizetype index)
const {
return &m_attributes.at(index); }
348 qsizetype attributeCount()
const {
return m_attributes.count(); }
351 QVarLengthArray<QRhiVertexInputBinding, 8> m_bindings;
352 QVarLengthArray<QRhiVertexInputAttribute, 8> m_attributes;
354 friend bool operator==(
const QRhiVertexInputLayout &a,
const QRhiVertexInputLayout &b)
noexcept
356 return a.m_bindings == b.m_bindings && a.m_attributes == b.m_attributes;
359 friend bool operator!=(
const QRhiVertexInputLayout &a,
const QRhiVertexInputLayout &b)
noexcept
364 friend size_t qHash(
const QRhiVertexInputLayout &v, size_t seed = 0)
noexcept
366 QtPrivate::QHashCombine hash(seed);
367 seed = hash(seed, v.m_bindings);
368 seed = hash(seed, v.m_attributes);
372 friend Q_GUI_EXPORT QDebug operator<<(QDebug,
const QRhiVertexInputLayout &);
375#ifndef QT_NO_DEBUG_STREAM
376Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiVertexInputLayout &);
385 TessellationEvaluation,
391 QRhiShaderStage() =
default;
392 QRhiShaderStage(Type type,
const QShader &shader,
393 QShader::Variant v = QShader::StandardShader);
395 Type type()
const {
return m_type; }
396 void setType(Type t) { m_type = t; }
398 QShader shader()
const {
return m_shader; }
399 void setShader(
const QShader &s) { m_shader = s; }
401 QShader::Variant shaderVariant()
const {
return m_shaderVariant; }
402 void setShaderVariant(QShader::Variant v) { m_shaderVariant = v; }
405 Type m_type = Vertex;
407 QShader::Variant m_shaderVariant = QShader::StandardShader;
409 friend bool operator==(
const QRhiShaderStage &a,
const QRhiShaderStage &b)
noexcept
411 return a.m_type == b.m_type
412 && a.m_shader == b.m_shader
413 && a.m_shaderVariant == b.m_shaderVariant;
416 friend bool operator!=(
const QRhiShaderStage &a,
const QRhiShaderStage &b)
noexcept
421 friend size_t qHash(
const QRhiShaderStage &v, size_t seed = 0)
noexcept
423 QtPrivate::QHashCombine hash(seed);
424 seed = hash(seed, v.m_type);
425 seed = hash(seed, v.m_shader);
426 seed = hash(seed, v.m_shaderVariant);
433#ifndef QT_NO_DEBUG_STREAM
434Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiShaderStage &);
437using QRhiGraphicsShaderStage = QRhiShaderStage;
456 VertexStage = 1 << 0,
457 TessellationControlStage = 1 << 1,
458 TessellationEvaluationStage = 1 << 2,
459 GeometryStage = 1 << 3,
460 FragmentStage = 1 << 4,
461 ComputeStage = 1 << 5
463 Q_DECLARE_FLAGS(StageFlags, StageFlag)
465 QRhiShaderResourceBinding() =
default;
467 bool isLayoutCompatible(
const QRhiShaderResourceBinding &other)
const;
469 static QRhiShaderResourceBinding uniformBuffer(
int binding, StageFlags stage, QRhiBuffer *buf);
470 static QRhiShaderResourceBinding uniformBuffer(
int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size);
471 static QRhiShaderResourceBinding uniformBufferWithDynamicOffset(
int binding, StageFlags stage, QRhiBuffer *buf, quint32 size);
473 static QRhiShaderResourceBinding sampledTexture(
int binding, StageFlags stage, QRhiTexture *tex, QRhiSampler *sampler);
475 struct TextureAndSampler {
477 QRhiSampler *sampler;
479 static QRhiShaderResourceBinding sampledTextures(
int binding, StageFlags stage,
int count,
const TextureAndSampler *texSamplers);
481 static QRhiShaderResourceBinding texture(
int binding, StageFlags stage, QRhiTexture *tex);
482 static QRhiShaderResourceBinding textures(
int binding, StageFlags stage,
int count, QRhiTexture **tex);
483 static QRhiShaderResourceBinding sampler(
int binding, StageFlags stage, QRhiSampler *sampler);
485 static QRhiShaderResourceBinding imageLoad(
int binding, StageFlags stage, QRhiTexture *tex,
int level);
486 static QRhiShaderResourceBinding imageStore(
int binding, StageFlags stage, QRhiTexture *tex,
int level);
487 static QRhiShaderResourceBinding imageLoadStore(
int binding, StageFlags stage, QRhiTexture *tex,
int level);
489 static QRhiShaderResourceBinding bufferLoad(
int binding, StageFlags stage, QRhiBuffer *buf);
490 static QRhiShaderResourceBinding bufferLoad(
int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size);
491 static QRhiShaderResourceBinding bufferStore(
int binding, StageFlags stage, QRhiBuffer *buf);
492 static QRhiShaderResourceBinding bufferStore(
int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size);
493 static QRhiShaderResourceBinding bufferLoadStore(
int binding, StageFlags stage, QRhiBuffer *buf);
494 static QRhiShaderResourceBinding bufferLoadStore(
int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size);
499 QRhiShaderResourceBinding::StageFlags stage;
500 QRhiShaderResourceBinding::Type type;
501 struct UniformBufferData {
505 bool hasDynamicOffset;
507 static constexpr int MAX_TEX_SAMPLER_ARRAY_SIZE = 16;
508 struct TextureAndOrSamplerData {
510 TextureAndSampler texSamplers[MAX_TEX_SAMPLER_ARRAY_SIZE];
512 struct StorageImageData {
516 struct StorageBufferData {
522 UniformBufferData ubuf;
523 TextureAndOrSamplerData stex;
524 StorageImageData simage;
525 StorageBufferData sbuf;
528 int arraySize()
const
530 return type == QRhiShaderResourceBinding::SampledTexture || type == QRhiShaderResourceBinding::Texture
535 template<
typename Output>
536 Output serialize(Output dst)
const
539 *dst++ = quint32(binding);
540 *dst++ = quint32(stage);
541 *dst++ = quint32(type);
542 *dst++ = quint32(arraySize());
547 static constexpr int LAYOUT_DESC_ENTRIES_PER_BINDING = 4;
549 template<
typename Output>
550 static void serializeLayoutDescription(
const QRhiShaderResourceBinding *first,
551 const QRhiShaderResourceBinding *last,
554 while (first != last) {
555 dst = first->d.serialize(dst);
562 friend class QRhiImplementation;
565Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiShaderResourceBinding::StageFlags)
567Q_DECLARE_TYPEINFO(QRhiShaderResourceBinding, Q_PRIMITIVE_TYPE);
569Q_GUI_EXPORT
bool operator==(
const QRhiShaderResourceBinding &a,
const QRhiShaderResourceBinding &b)
noexcept;
570Q_GUI_EXPORT
bool operator!=(
const QRhiShaderResourceBinding &a,
const QRhiShaderResourceBinding &b)
noexcept;
571Q_GUI_EXPORT size_t qHash(
const QRhiShaderResourceBinding &b, size_t seed = 0)
noexcept;
572#ifndef QT_NO_DEBUG_STREAM
573Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiShaderResourceBinding &);
579 QRhiColorAttachment() =
default;
580 QRhiColorAttachment(QRhiTexture *texture);
581 QRhiColorAttachment(QRhiRenderBuffer *renderBuffer);
583 QRhiTexture *texture()
const {
return m_texture; }
584 void setTexture(QRhiTexture *tex) { m_texture = tex; }
586 QRhiRenderBuffer *renderBuffer()
const {
return m_renderBuffer; }
587 void setRenderBuffer(QRhiRenderBuffer *rb) { m_renderBuffer = rb; }
589 int layer()
const {
return m_layer; }
590 void setLayer(
int layer) { m_layer = layer; }
592 int level()
const {
return m_level; }
593 void setLevel(
int level) { m_level = level; }
595 QRhiTexture *resolveTexture()
const {
return m_resolveTexture; }
596 void setResolveTexture(QRhiTexture *tex) { m_resolveTexture = tex; }
598 int resolveLayer()
const {
return m_resolveLayer; }
599 void setResolveLayer(
int layer) { m_resolveLayer = layer; }
601 int resolveLevel()
const {
return m_resolveLevel; }
602 void setResolveLevel(
int level) { m_resolveLevel = level; }
604 int multiViewCount()
const {
return m_multiViewCount; }
605 void setMultiViewCount(
int count) { m_multiViewCount = count; }
608 QRhiTexture *m_texture =
nullptr;
609 QRhiRenderBuffer *m_renderBuffer =
nullptr;
612 QRhiTexture *m_resolveTexture =
nullptr;
613 int m_resolveLayer = 0;
614 int m_resolveLevel = 0;
615 int m_multiViewCount = 0;
623 QRhiTextureRenderTargetDescription() =
default;
624 QRhiTextureRenderTargetDescription(
const QRhiColorAttachment &colorAttachment);
625 QRhiTextureRenderTargetDescription(
const QRhiColorAttachment &colorAttachment, QRhiRenderBuffer *depthStencilBuffer);
626 QRhiTextureRenderTargetDescription(
const QRhiColorAttachment &colorAttachment, QRhiTexture *depthTexture);
628 void setColorAttachments(std::initializer_list<QRhiColorAttachment> list) { m_colorAttachments = list; }
629 template<
typename InputIterator>
630 void setColorAttachments(InputIterator first, InputIterator last)
632 m_colorAttachments.clear();
633 std::copy(first, last, std::back_inserter(m_colorAttachments));
635 const QRhiColorAttachment *cbeginColorAttachments()
const {
return m_colorAttachments.cbegin(); }
636 const QRhiColorAttachment *cendColorAttachments()
const {
return m_colorAttachments.cend(); }
637 const QRhiColorAttachment *colorAttachmentAt(qsizetype index)
const {
return &m_colorAttachments.at(index); }
638 qsizetype colorAttachmentCount()
const {
return m_colorAttachments.count(); }
640 QRhiRenderBuffer *depthStencilBuffer()
const {
return m_depthStencilBuffer; }
641 void setDepthStencilBuffer(QRhiRenderBuffer *renderBuffer) { m_depthStencilBuffer = renderBuffer; }
643 QRhiTexture *depthTexture()
const {
return m_depthTexture; }
644 void setDepthTexture(QRhiTexture *texture) { m_depthTexture = texture; }
646 QRhiTexture *depthResolveTexture()
const {
return m_depthResolveTexture; }
647 void setDepthResolveTexture(QRhiTexture *tex) { m_depthResolveTexture = tex; }
649 QRhiShadingRateMap *shadingRateMap()
const {
return m_shadingRateMap; }
650 void setShadingRateMap(QRhiShadingRateMap *map) { m_shadingRateMap = map; }
653 QVarLengthArray<QRhiColorAttachment, 8> m_colorAttachments;
654 QRhiRenderBuffer *m_depthStencilBuffer =
nullptr;
655 QRhiTexture *m_depthTexture =
nullptr;
656 QRhiTexture *m_depthResolveTexture =
nullptr;
657 QRhiShadingRateMap *m_shadingRateMap =
nullptr;
663 QRhiTextureSubresourceUploadDescription() =
default;
664 explicit QRhiTextureSubresourceUploadDescription(
const QImage &image);
665 QRhiTextureSubresourceUploadDescription(
const void *data, quint32 size);
666 explicit QRhiTextureSubresourceUploadDescription(
const QByteArray &data);
668 QImage image()
const {
return m_image; }
669 void setImage(
const QImage &image) { m_image = image; }
671 QByteArray data()
const {
return m_data; }
672 void setData(
const QByteArray &data) { m_data = data; }
674 quint32 dataStride()
const {
return m_dataStride; }
675 void setDataStride(quint32 stride) { m_dataStride = stride; }
677 QPoint destinationTopLeft()
const {
return m_destinationTopLeft; }
678 void setDestinationTopLeft(
const QPoint &p) { m_destinationTopLeft = p; }
680 QSize sourceSize()
const {
return m_sourceSize; }
681 void setSourceSize(
const QSize &size) { m_sourceSize = size; }
683 QPoint sourceTopLeft()
const {
return m_sourceTopLeft; }
684 void setSourceTopLeft(
const QPoint &p) { m_sourceTopLeft = p; }
689 quint32 m_dataStride = 0;
690 QPoint m_destinationTopLeft;
692 QPoint m_sourceTopLeft;
700 QRhiTextureUploadEntry() =
default;
701 QRhiTextureUploadEntry(
int layer,
int level,
const QRhiTextureSubresourceUploadDescription &desc);
703 int layer()
const {
return m_layer; }
704 void setLayer(
int layer) { m_layer = layer; }
706 int level()
const {
return m_level; }
707 void setLevel(
int level) { m_level = level; }
709 QRhiTextureSubresourceUploadDescription description()
const {
return m_desc; }
710 void setDescription(
const QRhiTextureSubresourceUploadDescription &desc) { m_desc = desc; }
715 QRhiTextureSubresourceUploadDescription m_desc;
723 QRhiTextureUploadDescription() =
default;
724 QRhiTextureUploadDescription(
const QRhiTextureUploadEntry &entry);
725 QRhiTextureUploadDescription(std::initializer_list<QRhiTextureUploadEntry> list);
727 void setEntries(std::initializer_list<QRhiTextureUploadEntry> list) { m_entries = list; }
728 template<
typename InputIterator>
729 void setEntries(InputIterator first, InputIterator last)
732 std::copy(first, last, std::back_inserter(m_entries));
734 const QRhiTextureUploadEntry *cbeginEntries()
const {
return m_entries.cbegin(); }
735 const QRhiTextureUploadEntry *cendEntries()
const {
return m_entries.cend(); }
736 const QRhiTextureUploadEntry *entryAt(qsizetype index)
const {
return &m_entries.at(index); }
737 qsizetype entryCount()
const {
return m_entries.count(); }
740 QVarLengthArray<QRhiTextureUploadEntry, 16> m_entries;
746 QRhiTextureCopyDescription() =
default;
748 QSize pixelSize()
const {
return m_pixelSize; }
749 void setPixelSize(
const QSize &sz) { m_pixelSize = sz; }
751 int sourceLayer()
const {
return m_sourceLayer; }
752 void setSourceLayer(
int layer) { m_sourceLayer = layer; }
754 int sourceLevel()
const {
return m_sourceLevel; }
755 void setSourceLevel(
int level) { m_sourceLevel = level; }
757 QPoint sourceTopLeft()
const {
return m_sourceTopLeft; }
758 void setSourceTopLeft(
const QPoint &p) { m_sourceTopLeft = p; }
760 int destinationLayer()
const {
return m_destinationLayer; }
761 void setDestinationLayer(
int layer) { m_destinationLayer = layer; }
763 int destinationLevel()
const {
return m_destinationLevel; }
764 void setDestinationLevel(
int level) { m_destinationLevel = level; }
766 QPoint destinationTopLeft()
const {
return m_destinationTopLeft; }
767 void setDestinationTopLeft(
const QPoint &p) { m_destinationTopLeft = p; }
771 int m_sourceLayer = 0;
772 int m_sourceLevel = 0;
773 QPoint m_sourceTopLeft;
774 int m_destinationLayer = 0;
775 int m_destinationLevel = 0;
776 QPoint m_destinationTopLeft;
784 QRhiReadbackDescription() =
default;
785 QRhiReadbackDescription(QRhiTexture *texture);
787 QRhiTexture *texture()
const {
return m_texture; }
788 void setTexture(QRhiTexture *tex) { m_texture = tex; }
790 int layer()
const {
return m_layer; }
791 void setLayer(
int layer) { m_layer = layer; }
793 int level()
const {
return m_level; }
794 void setLevel(
int level) { m_level = level; }
796 QRect rect()
const {
return m_rect; }
797 void setRect(
const QRect &rectangle) { m_rect = rectangle; }
800 QRhiTexture *m_texture =
nullptr;
820 RenderPassDescriptor,
821 SwapChainRenderTarget,
823 ShaderResourceBindings,
831 virtual ~QRhiResource();
833 virtual Type resourceType()
const = 0;
835 virtual void destroy() = 0;
839 QByteArray name()
const;
840 void setName(
const QByteArray &name);
842 quint64 globalResourceId()
const;
847 QRhiResource(QRhiImplementation *rhi);
848 Q_DISABLE_COPY(QRhiResource)
849 friend class QRhiImplementation;
850 QRhiImplementation *m_rhi =
nullptr;
852 QByteArray m_objectName;
865 VertexBuffer = 1 << 0,
866 IndexBuffer = 1 << 1,
867 UniformBuffer = 1 << 2,
868 StorageBuffer = 1 << 3
870 Q_DECLARE_FLAGS(UsageFlags, UsageFlag)
872 struct NativeBuffer {
873 const void *objects[3];
877 QRhiResource::Type resourceType()
const override;
879 Type type()
const {
return m_type; }
880 void setType(Type t) { m_type = t; }
882 UsageFlags usage()
const {
return m_usage; }
883 void setUsage(UsageFlags u) { m_usage = u; }
885 quint32 size()
const {
return m_size; }
886 void setSize(quint32 sz) { m_size = sz; }
888 virtual bool create() = 0;
890 virtual NativeBuffer nativeBuffer();
892 virtual char *beginFullDynamicBufferUpdateForCurrentFrame();
893 virtual void endFullDynamicBufferUpdateForCurrentFrame();
894 virtual void fullDynamicBufferUpdateForCurrentFrame(
const void *data, quint32 size = 0);
897 QRhiBuffer(QRhiImplementation *rhi, Type type_, UsageFlags usage_, quint32 size_);
903Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiBuffer::UsageFlags)
905class Q_GUI_EXPORT QRhiTexture :
public QRhiResource
909 RenderTarget = 1 << 0,
913 UsedAsTransferSource = 1 << 5,
914 UsedWithGenerateMips = 1 << 6,
915 UsedWithLoadStore = 1 << 7,
916 UsedAsCompressedAtlas = 1 << 8,
917 ExternalOES = 1 << 9,
918 ThreeDimensional = 1 << 10,
919 TextureRectangleGL = 1 << 11,
920 TextureArray = 1 << 12,
921 OneDimensional = 1 << 13,
922 UsedAsShadingRateMap = 1 << 14
924 Q_DECLARE_FLAGS(Flags, Flag)
988 struct NativeTexture {
993 QRhiResource::Type resourceType()
const override;
995 Format format()
const {
return m_format; }
996 void setFormat(Format fmt) { m_format = fmt; }
998 QSize pixelSize()
const {
return m_pixelSize; }
999 void setPixelSize(
const QSize &sz) { m_pixelSize = sz; }
1001 int depth()
const {
return m_depth; }
1002 void setDepth(
int depth) { m_depth = depth; }
1004 int arraySize()
const {
return m_arraySize; }
1005 void setArraySize(
int arraySize) { m_arraySize = arraySize; }
1007 int arrayRangeStart()
const {
return m_arrayRangeStart; }
1008 int arrayRangeLength()
const {
return m_arrayRangeLength; }
1009 void setArrayRange(
int startIndex,
int count)
1011 m_arrayRangeStart = startIndex;
1012 m_arrayRangeLength = count;
1015 Flags flags()
const {
return m_flags; }
1016 void setFlags(Flags f) { m_flags = f; }
1018 int sampleCount()
const {
return m_sampleCount; }
1019 void setSampleCount(
int s) { m_sampleCount = s; }
1022 QRhiTexture::Format format;
1025 ViewFormat readViewFormat()
const {
return m_readViewFormat; }
1026 void setReadViewFormat(
const ViewFormat &fmt) { m_readViewFormat = fmt; }
1027 ViewFormat writeViewFormat()
const {
return m_writeViewFormat; }
1028 void setWriteViewFormat(
const ViewFormat &fmt) { m_writeViewFormat = fmt; }
1030 virtual bool create() = 0;
1031 virtual NativeTexture nativeTexture();
1032 virtual bool createFrom(NativeTexture src);
1033 virtual void setNativeLayout(
int layout);
1036 QRhiTexture(QRhiImplementation *rhi, Format format_,
const QSize &pixelSize_,
int depth_,
1037 int arraySize_,
int sampleCount_, Flags flags_);
1044 int m_arrayRangeStart = -1;
1045 int m_arrayRangeLength = -1;
1046 ViewFormat m_readViewFormat = { UnknownFormat,
false };
1047 ViewFormat m_writeViewFormat = { UnknownFormat,
false };
1050Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiTexture::Flags)
1052class Q_GUI_EXPORT QRhiSampler :
public QRhiResource
1078 QRhiResource::Type resourceType()
const override;
1080 Filter magFilter()
const {
return m_magFilter; }
1081 void setMagFilter(Filter f) { m_magFilter = f; }
1083 Filter minFilter()
const {
return m_minFilter; }
1084 void setMinFilter(Filter f) { m_minFilter = f; }
1086 Filter mipmapMode()
const {
return m_mipmapMode; }
1087 void setMipmapMode(Filter f) { m_mipmapMode = f; }
1089 AddressMode addressU()
const {
return m_addressU; }
1090 void setAddressU(AddressMode mode) { m_addressU = mode; }
1092 AddressMode addressV()
const {
return m_addressV; }
1093 void setAddressV(AddressMode mode) { m_addressV = mode; }
1095 AddressMode addressW()
const {
return m_addressW; }
1096 void setAddressW(AddressMode mode) { m_addressW = mode; }
1098 CompareOp textureCompareOp()
const {
return m_compareOp; }
1099 void setTextureCompareOp(CompareOp op) { m_compareOp = op; }
1101 virtual bool create() = 0;
1104 QRhiSampler(QRhiImplementation *rhi,
1105 Filter magFilter_, Filter minFilter_, Filter mipmapMode_,
1106 AddressMode u_, AddressMode v_, AddressMode w_);
1109 Filter m_mipmapMode;
1110 AddressMode m_addressU;
1111 AddressMode m_addressV;
1112 AddressMode m_addressW;
1113 CompareOp m_compareOp;
1125 UsedWithSwapChainOnly = 1 << 0
1127 Q_DECLARE_FLAGS(Flags, Flag)
1129 struct NativeRenderBuffer {
1133 QRhiResource::Type resourceType()
const override;
1135 Type type()
const {
return m_type; }
1136 void setType(Type t) { m_type = t; }
1138 QSize pixelSize()
const {
return m_pixelSize; }
1139 void setPixelSize(
const QSize &sz) { m_pixelSize = sz; }
1141 int sampleCount()
const {
return m_sampleCount; }
1142 void setSampleCount(
int s) { m_sampleCount = s; }
1144 Flags flags()
const {
return m_flags; }
1145 void setFlags(Flags f) { m_flags = f; }
1147 virtual bool create() = 0;
1148 virtual bool createFrom(NativeRenderBuffer src);
1150 virtual QRhiTexture::Format backingFormat()
const = 0;
1153 QRhiRenderBuffer(QRhiImplementation *rhi, Type type_,
const QSize &pixelSize_,
1154 int sampleCount_, Flags flags_, QRhiTexture::Format backingFormatHint_);
1159 QRhiTexture::Format m_backingFormatHint;
1162Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiRenderBuffer::Flags)
1164class Q_GUI_EXPORT QRhiShadingRateMap :
public QRhiResource
1167 struct NativeShadingRateMap {
1171 QRhiResource::Type resourceType()
const override;
1173 virtual bool createFrom(NativeShadingRateMap src);
1174 virtual bool createFrom(QRhiTexture *src);
1177 QRhiShadingRateMap(QRhiImplementation *rhi);
1183 QRhiResource::Type resourceType()
const override;
1185 virtual bool isCompatible(
const QRhiRenderPassDescriptor *other)
const = 0;
1186 virtual const QRhiNativeHandles *nativeHandles();
1188 virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor()
const = 0;
1190 virtual QVector<quint32> serializedFormat()
const = 0;
1193 QRhiRenderPassDescriptor(QRhiImplementation *rhi);
1199 virtual QSize pixelSize()
const = 0;
1200 virtual float devicePixelRatio()
const = 0;
1201 virtual int sampleCount()
const = 0;
1203 QRhiRenderPassDescriptor *renderPassDescriptor()
const {
return m_renderPassDesc; }
1204 void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; }
1207 QRhiRenderTarget(QRhiImplementation *rhi);
1208 QRhiRenderPassDescriptor *m_renderPassDesc =
nullptr;
1214 QRhiResource::Type resourceType()
const override;
1215 QRhiSwapChain *swapChain()
const {
return m_swapchain; }
1218 QRhiSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain_);
1219 QRhiSwapChain *m_swapchain;
1226 PreserveColorContents = 1 << 0,
1227 PreserveDepthStencilContents = 1 << 1,
1228 DoNotStoreDepthStencilContents = 1 << 2
1230 Q_DECLARE_FLAGS(Flags, Flag)
1232 QRhiResource::Type resourceType()
const override;
1234 QRhiTextureRenderTargetDescription description()
const {
return m_desc; }
1235 void setDescription(
const QRhiTextureRenderTargetDescription &desc) { m_desc = desc; }
1237 Flags flags()
const {
return m_flags; }
1238 void setFlags(Flags f) { m_flags = f; }
1240 virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() = 0;
1242 virtual bool create() = 0;
1245 QRhiTextureRenderTarget(QRhiImplementation *rhi,
const QRhiTextureRenderTargetDescription &desc_, Flags flags_);
1246 QRhiTextureRenderTargetDescription m_desc;
1250Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiTextureRenderTarget::Flags)
1252class Q_GUI_EXPORT QRhiShaderResourceBindings :
public QRhiResource
1255 QRhiResource::Type resourceType()
const override;
1257 void setBindings(std::initializer_list<QRhiShaderResourceBinding> list) { m_bindings = list; }
1258 template<
typename InputIterator>
1259 void setBindings(InputIterator first, InputIterator last)
1262 std::copy(first, last, std::back_inserter(m_bindings));
1264 const QRhiShaderResourceBinding *cbeginBindings()
const {
return m_bindings.cbegin(); }
1265 const QRhiShaderResourceBinding *cendBindings()
const {
return m_bindings.cend(); }
1266 const QRhiShaderResourceBinding *bindingAt(qsizetype index)
const {
return &m_bindings.at(index); }
1267 qsizetype bindingCount()
const {
return m_bindings.count(); }
1269 bool isLayoutCompatible(
const QRhiShaderResourceBindings *other)
const;
1271 QVector<quint32> serializedLayoutDescription()
const {
return m_layoutDesc; }
1273 virtual bool create() = 0;
1276 BindingsAreSorted = 0x01
1278 Q_DECLARE_FLAGS(UpdateFlags, UpdateFlag)
1280 virtual void updateResources(UpdateFlags flags = {}) = 0;
1283 static constexpr int BINDING_PREALLOC = 12;
1284 QRhiShaderResourceBindings(QRhiImplementation *rhi);
1285 QVarLengthArray<QRhiShaderResourceBinding, BINDING_PREALLOC> m_bindings;
1286 size_t m_layoutDescHash = 0;
1290 QVector<quint32> m_layoutDesc;
1291 friend class QRhiImplementation;
1292#ifndef QT_NO_DEBUG_STREAM
1293 friend Q_GUI_EXPORT QDebug operator<<(QDebug,
const QRhiShaderResourceBindings &);
1297Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiShaderResourceBindings::UpdateFlags)
1299#ifndef QT_NO_DEBUG_STREAM
1300Q_GUI_EXPORT QDebug operator<<(QDebug,
const QRhiShaderResourceBindings &);
1306using QRhiShaderResourceBindingSet = QRhiShaderResourceBindings;
1312 UsesBlendConstants = 1 << 0,
1313 UsesStencilRef = 1 << 1,
1314 UsesScissor = 1 << 2,
1315 CompileShadersWithDebugInfo = 1 << 3,
1316 UsesShadingRate = 1 << 4
1318 Q_DECLARE_FLAGS(Flags, Flag)
1341 enum ColorMaskComponent {
1347 Q_DECLARE_FLAGS(ColorMask, ColorMaskComponent)
1361 OneMinusConstantColor,
1363 OneMinusConstantAlpha,
1379 struct TargetBlend {
1380 ColorMask colorWrite = ColorMask(0xF);
1381 bool enable =
false;
1382 BlendFactor srcColor = One;
1383 BlendFactor dstColor = OneMinusSrcAlpha;
1384 BlendOp opColor = Add;
1385 BlendFactor srcAlpha = One;
1386 BlendFactor dstAlpha = OneMinusSrcAlpha;
1387 BlendOp opAlpha = Add;
1412 struct StencilOpState {
1413 StencilOp failOp = Keep;
1414 StencilOp depthFailOp = Keep;
1415 StencilOp passOp = Keep;
1416 CompareOp compareOp = Always;
1424 QRhiResource::Type resourceType()
const override;
1426 Flags flags()
const {
return m_flags; }
1427 void setFlags(Flags f) { m_flags = f; }
1429 Topology topology()
const {
return m_topology; }
1430 void setTopology(Topology t) { m_topology = t; }
1432 CullMode cullMode()
const {
return m_cullMode; }
1433 void setCullMode(CullMode mode) { m_cullMode = mode; }
1435 FrontFace frontFace()
const {
return m_frontFace; }
1436 void setFrontFace(FrontFace f) { m_frontFace = f; }
1438 void setTargetBlends(std::initializer_list<TargetBlend> list) { m_targetBlends = list; }
1439 template<
typename InputIterator>
1440 void setTargetBlends(InputIterator first, InputIterator last)
1442 m_targetBlends.clear();
1443 std::copy(first, last, std::back_inserter(m_targetBlends));
1445 const TargetBlend *cbeginTargetBlends()
const {
return m_targetBlends.cbegin(); }
1446 const TargetBlend *cendTargetBlends()
const {
return m_targetBlends.cend(); }
1447 const TargetBlend *targetBlendAt(qsizetype index)
const {
return &m_targetBlends.at(index); }
1448 qsizetype targetBlendCount()
const {
return m_targetBlends.count(); }
1450 bool hasDepthTest()
const {
return m_depthTest; }
1451 void setDepthTest(
bool enable) { m_depthTest = enable; }
1453 bool hasDepthWrite()
const {
return m_depthWrite; }
1454 void setDepthWrite(
bool enable) { m_depthWrite = enable; }
1456 bool hasDepthClamp()
const {
return m_depthClamp; }
1457 void setDepthClamp(
bool enable) { m_depthClamp = enable; }
1459 CompareOp depthOp()
const {
return m_depthOp; }
1460 void setDepthOp(CompareOp op) { m_depthOp = op; }
1462 bool hasStencilTest()
const {
return m_stencilTest; }
1463 void setStencilTest(
bool enable) { m_stencilTest = enable; }
1465 StencilOpState stencilFront()
const {
return m_stencilFront; }
1466 void setStencilFront(
const StencilOpState &state) { m_stencilFront = state; }
1468 StencilOpState stencilBack()
const {
return m_stencilBack; }
1469 void setStencilBack(
const StencilOpState &state) { m_stencilBack = state; }
1471 quint32 stencilReadMask()
const {
return m_stencilReadMask; }
1472 void setStencilReadMask(quint32 mask) { m_stencilReadMask = mask; }
1474 quint32 stencilWriteMask()
const {
return m_stencilWriteMask; }
1475 void setStencilWriteMask(quint32 mask) { m_stencilWriteMask = mask; }
1477 int sampleCount()
const {
return m_sampleCount; }
1478 void setSampleCount(
int s) { m_sampleCount = s; }
1480 float lineWidth()
const {
return m_lineWidth; }
1481 void setLineWidth(
float width) { m_lineWidth = width; }
1483 int depthBias()
const {
return m_depthBias; }
1484 void setDepthBias(
int bias) { m_depthBias = bias; }
1486 float slopeScaledDepthBias()
const {
return m_slopeScaledDepthBias; }
1487 void setSlopeScaledDepthBias(
float bias) { m_slopeScaledDepthBias = bias; }
1489 void setShaderStages(std::initializer_list<QRhiShaderStage> list) { m_shaderStages = list; }
1490 template<
typename InputIterator>
1491 void setShaderStages(InputIterator first, InputIterator last)
1493 m_shaderStages.clear();
1494 std::copy(first, last, std::back_inserter(m_shaderStages));
1496 const QRhiShaderStage *cbeginShaderStages()
const {
return m_shaderStages.cbegin(); }
1497 const QRhiShaderStage *cendShaderStages()
const {
return m_shaderStages.cend(); }
1498 const QRhiShaderStage *shaderStageAt(qsizetype index)
const {
return &m_shaderStages.at(index); }
1499 qsizetype shaderStageCount()
const {
return m_shaderStages.count(); }
1501 QRhiVertexInputLayout vertexInputLayout()
const {
return m_vertexInputLayout; }
1502 void setVertexInputLayout(
const QRhiVertexInputLayout &layout) { m_vertexInputLayout = layout; }
1504 QRhiShaderResourceBindings *shaderResourceBindings()
const {
return m_shaderResourceBindings; }
1505 void setShaderResourceBindings(QRhiShaderResourceBindings *srb) { m_shaderResourceBindings = srb; }
1507 QRhiRenderPassDescriptor *renderPassDescriptor()
const {
return m_renderPassDesc; }
1508 void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; }
1510 int patchControlPointCount()
const {
return m_patchControlPointCount; }
1511 void setPatchControlPointCount(
int count) { m_patchControlPointCount = count; }
1513 PolygonMode polygonMode()
const {
return m_polygonMode; }
1514 void setPolygonMode(PolygonMode mode) {m_polygonMode = mode; }
1516 int multiViewCount()
const {
return m_multiViewCount; }
1517 void setMultiViewCount(
int count) { m_multiViewCount = count; }
1519 virtual bool create() = 0;
1522 QRhiGraphicsPipeline(QRhiImplementation *rhi);
1524 Topology m_topology = Triangles;
1525 CullMode m_cullMode = None;
1526 FrontFace m_frontFace = CCW;
1527 QVarLengthArray<TargetBlend, 8> m_targetBlends;
1528 bool m_depthTest =
false;
1529 bool m_depthWrite =
false;
1530 bool m_depthClamp =
false;
1531 CompareOp m_depthOp = Less;
1532 bool m_stencilTest =
false;
1533 StencilOpState m_stencilFront;
1534 StencilOpState m_stencilBack;
1535 quint32 m_stencilReadMask = 0xFF;
1536 quint32 m_stencilWriteMask = 0xFF;
1537 int m_sampleCount = 1;
1538 float m_lineWidth = 1.0f;
1539 int m_depthBias = 0;
1540 float m_slopeScaledDepthBias = 0.0f;
1541 int m_patchControlPointCount = 3;
1542 PolygonMode m_polygonMode = Fill;
1543 int m_multiViewCount = 0;
1544 QVarLengthArray<QRhiShaderStage, 4> m_shaderStages;
1545 QRhiVertexInputLayout m_vertexInputLayout;
1546 QRhiShaderResourceBindings *m_shaderResourceBindings =
nullptr;
1547 QRhiRenderPassDescriptor *m_renderPassDesc =
nullptr;
1550Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiGraphicsPipeline::Flags)
1551Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiGraphicsPipeline::ColorMask)
1552Q_DECLARE_TYPEINFO(QRhiGraphicsPipeline::TargetBlend, Q_RELOCATABLE_TYPE);
1575 } colorComponentValue;
1583#ifndef QT_NO_DEBUG_STREAM
1584Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiSwapChainHdrInfo &);
1596 SurfaceHasPreMulAlpha = 1 << 0,
1597 SurfaceHasNonPreMulAlpha = 1 << 1,
1599 UsedAsTransferSource = 1 << 3,
1601 MinimalBufferCount = 1 << 5
1603 Q_DECLARE_FLAGS(Flags, Flag)
1607 HDRExtendedSrgbLinear,
1609 HDRExtendedDisplayP3Linear
1612 enum StereoTargetBuffer {
1617 QRhiResource::Type resourceType()
const override;
1619 QWindow *window()
const {
return m_window; }
1620 void setWindow(QWindow *window) { m_window = window; }
1622 QRhiSwapChainProxyData proxyData()
const {
return m_proxyData; }
1623 void setProxyData(
const QRhiSwapChainProxyData &d) { m_proxyData = d; }
1625 Flags flags()
const {
return m_flags; }
1626 void setFlags(Flags f) { m_flags = f; }
1628 Format format()
const {
return m_format; }
1629 void setFormat(Format f) { m_format = f; }
1631 QRhiRenderBuffer *depthStencil()
const {
return m_depthStencil; }
1632 void setDepthStencil(QRhiRenderBuffer *ds) { m_depthStencil = ds; }
1634 int sampleCount()
const {
return m_sampleCount; }
1635 void setSampleCount(
int samples) { m_sampleCount = samples; }
1637 QRhiRenderPassDescriptor *renderPassDescriptor()
const {
return m_renderPassDesc; }
1638 void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; }
1640 QRhiShadingRateMap *shadingRateMap()
const {
return m_shadingRateMap; }
1641 void setShadingRateMap(QRhiShadingRateMap *map) { m_shadingRateMap = map; }
1643 QSize currentPixelSize()
const {
return m_currentPixelSize; }
1645 virtual QRhiCommandBuffer *currentFrameCommandBuffer() = 0;
1646 virtual QRhiRenderTarget *currentFrameRenderTarget() = 0;
1647 virtual QRhiRenderTarget *currentFrameRenderTarget(StereoTargetBuffer targetBuffer);
1648 virtual QSize surfacePixelSize() = 0;
1649 virtual bool isFormatSupported(Format f) = 0;
1650 virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() = 0;
1651 virtual bool createOrResize() = 0;
1652 virtual QRhiSwapChainHdrInfo hdrInfo();
1655 QRhiSwapChain(QRhiImplementation *rhi);
1656 QWindow *m_window =
nullptr;
1658 Format m_format = SDR;
1659 QRhiRenderBuffer *m_depthStencil =
nullptr;
1660 int m_sampleCount = 1;
1661 QRhiRenderPassDescriptor *m_renderPassDesc =
nullptr;
1662 QSize m_currentPixelSize;
1663 QRhiSwapChainProxyData m_proxyData;
1664 QRhiShadingRateMap *m_shadingRateMap =
nullptr;
1667Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiSwapChain::Flags)
1669class Q_GUI_EXPORT QRhiComputePipeline :
public QRhiResource
1673 CompileShadersWithDebugInfo = 1 << 0
1675 Q_DECLARE_FLAGS(Flags, Flag)
1677 QRhiResource::Type resourceType()
const override;
1678 virtual bool create() = 0;
1680 Flags flags()
const {
return m_flags; }
1681 void setFlags(Flags f) { m_flags = f; }
1683 QRhiShaderStage shaderStage()
const {
return m_shaderStage; }
1684 void setShaderStage(
const QRhiShaderStage &stage) { m_shaderStage = stage; }
1686 QRhiShaderResourceBindings *shaderResourceBindings()
const {
return m_shaderResourceBindings; }
1687 void setShaderResourceBindings(QRhiShaderResourceBindings *srb) { m_shaderResourceBindings = srb; }
1690 QRhiComputePipeline(QRhiImplementation *rhi);
1692 QRhiShaderStage m_shaderStage;
1693 QRhiShaderResourceBindings *m_shaderResourceBindings =
nullptr;
1696Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiComputePipeline::Flags)
1698class Q_GUI_EXPORT QRhiCommandBuffer :
public QRhiResource
1706 enum BeginPassFlag {
1707 ExternalContent = 0x01,
1708 DoNotTrackResourcesForCompute = 0x02
1710 Q_DECLARE_FLAGS(BeginPassFlags, BeginPassFlag)
1712 QRhiResource::Type resourceType()
const override;
1714 void resourceUpdate(QRhiResourceUpdateBatch *resourceUpdates);
1716 void beginPass(QRhiRenderTarget *rt,
1717 const QColor &colorClearValue,
1718 const QRhiDepthStencilClearValue &depthStencilClearValue,
1719 QRhiResourceUpdateBatch *resourceUpdates =
nullptr,
1720 BeginPassFlags flags = {});
1721 void endPass(QRhiResourceUpdateBatch *resourceUpdates =
nullptr);
1723 void setGraphicsPipeline(QRhiGraphicsPipeline *ps);
1724 using DynamicOffset = std::pair<
int, quint32>;
1725 void setShaderResources(QRhiShaderResourceBindings *srb =
nullptr,
1726 int dynamicOffsetCount = 0,
1727 const DynamicOffset *dynamicOffsets =
nullptr);
1728 using VertexInput = std::pair<QRhiBuffer *, quint32>;
1729 void setVertexInput(
int startBinding,
int bindingCount,
const VertexInput *bindings,
1730 QRhiBuffer *indexBuf =
nullptr, quint32 indexOffset = 0,
1731 IndexFormat indexFormat = IndexUInt16);
1733 void setViewport(
const QRhiViewport &viewport);
1734 void setScissor(
const QRhiScissor &scissor);
1735 void setBlendConstants(
const QColor &c);
1736 void setStencilRef(quint32 refValue);
1737 void setShadingRate(
const QSize &coarsePixelSize);
1739 void draw(quint32 vertexCount,
1740 quint32 instanceCount = 1,
1741 quint32 firstVertex = 0,
1742 quint32 firstInstance = 0);
1744 void drawIndexed(quint32 indexCount,
1745 quint32 instanceCount = 1,
1746 quint32 firstIndex = 0,
1747 qint32 vertexOffset = 0,
1748 quint32 firstInstance = 0);
1750 void debugMarkBegin(
const QByteArray &name);
1751 void debugMarkEnd();
1752 void debugMarkMsg(
const QByteArray &msg);
1754 void beginComputePass(QRhiResourceUpdateBatch *resourceUpdates =
nullptr, BeginPassFlags flags = {});
1755 void endComputePass(QRhiResourceUpdateBatch *resourceUpdates =
nullptr);
1756 void setComputePipeline(QRhiComputePipeline *ps);
1757 void dispatch(
int x,
int y,
int z);
1759 const QRhiNativeHandles *nativeHandles();
1760 void beginExternal();
1763 double lastCompletedGpuTime();
1766 QRhiCommandBuffer(QRhiImplementation *rhi);
1769Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiCommandBuffer::BeginPassFlags)
1771struct Q_GUI_EXPORT QRhiReadbackResult
1773 std::function<
void()> completed =
nullptr;
1774 QRhiTexture::Format format;
1782 ~QRhiResourceUpdateBatch();
1786 void merge(QRhiResourceUpdateBatch *other);
1787 bool hasOptimalCapacity()
const;
1789 void updateDynamicBuffer(QRhiBuffer *buf, quint32 offset, quint32 size,
const void *data);
1790 void updateDynamicBuffer(QRhiBuffer *buf, quint32 offset, QByteArray data);
1791 void uploadStaticBuffer(QRhiBuffer *buf, quint32 offset, quint32 size,
const void *data);
1792 void uploadStaticBuffer(QRhiBuffer *buf, quint32 offset, QByteArray data);
1793 void uploadStaticBuffer(QRhiBuffer *buf,
const void *data);
1794 void uploadStaticBuffer(QRhiBuffer *buf, QByteArray data);
1795 void readBackBuffer(QRhiBuffer *buf, quint32 offset, quint32 size, QRhiReadbackResult *result);
1796 void uploadTexture(QRhiTexture *tex,
const QRhiTextureUploadDescription &desc);
1797 void uploadTexture(QRhiTexture *tex,
const QImage &image);
1798 void copyTexture(QRhiTexture *dst, QRhiTexture *src,
const QRhiTextureCopyDescription &desc = QRhiTextureCopyDescription());
1799 void readBackTexture(
const QRhiReadbackDescription &rb, QRhiReadbackResult *result);
1800 void generateMips(QRhiTexture *tex);
1803 QRhiResourceUpdateBatch(QRhiImplementation *rhi);
1804 Q_DISABLE_COPY(QRhiResourceUpdateBatch)
1805 QRhiResourceUpdateBatchPrivate *d;
1806 friend class QRhiResourceUpdateBatchPrivate;
1821 QByteArray deviceName;
1822 quint64 deviceId = 0;
1823 quint64 vendorId = 0;
1824 DeviceType deviceType = UnknownDevice;
1829#ifndef QT_NO_DEBUG_STREAM
1830Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiDriverInfo &);
1835 qint64 totalPipelineCreationTime = 0;
1837 quint32 blockCount = 0;
1838 quint32 allocCount = 0;
1839 quint64 usedBytes = 0;
1840 quint64 unusedBytes = 0;
1842 quint64 totalUsageBytes = 0;
1847#ifndef QT_NO_DEBUG_STREAM
1848Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiStats &);
1854 virtual ~QRhiAdapter();
1855 virtual QRhiDriverInfo info()
const = 0;
1865 enum Implementation {
1875 EnableDebugMarkers = 1 << 0,
1876 PreferSoftwareRenderer = 1 << 1,
1877 EnablePipelineCacheDataSave = 1 << 2,
1878 EnableTimestamps = 1 << 3,
1879 SuppressSmokeTestWarnings = 1 << 4
1881 Q_DECLARE_FLAGS(Flags, Flag)
1883 enum FrameOpResult {
1886 FrameOpSwapChainOutOfDate,
1891 MultisampleTexture = 1,
1892 MultisampleRenderBuffer,
1896 CustomInstanceStepRate,
1898 NonDynamicUniformBuffers,
1899 NonFourAlignedEffectiveIndexBufferOffset,
1905 VertexShaderPointSize,
1908 TriangleFanTopology,
1909 ReadBackNonUniformBuffer,
1910 ReadBackNonBaseMipLevel,
1912 RenderToNonBaseMipLevel,
1914 ScreenSpaceDerivatives,
1915 ReadBackAnyTextureFormat,
1916 PipelineCacheDataLoadSave,
1919 ThreeDimensionalTextures,
1920 RenderTo3DTextureSlice,
1926 OneDimensionalTextures,
1927 OneDimensionalTextureMipmaps,
1929 RenderToOneDimensionalTexture,
1930 ThreeDimensionalTextureMipmaps,
1933 ResolveDepthStencil,
1934 VariableRateShading,
1935 VariableRateShadingMap,
1936 VariableRateShadingMapWithTexture,
1937 PerRenderTargetBlending,
1939 InstanceIndexIncludesBaseInstance
1942 enum BeginFrameFlag {
1944 Q_DECLARE_FLAGS(BeginFrameFlags, BeginFrameFlag)
1947 SkipPresent = 1 << 0
1949 Q_DECLARE_FLAGS(EndFrameFlags, EndFrameFlag)
1951 enum ResourceLimit {
1954 MaxColorAttachments,
1956 MaxAsyncReadbackFrames,
1957 MaxThreadGroupsPerDimension,
1958 MaxThreadsPerThreadGroup,
1962 TextureArraySizeMax,
1963 MaxUniformBufferRange,
1966 ShadingRateImageTileSize
1971 static QRhi *create(Implementation impl,
1972 QRhiInitParams *params,
1974 QRhiNativeHandles *importDevice =
nullptr);
1975 static QRhi *create(Implementation impl,
1976 QRhiInitParams *params,
1978 QRhiNativeHandles *importDevice,
1979 QRhiAdapter *adapter);
1980 static bool probe(Implementation impl, QRhiInitParams *params);
1981 using AdapterList = QVector<QRhiAdapter *>;
1982 static AdapterList enumerateAdapters(Implementation impl,
1983 QRhiInitParams *params,
1984 QRhiNativeHandles *nativeHandles =
nullptr);
1986 Implementation backend()
const;
1987 const char *backendName()
const;
1988 static const char *backendName(Implementation impl);
1989 QRhiDriverInfo driverInfo()
const;
1990 QThread *thread()
const;
1992 using CleanupCallback = std::function<
void(QRhi *)>;
1993 void addCleanupCallback(
const CleanupCallback &callback);
1994 void addCleanupCallback(
const void *key,
const CleanupCallback &callback);
1995 void removeCleanupCallback(
const void *key);
1997 QRhiGraphicsPipeline *newGraphicsPipeline();
1998 QRhiComputePipeline *newComputePipeline();
1999 QRhiShaderResourceBindings *newShaderResourceBindings();
2001 QRhiBuffer *newBuffer(QRhiBuffer::Type type,
2002 QRhiBuffer::UsageFlags usage,
2005 QRhiRenderBuffer *newRenderBuffer(QRhiRenderBuffer::Type type,
2006 const QSize &pixelSize,
2007 int sampleCount = 1,
2008 QRhiRenderBuffer::Flags flags = {},
2009 QRhiTexture::Format backingFormatHint = QRhiTexture::UnknownFormat);
2011 QRhiTexture *newTexture(QRhiTexture::Format format,
2012 const QSize &pixelSize,
2013 int sampleCount = 1,
2014 QRhiTexture::Flags flags = {});
2016 QRhiTexture *newTexture(QRhiTexture::Format format,
2017 int width,
int height,
int depth,
2018 int sampleCount = 1,
2019 QRhiTexture::Flags flags = {});
2021 QRhiTexture *newTextureArray(QRhiTexture::Format format,
2023 const QSize &pixelSize,
2024 int sampleCount = 1,
2025 QRhiTexture::Flags flags = {});
2027 QRhiSampler *newSampler(QRhiSampler::Filter magFilter,
2028 QRhiSampler::Filter minFilter,
2029 QRhiSampler::Filter mipmapMode,
2030 QRhiSampler::AddressMode addressU,
2031 QRhiSampler::AddressMode addressV,
2032 QRhiSampler::AddressMode addressW = QRhiSampler::Repeat);
2034 QRhiShadingRateMap *newShadingRateMap();
2036 QRhiTextureRenderTarget *newTextureRenderTarget(
const QRhiTextureRenderTargetDescription &desc,
2037 QRhiTextureRenderTarget::Flags flags = {});
2039 QRhiSwapChain *newSwapChain();
2040 FrameOpResult beginFrame(QRhiSwapChain *swapChain, BeginFrameFlags flags = {});
2041 FrameOpResult endFrame(QRhiSwapChain *swapChain, EndFrameFlags flags = {});
2042 bool isRecordingFrame()
const;
2043 int currentFrameSlot()
const;
2045 FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb, BeginFrameFlags flags = {});
2046 FrameOpResult endOffscreenFrame(EndFrameFlags flags = {});
2048 QRhi::FrameOpResult finish();
2050 QRhiResourceUpdateBatch *nextResourceUpdateBatch();
2052 QList<
int> supportedSampleCounts()
const;
2054 int ubufAlignment()
const;
2055 int ubufAligned(
int v)
const;
2057 static int mipLevelsForSize(
const QSize &size);
2058 static QSize sizeForMipLevel(
int mipLevel,
const QSize &baseLevelSize);
2060 bool isYUpInFramebuffer()
const;
2061 bool isYUpInNDC()
const;
2062 bool isClipDepthZeroToOne()
const;
2064 QMatrix4x4 clipSpaceCorrMatrix()
const;
2066 bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags = {})
const;
2067 bool isFeatureSupported(QRhi::Feature feature)
const;
2068 int resourceLimit(ResourceLimit limit)
const;
2070 const QRhiNativeHandles *nativeHandles();
2071 bool makeThreadLocalNativeContextCurrent();
2072 void setQueueSubmitParams(QRhiNativeHandles *params);
2074 static constexpr int MAX_MIP_LEVELS = 16;
2076 void releaseCachedResources();
2078 bool isDeviceLost()
const;
2080 QByteArray pipelineCacheData();
2081 void setPipelineCacheData(
const QByteArray &data);
2083 QRhiStats statistics()
const;
2085 static QRhiSwapChainProxyData updateSwapChainProxyData(Implementation impl, QWindow *window);
2087 QList<QSize> supportedShadingRates(
int sampleCount)
const;
2093 Q_DISABLE_COPY(QRhi)
2094 QRhiImplementation *d =
nullptr;
2097Q_DECLARE_OPERATORS_FOR_FLAGS(QRhi::Flags)
2098Q_DECLARE_OPERATORS_FOR_FLAGS(QRhi::BeginFrameFlags)
2099Q_DECLARE_OPERATORS_FOR_FLAGS(QRhi::EndFrameFlags)
2103#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
\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
\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