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;
44class QRhiIndirectCommandBuffer;
45struct QRhiIndirectCommandBufferBuildInfo;
50 QRhiDepthStencilClearValue() =
default;
51 QRhiDepthStencilClearValue(
float d, quint32 s);
53 float depthClearValue()
const {
return m_d; }
54 void setDepthClearValue(
float d) { m_d = d; }
56 quint32 stencilClearValue()
const {
return m_s; }
57 void setStencilClearValue(quint32 s) { m_s = s; }
63 friend bool operator==(
const QRhiDepthStencilClearValue &a,
const QRhiDepthStencilClearValue &b)
noexcept
65 return a.m_d == b.m_d && a.m_s == b.m_s;
68 friend bool operator!=(
const QRhiDepthStencilClearValue &a,
const QRhiDepthStencilClearValue &b)
noexcept
73 friend size_t qHash(
const QRhiDepthStencilClearValue &v, size_t seed = 0)
noexcept
75 QtPrivate::QHashCombine hash(seed);
76 seed = hash(seed, v.m_d);
77 seed = hash(seed, v.m_s);
84#ifndef QT_NO_DEBUG_STREAM
85Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiDepthStencilClearValue &);
91 QRhiViewport() =
default;
92 QRhiViewport(
float x,
float y,
float w,
float h,
float minDepth = 0.0f,
float maxDepth = 1.0f);
94 std::array<
float, 4> viewport()
const {
return m_rect; }
95 void setViewport(
float x,
float y,
float w,
float h) {
96 m_rect[0] = x; m_rect[1] = y; m_rect[2] = w; m_rect[3] = h;
99 float minDepth()
const {
return m_minDepth; }
100 void setMinDepth(
float minDepth) { m_minDepth = minDepth; }
102 float maxDepth()
const {
return m_maxDepth; }
103 void setMaxDepth(
float maxDepth) { m_maxDepth = maxDepth; }
106 std::array<
float, 4> m_rect { { 0.0f, 0.0f, 0.0f, 0.0f } };
107 float m_minDepth = 0.0f;
108 float m_maxDepth = 1.0f;
110 friend bool operator==(
const QRhiViewport &a,
const QRhiViewport &b)
noexcept
112 return a.m_rect == b.m_rect
113 && a.m_minDepth == b.m_minDepth
114 && a.m_maxDepth == b.m_maxDepth;
117 friend bool operator!=(
const QRhiViewport &a,
const QRhiViewport &b)
noexcept
122 friend size_t qHash(
const QRhiViewport &v, size_t seed = 0)
noexcept
124 QtPrivate::QHashCombine hash(seed);
125 seed = hash(seed, v.m_rect[0]);
126 seed = hash(seed, v.m_rect[1]);
127 seed = hash(seed, v.m_rect[2]);
128 seed = hash(seed, v.m_rect[3]);
129 seed = hash(seed, v.m_minDepth);
130 seed = hash(seed, v.m_maxDepth);
137#ifndef QT_NO_DEBUG_STREAM
138Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiViewport &);
144 QRhiScissor() =
default;
145 QRhiScissor(
int x,
int y,
int w,
int h);
147 std::array<
int, 4> scissor()
const {
return m_rect; }
148 void setScissor(
int x,
int y,
int w,
int h) {
149 m_rect[0] = x; m_rect[1] = y; m_rect[2] = w; m_rect[3] = h;
153 std::array<
int, 4> m_rect { { 0, 0, 0, 0 } };
155 friend bool operator==(
const QRhiScissor &a,
const QRhiScissor &b)
noexcept
157 return a.m_rect == b.m_rect;
160 friend bool operator!=(
const QRhiScissor &a,
const QRhiScissor &b)
noexcept
165 friend size_t qHash(
const QRhiScissor &v, size_t seed = 0)
noexcept
167 QtPrivate::QHashCombine hash(seed);
168 seed = hash(seed, v.m_rect[0]);
169 seed = hash(seed, v.m_rect[1]);
170 seed = hash(seed, v.m_rect[2]);
171 seed = hash(seed, v.m_rect[3]);
178#ifndef QT_NO_DEBUG_STREAM
179Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiScissor &);
185 enum Classification {
190 QRhiVertexInputBinding() =
default;
191 QRhiVertexInputBinding(quint32 stride, Classification cls = PerVertex, quint32 stepRate = 1);
193 quint32 stride()
const {
return m_stride; }
194 void setStride(quint32 s) { m_stride = s; }
196 Classification classification()
const {
return m_classification; }
197 void setClassification(Classification c) { m_classification = c; }
199 quint32 instanceStepRate()
const {
return m_instanceStepRate; }
200 void setInstanceStepRate(quint32 rate) { m_instanceStepRate = rate; }
203 quint32 m_stride = 0;
204 Classification m_classification = PerVertex;
205 quint32 m_instanceStepRate = 1;
207 friend bool operator==(
const QRhiVertexInputBinding &a,
const QRhiVertexInputBinding &b)
noexcept
209 return a.m_stride == b.m_stride
210 && a.m_classification == b.m_classification
211 && a.m_instanceStepRate == b.m_instanceStepRate;
214 friend bool operator!=(
const QRhiVertexInputBinding &a,
const QRhiVertexInputBinding &b)
noexcept
219 friend size_t qHash(
const QRhiVertexInputBinding &v, size_t seed = 0)
noexcept
221 QtPrivate::QHashCombine hash(seed);
222 seed = hash(seed, v.m_stride);
223 seed = hash(seed, v.m_classification);
224 seed = hash(seed, v.m_instanceStepRate);
231#ifndef QT_NO_DEBUG_STREAM
232Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiVertexInputBinding &);
268 QRhiVertexInputAttribute() =
default;
269 QRhiVertexInputAttribute(
int binding,
int location, Format format, quint32 offset,
int matrixSlice = -1);
271 int binding()
const {
return m_binding; }
272 void setBinding(
int b) { m_binding = b; }
274 int location()
const {
return m_location; }
275 void setLocation(
int loc) { m_location = loc; }
277 Format format()
const {
return m_format; }
278 void setFormat(Format f) { m_format = f; }
280 quint32 offset()
const {
return m_offset; }
281 void setOffset(quint32 ofs) { m_offset = ofs; }
283 int matrixSlice()
const {
return m_matrixSlice; }
284 void setMatrixSlice(
int slice) { m_matrixSlice = slice; }
289 Format m_format = Float4;
290 quint32 m_offset = 0;
291 int m_matrixSlice = -1;
293 friend bool operator==(
const QRhiVertexInputAttribute &a,
const QRhiVertexInputAttribute &b)
noexcept
295 return a.m_binding == b.m_binding
296 && a.m_location == b.m_location
297 && a.m_format == b.m_format
298 && a.m_offset == b.m_offset;
302 friend bool operator!=(
const QRhiVertexInputAttribute &a,
const QRhiVertexInputAttribute &b)
noexcept
307 friend size_t qHash(
const QRhiVertexInputAttribute &v, size_t seed = 0)
noexcept
309 QtPrivate::QHashCombine hash(seed);
310 seed = hash(seed, v.m_binding);
311 seed = hash(seed, v.m_location);
312 seed = hash(seed, v.m_format);
313 seed = hash(seed, v.m_offset);
320#ifndef QT_NO_DEBUG_STREAM
321Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiVertexInputAttribute &);
327 QRhiVertexInputLayout() =
default;
329 void setBindings(std::initializer_list<QRhiVertexInputBinding> list) { m_bindings = list; }
330 template<
typename InputIterator>
331 void setBindings(InputIterator first, InputIterator last)
334 std::copy(first, last, std::back_inserter(m_bindings));
336 const QRhiVertexInputBinding *cbeginBindings()
const {
return m_bindings.cbegin(); }
337 const QRhiVertexInputBinding *cendBindings()
const {
return m_bindings.cend(); }
338 const QRhiVertexInputBinding *bindingAt(qsizetype index)
const {
return &m_bindings.at(index); }
339 qsizetype bindingCount()
const {
return m_bindings.count(); }
341 void setAttributes(std::initializer_list<QRhiVertexInputAttribute> list) { m_attributes = list; }
342 template<
typename InputIterator>
343 void setAttributes(InputIterator first, InputIterator last)
345 m_attributes.clear();
346 std::copy(first, last, std::back_inserter(m_attributes));
348 const QRhiVertexInputAttribute *cbeginAttributes()
const {
return m_attributes.cbegin(); }
349 const QRhiVertexInputAttribute *cendAttributes()
const {
return m_attributes.cend(); }
350 const QRhiVertexInputAttribute *attributeAt(qsizetype index)
const {
return &m_attributes.at(index); }
351 qsizetype attributeCount()
const {
return m_attributes.count(); }
354 QVarLengthArray<QRhiVertexInputBinding, 8> m_bindings;
355 QVarLengthArray<QRhiVertexInputAttribute, 8> m_attributes;
357 friend bool operator==(
const QRhiVertexInputLayout &a,
const QRhiVertexInputLayout &b)
noexcept
359 return a.m_bindings == b.m_bindings && a.m_attributes == b.m_attributes;
362 friend bool operator!=(
const QRhiVertexInputLayout &a,
const QRhiVertexInputLayout &b)
noexcept
367 friend size_t qHash(
const QRhiVertexInputLayout &v, size_t seed = 0)
noexcept
369 QtPrivate::QHashCombine hash(seed);
370 seed = hash(seed, v.m_bindings);
371 seed = hash(seed, v.m_attributes);
375 friend Q_GUI_EXPORT QDebug operator<<(QDebug,
const QRhiVertexInputLayout &);
378#ifndef QT_NO_DEBUG_STREAM
379Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiVertexInputLayout &);
388 TessellationEvaluation,
394 QRhiShaderStage() =
default;
395 QRhiShaderStage(Type type,
const QShader &shader,
396 QShader::Variant v = QShader::StandardShader);
398 Type type()
const {
return m_type; }
399 void setType(Type t) { m_type = t; }
401 QShader shader()
const {
return m_shader; }
402 void setShader(
const QShader &s) { m_shader = s; }
404 QShader::Variant shaderVariant()
const {
return m_shaderVariant; }
405 void setShaderVariant(QShader::Variant v) { m_shaderVariant = v; }
408 Type m_type = Vertex;
410 QShader::Variant m_shaderVariant = QShader::StandardShader;
412 friend bool operator==(
const QRhiShaderStage &a,
const QRhiShaderStage &b)
noexcept
414 return a.m_type == b.m_type
415 && a.m_shader == b.m_shader
416 && a.m_shaderVariant == b.m_shaderVariant;
419 friend bool operator!=(
const QRhiShaderStage &a,
const QRhiShaderStage &b)
noexcept
424 friend size_t qHash(
const QRhiShaderStage &v, size_t seed = 0)
noexcept
426 QtPrivate::QHashCombine hash(seed);
427 seed = hash(seed, v.m_type);
428 seed = hash(seed, v.m_shader);
429 seed = hash(seed, v.m_shaderVariant);
436#ifndef QT_NO_DEBUG_STREAM
437Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiShaderStage &);
440using QRhiGraphicsShaderStage = QRhiShaderStage;
459 VertexStage = 1 << 0,
460 TessellationControlStage = 1 << 1,
461 TessellationEvaluationStage = 1 << 2,
462 GeometryStage = 1 << 3,
463 FragmentStage = 1 << 4,
464 ComputeStage = 1 << 5
466 Q_DECLARE_FLAGS(StageFlags, StageFlag)
468 QRhiShaderResourceBinding() =
default;
470 bool isLayoutCompatible(
const QRhiShaderResourceBinding &other)
const;
472 static QRhiShaderResourceBinding uniformBuffer(
int binding, StageFlags stage, QRhiBuffer *buf);
473 static QRhiShaderResourceBinding uniformBuffer(
int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size);
474 static QRhiShaderResourceBinding uniformBufferWithDynamicOffset(
int binding, StageFlags stage, QRhiBuffer *buf, quint32 size);
476 static QRhiShaderResourceBinding sampledTexture(
int binding, StageFlags stage, QRhiTexture *tex, QRhiSampler *sampler);
478 struct TextureAndSampler {
480 QRhiSampler *sampler;
482 static QRhiShaderResourceBinding sampledTextures(
int binding, StageFlags stage,
int count,
const TextureAndSampler *texSamplers);
484 static QRhiShaderResourceBinding texture(
int binding, StageFlags stage, QRhiTexture *tex);
485 static QRhiShaderResourceBinding textures(
int binding, StageFlags stage,
int count, QRhiTexture **tex);
486 static QRhiShaderResourceBinding sampler(
int binding, StageFlags stage, QRhiSampler *sampler);
488 static QRhiShaderResourceBinding imageLoad(
int binding, StageFlags stage, QRhiTexture *tex,
int level);
489 static QRhiShaderResourceBinding imageStore(
int binding, StageFlags stage, QRhiTexture *tex,
int level);
490 static QRhiShaderResourceBinding imageLoadStore(
int binding, StageFlags stage, QRhiTexture *tex,
int level);
492 static QRhiShaderResourceBinding bufferLoad(
int binding, StageFlags stage, QRhiBuffer *buf);
493 static QRhiShaderResourceBinding bufferLoad(
int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size);
494 static QRhiShaderResourceBinding bufferStore(
int binding, StageFlags stage, QRhiBuffer *buf);
495 static QRhiShaderResourceBinding bufferStore(
int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size);
496 static QRhiShaderResourceBinding bufferLoadStore(
int binding, StageFlags stage, QRhiBuffer *buf);
497 static QRhiShaderResourceBinding bufferLoadStore(
int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size);
502 QRhiShaderResourceBinding::StageFlags stage;
503 QRhiShaderResourceBinding::Type type;
504 struct UniformBufferData {
508 bool hasDynamicOffset;
510 static constexpr int MAX_TEX_SAMPLER_ARRAY_SIZE = 16;
511 struct TextureAndOrSamplerData {
512 QVarLengthArray<TextureAndSampler, 4> texSamplers;
513 int count()
const {
return int(texSamplers.size()); }
515 struct StorageImageData {
519 struct StorageBufferData {
525 UniformBufferData ubuf;
526 StorageImageData simage;
527 StorageBufferData sbuf;
529 TextureAndOrSamplerData stex;
531 int arraySize()
const
533 return type == QRhiShaderResourceBinding::SampledTexture || type == QRhiShaderResourceBinding::Texture
538 template<
typename Output>
539 Output serialize(Output dst)
const
542 *dst++ = quint32(binding);
543 *dst++ = quint32(stage);
544 *dst++ = quint32(type);
545 *dst++ = quint32(arraySize());
550 static constexpr int LAYOUT_DESC_ENTRIES_PER_BINDING = 4;
552 template<
typename Output>
553 static void serializeLayoutDescription(
const QRhiShaderResourceBinding *first,
554 const QRhiShaderResourceBinding *last,
557 while (first != last) {
558 dst = first->d.serialize(dst);
565 friend class QRhiImplementation;
568Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiShaderResourceBinding::StageFlags)
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 QRhiBufferCopyDescription() =
default;
753 quint32 size()
const {
return m_size; }
754 void setSize(quint32 sz) { m_size = sz; }
756 quint32 sourceOffset()
const {
return m_sourceOffset; }
757 void setSourceOffset(quint32 offset) { m_sourceOffset = offset; }
759 quint32 destinationOffset()
const {
return m_destinationOffset; }
760 void setDestinationOffset(quint32 offset) { m_destinationOffset = offset; }
764 quint32 m_sourceOffset = 0;
765 quint32 m_destinationOffset = 0;
773 QRhiTextureCopyDescription() =
default;
775 QSize pixelSize()
const {
return m_pixelSize; }
776 void setPixelSize(
const QSize &sz) { m_pixelSize = sz; }
778 int sourceLayer()
const {
return m_sourceLayer; }
779 void setSourceLayer(
int layer) { m_sourceLayer = layer; }
781 int sourceLevel()
const {
return m_sourceLevel; }
782 void setSourceLevel(
int level) { m_sourceLevel = level; }
784 QPoint sourceTopLeft()
const {
return m_sourceTopLeft; }
785 void setSourceTopLeft(
const QPoint &p) { m_sourceTopLeft = p; }
787 int destinationLayer()
const {
return m_destinationLayer; }
788 void setDestinationLayer(
int layer) { m_destinationLayer = layer; }
790 int destinationLevel()
const {
return m_destinationLevel; }
791 void setDestinationLevel(
int level) { m_destinationLevel = level; }
793 QPoint destinationTopLeft()
const {
return m_destinationTopLeft; }
794 void setDestinationTopLeft(
const QPoint &p) { m_destinationTopLeft = p; }
798 int m_sourceLayer = 0;
799 int m_sourceLevel = 0;
800 QPoint m_sourceTopLeft;
801 int m_destinationLayer = 0;
802 int m_destinationLevel = 0;
803 QPoint m_destinationTopLeft;
811 QRhiReadbackDescription() =
default;
812 QRhiReadbackDescription(QRhiTexture *texture);
814 QRhiTexture *texture()
const {
return m_texture; }
815 void setTexture(QRhiTexture *tex) { m_texture = tex; }
817 int layer()
const {
return m_layer; }
818 void setLayer(
int layer) { m_layer = layer; }
820 int level()
const {
return m_level; }
821 void setLevel(
int level) { m_level = level; }
823 QRect rect()
const {
return m_rect; }
824 void setRect(
const QRect &rectangle) { m_rect = rectangle; }
827 QRhiTexture *m_texture =
nullptr;
847 RenderPassDescriptor,
848 SwapChainRenderTarget,
850 ShaderResourceBindings,
856 IndirectCommandBuffer
859 virtual ~QRhiResource();
861 virtual Type resourceType()
const = 0;
863 virtual void destroy() = 0;
867 QByteArray name()
const;
868 void setName(
const QByteArray &name);
870 quint64 globalResourceId()
const;
875 QRhiResource(QRhiImplementation *rhi);
876 Q_DISABLE_COPY(QRhiResource)
877 friend class QRhiImplementation;
878 QRhiImplementation *m_rhi =
nullptr;
880 QByteArray m_objectName;
893 VertexBuffer = 1 << 0,
894 IndexBuffer = 1 << 1,
895 UniformBuffer = 1 << 2,
896 StorageBuffer = 1 << 3,
897 IndirectBuffer = 1 << 4,
899 Q_DECLARE_FLAGS(UsageFlags, UsageFlag)
901 struct NativeBuffer {
902 const void *objects[3];
906 QRhiResource::Type resourceType()
const override;
908 Type type()
const {
return m_type; }
909 void setType(Type t) { m_type = t; }
911 UsageFlags usage()
const {
return m_usage; }
912 void setUsage(UsageFlags u) { m_usage = u; }
914 quint32 size()
const {
return m_size; }
915 void setSize(quint32 sz) { m_size = sz; }
917 virtual bool create() = 0;
919 virtual NativeBuffer nativeBuffer();
921 virtual char *beginFullDynamicBufferUpdateForCurrentFrame();
922 virtual void endFullDynamicBufferUpdateForCurrentFrame();
923 virtual void fullDynamicBufferUpdateForCurrentFrame(
const void *data, quint32 size = 0);
926 QRhiBuffer(QRhiImplementation *rhi, Type type_, UsageFlags usage_, quint32 size_);
932Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiBuffer::UsageFlags)
934class Q_GUI_EXPORT QRhiTexture :
public QRhiResource
938 RenderTarget = 1 << 0,
942 UsedAsTransferSource = 1 << 5,
943 UsedWithGenerateMips = 1 << 6,
944 UsedWithLoadStore = 1 << 7,
945 UsedAsCompressedAtlas = 1 << 8,
946 ExternalOES = 1 << 9,
947 ThreeDimensional = 1 << 10,
948 TextureRectangleGL = 1 << 11,
949 TextureArray = 1 << 12,
950 OneDimensional = 1 << 13,
951 UsedAsShadingRateMap = 1 << 14
953 Q_DECLARE_FLAGS(Flags, Flag)
1017 struct NativeTexture {
1022 QRhiResource::Type resourceType()
const override;
1024 Format format()
const {
return m_format; }
1025 void setFormat(Format fmt) { m_format = fmt; }
1027 QSize pixelSize()
const {
return m_pixelSize; }
1028 void setPixelSize(
const QSize &sz) { m_pixelSize = sz; }
1030 int depth()
const {
return m_depth; }
1031 void setDepth(
int depth) { m_depth = depth; }
1033 int arraySize()
const {
return m_arraySize; }
1034 void setArraySize(
int arraySize) { m_arraySize = arraySize; }
1036 int arrayRangeStart()
const {
return m_arrayRangeStart; }
1037 int arrayRangeLength()
const {
return m_arrayRangeLength; }
1038 void setArrayRange(
int startIndex,
int count)
1040 m_arrayRangeStart = startIndex;
1041 m_arrayRangeLength = count;
1044 Flags flags()
const {
return m_flags; }
1045 void setFlags(Flags f) { m_flags = f; }
1047 int sampleCount()
const {
return m_sampleCount; }
1048 void setSampleCount(
int s) { m_sampleCount = s; }
1051 QRhiTexture::Format format;
1054 ViewFormat readViewFormat()
const {
return m_readViewFormat; }
1055 void setReadViewFormat(
const ViewFormat &fmt) { m_readViewFormat = fmt; }
1056 ViewFormat writeViewFormat()
const {
return m_writeViewFormat; }
1057 void setWriteViewFormat(
const ViewFormat &fmt) { m_writeViewFormat = fmt; }
1059 virtual bool create() = 0;
1060 virtual NativeTexture nativeTexture();
1061 virtual bool createFrom(NativeTexture src);
1062 virtual void setNativeLayout(
int layout);
1065 QRhiTexture(QRhiImplementation *rhi, Format format_,
const QSize &pixelSize_,
int depth_,
1066 int arraySize_,
int sampleCount_, Flags flags_);
1073 int m_arrayRangeStart = -1;
1074 int m_arrayRangeLength = -1;
1075 ViewFormat m_readViewFormat = { UnknownFormat,
false };
1076 ViewFormat m_writeViewFormat = { UnknownFormat,
false };
1079Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiTexture::Flags)
1081class Q_GUI_EXPORT QRhiSampler :
public QRhiResource
1107 QRhiResource::Type resourceType()
const override;
1109 Filter magFilter()
const {
return m_magFilter; }
1110 void setMagFilter(Filter f) { m_magFilter = f; }
1112 Filter minFilter()
const {
return m_minFilter; }
1113 void setMinFilter(Filter f) { m_minFilter = f; }
1115 Filter mipmapMode()
const {
return m_mipmapMode; }
1116 void setMipmapMode(Filter f) { m_mipmapMode = f; }
1118 AddressMode addressU()
const {
return m_addressU; }
1119 void setAddressU(AddressMode mode) { m_addressU = mode; }
1121 AddressMode addressV()
const {
return m_addressV; }
1122 void setAddressV(AddressMode mode) { m_addressV = mode; }
1124 AddressMode addressW()
const {
return m_addressW; }
1125 void setAddressW(AddressMode mode) { m_addressW = mode; }
1127 CompareOp textureCompareOp()
const {
return m_compareOp; }
1128 void setTextureCompareOp(CompareOp op) { m_compareOp = op; }
1130 virtual bool create() = 0;
1133 QRhiSampler(QRhiImplementation *rhi,
1134 Filter magFilter_, Filter minFilter_, Filter mipmapMode_,
1135 AddressMode u_, AddressMode v_, AddressMode w_);
1138 Filter m_mipmapMode;
1139 AddressMode m_addressU;
1140 AddressMode m_addressV;
1141 AddressMode m_addressW;
1142 CompareOp m_compareOp;
1154 UsedWithSwapChainOnly = 1 << 0,
1155 NoTransientBacking = 1 << 1
1157 Q_DECLARE_FLAGS(Flags, Flag)
1159 struct NativeRenderBuffer {
1163 QRhiResource::Type resourceType()
const override;
1165 Type type()
const {
return m_type; }
1166 void setType(Type t) { m_type = t; }
1168 QSize pixelSize()
const {
return m_pixelSize; }
1169 void setPixelSize(
const QSize &sz) { m_pixelSize = sz; }
1171 int sampleCount()
const {
return m_sampleCount; }
1172 void setSampleCount(
int s) { m_sampleCount = s; }
1174 Flags flags()
const {
return m_flags; }
1175 void setFlags(Flags f) { m_flags = f; }
1177 virtual bool create() = 0;
1178 virtual bool createFrom(NativeRenderBuffer src);
1180 virtual QRhiTexture::Format backingFormat()
const = 0;
1183 QRhiRenderBuffer(QRhiImplementation *rhi, Type type_,
const QSize &pixelSize_,
1184 int sampleCount_, Flags flags_, QRhiTexture::Format backingFormatHint_);
1189 QRhiTexture::Format m_backingFormatHint;
1192Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiRenderBuffer::Flags)
1194class Q_GUI_EXPORT QRhiShadingRateMap :
public QRhiResource
1197 struct NativeShadingRateMap {
1201 QRhiResource::Type resourceType()
const override;
1203 virtual bool createFrom(NativeShadingRateMap src);
1204 virtual bool createFrom(QRhiTexture *src);
1206 virtual QSize logicalSize()
const;
1209 QRhiShadingRateMap(QRhiImplementation *rhi);
1215 QRhiResource::Type resourceType()
const override;
1217 virtual bool isCompatible(
const QRhiRenderPassDescriptor *other)
const = 0;
1218 virtual const QRhiNativeHandles *nativeHandles();
1220 virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor()
const = 0;
1222 virtual QVector<quint32> serializedFormat()
const = 0;
1225 QRhiRenderPassDescriptor(QRhiImplementation *rhi);
1231 virtual QSize pixelSize()
const = 0;
1232 virtual float devicePixelRatio()
const = 0;
1233 virtual int sampleCount()
const = 0;
1235 QRhiRenderPassDescriptor *renderPassDescriptor()
const {
return m_renderPassDesc; }
1236 void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; }
1239 QRhiRenderTarget(QRhiImplementation *rhi);
1240 QRhiRenderPassDescriptor *m_renderPassDesc =
nullptr;
1246 QRhiResource::Type resourceType()
const override;
1247 QRhiSwapChain *swapChain()
const {
return m_swapchain; }
1250 QRhiSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain_);
1251 QRhiSwapChain *m_swapchain;
1258 PreserveColorContents = 1 << 0,
1259 PreserveDepthStencilContents = 1 << 1,
1260 DoNotStoreDepthStencilContents = 1 << 2
1262 Q_DECLARE_FLAGS(Flags, Flag)
1264 QRhiResource::Type resourceType()
const override;
1266 QRhiTextureRenderTargetDescription description()
const {
return m_desc; }
1267 void setDescription(
const QRhiTextureRenderTargetDescription &desc) { m_desc = desc; }
1269 Flags flags()
const {
return m_flags; }
1270 void setFlags(Flags f) { m_flags = f; }
1272 virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() = 0;
1274 virtual bool create() = 0;
1277 QRhiTextureRenderTarget(QRhiImplementation *rhi,
const QRhiTextureRenderTargetDescription &desc_, Flags flags_);
1278 QRhiTextureRenderTargetDescription m_desc;
1282Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiTextureRenderTarget::Flags)
1284class Q_GUI_EXPORT QRhiShaderResourceBindings :
public QRhiResource
1287 QRhiResource::Type resourceType()
const override;
1289 void setBindings(std::initializer_list<QRhiShaderResourceBinding> list) { m_bindings = list; }
1290 template<
typename InputIterator>
1291 void setBindings(InputIterator first, InputIterator last)
1294 std::copy(first, last, std::back_inserter(m_bindings));
1296 const QRhiShaderResourceBinding *cbeginBindings()
const {
return m_bindings.cbegin(); }
1297 const QRhiShaderResourceBinding *cendBindings()
const {
return m_bindings.cend(); }
1298 const QRhiShaderResourceBinding *bindingAt(qsizetype index)
const {
return &m_bindings.at(index); }
1299 qsizetype bindingCount()
const {
return m_bindings.count(); }
1301 bool isLayoutCompatible(
const QRhiShaderResourceBindings *other)
const;
1303 QVector<quint32> serializedLayoutDescription()
const {
return m_layoutDesc; }
1305 virtual bool create() = 0;
1308 BindingsAreSorted = 0x01
1310 Q_DECLARE_FLAGS(UpdateFlags, UpdateFlag)
1312 virtual void updateResources(UpdateFlags flags = {}) = 0;
1315 static constexpr int BINDING_PREALLOC = 12;
1316 QRhiShaderResourceBindings(QRhiImplementation *rhi);
1317 QVarLengthArray<QRhiShaderResourceBinding, BINDING_PREALLOC> m_bindings;
1318 size_t m_layoutDescHash = 0;
1322 QVector<quint32> m_layoutDesc;
1323 friend class QRhiImplementation;
1324#ifndef QT_NO_DEBUG_STREAM
1325 friend Q_GUI_EXPORT QDebug operator<<(QDebug,
const QRhiShaderResourceBindings &);
1329Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiShaderResourceBindings::UpdateFlags)
1331#ifndef QT_NO_DEBUG_STREAM
1332Q_GUI_EXPORT QDebug operator<<(QDebug,
const QRhiShaderResourceBindings &);
1338using QRhiShaderResourceBindingSet = QRhiShaderResourceBindings;
1344 UsesBlendConstants = 1 << 0,
1345 UsesStencilRef = 1 << 1,
1346 UsesScissor = 1 << 2,
1347 CompileShadersWithDebugInfo = 1 << 3,
1348 UsesShadingRate = 1 << 4,
1349 UsesIndirectDraws = 1 << 5
1351 Q_DECLARE_FLAGS(Flags, Flag)
1374 enum ColorMaskComponent {
1380 Q_DECLARE_FLAGS(ColorMask, ColorMaskComponent)
1394 OneMinusConstantColor,
1396 OneMinusConstantAlpha,
1412 struct TargetBlend {
1413 ColorMask colorWrite = ColorMask(0xF);
1414 bool enable =
false;
1415 BlendFactor srcColor = One;
1416 BlendFactor dstColor = OneMinusSrcAlpha;
1417 BlendOp opColor = Add;
1418 BlendFactor srcAlpha = One;
1419 BlendFactor dstAlpha = OneMinusSrcAlpha;
1420 BlendOp opAlpha = Add;
1445 struct StencilOpState {
1446 StencilOp failOp = Keep;
1447 StencilOp depthFailOp = Keep;
1448 StencilOp passOp = Keep;
1449 CompareOp compareOp = Always;
1457 QRhiResource::Type resourceType()
const override;
1459 Flags flags()
const {
return m_flags; }
1460 void setFlags(Flags f) { m_flags = f; }
1462 Topology topology()
const {
return m_topology; }
1463 void setTopology(Topology t) { m_topology = t; }
1465 CullMode cullMode()
const {
return m_cullMode; }
1466 void setCullMode(CullMode mode) { m_cullMode = mode; }
1468 FrontFace frontFace()
const {
return m_frontFace; }
1469 void setFrontFace(FrontFace f) { m_frontFace = f; }
1471 void setTargetBlends(std::initializer_list<TargetBlend> list) { m_targetBlends = list; }
1472 template<
typename InputIterator>
1473 void setTargetBlends(InputIterator first, InputIterator last)
1475 m_targetBlends.clear();
1476 std::copy(first, last, std::back_inserter(m_targetBlends));
1478 const TargetBlend *cbeginTargetBlends()
const {
return m_targetBlends.cbegin(); }
1479 const TargetBlend *cendTargetBlends()
const {
return m_targetBlends.cend(); }
1480 const TargetBlend *targetBlendAt(qsizetype index)
const {
return &m_targetBlends.at(index); }
1481 qsizetype targetBlendCount()
const {
return m_targetBlends.count(); }
1483 bool hasDepthTest()
const {
return m_depthTest; }
1484 void setDepthTest(
bool enable) { m_depthTest = enable; }
1486 bool hasDepthWrite()
const {
return m_depthWrite; }
1487 void setDepthWrite(
bool enable) { m_depthWrite = enable; }
1489 bool hasDepthClamp()
const {
return m_depthClamp; }
1490 void setDepthClamp(
bool enable) { m_depthClamp = enable; }
1492 CompareOp depthOp()
const {
return m_depthOp; }
1493 void setDepthOp(CompareOp op) { m_depthOp = op; }
1495 bool hasStencilTest()
const {
return m_stencilTest; }
1496 void setStencilTest(
bool enable) { m_stencilTest = enable; }
1498 StencilOpState stencilFront()
const {
return m_stencilFront; }
1499 void setStencilFront(
const StencilOpState &state) { m_stencilFront = state; }
1501 StencilOpState stencilBack()
const {
return m_stencilBack; }
1502 void setStencilBack(
const StencilOpState &state) { m_stencilBack = state; }
1504 quint32 stencilReadMask()
const {
return m_stencilReadMask; }
1505 void setStencilReadMask(quint32 mask) { m_stencilReadMask = mask; }
1507 quint32 stencilWriteMask()
const {
return m_stencilWriteMask; }
1508 void setStencilWriteMask(quint32 mask) { m_stencilWriteMask = mask; }
1510 int sampleCount()
const {
return m_sampleCount; }
1511 void setSampleCount(
int s) { m_sampleCount = s; }
1513 float lineWidth()
const {
return m_lineWidth; }
1514 void setLineWidth(
float width) { m_lineWidth = width; }
1516 int depthBias()
const {
return m_depthBias; }
1517 void setDepthBias(
int bias) { m_depthBias = bias; }
1519 float slopeScaledDepthBias()
const {
return m_slopeScaledDepthBias; }
1520 void setSlopeScaledDepthBias(
float bias) { m_slopeScaledDepthBias = bias; }
1522 void setShaderStages(std::initializer_list<QRhiShaderStage> list) { m_shaderStages = list; }
1523 template<
typename InputIterator>
1524 void setShaderStages(InputIterator first, InputIterator last)
1526 m_shaderStages.clear();
1527 std::copy(first, last, std::back_inserter(m_shaderStages));
1529 const QRhiShaderStage *cbeginShaderStages()
const {
return m_shaderStages.cbegin(); }
1530 const QRhiShaderStage *cendShaderStages()
const {
return m_shaderStages.cend(); }
1531 const QRhiShaderStage *shaderStageAt(qsizetype index)
const {
return &m_shaderStages.at(index); }
1532 qsizetype shaderStageCount()
const {
return m_shaderStages.count(); }
1534 QRhiVertexInputLayout vertexInputLayout()
const {
return m_vertexInputLayout; }
1535 void setVertexInputLayout(
const QRhiVertexInputLayout &layout) { m_vertexInputLayout = layout; }
1537 QRhiShaderResourceBindings *shaderResourceBindings()
const {
return m_shaderResourceBindings; }
1538 void setShaderResourceBindings(QRhiShaderResourceBindings *srb) { m_shaderResourceBindings = srb; }
1540 QRhiRenderPassDescriptor *renderPassDescriptor()
const {
return m_renderPassDesc; }
1541 void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; }
1543 int patchControlPointCount()
const {
return m_patchControlPointCount; }
1544 void setPatchControlPointCount(
int count) { m_patchControlPointCount = count; }
1546 PolygonMode polygonMode()
const {
return m_polygonMode; }
1547 void setPolygonMode(PolygonMode mode) {m_polygonMode = mode; }
1549 int multiViewCount()
const {
return m_multiViewCount; }
1550 void setMultiViewCount(
int count) { m_multiViewCount = count; }
1552 virtual bool create() = 0;
1555 QRhiGraphicsPipeline(QRhiImplementation *rhi);
1557 Topology m_topology = Triangles;
1558 CullMode m_cullMode = None;
1559 FrontFace m_frontFace = CCW;
1560 QVarLengthArray<TargetBlend, 8> m_targetBlends;
1561 bool m_depthTest =
false;
1562 bool m_depthWrite =
false;
1563 bool m_depthClamp =
false;
1564 CompareOp m_depthOp = Less;
1565 bool m_stencilTest =
false;
1566 StencilOpState m_stencilFront;
1567 StencilOpState m_stencilBack;
1568 quint32 m_stencilReadMask = 0xFF;
1569 quint32 m_stencilWriteMask = 0xFF;
1570 int m_sampleCount = 1;
1571 float m_lineWidth = 1.0f;
1572 int m_depthBias = 0;
1573 float m_slopeScaledDepthBias = 0.0f;
1574 int m_patchControlPointCount = 3;
1575 PolygonMode m_polygonMode = Fill;
1576 int m_multiViewCount = 0;
1577 QVarLengthArray<QRhiShaderStage, 4> m_shaderStages;
1578 QRhiVertexInputLayout m_vertexInputLayout;
1579 QRhiShaderResourceBindings *m_shaderResourceBindings =
nullptr;
1580 QRhiRenderPassDescriptor *m_renderPassDesc =
nullptr;
1583Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiGraphicsPipeline::Flags)
1584Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiGraphicsPipeline::ColorMask)
1585Q_DECLARE_TYPEINFO(QRhiGraphicsPipeline::TargetBlend, Q_RELOCATABLE_TYPE);
1608 } colorComponentValue;
1616#ifndef QT_NO_DEBUG_STREAM
1617Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiSwapChainHdrInfo &);
1629 SurfaceHasPreMulAlpha = 1 << 0,
1630 SurfaceHasNonPreMulAlpha = 1 << 1,
1632 UsedAsTransferSource = 1 << 3,
1634 MinimalBufferCount = 1 << 5
1636 Q_DECLARE_FLAGS(Flags, Flag)
1640 HDRExtendedSrgbLinear,
1642 HDRExtendedDisplayP3Linear
1645 enum StereoTargetBuffer {
1650 QRhiResource::Type resourceType()
const override;
1652 QWindow *window()
const {
return m_window; }
1653 void setWindow(QWindow *window) { m_window = window; }
1655 QRhiSwapChainProxyData proxyData()
const {
return m_proxyData; }
1656 void setProxyData(
const QRhiSwapChainProxyData &d) { m_proxyData = d; }
1658 Flags flags()
const {
return m_flags; }
1659 void setFlags(Flags f) { m_flags = f; }
1661 Format format()
const {
return m_format; }
1662 void setFormat(Format f) { m_format = f; }
1664 QRhiRenderBuffer *depthStencil()
const {
return m_depthStencil; }
1665 void setDepthStencil(QRhiRenderBuffer *ds) { m_depthStencil = ds; }
1667 int sampleCount()
const {
return m_sampleCount; }
1668 void setSampleCount(
int samples) { m_sampleCount = samples; }
1670 QRhiRenderPassDescriptor *renderPassDescriptor()
const {
return m_renderPassDesc; }
1671 void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; }
1673 QRhiShadingRateMap *shadingRateMap()
const {
return m_shadingRateMap; }
1674 void setShadingRateMap(QRhiShadingRateMap *map) { m_shadingRateMap = map; }
1676 QSize currentPixelSize()
const {
return m_currentPixelSize; }
1678 virtual QRhiCommandBuffer *currentFrameCommandBuffer() = 0;
1679 virtual QRhiRenderTarget *currentFrameRenderTarget() = 0;
1680 virtual QRhiRenderTarget *currentFrameRenderTarget(StereoTargetBuffer targetBuffer);
1681 virtual QSize surfacePixelSize() = 0;
1682 virtual bool isFormatSupported(Format f) = 0;
1683 virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() = 0;
1684 virtual bool createOrResize() = 0;
1685 virtual QRhiSwapChainHdrInfo hdrInfo();
1688 QRhiSwapChain(QRhiImplementation *rhi);
1689 QWindow *m_window =
nullptr;
1691 Format m_format = SDR;
1692 QRhiRenderBuffer *m_depthStencil =
nullptr;
1693 int m_sampleCount = 1;
1694 QRhiRenderPassDescriptor *m_renderPassDesc =
nullptr;
1695 QSize m_currentPixelSize;
1696 QRhiSwapChainProxyData m_proxyData;
1697 QRhiShadingRateMap *m_shadingRateMap =
nullptr;
1700Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiSwapChain::Flags)
1702class Q_GUI_EXPORT QRhiComputePipeline :
public QRhiResource
1706 CompileShadersWithDebugInfo = 1 << 0
1708 Q_DECLARE_FLAGS(Flags, Flag)
1710 QRhiResource::Type resourceType()
const override;
1711 virtual bool create() = 0;
1713 Flags flags()
const {
return m_flags; }
1714 void setFlags(Flags f) { m_flags = f; }
1716 QRhiShaderStage shaderStage()
const {
return m_shaderStage; }
1717 void setShaderStage(
const QRhiShaderStage &stage) { m_shaderStage = stage; }
1719 QRhiShaderResourceBindings *shaderResourceBindings()
const {
return m_shaderResourceBindings; }
1720 void setShaderResourceBindings(QRhiShaderResourceBindings *srb) { m_shaderResourceBindings = srb; }
1723 QRhiComputePipeline(QRhiImplementation *rhi);
1725 QRhiShaderStage m_shaderStage;
1726 QRhiShaderResourceBindings *m_shaderResourceBindings =
nullptr;
1729Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiComputePipeline::Flags)
1731struct QRhiIndirectDrawCommand
1733 quint32 vertexCount;
1734 quint32 instanceCount = 1;
1735 quint32 firstVertex = 0;
1736 quint32 firstInstance = 0;
1756static_assert(
sizeof(QRhiIndirectDrawCommand) == 16);
1768 QRhiResource::Type resourceType()
const override;
1770 Type type()
const {
return m_type; }
1771 void setType(Type t) { m_type = t; }
1773 quint32 maxCommandCount()
const {
return m_maxCommandCount; }
1774 void setMaxCommandCount(quint32 count) { m_maxCommandCount = count; }
1776 virtual bool create() = 0;
1779 void draw(quint32 vertexCount, quint32 instanceCount = 1,
1780 quint32 firstVertex = 0, quint32 firstInstance = 0);
1781 void drawIndexed(quint32 indexCount, quint32 instanceCount = 1, quint32 firstIndex = 0,
1782 qint32 vertexOffset = 0, quint32 firstInstance = 0);
1784 quint32 recordedCommandCount()
const {
return m_commandCount; }
1785 bool isGpuBuilt()
const {
return m_gpuBuilt; }
1786 quint32 commandCount()
const {
return m_gpuBuilt ? m_gpuBuiltCommandCount : m_commandCount; }
1789 QRhiIndirectCommandBuffer(QRhiImplementation *rhi, Type type_, quint32 maxCommandCount_);
1792 quint32 m_maxCommandCount;
1794 quint32 m_commandCount = 0;
1795 quint64 m_generation = 0;
1796 bool m_gpuBuilt =
false;
1797 quint32 m_gpuBuiltCommandCount = 0;
1808 enum BeginPassFlag {
1809 ExternalContent = 0x01,
1810 DoNotTrackResourcesForCompute = 0x02
1812 Q_DECLARE_FLAGS(BeginPassFlags, BeginPassFlag)
1814 QRhiResource::Type resourceType()
const override;
1816 void resourceUpdate(QRhiResourceUpdateBatch *resourceUpdates);
1818 void beginPass(QRhiRenderTarget *rt,
1819 const QColor &colorClearValue,
1820 const QRhiDepthStencilClearValue &depthStencilClearValue,
1821 QRhiResourceUpdateBatch *resourceUpdates =
nullptr,
1822 BeginPassFlags flags = {});
1823 void endPass(QRhiResourceUpdateBatch *resourceUpdates =
nullptr);
1825 void setGraphicsPipeline(QRhiGraphicsPipeline *ps);
1826 using DynamicOffset = std::pair<
int, quint32>;
1827 void setShaderResources(QRhiShaderResourceBindings *srb =
nullptr,
1828 int dynamicOffsetCount = 0,
1829 const DynamicOffset *dynamicOffsets =
nullptr);
1830 using VertexInput = std::pair<QRhiBuffer *, quint32>;
1831 void setVertexInput(
int startBinding,
int bindingCount,
const VertexInput *bindings,
1832 QRhiBuffer *indexBuf =
nullptr, quint32 indexOffset = 0,
1833 IndexFormat indexFormat = IndexUInt16);
1835 void setViewport(
const QRhiViewport &viewport);
1836 void setScissor(
const QRhiScissor &scissor);
1837 void setBlendConstants(
const QColor &c);
1838 void setStencilRef(quint32 refValue);
1839 void setShadingRate(
const QSize &coarsePixelSize);
1840 void setPushConstants(quint32 offset, quint32 size,
const void *data);
1842 void draw(quint32 vertexCount,
1843 quint32 instanceCount = 1,
1844 quint32 firstVertex = 0,
1845 quint32 firstInstance = 0);
1847 void drawIndexed(quint32 indexCount,
1848 quint32 instanceCount = 1,
1849 quint32 firstIndex = 0,
1850 qint32 vertexOffset = 0,
1851 quint32 firstInstance = 0);
1853 void drawIndirect(QRhiBuffer *indirectBuffer,
1854 quint32 indirectBufferOffset,
1856 quint32 stride =
sizeof(QRhiIndirectDrawCommand));
1858 void drawIndexedIndirect(QRhiBuffer *indirectBuffer,
1859 quint32 indirectBufferOffset,
1861 quint32 stride =
sizeof(QRhiIndexedIndirectDrawCommand));
1863 void drawIndirectCount(QRhiBuffer *indirectBuffer,
1864 quint32 indirectBufferOffset,
1865 QRhiBuffer *countBuffer,
1866 quint32 countBufferOffset,
1867 quint32 maxDrawCount,
1868 quint32 stride =
sizeof(QRhiIndirectDrawCommand));
1870 void drawIndexedIndirectCount(QRhiBuffer *indirectBuffer,
1871 quint32 indirectBufferOffset,
1872 QRhiBuffer *countBuffer,
1873 quint32 countBufferOffset,
1874 quint32 maxDrawCount,
1875 quint32 stride =
sizeof(QRhiIndexedIndirectDrawCommand));
1877 void buildIndirect(QRhiIndirectCommandBuffer *icb,
1878 const QRhiIndirectCommandBufferBuildInfo &info);
1880 void executeIndirect(QRhiIndirectCommandBuffer *icb,
1881 quint32 firstCommand = 0,
1882 quint32 commandCount = 0xFFFFFFFFu);
1884 void debugMarkBegin(
const QByteArray &name);
1885 void debugMarkEnd();
1886 void debugMarkMsg(
const QByteArray &msg);
1888 void beginComputePass(QRhiResourceUpdateBatch *resourceUpdates =
nullptr, BeginPassFlags flags = {});
1889 void endComputePass(QRhiResourceUpdateBatch *resourceUpdates =
nullptr);
1890 void setComputePipeline(QRhiComputePipeline *ps);
1891 void dispatch(
int x,
int y,
int z);
1892 void dispatchIndirect(QRhiBuffer *indirectBuffer,
1893 quint32 indirectBufferOffset = 0);
1895 const QRhiNativeHandles *nativeHandles();
1896 void beginExternal();
1899 double lastCompletedGpuTime();
1902 QRhiCommandBuffer(QRhiImplementation *rhi);
1905Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiCommandBuffer::BeginPassFlags)
1907struct QRhiIndirectCommandBufferBuildInfo
1909 QRhiGraphicsPipeline::Topology topology = QRhiGraphicsPipeline::Triangles;
1910 QRhiBuffer *sourceBuffer =
nullptr;
1911 quint32 sourceBufferOffset = 0;
1912 quint32 commandCount = 0;
1914 QRhiBuffer *countBuffer =
nullptr;
1915 quint32 countBufferOffset = 0;
1916 QRhiBuffer *indexBuffer =
nullptr;
1917 quint32 indexBufferOffset = 0;
1918 QRhiCommandBuffer::IndexFormat indexFormat = QRhiCommandBuffer::IndexUInt16;
1923 std::function<
void()> completed =
nullptr;
1924 QRhiTexture::Format format;
1932 ~QRhiResourceUpdateBatch();
1936 void merge(QRhiResourceUpdateBatch *other);
1937 bool hasOptimalCapacity()
const;
1939 void updateDynamicBuffer(QRhiBuffer *buf, quint32 offset, quint32 size,
const void *data);
1940 void updateDynamicBuffer(QRhiBuffer *buf, quint32 offset, QByteArray data);
1941 void uploadStaticBuffer(QRhiBuffer *buf, quint32 offset, quint32 size,
const void *data);
1942 void uploadStaticBuffer(QRhiBuffer *buf, quint32 offset, QByteArray data);
1943 void uploadStaticBuffer(QRhiBuffer *buf,
const void *data);
1944 void uploadStaticBuffer(QRhiBuffer *buf, QByteArray data);
1945 void readBackBuffer(QRhiBuffer *buf, quint32 offset, quint32 size, QRhiReadbackResult *result);
1946 void copyBuffer(QRhiBuffer *dst, QRhiBuffer *src,
const QRhiBufferCopyDescription &desc = QRhiBufferCopyDescription());
1947 void clearStorageBuffer(QRhiBuffer *buf, quint32 offset, quint32 size, quint8 value);
1948 void clearStorageBuffer(QRhiBuffer *buf, quint8 value);
1949 void uploadTexture(QRhiTexture *tex,
const QRhiTextureUploadDescription &desc);
1950 void uploadTexture(QRhiTexture *tex,
const QImage &image);
1951 void copyTexture(QRhiTexture *dst, QRhiTexture *src,
const QRhiTextureCopyDescription &desc = QRhiTextureCopyDescription());
1952 void readBackTexture(
const QRhiReadbackDescription &rb, QRhiReadbackResult *result);
1953 void generateMips(QRhiTexture *tex);
1954 void commitIndirectCommandBuffer(QRhiIndirectCommandBuffer *icb);
1957 QRhiResourceUpdateBatch(QRhiImplementation *rhi);
1958 Q_DISABLE_COPY(QRhiResourceUpdateBatch)
1959 QRhiResourceUpdateBatchPrivate *d;
1960 friend class QRhiResourceUpdateBatchPrivate;
1975 QByteArray deviceName;
1976 quint64 deviceId = 0;
1977 quint64 vendorId = 0;
1978 DeviceType deviceType = UnknownDevice;
1983#ifndef QT_NO_DEBUG_STREAM
1984Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiDriverInfo &);
1989 qint64 totalPipelineCreationTime = 0;
1991 quint32 blockCount = 0;
1992 quint32 allocCount = 0;
1993 quint64 usedBytes = 0;
1994 quint64 unusedBytes = 0;
1996 quint64 totalUsageBytes = 0;
2001#ifndef QT_NO_DEBUG_STREAM
2002Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiStats &);
2008 virtual ~QRhiAdapter();
2009 virtual QRhiDriverInfo info()
const = 0;
2019 enum Implementation {
2029 EnableDebugMarkers = 1 << 0,
2030 PreferSoftwareRenderer = 1 << 1,
2031 EnablePipelineCacheDataSave = 1 << 2,
2032 EnableTimestamps = 1 << 3,
2033 SuppressSmokeTestWarnings = 1 << 4
2035 Q_DECLARE_FLAGS(Flags, Flag)
2037 enum FrameOpResult {
2040 FrameOpSwapChainOutOfDate,
2045 MultisampleTexture = 1,
2046 MultisampleRenderBuffer,
2050 CustomInstanceStepRate,
2052 NonDynamicUniformBuffers,
2053 NonFourAlignedEffectiveIndexBufferOffset,
2059 VertexShaderPointSize,
2062 TriangleFanTopology,
2063 ReadBackNonUniformBuffer,
2064 ReadBackNonBaseMipLevel,
2066 RenderToNonBaseMipLevel,
2068 ScreenSpaceDerivatives,
2069 ReadBackAnyTextureFormat,
2070 PipelineCacheDataLoadSave,
2073 ThreeDimensionalTextures,
2074 RenderTo3DTextureSlice,
2080 OneDimensionalTextures,
2081 OneDimensionalTextureMipmaps,
2083 RenderToOneDimensionalTexture,
2084 ThreeDimensionalTextureMipmaps,
2087 ResolveDepthStencil,
2088 VariableRateShading,
2089 VariableRateShadingMap,
2090 VariableRateShadingMapWithTexture,
2091 PerRenderTargetBlending,
2093 InstanceIndexIncludesBaseInstance,
2097 ShaderDrawParameters,
2102 StaticBuffersOnGpuTimeline
2105 enum BeginFrameFlag {
2107 Q_DECLARE_FLAGS(BeginFrameFlags, BeginFrameFlag)
2110 SkipPresent = 1 << 0
2112 Q_DECLARE_FLAGS(EndFrameFlags, EndFrameFlag)
2114 enum ResourceLimit {
2117 MaxColorAttachments,
2119 MaxAsyncReadbackFrames,
2120 MaxThreadGroupsPerDimension,
2121 MaxThreadsPerThreadGroup,
2125 TextureArraySizeMax,
2126 MaxUniformBufferRange,
2129 ShadingRateImageTileSize,
2130 MaxVertexStorageBuffers,
2131 MaxFragmentStorageBuffers,
2132 MaxPushConstantsSize
2137 static QRhi *create(Implementation impl,
2138 QRhiInitParams *params,
2140 QRhiNativeHandles *importDevice =
nullptr);
2141 static QRhi *create(Implementation impl,
2142 QRhiInitParams *params,
2144 QRhiNativeHandles *importDevice,
2145 QRhiAdapter *adapter);
2146 static bool probe(Implementation impl, QRhiInitParams *params);
2147 using AdapterList = QVector<QRhiAdapter *>;
2148 static AdapterList enumerateAdapters(Implementation impl,
2149 QRhiInitParams *params,
2150 QRhiNativeHandles *nativeHandles =
nullptr);
2152 Implementation backend()
const;
2153 const char *backendName()
const;
2154 static const char *backendName(Implementation impl);
2155 QRhiDriverInfo driverInfo()
const;
2156 QThread *thread()
const;
2158 using CleanupCallback = std::function<
void(QRhi *)>;
2159 void addCleanupCallback(
const CleanupCallback &callback);
2160 void addCleanupCallback(
const void *key,
const CleanupCallback &callback);
2161 void removeCleanupCallback(
const void *key);
2163 QRhiGraphicsPipeline *newGraphicsPipeline();
2164 QRhiComputePipeline *newComputePipeline();
2165 QRhiShaderResourceBindings *newShaderResourceBindings();
2167 QRhiBuffer *newBuffer(QRhiBuffer::Type type,
2168 QRhiBuffer::UsageFlags usage,
2171 QRhiRenderBuffer *newRenderBuffer(QRhiRenderBuffer::Type type,
2172 const QSize &pixelSize,
2173 int sampleCount = 1,
2174 QRhiRenderBuffer::Flags flags = {},
2175 QRhiTexture::Format backingFormatHint = QRhiTexture::UnknownFormat);
2177 QRhiTexture *newTexture(QRhiTexture::Format format,
2178 const QSize &pixelSize,
2179 int sampleCount = 1,
2180 QRhiTexture::Flags flags = {});
2182 QRhiTexture *newTexture(QRhiTexture::Format format,
2183 int width,
int height,
int depth,
2184 int sampleCount = 1,
2185 QRhiTexture::Flags flags = {});
2187 QRhiTexture *newTextureArray(QRhiTexture::Format format,
2189 const QSize &pixelSize,
2190 int sampleCount = 1,
2191 QRhiTexture::Flags flags = {});
2193 QRhiSampler *newSampler(QRhiSampler::Filter magFilter,
2194 QRhiSampler::Filter minFilter,
2195 QRhiSampler::Filter mipmapMode,
2196 QRhiSampler::AddressMode addressU,
2197 QRhiSampler::AddressMode addressV,
2198 QRhiSampler::AddressMode addressW = QRhiSampler::Repeat);
2200 QRhiShadingRateMap *newShadingRateMap();
2202 QRhiIndirectCommandBuffer *newIndirectCommandBuffer(QRhiIndirectCommandBuffer::Type type,
2203 quint32 maxCommandCount);
2205 QRhiTextureRenderTarget *newTextureRenderTarget(
const QRhiTextureRenderTargetDescription &desc,
2206 QRhiTextureRenderTarget::Flags flags = {});
2208 QRhiSwapChain *newSwapChain();
2209 FrameOpResult beginFrame(QRhiSwapChain *swapChain, BeginFrameFlags flags = {});
2210 FrameOpResult endFrame(QRhiSwapChain *swapChain, EndFrameFlags flags = {});
2211 bool isRecordingFrame()
const;
2212 int currentFrameSlot()
const;
2214 FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb, BeginFrameFlags flags = {});
2215 FrameOpResult endOffscreenFrame(EndFrameFlags flags = {});
2217 QRhi::FrameOpResult finish();
2219 QRhiResourceUpdateBatch *nextResourceUpdateBatch();
2221 QList<
int> supportedSampleCounts()
const;
2223 int ubufAlignment()
const;
2224 int ubufAligned(
int v)
const;
2226 static int mipLevelsForSize(
const QSize &size);
2227 static QSize sizeForMipLevel(
int mipLevel,
const QSize &baseLevelSize);
2229 bool isYUpInFramebuffer()
const;
2230 bool isYUpInNDC()
const;
2231 bool isClipDepthZeroToOne()
const;
2233 QMatrix4x4 clipSpaceCorrMatrix()
const;
2235 bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags = {})
const;
2236 bool isFeatureSupported(QRhi::Feature feature)
const;
2237 int resourceLimit(ResourceLimit limit)
const;
2239 const QRhiNativeHandles *nativeHandles();
2240 bool makeThreadLocalNativeContextCurrent();
2241 void setQueueSubmitParams(QRhiNativeHandles *params);
2243 static constexpr int MAX_MIP_LEVELS = 16;
2245 void releaseCachedResources();
2247 bool isDeviceLost()
const;
2249 QByteArray pipelineCacheData();
2250 void setPipelineCacheData(
const QByteArray &data);
2252 QRhiStats statistics()
const;
2254 static QRhiSwapChainProxyData updateSwapChainProxyData(Implementation impl, QWindow *window);
2256 QList<QSize> supportedShadingRates(
int sampleCount)
const;
2262 Q_DISABLE_COPY(QRhi)
2263 QRhiImplementation *d =
nullptr;
2266Q_DECLARE_OPERATORS_FOR_FLAGS(QRhi::Flags)
2267Q_DECLARE_OPERATORS_FOR_FLAGS(QRhi::BeginFrameFlags)
2268Q_DECLARE_OPERATORS_FOR_FLAGS(QRhi::EndFrameFlags)
2272#include <rhi/qrhi_platform.h>
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
\variable QRhiDispatchIndirectCommand::x
\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]
\variable QRhiIndexedIndirectDrawCommand::indexCount
\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
\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