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 {
513 TextureAndSampler texSamplers[MAX_TEX_SAMPLER_ARRAY_SIZE];
515 struct StorageImageData {
519 struct StorageBufferData {
525 UniformBufferData ubuf;
526 TextureAndOrSamplerData stex;
527 StorageImageData simage;
528 StorageBufferData sbuf;
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_DECLARE_TYPEINFO(QRhiShaderResourceBinding, Q_PRIMITIVE_TYPE);
572Q_GUI_EXPORT
bool operator==(
const QRhiShaderResourceBinding &a,
const QRhiShaderResourceBinding &b)
noexcept;
573Q_GUI_EXPORT
bool operator!=(
const QRhiShaderResourceBinding &a,
const QRhiShaderResourceBinding &b)
noexcept;
574Q_GUI_EXPORT size_t qHash(
const QRhiShaderResourceBinding &b, size_t seed = 0)
noexcept;
575#ifndef QT_NO_DEBUG_STREAM
576Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiShaderResourceBinding &);
582 QRhiColorAttachment() =
default;
583 QRhiColorAttachment(QRhiTexture *texture);
584 QRhiColorAttachment(QRhiRenderBuffer *renderBuffer);
586 QRhiTexture *texture()
const {
return m_texture; }
587 void setTexture(QRhiTexture *tex) { m_texture = tex; }
589 QRhiRenderBuffer *renderBuffer()
const {
return m_renderBuffer; }
590 void setRenderBuffer(QRhiRenderBuffer *rb) { m_renderBuffer = rb; }
592 int layer()
const {
return m_layer; }
593 void setLayer(
int layer) { m_layer = layer; }
595 int level()
const {
return m_level; }
596 void setLevel(
int level) { m_level = level; }
598 QRhiTexture *resolveTexture()
const {
return m_resolveTexture; }
599 void setResolveTexture(QRhiTexture *tex) { m_resolveTexture = tex; }
601 int resolveLayer()
const {
return m_resolveLayer; }
602 void setResolveLayer(
int layer) { m_resolveLayer = layer; }
604 int resolveLevel()
const {
return m_resolveLevel; }
605 void setResolveLevel(
int level) { m_resolveLevel = level; }
607 int multiViewCount()
const {
return m_multiViewCount; }
608 void setMultiViewCount(
int count) { m_multiViewCount = count; }
611 QRhiTexture *m_texture =
nullptr;
612 QRhiRenderBuffer *m_renderBuffer =
nullptr;
615 QRhiTexture *m_resolveTexture =
nullptr;
616 int m_resolveLayer = 0;
617 int m_resolveLevel = 0;
618 int m_multiViewCount = 0;
626 QRhiTextureRenderTargetDescription() =
default;
627 QRhiTextureRenderTargetDescription(
const QRhiColorAttachment &colorAttachment);
628 QRhiTextureRenderTargetDescription(
const QRhiColorAttachment &colorAttachment, QRhiRenderBuffer *depthStencilBuffer);
629 QRhiTextureRenderTargetDescription(
const QRhiColorAttachment &colorAttachment, QRhiTexture *depthTexture);
631 void setColorAttachments(std::initializer_list<QRhiColorAttachment> list) { m_colorAttachments = list; }
632 template<
typename InputIterator>
633 void setColorAttachments(InputIterator first, InputIterator last)
635 m_colorAttachments.clear();
636 std::copy(first, last, std::back_inserter(m_colorAttachments));
638 const QRhiColorAttachment *cbeginColorAttachments()
const {
return m_colorAttachments.cbegin(); }
639 const QRhiColorAttachment *cendColorAttachments()
const {
return m_colorAttachments.cend(); }
640 const QRhiColorAttachment *colorAttachmentAt(qsizetype index)
const {
return &m_colorAttachments.at(index); }
641 qsizetype colorAttachmentCount()
const {
return m_colorAttachments.count(); }
643 QRhiRenderBuffer *depthStencilBuffer()
const {
return m_depthStencilBuffer; }
644 void setDepthStencilBuffer(QRhiRenderBuffer *renderBuffer) { m_depthStencilBuffer = renderBuffer; }
646 QRhiTexture *depthTexture()
const {
return m_depthTexture; }
647 void setDepthTexture(QRhiTexture *texture) { m_depthTexture = texture; }
649 int depthLayer()
const {
return m_depthLayer; }
650 void setDepthLayer(
int depthLayer) { m_depthLayer = depthLayer; }
652 QRhiTexture *depthResolveTexture()
const {
return m_depthResolveTexture; }
653 void setDepthResolveTexture(QRhiTexture *tex) { m_depthResolveTexture = tex; }
655 QRhiShadingRateMap *shadingRateMap()
const {
return m_shadingRateMap; }
656 void setShadingRateMap(QRhiShadingRateMap *map) { m_shadingRateMap = map; }
659 QVarLengthArray<QRhiColorAttachment, 8> m_colorAttachments;
660 QRhiRenderBuffer *m_depthStencilBuffer =
nullptr;
661 QRhiTexture *m_depthTexture =
nullptr;
662 QRhiTexture *m_depthResolveTexture =
nullptr;
663 QRhiShadingRateMap *m_shadingRateMap =
nullptr;
664 int m_depthLayer = -1;
670 QRhiTextureSubresourceUploadDescription() =
default;
671 explicit QRhiTextureSubresourceUploadDescription(
const QImage &image);
672 QRhiTextureSubresourceUploadDescription(
const void *data, quint32 size);
673 explicit QRhiTextureSubresourceUploadDescription(
const QByteArray &data);
675 QImage image()
const {
return m_image; }
676 void setImage(
const QImage &image) { m_image = image; }
678 QByteArray data()
const {
return m_data; }
679 void setData(
const QByteArray &data) { m_data = data; }
681 quint32 dataStride()
const {
return m_dataStride; }
682 void setDataStride(quint32 stride) { m_dataStride = stride; }
684 QPoint destinationTopLeft()
const {
return m_destinationTopLeft; }
685 void setDestinationTopLeft(
const QPoint &p) { m_destinationTopLeft = p; }
687 QSize sourceSize()
const {
return m_sourceSize; }
688 void setSourceSize(
const QSize &size) { m_sourceSize = size; }
690 QPoint sourceTopLeft()
const {
return m_sourceTopLeft; }
691 void setSourceTopLeft(
const QPoint &p) { m_sourceTopLeft = p; }
696 quint32 m_dataStride = 0;
697 QPoint m_destinationTopLeft;
699 QPoint m_sourceTopLeft;
707 QRhiTextureUploadEntry() =
default;
708 QRhiTextureUploadEntry(
int layer,
int level,
const QRhiTextureSubresourceUploadDescription &desc);
710 int layer()
const {
return m_layer; }
711 void setLayer(
int layer) { m_layer = layer; }
713 int level()
const {
return m_level; }
714 void setLevel(
int level) { m_level = level; }
716 QRhiTextureSubresourceUploadDescription description()
const {
return m_desc; }
717 void setDescription(
const QRhiTextureSubresourceUploadDescription &desc) { m_desc = desc; }
722 QRhiTextureSubresourceUploadDescription m_desc;
730 QRhiTextureUploadDescription() =
default;
731 QRhiTextureUploadDescription(
const QRhiTextureUploadEntry &entry);
732 QRhiTextureUploadDescription(std::initializer_list<QRhiTextureUploadEntry> list);
734 void setEntries(std::initializer_list<QRhiTextureUploadEntry> list) { m_entries = list; }
735 template<
typename InputIterator>
736 void setEntries(InputIterator first, InputIterator last)
739 std::copy(first, last, std::back_inserter(m_entries));
741 const QRhiTextureUploadEntry *cbeginEntries()
const {
return m_entries.cbegin(); }
742 const QRhiTextureUploadEntry *cendEntries()
const {
return m_entries.cend(); }
743 const QRhiTextureUploadEntry *entryAt(qsizetype index)
const {
return &m_entries.at(index); }
744 qsizetype entryCount()
const {
return m_entries.count(); }
747 QVarLengthArray<QRhiTextureUploadEntry, 16> m_entries;
753 QRhiTextureCopyDescription() =
default;
755 QSize pixelSize()
const {
return m_pixelSize; }
756 void setPixelSize(
const QSize &sz) { m_pixelSize = sz; }
758 int sourceLayer()
const {
return m_sourceLayer; }
759 void setSourceLayer(
int layer) { m_sourceLayer = layer; }
761 int sourceLevel()
const {
return m_sourceLevel; }
762 void setSourceLevel(
int level) { m_sourceLevel = level; }
764 QPoint sourceTopLeft()
const {
return m_sourceTopLeft; }
765 void setSourceTopLeft(
const QPoint &p) { m_sourceTopLeft = p; }
767 int destinationLayer()
const {
return m_destinationLayer; }
768 void setDestinationLayer(
int layer) { m_destinationLayer = layer; }
770 int destinationLevel()
const {
return m_destinationLevel; }
771 void setDestinationLevel(
int level) { m_destinationLevel = level; }
773 QPoint destinationTopLeft()
const {
return m_destinationTopLeft; }
774 void setDestinationTopLeft(
const QPoint &p) { m_destinationTopLeft = p; }
778 int m_sourceLayer = 0;
779 int m_sourceLevel = 0;
780 QPoint m_sourceTopLeft;
781 int m_destinationLayer = 0;
782 int m_destinationLevel = 0;
783 QPoint m_destinationTopLeft;
791 QRhiReadbackDescription() =
default;
792 QRhiReadbackDescription(QRhiTexture *texture);
794 QRhiTexture *texture()
const {
return m_texture; }
795 void setTexture(QRhiTexture *tex) { m_texture = tex; }
797 int layer()
const {
return m_layer; }
798 void setLayer(
int layer) { m_layer = layer; }
800 int level()
const {
return m_level; }
801 void setLevel(
int level) { m_level = level; }
803 QRect rect()
const {
return m_rect; }
804 void setRect(
const QRect &rectangle) { m_rect = rectangle; }
807 QRhiTexture *m_texture =
nullptr;
827 RenderPassDescriptor,
828 SwapChainRenderTarget,
830 ShaderResourceBindings,
836 IndirectCommandBuffer
839 virtual ~QRhiResource();
841 virtual Type resourceType()
const = 0;
843 virtual void destroy() = 0;
847 QByteArray name()
const;
848 void setName(
const QByteArray &name);
850 quint64 globalResourceId()
const;
855 QRhiResource(QRhiImplementation *rhi);
856 Q_DISABLE_COPY(QRhiResource)
857 friend class QRhiImplementation;
858 QRhiImplementation *m_rhi =
nullptr;
860 QByteArray m_objectName;
873 VertexBuffer = 1 << 0,
874 IndexBuffer = 1 << 1,
875 UniformBuffer = 1 << 2,
876 StorageBuffer = 1 << 3,
877 IndirectBuffer = 1 << 4,
879 Q_DECLARE_FLAGS(UsageFlags, UsageFlag)
881 struct NativeBuffer {
882 const void *objects[3];
886 QRhiResource::Type resourceType()
const override;
888 Type type()
const {
return m_type; }
889 void setType(Type t) { m_type = t; }
891 UsageFlags usage()
const {
return m_usage; }
892 void setUsage(UsageFlags u) { m_usage = u; }
894 quint32 size()
const {
return m_size; }
895 void setSize(quint32 sz) { m_size = sz; }
897 virtual bool create() = 0;
899 virtual NativeBuffer nativeBuffer();
901 virtual char *beginFullDynamicBufferUpdateForCurrentFrame();
902 virtual void endFullDynamicBufferUpdateForCurrentFrame();
903 virtual void fullDynamicBufferUpdateForCurrentFrame(
const void *data, quint32 size = 0);
906 QRhiBuffer(QRhiImplementation *rhi, Type type_, UsageFlags usage_, quint32 size_);
912Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiBuffer::UsageFlags)
914class Q_GUI_EXPORT QRhiTexture :
public QRhiResource
918 RenderTarget = 1 << 0,
922 UsedAsTransferSource = 1 << 5,
923 UsedWithGenerateMips = 1 << 6,
924 UsedWithLoadStore = 1 << 7,
925 UsedAsCompressedAtlas = 1 << 8,
926 ExternalOES = 1 << 9,
927 ThreeDimensional = 1 << 10,
928 TextureRectangleGL = 1 << 11,
929 TextureArray = 1 << 12,
930 OneDimensional = 1 << 13,
931 UsedAsShadingRateMap = 1 << 14
933 Q_DECLARE_FLAGS(Flags, Flag)
997 struct NativeTexture {
1002 QRhiResource::Type resourceType()
const override;
1004 Format format()
const {
return m_format; }
1005 void setFormat(Format fmt) { m_format = fmt; }
1007 QSize pixelSize()
const {
return m_pixelSize; }
1008 void setPixelSize(
const QSize &sz) { m_pixelSize = sz; }
1010 int depth()
const {
return m_depth; }
1011 void setDepth(
int depth) { m_depth = depth; }
1013 int arraySize()
const {
return m_arraySize; }
1014 void setArraySize(
int arraySize) { m_arraySize = arraySize; }
1016 int arrayRangeStart()
const {
return m_arrayRangeStart; }
1017 int arrayRangeLength()
const {
return m_arrayRangeLength; }
1018 void setArrayRange(
int startIndex,
int count)
1020 m_arrayRangeStart = startIndex;
1021 m_arrayRangeLength = count;
1024 Flags flags()
const {
return m_flags; }
1025 void setFlags(Flags f) { m_flags = f; }
1027 int sampleCount()
const {
return m_sampleCount; }
1028 void setSampleCount(
int s) { m_sampleCount = s; }
1031 QRhiTexture::Format format;
1034 ViewFormat readViewFormat()
const {
return m_readViewFormat; }
1035 void setReadViewFormat(
const ViewFormat &fmt) { m_readViewFormat = fmt; }
1036 ViewFormat writeViewFormat()
const {
return m_writeViewFormat; }
1037 void setWriteViewFormat(
const ViewFormat &fmt) { m_writeViewFormat = fmt; }
1039 virtual bool create() = 0;
1040 virtual NativeTexture nativeTexture();
1041 virtual bool createFrom(NativeTexture src);
1042 virtual void setNativeLayout(
int layout);
1045 QRhiTexture(QRhiImplementation *rhi, Format format_,
const QSize &pixelSize_,
int depth_,
1046 int arraySize_,
int sampleCount_, Flags flags_);
1053 int m_arrayRangeStart = -1;
1054 int m_arrayRangeLength = -1;
1055 ViewFormat m_readViewFormat = { UnknownFormat,
false };
1056 ViewFormat m_writeViewFormat = { UnknownFormat,
false };
1059Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiTexture::Flags)
1061class Q_GUI_EXPORT QRhiSampler :
public QRhiResource
1087 QRhiResource::Type resourceType()
const override;
1089 Filter magFilter()
const {
return m_magFilter; }
1090 void setMagFilter(Filter f) { m_magFilter = f; }
1092 Filter minFilter()
const {
return m_minFilter; }
1093 void setMinFilter(Filter f) { m_minFilter = f; }
1095 Filter mipmapMode()
const {
return m_mipmapMode; }
1096 void setMipmapMode(Filter f) { m_mipmapMode = f; }
1098 AddressMode addressU()
const {
return m_addressU; }
1099 void setAddressU(AddressMode mode) { m_addressU = mode; }
1101 AddressMode addressV()
const {
return m_addressV; }
1102 void setAddressV(AddressMode mode) { m_addressV = mode; }
1104 AddressMode addressW()
const {
return m_addressW; }
1105 void setAddressW(AddressMode mode) { m_addressW = mode; }
1107 CompareOp textureCompareOp()
const {
return m_compareOp; }
1108 void setTextureCompareOp(CompareOp op) { m_compareOp = op; }
1110 virtual bool create() = 0;
1113 QRhiSampler(QRhiImplementation *rhi,
1114 Filter magFilter_, Filter minFilter_, Filter mipmapMode_,
1115 AddressMode u_, AddressMode v_, AddressMode w_);
1118 Filter m_mipmapMode;
1119 AddressMode m_addressU;
1120 AddressMode m_addressV;
1121 AddressMode m_addressW;
1122 CompareOp m_compareOp;
1134 UsedWithSwapChainOnly = 1 << 0,
1135 NoTransientBacking = 1 << 1
1137 Q_DECLARE_FLAGS(Flags, Flag)
1139 struct NativeRenderBuffer {
1143 QRhiResource::Type resourceType()
const override;
1145 Type type()
const {
return m_type; }
1146 void setType(Type t) { m_type = t; }
1148 QSize pixelSize()
const {
return m_pixelSize; }
1149 void setPixelSize(
const QSize &sz) { m_pixelSize = sz; }
1151 int sampleCount()
const {
return m_sampleCount; }
1152 void setSampleCount(
int s) { m_sampleCount = s; }
1154 Flags flags()
const {
return m_flags; }
1155 void setFlags(Flags f) { m_flags = f; }
1157 virtual bool create() = 0;
1158 virtual bool createFrom(NativeRenderBuffer src);
1160 virtual QRhiTexture::Format backingFormat()
const = 0;
1163 QRhiRenderBuffer(QRhiImplementation *rhi, Type type_,
const QSize &pixelSize_,
1164 int sampleCount_, Flags flags_, QRhiTexture::Format backingFormatHint_);
1169 QRhiTexture::Format m_backingFormatHint;
1172Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiRenderBuffer::Flags)
1174class Q_GUI_EXPORT QRhiShadingRateMap :
public QRhiResource
1177 struct NativeShadingRateMap {
1181 QRhiResource::Type resourceType()
const override;
1183 virtual bool createFrom(NativeShadingRateMap src);
1184 virtual bool createFrom(QRhiTexture *src);
1187 QRhiShadingRateMap(QRhiImplementation *rhi);
1193 QRhiResource::Type resourceType()
const override;
1195 virtual bool isCompatible(
const QRhiRenderPassDescriptor *other)
const = 0;
1196 virtual const QRhiNativeHandles *nativeHandles();
1198 virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor()
const = 0;
1200 virtual QVector<quint32> serializedFormat()
const = 0;
1203 QRhiRenderPassDescriptor(QRhiImplementation *rhi);
1209 virtual QSize pixelSize()
const = 0;
1210 virtual float devicePixelRatio()
const = 0;
1211 virtual int sampleCount()
const = 0;
1213 QRhiRenderPassDescriptor *renderPassDescriptor()
const {
return m_renderPassDesc; }
1214 void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; }
1217 QRhiRenderTarget(QRhiImplementation *rhi);
1218 QRhiRenderPassDescriptor *m_renderPassDesc =
nullptr;
1224 QRhiResource::Type resourceType()
const override;
1225 QRhiSwapChain *swapChain()
const {
return m_swapchain; }
1228 QRhiSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain_);
1229 QRhiSwapChain *m_swapchain;
1236 PreserveColorContents = 1 << 0,
1237 PreserveDepthStencilContents = 1 << 1,
1238 DoNotStoreDepthStencilContents = 1 << 2
1240 Q_DECLARE_FLAGS(Flags, Flag)
1242 QRhiResource::Type resourceType()
const override;
1244 QRhiTextureRenderTargetDescription description()
const {
return m_desc; }
1245 void setDescription(
const QRhiTextureRenderTargetDescription &desc) { m_desc = desc; }
1247 Flags flags()
const {
return m_flags; }
1248 void setFlags(Flags f) { m_flags = f; }
1250 virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() = 0;
1252 virtual bool create() = 0;
1255 QRhiTextureRenderTarget(QRhiImplementation *rhi,
const QRhiTextureRenderTargetDescription &desc_, Flags flags_);
1256 QRhiTextureRenderTargetDescription m_desc;
1260Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiTextureRenderTarget::Flags)
1262class Q_GUI_EXPORT QRhiShaderResourceBindings :
public QRhiResource
1265 QRhiResource::Type resourceType()
const override;
1267 void setBindings(std::initializer_list<QRhiShaderResourceBinding> list) { m_bindings = list; }
1268 template<
typename InputIterator>
1269 void setBindings(InputIterator first, InputIterator last)
1272 std::copy(first, last, std::back_inserter(m_bindings));
1274 const QRhiShaderResourceBinding *cbeginBindings()
const {
return m_bindings.cbegin(); }
1275 const QRhiShaderResourceBinding *cendBindings()
const {
return m_bindings.cend(); }
1276 const QRhiShaderResourceBinding *bindingAt(qsizetype index)
const {
return &m_bindings.at(index); }
1277 qsizetype bindingCount()
const {
return m_bindings.count(); }
1279 bool isLayoutCompatible(
const QRhiShaderResourceBindings *other)
const;
1281 QVector<quint32> serializedLayoutDescription()
const {
return m_layoutDesc; }
1283 virtual bool create() = 0;
1286 BindingsAreSorted = 0x01
1288 Q_DECLARE_FLAGS(UpdateFlags, UpdateFlag)
1290 virtual void updateResources(UpdateFlags flags = {}) = 0;
1293 static constexpr int BINDING_PREALLOC = 12;
1294 QRhiShaderResourceBindings(QRhiImplementation *rhi);
1295 QVarLengthArray<QRhiShaderResourceBinding, BINDING_PREALLOC> m_bindings;
1296 size_t m_layoutDescHash = 0;
1300 QVector<quint32> m_layoutDesc;
1301 friend class QRhiImplementation;
1302#ifndef QT_NO_DEBUG_STREAM
1303 friend Q_GUI_EXPORT QDebug operator<<(QDebug,
const QRhiShaderResourceBindings &);
1307Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiShaderResourceBindings::UpdateFlags)
1309#ifndef QT_NO_DEBUG_STREAM
1310Q_GUI_EXPORT QDebug operator<<(QDebug,
const QRhiShaderResourceBindings &);
1316using QRhiShaderResourceBindingSet = QRhiShaderResourceBindings;
1322 UsesBlendConstants = 1 << 0,
1323 UsesStencilRef = 1 << 1,
1324 UsesScissor = 1 << 2,
1325 CompileShadersWithDebugInfo = 1 << 3,
1326 UsesShadingRate = 1 << 4,
1327 UsesIndirectDraws = 1 << 5
1329 Q_DECLARE_FLAGS(Flags, Flag)
1352 enum ColorMaskComponent {
1358 Q_DECLARE_FLAGS(ColorMask, ColorMaskComponent)
1372 OneMinusConstantColor,
1374 OneMinusConstantAlpha,
1390 struct TargetBlend {
1391 ColorMask colorWrite = ColorMask(0xF);
1392 bool enable =
false;
1393 BlendFactor srcColor = One;
1394 BlendFactor dstColor = OneMinusSrcAlpha;
1395 BlendOp opColor = Add;
1396 BlendFactor srcAlpha = One;
1397 BlendFactor dstAlpha = OneMinusSrcAlpha;
1398 BlendOp opAlpha = Add;
1423 struct StencilOpState {
1424 StencilOp failOp = Keep;
1425 StencilOp depthFailOp = Keep;
1426 StencilOp passOp = Keep;
1427 CompareOp compareOp = Always;
1435 QRhiResource::Type resourceType()
const override;
1437 Flags flags()
const {
return m_flags; }
1438 void setFlags(Flags f) { m_flags = f; }
1440 Topology topology()
const {
return m_topology; }
1441 void setTopology(Topology t) { m_topology = t; }
1443 CullMode cullMode()
const {
return m_cullMode; }
1444 void setCullMode(CullMode mode) { m_cullMode = mode; }
1446 FrontFace frontFace()
const {
return m_frontFace; }
1447 void setFrontFace(FrontFace f) { m_frontFace = f; }
1449 void setTargetBlends(std::initializer_list<TargetBlend> list) { m_targetBlends = list; }
1450 template<
typename InputIterator>
1451 void setTargetBlends(InputIterator first, InputIterator last)
1453 m_targetBlends.clear();
1454 std::copy(first, last, std::back_inserter(m_targetBlends));
1456 const TargetBlend *cbeginTargetBlends()
const {
return m_targetBlends.cbegin(); }
1457 const TargetBlend *cendTargetBlends()
const {
return m_targetBlends.cend(); }
1458 const TargetBlend *targetBlendAt(qsizetype index)
const {
return &m_targetBlends.at(index); }
1459 qsizetype targetBlendCount()
const {
return m_targetBlends.count(); }
1461 bool hasDepthTest()
const {
return m_depthTest; }
1462 void setDepthTest(
bool enable) { m_depthTest = enable; }
1464 bool hasDepthWrite()
const {
return m_depthWrite; }
1465 void setDepthWrite(
bool enable) { m_depthWrite = enable; }
1467 bool hasDepthClamp()
const {
return m_depthClamp; }
1468 void setDepthClamp(
bool enable) { m_depthClamp = enable; }
1470 CompareOp depthOp()
const {
return m_depthOp; }
1471 void setDepthOp(CompareOp op) { m_depthOp = op; }
1473 bool hasStencilTest()
const {
return m_stencilTest; }
1474 void setStencilTest(
bool enable) { m_stencilTest = enable; }
1476 StencilOpState stencilFront()
const {
return m_stencilFront; }
1477 void setStencilFront(
const StencilOpState &state) { m_stencilFront = state; }
1479 StencilOpState stencilBack()
const {
return m_stencilBack; }
1480 void setStencilBack(
const StencilOpState &state) { m_stencilBack = state; }
1482 quint32 stencilReadMask()
const {
return m_stencilReadMask; }
1483 void setStencilReadMask(quint32 mask) { m_stencilReadMask = mask; }
1485 quint32 stencilWriteMask()
const {
return m_stencilWriteMask; }
1486 void setStencilWriteMask(quint32 mask) { m_stencilWriteMask = mask; }
1488 int sampleCount()
const {
return m_sampleCount; }
1489 void setSampleCount(
int s) { m_sampleCount = s; }
1491 float lineWidth()
const {
return m_lineWidth; }
1492 void setLineWidth(
float width) { m_lineWidth = width; }
1494 int depthBias()
const {
return m_depthBias; }
1495 void setDepthBias(
int bias) { m_depthBias = bias; }
1497 float slopeScaledDepthBias()
const {
return m_slopeScaledDepthBias; }
1498 void setSlopeScaledDepthBias(
float bias) { m_slopeScaledDepthBias = bias; }
1500 void setShaderStages(std::initializer_list<QRhiShaderStage> list) { m_shaderStages = list; }
1501 template<
typename InputIterator>
1502 void setShaderStages(InputIterator first, InputIterator last)
1504 m_shaderStages.clear();
1505 std::copy(first, last, std::back_inserter(m_shaderStages));
1507 const QRhiShaderStage *cbeginShaderStages()
const {
return m_shaderStages.cbegin(); }
1508 const QRhiShaderStage *cendShaderStages()
const {
return m_shaderStages.cend(); }
1509 const QRhiShaderStage *shaderStageAt(qsizetype index)
const {
return &m_shaderStages.at(index); }
1510 qsizetype shaderStageCount()
const {
return m_shaderStages.count(); }
1512 QRhiVertexInputLayout vertexInputLayout()
const {
return m_vertexInputLayout; }
1513 void setVertexInputLayout(
const QRhiVertexInputLayout &layout) { m_vertexInputLayout = layout; }
1515 QRhiShaderResourceBindings *shaderResourceBindings()
const {
return m_shaderResourceBindings; }
1516 void setShaderResourceBindings(QRhiShaderResourceBindings *srb) { m_shaderResourceBindings = srb; }
1518 QRhiRenderPassDescriptor *renderPassDescriptor()
const {
return m_renderPassDesc; }
1519 void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; }
1521 int patchControlPointCount()
const {
return m_patchControlPointCount; }
1522 void setPatchControlPointCount(
int count) { m_patchControlPointCount = count; }
1524 PolygonMode polygonMode()
const {
return m_polygonMode; }
1525 void setPolygonMode(PolygonMode mode) {m_polygonMode = mode; }
1527 int multiViewCount()
const {
return m_multiViewCount; }
1528 void setMultiViewCount(
int count) { m_multiViewCount = count; }
1530 virtual bool create() = 0;
1533 QRhiGraphicsPipeline(QRhiImplementation *rhi);
1535 Topology m_topology = Triangles;
1536 CullMode m_cullMode = None;
1537 FrontFace m_frontFace = CCW;
1538 QVarLengthArray<TargetBlend, 8> m_targetBlends;
1539 bool m_depthTest =
false;
1540 bool m_depthWrite =
false;
1541 bool m_depthClamp =
false;
1542 CompareOp m_depthOp = Less;
1543 bool m_stencilTest =
false;
1544 StencilOpState m_stencilFront;
1545 StencilOpState m_stencilBack;
1546 quint32 m_stencilReadMask = 0xFF;
1547 quint32 m_stencilWriteMask = 0xFF;
1548 int m_sampleCount = 1;
1549 float m_lineWidth = 1.0f;
1550 int m_depthBias = 0;
1551 float m_slopeScaledDepthBias = 0.0f;
1552 int m_patchControlPointCount = 3;
1553 PolygonMode m_polygonMode = Fill;
1554 int m_multiViewCount = 0;
1555 QVarLengthArray<QRhiShaderStage, 4> m_shaderStages;
1556 QRhiVertexInputLayout m_vertexInputLayout;
1557 QRhiShaderResourceBindings *m_shaderResourceBindings =
nullptr;
1558 QRhiRenderPassDescriptor *m_renderPassDesc =
nullptr;
1561Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiGraphicsPipeline::Flags)
1562Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiGraphicsPipeline::ColorMask)
1563Q_DECLARE_TYPEINFO(QRhiGraphicsPipeline::TargetBlend, Q_RELOCATABLE_TYPE);
1586 } colorComponentValue;
1594#ifndef QT_NO_DEBUG_STREAM
1595Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiSwapChainHdrInfo &);
1607 SurfaceHasPreMulAlpha = 1 << 0,
1608 SurfaceHasNonPreMulAlpha = 1 << 1,
1610 UsedAsTransferSource = 1 << 3,
1612 MinimalBufferCount = 1 << 5
1614 Q_DECLARE_FLAGS(Flags, Flag)
1618 HDRExtendedSrgbLinear,
1620 HDRExtendedDisplayP3Linear
1623 enum StereoTargetBuffer {
1628 QRhiResource::Type resourceType()
const override;
1630 QWindow *window()
const {
return m_window; }
1631 void setWindow(QWindow *window) { m_window = window; }
1633 QRhiSwapChainProxyData proxyData()
const {
return m_proxyData; }
1634 void setProxyData(
const QRhiSwapChainProxyData &d) { m_proxyData = d; }
1636 Flags flags()
const {
return m_flags; }
1637 void setFlags(Flags f) { m_flags = f; }
1639 Format format()
const {
return m_format; }
1640 void setFormat(Format f) { m_format = f; }
1642 QRhiRenderBuffer *depthStencil()
const {
return m_depthStencil; }
1643 void setDepthStencil(QRhiRenderBuffer *ds) { m_depthStencil = ds; }
1645 int sampleCount()
const {
return m_sampleCount; }
1646 void setSampleCount(
int samples) { m_sampleCount = samples; }
1648 QRhiRenderPassDescriptor *renderPassDescriptor()
const {
return m_renderPassDesc; }
1649 void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; }
1651 QRhiShadingRateMap *shadingRateMap()
const {
return m_shadingRateMap; }
1652 void setShadingRateMap(QRhiShadingRateMap *map) { m_shadingRateMap = map; }
1654 QSize currentPixelSize()
const {
return m_currentPixelSize; }
1656 virtual QRhiCommandBuffer *currentFrameCommandBuffer() = 0;
1657 virtual QRhiRenderTarget *currentFrameRenderTarget() = 0;
1658 virtual QRhiRenderTarget *currentFrameRenderTarget(StereoTargetBuffer targetBuffer);
1659 virtual QSize surfacePixelSize() = 0;
1660 virtual bool isFormatSupported(Format f) = 0;
1661 virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() = 0;
1662 virtual bool createOrResize() = 0;
1663 virtual QRhiSwapChainHdrInfo hdrInfo();
1666 QRhiSwapChain(QRhiImplementation *rhi);
1667 QWindow *m_window =
nullptr;
1669 Format m_format = SDR;
1670 QRhiRenderBuffer *m_depthStencil =
nullptr;
1671 int m_sampleCount = 1;
1672 QRhiRenderPassDescriptor *m_renderPassDesc =
nullptr;
1673 QSize m_currentPixelSize;
1674 QRhiSwapChainProxyData m_proxyData;
1675 QRhiShadingRateMap *m_shadingRateMap =
nullptr;
1678Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiSwapChain::Flags)
1680class Q_GUI_EXPORT QRhiComputePipeline :
public QRhiResource
1684 CompileShadersWithDebugInfo = 1 << 0
1686 Q_DECLARE_FLAGS(Flags, Flag)
1688 QRhiResource::Type resourceType()
const override;
1689 virtual bool create() = 0;
1691 Flags flags()
const {
return m_flags; }
1692 void setFlags(Flags f) { m_flags = f; }
1694 QRhiShaderStage shaderStage()
const {
return m_shaderStage; }
1695 void setShaderStage(
const QRhiShaderStage &stage) { m_shaderStage = stage; }
1697 QRhiShaderResourceBindings *shaderResourceBindings()
const {
return m_shaderResourceBindings; }
1698 void setShaderResourceBindings(QRhiShaderResourceBindings *srb) { m_shaderResourceBindings = srb; }
1701 QRhiComputePipeline(QRhiImplementation *rhi);
1703 QRhiShaderStage m_shaderStage;
1704 QRhiShaderResourceBindings *m_shaderResourceBindings =
nullptr;
1707Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiComputePipeline::Flags)
1709struct QRhiIndirectDrawCommand
1711 quint32 vertexCount;
1712 quint32 instanceCount = 1;
1713 quint32 firstVertex = 0;
1714 quint32 firstInstance = 0;
1734static_assert(
sizeof(QRhiIndirectDrawCommand) == 16);
1746 QRhiResource::Type resourceType()
const override;
1748 Type type()
const {
return m_type; }
1749 void setType(Type t) { m_type = t; }
1751 quint32 maxCommandCount()
const {
return m_maxCommandCount; }
1752 void setMaxCommandCount(quint32 count) { m_maxCommandCount = count; }
1754 virtual bool create() = 0;
1757 void draw(quint32 vertexCount, quint32 instanceCount = 1,
1758 quint32 firstVertex = 0, quint32 firstInstance = 0);
1759 void drawIndexed(quint32 indexCount, quint32 instanceCount = 1, quint32 firstIndex = 0,
1760 qint32 vertexOffset = 0, quint32 firstInstance = 0);
1762 quint32 recordedCommandCount()
const {
return m_commandCount; }
1763 bool isGpuBuilt()
const {
return m_gpuBuilt; }
1764 quint32 commandCount()
const {
return m_gpuBuilt ? m_gpuBuiltCommandCount : m_commandCount; }
1767 QRhiIndirectCommandBuffer(QRhiImplementation *rhi, Type type_, quint32 maxCommandCount_);
1770 quint32 m_maxCommandCount;
1772 quint32 m_commandCount = 0;
1773 quint64 m_generation = 0;
1774 bool m_gpuBuilt =
false;
1775 quint32 m_gpuBuiltCommandCount = 0;
1786 enum BeginPassFlag {
1787 ExternalContent = 0x01,
1788 DoNotTrackResourcesForCompute = 0x02
1790 Q_DECLARE_FLAGS(BeginPassFlags, BeginPassFlag)
1792 QRhiResource::Type resourceType()
const override;
1794 void resourceUpdate(QRhiResourceUpdateBatch *resourceUpdates);
1796 void beginPass(QRhiRenderTarget *rt,
1797 const QColor &colorClearValue,
1798 const QRhiDepthStencilClearValue &depthStencilClearValue,
1799 QRhiResourceUpdateBatch *resourceUpdates =
nullptr,
1800 BeginPassFlags flags = {});
1801 void endPass(QRhiResourceUpdateBatch *resourceUpdates =
nullptr);
1803 void setGraphicsPipeline(QRhiGraphicsPipeline *ps);
1804 using DynamicOffset = std::pair<
int, quint32>;
1805 void setShaderResources(QRhiShaderResourceBindings *srb =
nullptr,
1806 int dynamicOffsetCount = 0,
1807 const DynamicOffset *dynamicOffsets =
nullptr);
1808 using VertexInput = std::pair<QRhiBuffer *, quint32>;
1809 void setVertexInput(
int startBinding,
int bindingCount,
const VertexInput *bindings,
1810 QRhiBuffer *indexBuf =
nullptr, quint32 indexOffset = 0,
1811 IndexFormat indexFormat = IndexUInt16);
1813 void setViewport(
const QRhiViewport &viewport);
1814 void setScissor(
const QRhiScissor &scissor);
1815 void setBlendConstants(
const QColor &c);
1816 void setStencilRef(quint32 refValue);
1817 void setShadingRate(
const QSize &coarsePixelSize);
1819 void draw(quint32 vertexCount,
1820 quint32 instanceCount = 1,
1821 quint32 firstVertex = 0,
1822 quint32 firstInstance = 0);
1824 void drawIndexed(quint32 indexCount,
1825 quint32 instanceCount = 1,
1826 quint32 firstIndex = 0,
1827 qint32 vertexOffset = 0,
1828 quint32 firstInstance = 0);
1830 void drawIndirect(QRhiBuffer *indirectBuffer,
1831 quint32 indirectBufferOffset,
1833 quint32 stride =
sizeof(QRhiIndirectDrawCommand));
1835 void drawIndexedIndirect(QRhiBuffer *indirectBuffer,
1836 quint32 indirectBufferOffset,
1838 quint32 stride =
sizeof(QRhiIndexedIndirectDrawCommand));
1840 void drawIndirectCount(QRhiBuffer *indirectBuffer,
1841 quint32 indirectBufferOffset,
1842 QRhiBuffer *countBuffer,
1843 quint32 countBufferOffset,
1844 quint32 maxDrawCount,
1845 quint32 stride =
sizeof(QRhiIndirectDrawCommand));
1847 void drawIndexedIndirectCount(QRhiBuffer *indirectBuffer,
1848 quint32 indirectBufferOffset,
1849 QRhiBuffer *countBuffer,
1850 quint32 countBufferOffset,
1851 quint32 maxDrawCount,
1852 quint32 stride =
sizeof(QRhiIndexedIndirectDrawCommand));
1854 void buildIndirect(QRhiIndirectCommandBuffer *icb,
1855 const QRhiIndirectCommandBufferBuildInfo &info);
1857 void executeIndirect(QRhiIndirectCommandBuffer *icb,
1858 quint32 firstCommand = 0,
1859 quint32 commandCount = 0xFFFFFFFFu);
1861 void debugMarkBegin(
const QByteArray &name);
1862 void debugMarkEnd();
1863 void debugMarkMsg(
const QByteArray &msg);
1865 void beginComputePass(QRhiResourceUpdateBatch *resourceUpdates =
nullptr, BeginPassFlags flags = {});
1866 void endComputePass(QRhiResourceUpdateBatch *resourceUpdates =
nullptr);
1867 void setComputePipeline(QRhiComputePipeline *ps);
1868 void dispatch(
int x,
int y,
int z);
1869 void dispatchIndirect(QRhiBuffer *indirectBuffer,
1870 quint32 indirectBufferOffset = 0);
1872 const QRhiNativeHandles *nativeHandles();
1873 void beginExternal();
1876 double lastCompletedGpuTime();
1879 QRhiCommandBuffer(QRhiImplementation *rhi);
1882Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiCommandBuffer::BeginPassFlags)
1884struct QRhiIndirectCommandBufferBuildInfo
1886 QRhiGraphicsPipeline::Topology topology = QRhiGraphicsPipeline::Triangles;
1887 QRhiBuffer *sourceBuffer =
nullptr;
1888 quint32 sourceBufferOffset = 0;
1889 quint32 commandCount = 0;
1891 QRhiBuffer *countBuffer =
nullptr;
1892 quint32 countBufferOffset = 0;
1893 QRhiBuffer *indexBuffer =
nullptr;
1894 quint32 indexBufferOffset = 0;
1895 QRhiCommandBuffer::IndexFormat indexFormat = QRhiCommandBuffer::IndexUInt16;
1900 std::function<
void()> completed =
nullptr;
1901 QRhiTexture::Format format;
1909 ~QRhiResourceUpdateBatch();
1913 void merge(QRhiResourceUpdateBatch *other);
1914 bool hasOptimalCapacity()
const;
1916 void updateDynamicBuffer(QRhiBuffer *buf, quint32 offset, quint32 size,
const void *data);
1917 void updateDynamicBuffer(QRhiBuffer *buf, quint32 offset, QByteArray data);
1918 void uploadStaticBuffer(QRhiBuffer *buf, quint32 offset, quint32 size,
const void *data);
1919 void uploadStaticBuffer(QRhiBuffer *buf, quint32 offset, QByteArray data);
1920 void uploadStaticBuffer(QRhiBuffer *buf,
const void *data);
1921 void uploadStaticBuffer(QRhiBuffer *buf, QByteArray data);
1922 void readBackBuffer(QRhiBuffer *buf, quint32 offset, quint32 size, QRhiReadbackResult *result);
1923 void uploadTexture(QRhiTexture *tex,
const QRhiTextureUploadDescription &desc);
1924 void uploadTexture(QRhiTexture *tex,
const QImage &image);
1925 void copyTexture(QRhiTexture *dst, QRhiTexture *src,
const QRhiTextureCopyDescription &desc = QRhiTextureCopyDescription());
1926 void readBackTexture(
const QRhiReadbackDescription &rb, QRhiReadbackResult *result);
1927 void generateMips(QRhiTexture *tex);
1928 void commitIndirectCommandBuffer(QRhiIndirectCommandBuffer *icb);
1931 QRhiResourceUpdateBatch(QRhiImplementation *rhi);
1932 Q_DISABLE_COPY(QRhiResourceUpdateBatch)
1933 QRhiResourceUpdateBatchPrivate *d;
1934 friend class QRhiResourceUpdateBatchPrivate;
1949 QByteArray deviceName;
1950 quint64 deviceId = 0;
1951 quint64 vendorId = 0;
1952 DeviceType deviceType = UnknownDevice;
1957#ifndef QT_NO_DEBUG_STREAM
1958Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiDriverInfo &);
1963 qint64 totalPipelineCreationTime = 0;
1965 quint32 blockCount = 0;
1966 quint32 allocCount = 0;
1967 quint64 usedBytes = 0;
1968 quint64 unusedBytes = 0;
1970 quint64 totalUsageBytes = 0;
1975#ifndef QT_NO_DEBUG_STREAM
1976Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiStats &);
1982 virtual ~QRhiAdapter();
1983 virtual QRhiDriverInfo info()
const = 0;
1993 enum Implementation {
2003 EnableDebugMarkers = 1 << 0,
2004 PreferSoftwareRenderer = 1 << 1,
2005 EnablePipelineCacheDataSave = 1 << 2,
2006 EnableTimestamps = 1 << 3,
2007 SuppressSmokeTestWarnings = 1 << 4
2009 Q_DECLARE_FLAGS(Flags, Flag)
2011 enum FrameOpResult {
2014 FrameOpSwapChainOutOfDate,
2019 MultisampleTexture = 1,
2020 MultisampleRenderBuffer,
2024 CustomInstanceStepRate,
2026 NonDynamicUniformBuffers,
2027 NonFourAlignedEffectiveIndexBufferOffset,
2033 VertexShaderPointSize,
2036 TriangleFanTopology,
2037 ReadBackNonUniformBuffer,
2038 ReadBackNonBaseMipLevel,
2040 RenderToNonBaseMipLevel,
2042 ScreenSpaceDerivatives,
2043 ReadBackAnyTextureFormat,
2044 PipelineCacheDataLoadSave,
2047 ThreeDimensionalTextures,
2048 RenderTo3DTextureSlice,
2054 OneDimensionalTextures,
2055 OneDimensionalTextureMipmaps,
2057 RenderToOneDimensionalTexture,
2058 ThreeDimensionalTextureMipmaps,
2061 ResolveDepthStencil,
2062 VariableRateShading,
2063 VariableRateShadingMap,
2064 VariableRateShadingMapWithTexture,
2065 PerRenderTargetBlending,
2067 InstanceIndexIncludesBaseInstance,
2071 ShaderDrawParameters,
2076 enum BeginFrameFlag {
2078 Q_DECLARE_FLAGS(BeginFrameFlags, BeginFrameFlag)
2081 SkipPresent = 1 << 0
2083 Q_DECLARE_FLAGS(EndFrameFlags, EndFrameFlag)
2085 enum ResourceLimit {
2088 MaxColorAttachments,
2090 MaxAsyncReadbackFrames,
2091 MaxThreadGroupsPerDimension,
2092 MaxThreadsPerThreadGroup,
2096 TextureArraySizeMax,
2097 MaxUniformBufferRange,
2100 ShadingRateImageTileSize,
2101 MaxVertexStorageBuffers,
2102 MaxFragmentStorageBuffers
2107 static QRhi *create(Implementation impl,
2108 QRhiInitParams *params,
2110 QRhiNativeHandles *importDevice =
nullptr);
2111 static QRhi *create(Implementation impl,
2112 QRhiInitParams *params,
2114 QRhiNativeHandles *importDevice,
2115 QRhiAdapter *adapter);
2116 static bool probe(Implementation impl, QRhiInitParams *params);
2117 using AdapterList = QVector<QRhiAdapter *>;
2118 static AdapterList enumerateAdapters(Implementation impl,
2119 QRhiInitParams *params,
2120 QRhiNativeHandles *nativeHandles =
nullptr);
2122 Implementation backend()
const;
2123 const char *backendName()
const;
2124 static const char *backendName(Implementation impl);
2125 QRhiDriverInfo driverInfo()
const;
2126 QThread *thread()
const;
2128 using CleanupCallback = std::function<
void(QRhi *)>;
2129 void addCleanupCallback(
const CleanupCallback &callback);
2130 void addCleanupCallback(
const void *key,
const CleanupCallback &callback);
2131 void removeCleanupCallback(
const void *key);
2133 QRhiGraphicsPipeline *newGraphicsPipeline();
2134 QRhiComputePipeline *newComputePipeline();
2135 QRhiShaderResourceBindings *newShaderResourceBindings();
2137 QRhiBuffer *newBuffer(QRhiBuffer::Type type,
2138 QRhiBuffer::UsageFlags usage,
2141 QRhiRenderBuffer *newRenderBuffer(QRhiRenderBuffer::Type type,
2142 const QSize &pixelSize,
2143 int sampleCount = 1,
2144 QRhiRenderBuffer::Flags flags = {},
2145 QRhiTexture::Format backingFormatHint = QRhiTexture::UnknownFormat);
2147 QRhiTexture *newTexture(QRhiTexture::Format format,
2148 const QSize &pixelSize,
2149 int sampleCount = 1,
2150 QRhiTexture::Flags flags = {});
2152 QRhiTexture *newTexture(QRhiTexture::Format format,
2153 int width,
int height,
int depth,
2154 int sampleCount = 1,
2155 QRhiTexture::Flags flags = {});
2157 QRhiTexture *newTextureArray(QRhiTexture::Format format,
2159 const QSize &pixelSize,
2160 int sampleCount = 1,
2161 QRhiTexture::Flags flags = {});
2163 QRhiSampler *newSampler(QRhiSampler::Filter magFilter,
2164 QRhiSampler::Filter minFilter,
2165 QRhiSampler::Filter mipmapMode,
2166 QRhiSampler::AddressMode addressU,
2167 QRhiSampler::AddressMode addressV,
2168 QRhiSampler::AddressMode addressW = QRhiSampler::Repeat);
2170 QRhiShadingRateMap *newShadingRateMap();
2172 QRhiIndirectCommandBuffer *newIndirectCommandBuffer(QRhiIndirectCommandBuffer::Type type,
2173 quint32 maxCommandCount);
2175 QRhiTextureRenderTarget *newTextureRenderTarget(
const QRhiTextureRenderTargetDescription &desc,
2176 QRhiTextureRenderTarget::Flags flags = {});
2178 QRhiSwapChain *newSwapChain();
2179 FrameOpResult beginFrame(QRhiSwapChain *swapChain, BeginFrameFlags flags = {});
2180 FrameOpResult endFrame(QRhiSwapChain *swapChain, EndFrameFlags flags = {});
2181 bool isRecordingFrame()
const;
2182 int currentFrameSlot()
const;
2184 FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb, BeginFrameFlags flags = {});
2185 FrameOpResult endOffscreenFrame(EndFrameFlags flags = {});
2187 QRhi::FrameOpResult finish();
2189 QRhiResourceUpdateBatch *nextResourceUpdateBatch();
2191 QList<
int> supportedSampleCounts()
const;
2193 int ubufAlignment()
const;
2194 int ubufAligned(
int v)
const;
2196 static int mipLevelsForSize(
const QSize &size);
2197 static QSize sizeForMipLevel(
int mipLevel,
const QSize &baseLevelSize);
2199 bool isYUpInFramebuffer()
const;
2200 bool isYUpInNDC()
const;
2201 bool isClipDepthZeroToOne()
const;
2203 QMatrix4x4 clipSpaceCorrMatrix()
const;
2205 bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags = {})
const;
2206 bool isFeatureSupported(QRhi::Feature feature)
const;
2207 int resourceLimit(ResourceLimit limit)
const;
2209 const QRhiNativeHandles *nativeHandles();
2210 bool makeThreadLocalNativeContextCurrent();
2211 void setQueueSubmitParams(QRhiNativeHandles *params);
2213 static constexpr int MAX_MIP_LEVELS = 16;
2215 void releaseCachedResources();
2217 bool isDeviceLost()
const;
2219 QByteArray pipelineCacheData();
2220 void setPipelineCacheData(
const QByteArray &data);
2222 QRhiStats statistics()
const;
2224 static QRhiSwapChainProxyData updateSwapChainProxyData(Implementation impl, QWindow *window);
2226 QList<QSize> supportedShadingRates(
int sampleCount)
const;
2232 Q_DISABLE_COPY(QRhi)
2233 QRhiImplementation *d =
nullptr;
2236Q_DECLARE_OPERATORS_FOR_FLAGS(QRhi::Flags)
2237Q_DECLARE_OPERATORS_FOR_FLAGS(QRhi::BeginFrameFlags)
2238Q_DECLARE_OPERATORS_FOR_FLAGS(QRhi::EndFrameFlags)
2242#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
\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