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>
29#include <rhi/qshader.h>
35class QRhiImplementation;
37class QRhiRenderBuffer;
40class QRhiCommandBuffer;
41class QRhiResourceUpdateBatch;
44class QRhiShadingRateMap;
45class QRhiIndirectCommandBuffer;
46struct QRhiIndirectCommandBufferBuildInfo;
51 QRhiDepthStencilClearValue() =
default;
52 QRhiDepthStencilClearValue(
float d, quint32 s);
54 float depthClearValue()
const {
return m_d; }
55 void setDepthClearValue(
float d) { m_d = d; }
57 quint32 stencilClearValue()
const {
return m_s; }
58 void setStencilClearValue(quint32 s) { m_s = s; }
64 friend bool operator==(
const QRhiDepthStencilClearValue &a,
const QRhiDepthStencilClearValue &b)
noexcept
66 return a.m_d == b.m_d && a.m_s == b.m_s;
69 friend bool operator!=(
const QRhiDepthStencilClearValue &a,
const QRhiDepthStencilClearValue &b)
noexcept
74 friend size_t qHash(
const QRhiDepthStencilClearValue &v, size_t seed = 0)
noexcept
76 QtPrivate::QHashCombine hash(seed);
77 seed = hash(seed, v.m_d);
78 seed = hash(seed, v.m_s);
85#ifndef QT_NO_DEBUG_STREAM
86Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiDepthStencilClearValue &);
92 QRhiViewport() =
default;
93 QRhiViewport(
float x,
float y,
float w,
float h,
float minDepth = 0.0f,
float maxDepth = 1.0f);
95 std::array<
float, 4> viewport()
const {
return m_rect; }
96 void setViewport(
float x,
float y,
float w,
float h) {
97 m_rect[0] = x; m_rect[1] = y; m_rect[2] = w; m_rect[3] = h;
100 float minDepth()
const {
return m_minDepth; }
101 void setMinDepth(
float minDepth) { m_minDepth = minDepth; }
103 float maxDepth()
const {
return m_maxDepth; }
104 void setMaxDepth(
float maxDepth) { m_maxDepth = maxDepth; }
107 std::array<
float, 4> m_rect { { 0.0f, 0.0f, 0.0f, 0.0f } };
108 float m_minDepth = 0.0f;
109 float m_maxDepth = 1.0f;
111 friend bool operator==(
const QRhiViewport &a,
const QRhiViewport &b)
noexcept
113 return a.m_rect == b.m_rect
114 && a.m_minDepth == b.m_minDepth
115 && a.m_maxDepth == b.m_maxDepth;
118 friend bool operator!=(
const QRhiViewport &a,
const QRhiViewport &b)
noexcept
123 friend size_t qHash(
const QRhiViewport &v, size_t seed = 0)
noexcept
125 QtPrivate::QHashCombine hash(seed);
126 seed = hash(seed, v.m_rect[0]);
127 seed = hash(seed, v.m_rect[1]);
128 seed = hash(seed, v.m_rect[2]);
129 seed = hash(seed, v.m_rect[3]);
130 seed = hash(seed, v.m_minDepth);
131 seed = hash(seed, v.m_maxDepth);
138#ifndef QT_NO_DEBUG_STREAM
139Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiViewport &);
145 QRhiScissor() =
default;
146 QRhiScissor(
int x,
int y,
int w,
int h);
148 std::array<
int, 4> scissor()
const {
return m_rect; }
149 void setScissor(
int x,
int y,
int w,
int h) {
150 m_rect[0] = x; m_rect[1] = y; m_rect[2] = w; m_rect[3] = h;
154 std::array<
int, 4> m_rect { { 0, 0, 0, 0 } };
156 friend bool operator==(
const QRhiScissor &a,
const QRhiScissor &b)
noexcept
158 return a.m_rect == b.m_rect;
161 friend bool operator!=(
const QRhiScissor &a,
const QRhiScissor &b)
noexcept
166 friend size_t qHash(
const QRhiScissor &v, size_t seed = 0)
noexcept
168 QtPrivate::QHashCombine hash(seed);
169 seed = hash(seed, v.m_rect[0]);
170 seed = hash(seed, v.m_rect[1]);
171 seed = hash(seed, v.m_rect[2]);
172 seed = hash(seed, v.m_rect[3]);
179#ifndef QT_NO_DEBUG_STREAM
180Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiScissor &);
186 enum Classification {
191 QRhiVertexInputBinding() =
default;
192 QRhiVertexInputBinding(quint32 stride, Classification cls = PerVertex, quint32 stepRate = 1);
194 quint32 stride()
const {
return m_stride; }
195 void setStride(quint32 s) { m_stride = s; }
197 Classification classification()
const {
return m_classification; }
198 void setClassification(Classification c) { m_classification = c; }
200 quint32 instanceStepRate()
const {
return m_instanceStepRate; }
201 void setInstanceStepRate(quint32 rate) { m_instanceStepRate = rate; }
204 quint32 m_stride = 0;
205 Classification m_classification = PerVertex;
206 quint32 m_instanceStepRate = 1;
208 friend bool operator==(
const QRhiVertexInputBinding &a,
const QRhiVertexInputBinding &b)
noexcept
210 return a.m_stride == b.m_stride
211 && a.m_classification == b.m_classification
212 && a.m_instanceStepRate == b.m_instanceStepRate;
215 friend bool operator!=(
const QRhiVertexInputBinding &a,
const QRhiVertexInputBinding &b)
noexcept
220 friend size_t qHash(
const QRhiVertexInputBinding &v, size_t seed = 0)
noexcept
222 QtPrivate::QHashCombine hash(seed);
223 seed = hash(seed, v.m_stride);
224 seed = hash(seed, v.m_classification);
225 seed = hash(seed, v.m_instanceStepRate);
232#ifndef QT_NO_DEBUG_STREAM
233Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiVertexInputBinding &);
269 QRhiVertexInputAttribute() =
default;
270 QRhiVertexInputAttribute(
int binding,
int location, Format format, quint32 offset,
int matrixSlice = -1);
272 int binding()
const {
return m_binding; }
273 void setBinding(
int b) { m_binding = b; }
275 int location()
const {
return m_location; }
276 void setLocation(
int loc) { m_location = loc; }
278 Format format()
const {
return m_format; }
279 void setFormat(Format f) { m_format = f; }
281 quint32 offset()
const {
return m_offset; }
282 void setOffset(quint32 ofs) { m_offset = ofs; }
284 int matrixSlice()
const {
return m_matrixSlice; }
285 void setMatrixSlice(
int slice) { m_matrixSlice = slice; }
290 Format m_format = Float4;
291 quint32 m_offset = 0;
292 int m_matrixSlice = -1;
294 friend bool operator==(
const QRhiVertexInputAttribute &a,
const QRhiVertexInputAttribute &b)
noexcept
296 return a.m_binding == b.m_binding
297 && a.m_location == b.m_location
298 && a.m_format == b.m_format
299 && a.m_offset == b.m_offset;
303 friend bool operator!=(
const QRhiVertexInputAttribute &a,
const QRhiVertexInputAttribute &b)
noexcept
308 friend size_t qHash(
const QRhiVertexInputAttribute &v, size_t seed = 0)
noexcept
310 QtPrivate::QHashCombine hash(seed);
311 seed = hash(seed, v.m_binding);
312 seed = hash(seed, v.m_location);
313 seed = hash(seed, v.m_format);
314 seed = hash(seed, v.m_offset);
321#ifndef QT_NO_DEBUG_STREAM
322Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiVertexInputAttribute &);
328 QRhiVertexInputLayout() =
default;
330 void setBindings(std::initializer_list<QRhiVertexInputBinding> list) { m_bindings = list; }
331 template<
typename InputIterator>
332 void setBindings(InputIterator first, InputIterator last)
335 std::copy(first, last, std::back_inserter(m_bindings));
337 const QRhiVertexInputBinding *cbeginBindings()
const {
return m_bindings.cbegin(); }
338 const QRhiVertexInputBinding *cendBindings()
const {
return m_bindings.cend(); }
339 const QRhiVertexInputBinding *bindingAt(qsizetype index)
const {
return &m_bindings.at(index); }
340 qsizetype bindingCount()
const {
return m_bindings.count(); }
342 void setAttributes(std::initializer_list<QRhiVertexInputAttribute> list) { m_attributes = list; }
343 template<
typename InputIterator>
344 void setAttributes(InputIterator first, InputIterator last)
346 m_attributes.clear();
347 std::copy(first, last, std::back_inserter(m_attributes));
349 const QRhiVertexInputAttribute *cbeginAttributes()
const {
return m_attributes.cbegin(); }
350 const QRhiVertexInputAttribute *cendAttributes()
const {
return m_attributes.cend(); }
351 const QRhiVertexInputAttribute *attributeAt(qsizetype index)
const {
return &m_attributes.at(index); }
352 qsizetype attributeCount()
const {
return m_attributes.count(); }
355 QVarLengthArray<QRhiVertexInputBinding, 8> m_bindings;
356 QVarLengthArray<QRhiVertexInputAttribute, 8> m_attributes;
358 friend bool operator==(
const QRhiVertexInputLayout &a,
const QRhiVertexInputLayout &b)
noexcept
360 return a.m_bindings == b.m_bindings && a.m_attributes == b.m_attributes;
363 friend bool operator!=(
const QRhiVertexInputLayout &a,
const QRhiVertexInputLayout &b)
noexcept
368 friend size_t qHash(
const QRhiVertexInputLayout &v, size_t seed = 0)
noexcept
370 QtPrivate::QHashCombine hash(seed);
371 seed = hash(seed, v.m_bindings);
372 seed = hash(seed, v.m_attributes);
376 friend Q_GUI_EXPORT QDebug operator<<(QDebug,
const QRhiVertexInputLayout &);
379#ifndef QT_NO_DEBUG_STREAM
380Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiVertexInputLayout &);
389 TessellationEvaluation,
395 QRhiShaderStage() =
default;
396 QRhiShaderStage(Type type,
const QShader &shader,
397 QShader::Variant v = QShader::StandardShader);
399 Type type()
const {
return m_type; }
400 void setType(Type t) { m_type = t; }
402 QShader shader()
const {
return m_shader; }
403 void setShader(
const QShader &s) { m_shader = s; }
405 QShader::Variant shaderVariant()
const {
return m_shaderVariant; }
406 void setShaderVariant(QShader::Variant v) { m_shaderVariant = v; }
409 Type m_type = Vertex;
411 QShader::Variant m_shaderVariant = QShader::StandardShader;
413 friend bool operator==(
const QRhiShaderStage &a,
const QRhiShaderStage &b)
noexcept
415 return a.m_type == b.m_type
416 && a.m_shader == b.m_shader
417 && a.m_shaderVariant == b.m_shaderVariant;
420 friend bool operator!=(
const QRhiShaderStage &a,
const QRhiShaderStage &b)
noexcept
425 friend size_t qHash(
const QRhiShaderStage &v, size_t seed = 0)
noexcept
427 QtPrivate::QHashCombine hash(seed);
428 seed = hash(seed, v.m_type);
429 seed = hash(seed, v.m_shader);
430 seed = hash(seed, v.m_shaderVariant);
437#ifndef QT_NO_DEBUG_STREAM
438Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiShaderStage &);
441using QRhiGraphicsShaderStage = QRhiShaderStage;
460 VertexStage = 1 << 0,
461 TessellationControlStage = 1 << 1,
462 TessellationEvaluationStage = 1 << 2,
463 GeometryStage = 1 << 3,
464 FragmentStage = 1 << 4,
465 ComputeStage = 1 << 5
467 Q_DECLARE_FLAGS(StageFlags, StageFlag)
469 QRhiShaderResourceBinding() =
default;
471 bool isLayoutCompatible(
const QRhiShaderResourceBinding &other)
const;
473 static QRhiShaderResourceBinding uniformBuffer(
int binding, StageFlags stage, QRhiBuffer *buf);
474 static QRhiShaderResourceBinding uniformBuffer(
int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size);
475 static QRhiShaderResourceBinding uniformBufferWithDynamicOffset(
int binding, StageFlags stage, QRhiBuffer *buf, quint32 size);
477 static QRhiShaderResourceBinding sampledTexture(
int binding, StageFlags stage, QRhiTexture *tex, QRhiSampler *sampler);
479 struct TextureAndSampler {
481 QRhiSampler *sampler;
483 static QRhiShaderResourceBinding sampledTextures(
int binding, StageFlags stage,
int count,
const TextureAndSampler *texSamplers);
485 static QRhiShaderResourceBinding texture(
int binding, StageFlags stage, QRhiTexture *tex);
486 static QRhiShaderResourceBinding textures(
int binding, StageFlags stage,
int count, QRhiTexture **tex);
487 static QRhiShaderResourceBinding sampler(
int binding, StageFlags stage, QRhiSampler *sampler);
489 static QRhiShaderResourceBinding imageLoad(
int binding, StageFlags stage, QRhiTexture *tex,
int level);
490 static QRhiShaderResourceBinding imageStore(
int binding, StageFlags stage, QRhiTexture *tex,
int level);
491 static QRhiShaderResourceBinding imageLoadStore(
int binding, StageFlags stage, QRhiTexture *tex,
int level);
493 static QRhiShaderResourceBinding bufferLoad(
int binding, StageFlags stage, QRhiBuffer *buf);
494 static QRhiShaderResourceBinding bufferLoad(
int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size);
495 static QRhiShaderResourceBinding bufferStore(
int binding, StageFlags stage, QRhiBuffer *buf);
496 static QRhiShaderResourceBinding bufferStore(
int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size);
497 static QRhiShaderResourceBinding bufferLoadStore(
int binding, StageFlags stage, QRhiBuffer *buf);
498 static QRhiShaderResourceBinding bufferLoadStore(
int binding, StageFlags stage, QRhiBuffer *buf, quint32 offset, quint32 size);
503 QRhiShaderResourceBinding::StageFlags stage;
504 struct UniformBufferData {
508 bool hasDynamicOffset;
510 struct TextureAndOrSamplerData {
511 QVarLengthArray<TextureAndSampler, 4> texSamplers;
512 int count()
const {
return int(texSamplers.size()); }
514 struct StorageImageData {
518 struct StorageBufferData {
526 template<Type,
typename T>
527 struct Alternative : T
529 Alternative() =
default;
530 Alternative(
const T &t) : T(t) { }
532 std::variant<Alternative<UniformBuffer, UniformBufferData>,
533 Alternative<SampledTexture, TextureAndOrSamplerData>,
534 Alternative<Texture, TextureAndOrSamplerData>,
535 Alternative<Sampler, TextureAndOrSamplerData>,
536 Alternative<ImageLoad, StorageImageData>,
537 Alternative<ImageStore, StorageImageData>,
538 Alternative<ImageLoadStore, StorageImageData>,
539 Alternative<BufferLoad, StorageBufferData>,
540 Alternative<BufferStore, StorageBufferData>,
541 Alternative<BufferLoadStore, StorageBufferData>> u;
543 Type type()
const {
return Type(u.index()); }
545 template<
typename T, Type... Ts>
548 const T *p =
nullptr;
549 ((p = std::get_if<Ts>(&u)) || ...);
554 const UniformBufferData &ubuf()
const {
return get<UniformBufferData, UniformBuffer>(); }
555 const TextureAndOrSamplerData &stex()
const {
return get<TextureAndOrSamplerData, SampledTexture, Texture, Sampler>(); }
556 const StorageImageData &simage()
const {
return get<StorageImageData, ImageLoad, ImageStore, ImageLoadStore>(); }
557 const StorageBufferData &sbuf()
const {
return get<StorageBufferData, BufferLoad, BufferStore, BufferLoadStore>(); }
559 int arraySize()
const
561 return type() == QRhiShaderResourceBinding::SampledTexture || type() == QRhiShaderResourceBinding::Texture
566 template<
typename Output>
567 Output serialize(Output dst)
const
570 *dst++ = quint32(binding);
571 *dst++ = quint32(stage);
572 *dst++ = quint32(type());
573 *dst++ = quint32(arraySize());
578 static constexpr int LAYOUT_DESC_ENTRIES_PER_BINDING = 4;
580 template<
typename Output>
581 static void serializeLayoutDescription(
const QRhiShaderResourceBinding *first,
582 const QRhiShaderResourceBinding *last,
585 while (first != last) {
586 dst = first->d.serialize(dst);
593 friend class QRhiImplementation;
596Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiShaderResourceBinding::StageFlags)
598Q_GUI_EXPORT
bool operator==(
const QRhiShaderResourceBinding &a,
const QRhiShaderResourceBinding &b)
noexcept;
599Q_GUI_EXPORT
bool operator!=(
const QRhiShaderResourceBinding &a,
const QRhiShaderResourceBinding &b)
noexcept;
600Q_GUI_EXPORT size_t qHash(
const QRhiShaderResourceBinding &b, size_t seed = 0)
noexcept;
601#ifndef QT_NO_DEBUG_STREAM
602Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiShaderResourceBinding &);
608 QRhiColorAttachment() =
default;
609 QRhiColorAttachment(QRhiTexture *texture);
610 QRhiColorAttachment(QRhiRenderBuffer *renderBuffer);
612 QRhiTexture *texture()
const {
return m_texture; }
613 void setTexture(QRhiTexture *tex) { m_texture = tex; }
615 QRhiRenderBuffer *renderBuffer()
const {
return m_renderBuffer; }
616 void setRenderBuffer(QRhiRenderBuffer *rb) { m_renderBuffer = rb; }
618 int layer()
const {
return m_layer; }
619 void setLayer(
int layer) { m_layer = layer; }
621 int level()
const {
return m_level; }
622 void setLevel(
int level) { m_level = level; }
624 QRhiTexture *resolveTexture()
const {
return m_resolveTexture; }
625 void setResolveTexture(QRhiTexture *tex) { m_resolveTexture = tex; }
627 int resolveLayer()
const {
return m_resolveLayer; }
628 void setResolveLayer(
int layer) { m_resolveLayer = layer; }
630 int resolveLevel()
const {
return m_resolveLevel; }
631 void setResolveLevel(
int level) { m_resolveLevel = level; }
633 int multiViewCount()
const {
return m_multiViewCount; }
634 void setMultiViewCount(
int count) { m_multiViewCount = count; }
637 QRhiTexture *m_texture =
nullptr;
638 QRhiRenderBuffer *m_renderBuffer =
nullptr;
641 QRhiTexture *m_resolveTexture =
nullptr;
642 int m_resolveLayer = 0;
643 int m_resolveLevel = 0;
644 int m_multiViewCount = 0;
652 QRhiTextureRenderTargetDescription() =
default;
653 QRhiTextureRenderTargetDescription(
const QRhiColorAttachment &colorAttachment);
654 QRhiTextureRenderTargetDescription(
const QRhiColorAttachment &colorAttachment, QRhiRenderBuffer *depthStencilBuffer);
655 QRhiTextureRenderTargetDescription(
const QRhiColorAttachment &colorAttachment, QRhiTexture *depthTexture);
657 void setColorAttachments(std::initializer_list<QRhiColorAttachment> list) { m_colorAttachments = list; }
658 template<
typename InputIterator>
659 void setColorAttachments(InputIterator first, InputIterator last)
661 m_colorAttachments.clear();
662 std::copy(first, last, std::back_inserter(m_colorAttachments));
664 const QRhiColorAttachment *cbeginColorAttachments()
const {
return m_colorAttachments.cbegin(); }
665 const QRhiColorAttachment *cendColorAttachments()
const {
return m_colorAttachments.cend(); }
666 const QRhiColorAttachment *colorAttachmentAt(qsizetype index)
const {
return &m_colorAttachments.at(index); }
667 qsizetype colorAttachmentCount()
const {
return m_colorAttachments.count(); }
669 QRhiRenderBuffer *depthStencilBuffer()
const {
return m_depthStencilBuffer; }
670 void setDepthStencilBuffer(QRhiRenderBuffer *renderBuffer) { m_depthStencilBuffer = renderBuffer; }
672 QRhiTexture *depthTexture()
const {
return m_depthTexture; }
673 void setDepthTexture(QRhiTexture *texture) { m_depthTexture = texture; }
675 int depthLayer()
const {
return m_depthLayer; }
676 void setDepthLayer(
int depthLayer) { m_depthLayer = depthLayer; }
678 QRhiTexture *depthResolveTexture()
const {
return m_depthResolveTexture; }
679 void setDepthResolveTexture(QRhiTexture *tex) { m_depthResolveTexture = tex; }
681 QRhiShadingRateMap *shadingRateMap()
const {
return m_shadingRateMap; }
682 void setShadingRateMap(QRhiShadingRateMap *map) { m_shadingRateMap = map; }
685 QVarLengthArray<QRhiColorAttachment, 8> m_colorAttachments;
686 QRhiRenderBuffer *m_depthStencilBuffer =
nullptr;
687 QRhiTexture *m_depthTexture =
nullptr;
688 QRhiTexture *m_depthResolveTexture =
nullptr;
689 QRhiShadingRateMap *m_shadingRateMap =
nullptr;
690 int m_depthLayer = -1;
696 QRhiTextureSubresourceUploadDescription() =
default;
697 explicit QRhiTextureSubresourceUploadDescription(
const QImage &image);
698 QRhiTextureSubresourceUploadDescription(
const void *data, quint32 size);
699 explicit QRhiTextureSubresourceUploadDescription(
const QByteArray &data);
701 QImage image()
const {
return m_image; }
702 void setImage(
const QImage &image) { m_image = image; }
704 QByteArray data()
const {
return m_data; }
705 void setData(
const QByteArray &data) { m_data = data; }
707 quint32 dataStride()
const {
return m_dataStride; }
708 void setDataStride(quint32 stride) { m_dataStride = stride; }
710 QPoint destinationTopLeft()
const {
return m_destinationTopLeft; }
711 void setDestinationTopLeft(
const QPoint &p) { m_destinationTopLeft = p; }
713 QSize sourceSize()
const {
return m_sourceSize; }
714 void setSourceSize(
const QSize &size) { m_sourceSize = size; }
716 QPoint sourceTopLeft()
const {
return m_sourceTopLeft; }
717 void setSourceTopLeft(
const QPoint &p) { m_sourceTopLeft = p; }
722 quint32 m_dataStride = 0;
723 QPoint m_destinationTopLeft;
725 QPoint m_sourceTopLeft;
733 QRhiTextureUploadEntry() =
default;
734 QRhiTextureUploadEntry(
int layer,
int level,
const QRhiTextureSubresourceUploadDescription &desc);
736 int layer()
const {
return m_layer; }
737 void setLayer(
int layer) { m_layer = layer; }
739 int level()
const {
return m_level; }
740 void setLevel(
int level) { m_level = level; }
742 QRhiTextureSubresourceUploadDescription description()
const {
return m_desc; }
743 void setDescription(
const QRhiTextureSubresourceUploadDescription &desc) { m_desc = desc; }
748 QRhiTextureSubresourceUploadDescription m_desc;
756 QRhiTextureUploadDescription() =
default;
757 QRhiTextureUploadDescription(
const QRhiTextureUploadEntry &entry);
758 QRhiTextureUploadDescription(std::initializer_list<QRhiTextureUploadEntry> list);
760 void setEntries(std::initializer_list<QRhiTextureUploadEntry> list) { m_entries = list; }
761 template<
typename InputIterator>
762 void setEntries(InputIterator first, InputIterator last)
765 std::copy(first, last, std::back_inserter(m_entries));
767 const QRhiTextureUploadEntry *cbeginEntries()
const {
return m_entries.cbegin(); }
768 const QRhiTextureUploadEntry *cendEntries()
const {
return m_entries.cend(); }
769 const QRhiTextureUploadEntry *entryAt(qsizetype index)
const {
return &m_entries.at(index); }
770 qsizetype entryCount()
const {
return m_entries.count(); }
773 QVarLengthArray<QRhiTextureUploadEntry, 16> m_entries;
779 QRhiBufferCopyDescription() =
default;
781 quint32 size()
const {
return m_size; }
782 void setSize(quint32 sz) { m_size = sz; }
784 quint32 sourceOffset()
const {
return m_sourceOffset; }
785 void setSourceOffset(quint32 offset) { m_sourceOffset = offset; }
787 quint32 destinationOffset()
const {
return m_destinationOffset; }
788 void setDestinationOffset(quint32 offset) { m_destinationOffset = offset; }
792 quint32 m_sourceOffset = 0;
793 quint32 m_destinationOffset = 0;
801 QRhiTextureCopyDescription() =
default;
803 QSize pixelSize()
const {
return m_pixelSize; }
804 void setPixelSize(
const QSize &sz) { m_pixelSize = sz; }
806 int sourceLayer()
const {
return m_sourceLayer; }
807 void setSourceLayer(
int layer) { m_sourceLayer = layer; }
809 int sourceLevel()
const {
return m_sourceLevel; }
810 void setSourceLevel(
int level) { m_sourceLevel = level; }
812 QPoint sourceTopLeft()
const {
return m_sourceTopLeft; }
813 void setSourceTopLeft(
const QPoint &p) { m_sourceTopLeft = p; }
815 int destinationLayer()
const {
return m_destinationLayer; }
816 void setDestinationLayer(
int layer) { m_destinationLayer = layer; }
818 int destinationLevel()
const {
return m_destinationLevel; }
819 void setDestinationLevel(
int level) { m_destinationLevel = level; }
821 QPoint destinationTopLeft()
const {
return m_destinationTopLeft; }
822 void setDestinationTopLeft(
const QPoint &p) { m_destinationTopLeft = p; }
826 int m_sourceLayer = 0;
827 int m_sourceLevel = 0;
828 QPoint m_sourceTopLeft;
829 int m_destinationLayer = 0;
830 int m_destinationLevel = 0;
831 QPoint m_destinationTopLeft;
839 QRhiReadbackDescription() =
default;
840 QRhiReadbackDescription(QRhiTexture *texture);
842 QRhiTexture *texture()
const {
return m_texture; }
843 void setTexture(QRhiTexture *tex) { m_texture = tex; }
845 int layer()
const {
return m_layer; }
846 void setLayer(
int layer) { m_layer = layer; }
848 int level()
const {
return m_level; }
849 void setLevel(
int level) { m_level = level; }
851 QRect rect()
const {
return m_rect; }
852 void setRect(
const QRect &rectangle) { m_rect = rectangle; }
855 QRhiTexture *m_texture =
nullptr;
875 RenderPassDescriptor,
876 SwapChainRenderTarget,
878 ShaderResourceBindings,
884 IndirectCommandBuffer
887 virtual ~QRhiResource();
889 virtual Type resourceType()
const = 0;
891 virtual void destroy() = 0;
895 QByteArray name()
const;
896 void setName(
const QByteArray &name);
898 quint64 globalResourceId()
const;
903 QRhiResource(QRhiImplementation *rhi);
904 Q_DISABLE_COPY(QRhiResource)
905 friend class QRhiImplementation;
906 QRhiImplementation *m_rhi =
nullptr;
908 QByteArray m_objectName;
921 VertexBuffer = 1 << 0,
922 IndexBuffer = 1 << 1,
923 UniformBuffer = 1 << 2,
924 StorageBuffer = 1 << 3,
925 IndirectBuffer = 1 << 4,
927 Q_DECLARE_FLAGS(UsageFlags, UsageFlag)
929 struct NativeBuffer {
930 const void *objects[3];
934 QRhiResource::Type resourceType()
const override;
936 Type type()
const {
return m_type; }
937 void setType(Type t) { m_type = t; }
939 UsageFlags usage()
const {
return m_usage; }
940 void setUsage(UsageFlags u) { m_usage = u; }
942 quint32 size()
const {
return m_size; }
943 void setSize(quint32 sz) { m_size = sz; }
945 virtual bool create() = 0;
947 virtual NativeBuffer nativeBuffer();
949 virtual char *beginFullDynamicBufferUpdateForCurrentFrame();
950 virtual void endFullDynamicBufferUpdateForCurrentFrame();
951 virtual void fullDynamicBufferUpdateForCurrentFrame(
const void *data, quint32 size = 0);
954 QRhiBuffer(QRhiImplementation *rhi, Type type_, UsageFlags usage_, quint32 size_);
960Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiBuffer::UsageFlags)
962class Q_GUI_EXPORT QRhiTexture :
public QRhiResource
966 RenderTarget = 1 << 0,
970 UsedAsTransferSource = 1 << 5,
971 UsedWithGenerateMips = 1 << 6,
972 UsedWithLoadStore = 1 << 7,
973 UsedAsCompressedAtlas = 1 << 8,
974 ExternalOES = 1 << 9,
975 ThreeDimensional = 1 << 10,
976 TextureRectangleGL = 1 << 11,
977 TextureArray = 1 << 12,
978 OneDimensional = 1 << 13,
979 UsedAsShadingRateMap = 1 << 14
981 Q_DECLARE_FLAGS(Flags, Flag)
1045 struct NativeTexture {
1050 QRhiResource::Type resourceType()
const override;
1052 Format format()
const {
return m_format; }
1053 void setFormat(Format fmt) { m_format = fmt; }
1055 QSize pixelSize()
const {
return m_pixelSize; }
1056 void setPixelSize(
const QSize &sz) { m_pixelSize = sz; }
1058 int depth()
const {
return m_depth; }
1059 void setDepth(
int depth) { m_depth = depth; }
1061 int arraySize()
const {
return m_arraySize; }
1062 void setArraySize(
int arraySize) { m_arraySize = arraySize; }
1064 int arrayRangeStart()
const {
return m_arrayRangeStart; }
1065 int arrayRangeLength()
const {
return m_arrayRangeLength; }
1066 void setArrayRange(
int startIndex,
int count)
1068 m_arrayRangeStart = startIndex;
1069 m_arrayRangeLength = count;
1072 Flags flags()
const {
return m_flags; }
1073 void setFlags(Flags f) { m_flags = f; }
1075 int sampleCount()
const {
return m_sampleCount; }
1076 void setSampleCount(
int s) { m_sampleCount = s; }
1079 QRhiTexture::Format format;
1082 ViewFormat readViewFormat()
const {
return m_readViewFormat; }
1083 void setReadViewFormat(
const ViewFormat &fmt) { m_readViewFormat = fmt; }
1084 ViewFormat writeViewFormat()
const {
return m_writeViewFormat; }
1085 void setWriteViewFormat(
const ViewFormat &fmt) { m_writeViewFormat = fmt; }
1087 virtual bool create() = 0;
1088 virtual NativeTexture nativeTexture();
1089 virtual bool createFrom(NativeTexture src);
1090 virtual void setNativeLayout(
int layout);
1093 QRhiTexture(QRhiImplementation *rhi, Format format_,
const QSize &pixelSize_,
int depth_,
1094 int arraySize_,
int sampleCount_, Flags flags_);
1101 int m_arrayRangeStart = -1;
1102 int m_arrayRangeLength = -1;
1103 ViewFormat m_readViewFormat = { UnknownFormat,
false };
1104 ViewFormat m_writeViewFormat = { UnknownFormat,
false };
1107Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiTexture::Flags)
1109class Q_GUI_EXPORT QRhiSampler :
public QRhiResource
1135 QRhiResource::Type resourceType()
const override;
1137 Filter magFilter()
const {
return m_magFilter; }
1138 void setMagFilter(Filter f) { m_magFilter = f; }
1140 Filter minFilter()
const {
return m_minFilter; }
1141 void setMinFilter(Filter f) { m_minFilter = f; }
1143 Filter mipmapMode()
const {
return m_mipmapMode; }
1144 void setMipmapMode(Filter f) { m_mipmapMode = f; }
1146 AddressMode addressU()
const {
return m_addressU; }
1147 void setAddressU(AddressMode mode) { m_addressU = mode; }
1149 AddressMode addressV()
const {
return m_addressV; }
1150 void setAddressV(AddressMode mode) { m_addressV = mode; }
1152 AddressMode addressW()
const {
return m_addressW; }
1153 void setAddressW(AddressMode mode) { m_addressW = mode; }
1155 CompareOp textureCompareOp()
const {
return m_compareOp; }
1156 void setTextureCompareOp(CompareOp op) { m_compareOp = op; }
1158 virtual bool create() = 0;
1161 QRhiSampler(QRhiImplementation *rhi,
1162 Filter magFilter_, Filter minFilter_, Filter mipmapMode_,
1163 AddressMode u_, AddressMode v_, AddressMode w_);
1166 Filter m_mipmapMode;
1167 AddressMode m_addressU;
1168 AddressMode m_addressV;
1169 AddressMode m_addressW;
1170 CompareOp m_compareOp;
1182 UsedWithSwapChainOnly = 1 << 0,
1183 NoTransientBacking = 1 << 1
1185 Q_DECLARE_FLAGS(Flags, Flag)
1187 struct NativeRenderBuffer {
1191 QRhiResource::Type resourceType()
const override;
1193 Type type()
const {
return m_type; }
1194 void setType(Type t) { m_type = t; }
1196 QSize pixelSize()
const {
return m_pixelSize; }
1197 void setPixelSize(
const QSize &sz) { m_pixelSize = sz; }
1199 int sampleCount()
const {
return m_sampleCount; }
1200 void setSampleCount(
int s) { m_sampleCount = s; }
1202 Flags flags()
const {
return m_flags; }
1203 void setFlags(Flags f) { m_flags = f; }
1205 virtual bool create() = 0;
1206 virtual bool createFrom(NativeRenderBuffer src);
1208 virtual QRhiTexture::Format backingFormat()
const = 0;
1211 QRhiRenderBuffer(QRhiImplementation *rhi, Type type_,
const QSize &pixelSize_,
1212 int sampleCount_, Flags flags_, QRhiTexture::Format backingFormatHint_);
1217 QRhiTexture::Format m_backingFormatHint;
1220Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiRenderBuffer::Flags)
1222class Q_GUI_EXPORT QRhiShadingRateMap :
public QRhiResource
1225 struct NativeShadingRateMap {
1229 QRhiResource::Type resourceType()
const override;
1231 virtual bool createFrom(NativeShadingRateMap src);
1232 virtual bool createFrom(QRhiTexture *src);
1234 virtual QSize logicalSize()
const;
1237 QRhiShadingRateMap(QRhiImplementation *rhi);
1243 QRhiResource::Type resourceType()
const override;
1245 virtual bool isCompatible(
const QRhiRenderPassDescriptor *other)
const = 0;
1246 virtual const QRhiNativeHandles *nativeHandles();
1248 virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor()
const = 0;
1250 virtual QVector<quint32> serializedFormat()
const = 0;
1253 QRhiRenderPassDescriptor(QRhiImplementation *rhi);
1259 virtual QSize pixelSize()
const = 0;
1260 virtual float devicePixelRatio()
const = 0;
1261 virtual int sampleCount()
const = 0;
1263 QRhiRenderPassDescriptor *renderPassDescriptor()
const {
return m_renderPassDesc; }
1264 void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; }
1267 QRhiRenderTarget(QRhiImplementation *rhi);
1268 QRhiRenderPassDescriptor *m_renderPassDesc =
nullptr;
1274 QRhiResource::Type resourceType()
const override;
1275 QRhiSwapChain *swapChain()
const {
return m_swapchain; }
1278 QRhiSwapChainRenderTarget(QRhiImplementation *rhi, QRhiSwapChain *swapchain_);
1279 QRhiSwapChain *m_swapchain;
1286 PreserveColorContents = 1 << 0,
1287 PreserveDepthStencilContents = 1 << 1,
1288 DoNotStoreDepthStencilContents = 1 << 2
1290 Q_DECLARE_FLAGS(Flags, Flag)
1292 QRhiResource::Type resourceType()
const override;
1294 QRhiTextureRenderTargetDescription description()
const {
return m_desc; }
1295 void setDescription(
const QRhiTextureRenderTargetDescription &desc) { m_desc = desc; }
1297 Flags flags()
const {
return m_flags; }
1298 void setFlags(Flags f) { m_flags = f; }
1300 virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() = 0;
1302 virtual bool create() = 0;
1305 QRhiTextureRenderTarget(QRhiImplementation *rhi,
const QRhiTextureRenderTargetDescription &desc_, Flags flags_);
1306 QRhiTextureRenderTargetDescription m_desc;
1310Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiTextureRenderTarget::Flags)
1312class Q_GUI_EXPORT QRhiShaderResourceBindings :
public QRhiResource
1315 QRhiResource::Type resourceType()
const override;
1317 void setBindings(std::initializer_list<QRhiShaderResourceBinding> list) { m_bindings = list; }
1318 template<
typename InputIterator>
1319 void setBindings(InputIterator first, InputIterator last)
1322 std::copy(first, last, std::back_inserter(m_bindings));
1324 const QRhiShaderResourceBinding *cbeginBindings()
const {
return m_bindings.cbegin(); }
1325 const QRhiShaderResourceBinding *cendBindings()
const {
return m_bindings.cend(); }
1326 const QRhiShaderResourceBinding *bindingAt(qsizetype index)
const {
return &m_bindings.at(index); }
1327 qsizetype bindingCount()
const {
return m_bindings.count(); }
1329 bool isLayoutCompatible(
const QRhiShaderResourceBindings *other)
const;
1331 QVector<quint32> serializedLayoutDescription()
const {
return m_layoutDesc; }
1333 virtual bool create() = 0;
1336 BindingsAreSorted = 0x01
1338 Q_DECLARE_FLAGS(UpdateFlags, UpdateFlag)
1340 virtual void updateResources(UpdateFlags flags = {}) = 0;
1343 static constexpr int BINDING_PREALLOC = 12;
1344 QRhiShaderResourceBindings(QRhiImplementation *rhi);
1345 QVarLengthArray<QRhiShaderResourceBinding, BINDING_PREALLOC> m_bindings;
1346 size_t m_layoutDescHash = 0;
1350 QVector<quint32> m_layoutDesc;
1351 friend class QRhiImplementation;
1352#ifndef QT_NO_DEBUG_STREAM
1353 friend Q_GUI_EXPORT QDebug operator<<(QDebug,
const QRhiShaderResourceBindings &);
1357Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiShaderResourceBindings::UpdateFlags)
1359#ifndef QT_NO_DEBUG_STREAM
1360Q_GUI_EXPORT QDebug operator<<(QDebug,
const QRhiShaderResourceBindings &);
1366using QRhiShaderResourceBindingSet = QRhiShaderResourceBindings;
1372 UsesBlendConstants = 1 << 0,
1373 UsesStencilRef = 1 << 1,
1374 UsesScissor = 1 << 2,
1375 CompileShadersWithDebugInfo = 1 << 3,
1376 UsesShadingRate = 1 << 4,
1377 UsesIndirectDraws = 1 << 5
1379 Q_DECLARE_FLAGS(Flags, Flag)
1402 enum ColorMaskComponent {
1408 Q_DECLARE_FLAGS(ColorMask, ColorMaskComponent)
1422 OneMinusConstantColor,
1424 OneMinusConstantAlpha,
1440 struct TargetBlend {
1441 ColorMask colorWrite = ColorMask(0xF);
1442 bool enable =
false;
1443 BlendFactor srcColor = One;
1444 BlendFactor dstColor = OneMinusSrcAlpha;
1445 BlendOp opColor = Add;
1446 BlendFactor srcAlpha = One;
1447 BlendFactor dstAlpha = OneMinusSrcAlpha;
1448 BlendOp opAlpha = Add;
1473 struct StencilOpState {
1474 StencilOp failOp = Keep;
1475 StencilOp depthFailOp = Keep;
1476 StencilOp passOp = Keep;
1477 CompareOp compareOp = Always;
1485 QRhiResource::Type resourceType()
const override;
1487 Flags flags()
const {
return m_flags; }
1488 void setFlags(Flags f) { m_flags = f; }
1490 Topology topology()
const {
return m_topology; }
1491 void setTopology(Topology t) { m_topology = t; }
1493 CullMode cullMode()
const {
return m_cullMode; }
1494 void setCullMode(CullMode mode) { m_cullMode = mode; }
1496 FrontFace frontFace()
const {
return m_frontFace; }
1497 void setFrontFace(FrontFace f) { m_frontFace = f; }
1499 void setTargetBlends(std::initializer_list<TargetBlend> list) { m_targetBlends = list; }
1500 template<
typename InputIterator>
1501 void setTargetBlends(InputIterator first, InputIterator last)
1503 m_targetBlends.clear();
1504 std::copy(first, last, std::back_inserter(m_targetBlends));
1506 const TargetBlend *cbeginTargetBlends()
const {
return m_targetBlends.cbegin(); }
1507 const TargetBlend *cendTargetBlends()
const {
return m_targetBlends.cend(); }
1508 const TargetBlend *targetBlendAt(qsizetype index)
const {
return &m_targetBlends.at(index); }
1509 qsizetype targetBlendCount()
const {
return m_targetBlends.count(); }
1511 bool hasDepthTest()
const {
return m_depthTest; }
1512 void setDepthTest(
bool enable) { m_depthTest = enable; }
1514 bool hasDepthWrite()
const {
return m_depthWrite; }
1515 void setDepthWrite(
bool enable) { m_depthWrite = enable; }
1517 bool hasDepthClamp()
const {
return m_depthClamp; }
1518 void setDepthClamp(
bool enable) { m_depthClamp = enable; }
1520 CompareOp depthOp()
const {
return m_depthOp; }
1521 void setDepthOp(CompareOp op) { m_depthOp = op; }
1523 bool hasStencilTest()
const {
return m_stencilTest; }
1524 void setStencilTest(
bool enable) { m_stencilTest = enable; }
1526 StencilOpState stencilFront()
const {
return m_stencilFront; }
1527 void setStencilFront(
const StencilOpState &state) { m_stencilFront = state; }
1529 StencilOpState stencilBack()
const {
return m_stencilBack; }
1530 void setStencilBack(
const StencilOpState &state) { m_stencilBack = state; }
1532 quint32 stencilReadMask()
const {
return m_stencilReadMask; }
1533 void setStencilReadMask(quint32 mask) { m_stencilReadMask = mask; }
1535 quint32 stencilWriteMask()
const {
return m_stencilWriteMask; }
1536 void setStencilWriteMask(quint32 mask) { m_stencilWriteMask = mask; }
1538 int sampleCount()
const {
return m_sampleCount; }
1539 void setSampleCount(
int s) { m_sampleCount = s; }
1541 float lineWidth()
const {
return m_lineWidth; }
1542 void setLineWidth(
float width) { m_lineWidth = width; }
1544 int depthBias()
const {
return m_depthBias; }
1545 void setDepthBias(
int bias) { m_depthBias = bias; }
1547 float slopeScaledDepthBias()
const {
return m_slopeScaledDepthBias; }
1548 void setSlopeScaledDepthBias(
float bias) { m_slopeScaledDepthBias = bias; }
1550 void setShaderStages(std::initializer_list<QRhiShaderStage> list) { m_shaderStages = list; }
1551 template<
typename InputIterator>
1552 void setShaderStages(InputIterator first, InputIterator last)
1554 m_shaderStages.clear();
1555 std::copy(first, last, std::back_inserter(m_shaderStages));
1557 const QRhiShaderStage *cbeginShaderStages()
const {
return m_shaderStages.cbegin(); }
1558 const QRhiShaderStage *cendShaderStages()
const {
return m_shaderStages.cend(); }
1559 const QRhiShaderStage *shaderStageAt(qsizetype index)
const {
return &m_shaderStages.at(index); }
1560 qsizetype shaderStageCount()
const {
return m_shaderStages.count(); }
1562 QRhiVertexInputLayout vertexInputLayout()
const {
return m_vertexInputLayout; }
1563 void setVertexInputLayout(
const QRhiVertexInputLayout &layout) { m_vertexInputLayout = layout; }
1565 QRhiShaderResourceBindings *shaderResourceBindings()
const {
return m_shaderResourceBindings; }
1566 void setShaderResourceBindings(QRhiShaderResourceBindings *srb) { m_shaderResourceBindings = srb; }
1568 QRhiRenderPassDescriptor *renderPassDescriptor()
const {
return m_renderPassDesc; }
1569 void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; }
1571 int patchControlPointCount()
const {
return m_patchControlPointCount; }
1572 void setPatchControlPointCount(
int count) { m_patchControlPointCount = count; }
1574 PolygonMode polygonMode()
const {
return m_polygonMode; }
1575 void setPolygonMode(PolygonMode mode) {m_polygonMode = mode; }
1577 int multiViewCount()
const {
return m_multiViewCount; }
1578 void setMultiViewCount(
int count) { m_multiViewCount = count; }
1580 virtual bool create() = 0;
1583 QRhiGraphicsPipeline(QRhiImplementation *rhi);
1585 Topology m_topology = Triangles;
1586 CullMode m_cullMode = None;
1587 FrontFace m_frontFace = CCW;
1588 QVarLengthArray<TargetBlend, 8> m_targetBlends;
1589 bool m_depthTest =
false;
1590 bool m_depthWrite =
false;
1591 bool m_depthClamp =
false;
1592 CompareOp m_depthOp = Less;
1593 bool m_stencilTest =
false;
1594 StencilOpState m_stencilFront;
1595 StencilOpState m_stencilBack;
1596 quint32 m_stencilReadMask = 0xFF;
1597 quint32 m_stencilWriteMask = 0xFF;
1598 int m_sampleCount = 1;
1599 float m_lineWidth = 1.0f;
1600 int m_depthBias = 0;
1601 float m_slopeScaledDepthBias = 0.0f;
1602 int m_patchControlPointCount = 3;
1603 PolygonMode m_polygonMode = Fill;
1604 int m_multiViewCount = 0;
1605 QVarLengthArray<QRhiShaderStage, 4> m_shaderStages;
1606 QRhiVertexInputLayout m_vertexInputLayout;
1607 QRhiShaderResourceBindings *m_shaderResourceBindings =
nullptr;
1608 QRhiRenderPassDescriptor *m_renderPassDesc =
nullptr;
1611Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiGraphicsPipeline::Flags)
1612Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiGraphicsPipeline::ColorMask)
1613Q_DECLARE_TYPEINFO(QRhiGraphicsPipeline::TargetBlend, Q_RELOCATABLE_TYPE);
1634 float maxColorComponentValue;
1635 float maxPotentialColorComponentValue;
1636 } colorComponentValue;
1644#ifndef QT_NO_DEBUG_STREAM
1645Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiSwapChainHdrInfo &);
1657 SurfaceHasPreMulAlpha = 1 << 0,
1658 SurfaceHasNonPreMulAlpha = 1 << 1,
1660 UsedAsTransferSource = 1 << 3,
1662 MinimalBufferCount = 1 << 5
1664 Q_DECLARE_FLAGS(Flags, Flag)
1668 HDRExtendedSrgbLinear,
1670 HDRExtendedDisplayP3Linear
1673 enum StereoTargetBuffer {
1678 QRhiResource::Type resourceType()
const override;
1680 QWindow *window()
const {
return m_window; }
1681 void setWindow(QWindow *window) { m_window = window; }
1683 QRhiSwapChainProxyData proxyData()
const {
return m_proxyData; }
1684 void setProxyData(
const QRhiSwapChainProxyData &d) { m_proxyData = d; }
1686 Flags flags()
const {
return m_flags; }
1687 void setFlags(Flags f) { m_flags = f; }
1689 Format format()
const {
return m_format; }
1690 void setFormat(Format f) { m_format = f; }
1692 QRhiRenderBuffer *depthStencil()
const {
return m_depthStencil; }
1693 void setDepthStencil(QRhiRenderBuffer *ds) { m_depthStencil = ds; }
1695 int sampleCount()
const {
return m_sampleCount; }
1696 void setSampleCount(
int samples) { m_sampleCount = samples; }
1698 QRhiRenderPassDescriptor *renderPassDescriptor()
const {
return m_renderPassDesc; }
1699 void setRenderPassDescriptor(QRhiRenderPassDescriptor *desc) { m_renderPassDesc = desc; }
1701 QRhiShadingRateMap *shadingRateMap()
const {
return m_shadingRateMap; }
1702 void setShadingRateMap(QRhiShadingRateMap *map) { m_shadingRateMap = map; }
1704 QSize currentPixelSize()
const {
return m_currentPixelSize; }
1706 virtual QRhiCommandBuffer *currentFrameCommandBuffer() = 0;
1707 virtual QRhiRenderTarget *currentFrameRenderTarget() = 0;
1708 virtual QRhiRenderTarget *currentFrameRenderTarget(StereoTargetBuffer targetBuffer);
1709 virtual QSize surfacePixelSize() = 0;
1710 virtual bool isFormatSupported(Format f) = 0;
1711 virtual QRhiRenderPassDescriptor *newCompatibleRenderPassDescriptor() = 0;
1712 virtual bool createOrResize() = 0;
1713 virtual QRhiSwapChainHdrInfo hdrInfo();
1716 QRhiSwapChain(QRhiImplementation *rhi);
1717 QWindow *m_window =
nullptr;
1719 Format m_format = SDR;
1720 QRhiRenderBuffer *m_depthStencil =
nullptr;
1721 int m_sampleCount = 1;
1722 QRhiRenderPassDescriptor *m_renderPassDesc =
nullptr;
1723 QSize m_currentPixelSize;
1724 QRhiSwapChainProxyData m_proxyData;
1725 QRhiShadingRateMap *m_shadingRateMap =
nullptr;
1728Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiSwapChain::Flags)
1730class Q_GUI_EXPORT QRhiComputePipeline :
public QRhiResource
1734 CompileShadersWithDebugInfo = 1 << 0
1736 Q_DECLARE_FLAGS(Flags, Flag)
1738 QRhiResource::Type resourceType()
const override;
1739 virtual bool create() = 0;
1741 Flags flags()
const {
return m_flags; }
1742 void setFlags(Flags f) { m_flags = f; }
1744 QRhiShaderStage shaderStage()
const {
return m_shaderStage; }
1745 void setShaderStage(
const QRhiShaderStage &stage) { m_shaderStage = stage; }
1747 QRhiShaderResourceBindings *shaderResourceBindings()
const {
return m_shaderResourceBindings; }
1748 void setShaderResourceBindings(QRhiShaderResourceBindings *srb) { m_shaderResourceBindings = srb; }
1751 QRhiComputePipeline(QRhiImplementation *rhi);
1753 QRhiShaderStage m_shaderStage;
1754 QRhiShaderResourceBindings *m_shaderResourceBindings =
nullptr;
1757Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiComputePipeline::Flags)
1759struct QRhiIndirectDrawCommand
1761 quint32 vertexCount;
1762 quint32 instanceCount = 1;
1763 quint32 firstVertex = 0;
1764 quint32 firstInstance = 0;
1784static_assert(
sizeof(QRhiIndirectDrawCommand) == 16);
1796 QRhiResource::Type resourceType()
const override;
1798 Type type()
const {
return m_type; }
1799 void setType(Type t) { m_type = t; }
1801 quint32 maxCommandCount()
const {
return m_maxCommandCount; }
1802 void setMaxCommandCount(quint32 count) { m_maxCommandCount = count; }
1804 virtual bool create() = 0;
1807 void draw(quint32 vertexCount, quint32 instanceCount = 1,
1808 quint32 firstVertex = 0, quint32 firstInstance = 0);
1809 void drawIndexed(quint32 indexCount, quint32 instanceCount = 1, quint32 firstIndex = 0,
1810 qint32 vertexOffset = 0, quint32 firstInstance = 0);
1812 quint32 recordedCommandCount()
const {
return m_commandCount; }
1813 bool isGpuBuilt()
const {
return m_gpuBuilt; }
1814 quint32 commandCount()
const {
return m_gpuBuilt ? m_gpuBuiltCommandCount : m_commandCount; }
1817 QRhiIndirectCommandBuffer(QRhiImplementation *rhi, Type type_, quint32 maxCommandCount_);
1820 quint32 m_maxCommandCount;
1822 quint32 m_commandCount = 0;
1823 quint64 m_generation = 0;
1824 bool m_gpuBuilt =
false;
1825 quint32 m_gpuBuiltCommandCount = 0;
1836 enum BeginPassFlag {
1837 ExternalContent = 0x01,
1838 DoNotTrackResourcesForCompute = 0x02
1840 Q_DECLARE_FLAGS(BeginPassFlags, BeginPassFlag)
1842 QRhiResource::Type resourceType()
const override;
1844 void resourceUpdate(QRhiResourceUpdateBatch *resourceUpdates);
1846 void beginPass(QRhiRenderTarget *rt,
1847 const QColor &colorClearValue,
1848 const QRhiDepthStencilClearValue &depthStencilClearValue,
1849 QRhiResourceUpdateBatch *resourceUpdates =
nullptr,
1850 BeginPassFlags flags = {});
1851 void endPass(QRhiResourceUpdateBatch *resourceUpdates =
nullptr);
1853 void setGraphicsPipeline(QRhiGraphicsPipeline *ps);
1854 using DynamicOffset = std::pair<
int, quint32>;
1855 void setShaderResources(QRhiShaderResourceBindings *srb =
nullptr,
1856 int dynamicOffsetCount = 0,
1857 const DynamicOffset *dynamicOffsets =
nullptr);
1858 using VertexInput = std::pair<QRhiBuffer *, quint32>;
1859 void setVertexInput(
int startBinding,
int bindingCount,
const VertexInput *bindings,
1860 QRhiBuffer *indexBuf =
nullptr, quint32 indexOffset = 0,
1861 IndexFormat indexFormat = IndexUInt16);
1863 void setViewport(
const QRhiViewport &viewport);
1864 void setScissor(
const QRhiScissor &scissor);
1865 void setBlendConstants(
const QColor &c);
1866 void setStencilRef(quint32 refValue);
1867 void setShadingRate(
const QSize &coarsePixelSize);
1868 void setPushConstants(quint32 offset, quint32 size,
const void *data);
1870 void draw(quint32 vertexCount,
1871 quint32 instanceCount = 1,
1872 quint32 firstVertex = 0,
1873 quint32 firstInstance = 0);
1875 void drawIndexed(quint32 indexCount,
1876 quint32 instanceCount = 1,
1877 quint32 firstIndex = 0,
1878 qint32 vertexOffset = 0,
1879 quint32 firstInstance = 0);
1881 void drawIndirect(QRhiBuffer *indirectBuffer,
1882 quint32 indirectBufferOffset,
1884 quint32 stride =
sizeof(QRhiIndirectDrawCommand));
1886 void drawIndexedIndirect(QRhiBuffer *indirectBuffer,
1887 quint32 indirectBufferOffset,
1889 quint32 stride =
sizeof(QRhiIndexedIndirectDrawCommand));
1891 void drawIndirectCount(QRhiBuffer *indirectBuffer,
1892 quint32 indirectBufferOffset,
1893 QRhiBuffer *countBuffer,
1894 quint32 countBufferOffset,
1895 quint32 maxDrawCount,
1896 quint32 stride =
sizeof(QRhiIndirectDrawCommand));
1898 void drawIndexedIndirectCount(QRhiBuffer *indirectBuffer,
1899 quint32 indirectBufferOffset,
1900 QRhiBuffer *countBuffer,
1901 quint32 countBufferOffset,
1902 quint32 maxDrawCount,
1903 quint32 stride =
sizeof(QRhiIndexedIndirectDrawCommand));
1905 void buildIndirect(QRhiIndirectCommandBuffer *icb,
1906 const QRhiIndirectCommandBufferBuildInfo &info);
1908 void executeIndirect(QRhiIndirectCommandBuffer *icb,
1909 quint32 firstCommand = 0,
1910 quint32 commandCount = 0xFFFFFFFFu);
1912 void debugMarkBegin(
const QByteArray &name);
1913 void debugMarkEnd();
1914 void debugMarkMsg(
const QByteArray &msg);
1916 void beginComputePass(QRhiResourceUpdateBatch *resourceUpdates =
nullptr, BeginPassFlags flags = {});
1917 void endComputePass(QRhiResourceUpdateBatch *resourceUpdates =
nullptr);
1918 void setComputePipeline(QRhiComputePipeline *ps);
1919 void dispatch(
int x,
int y,
int z);
1920 void dispatchIndirect(QRhiBuffer *indirectBuffer,
1921 quint32 indirectBufferOffset = 0);
1923 const QRhiNativeHandles *nativeHandles();
1924 void beginExternal();
1927 double lastCompletedGpuTime();
1930 QRhiCommandBuffer(QRhiImplementation *rhi);
1933Q_DECLARE_OPERATORS_FOR_FLAGS(QRhiCommandBuffer::BeginPassFlags)
1935struct QRhiIndirectCommandBufferBuildInfo
1937 QRhiGraphicsPipeline::Topology topology = QRhiGraphicsPipeline::Triangles;
1938 QRhiBuffer *sourceBuffer =
nullptr;
1939 quint32 sourceBufferOffset = 0;
1940 quint32 commandCount = 0;
1942 QRhiBuffer *countBuffer =
nullptr;
1943 quint32 countBufferOffset = 0;
1944 QRhiBuffer *indexBuffer =
nullptr;
1945 quint32 indexBufferOffset = 0;
1946 QRhiCommandBuffer::IndexFormat indexFormat = QRhiCommandBuffer::IndexUInt16;
1951 std::function<
void()> completed =
nullptr;
1952 QRhiTexture::Format format;
1960 ~QRhiResourceUpdateBatch();
1964 void merge(QRhiResourceUpdateBatch *other);
1965 bool hasOptimalCapacity()
const;
1967 void updateDynamicBuffer(QRhiBuffer *buf, quint32 offset, quint32 size,
const void *data);
1968 void updateDynamicBuffer(QRhiBuffer *buf, quint32 offset, QByteArray data);
1969 void uploadStaticBuffer(QRhiBuffer *buf, quint32 offset, quint32 size,
const void *data);
1970 void uploadStaticBuffer(QRhiBuffer *buf, quint32 offset, QByteArray data);
1971 void uploadStaticBuffer(QRhiBuffer *buf,
const void *data);
1972 void uploadStaticBuffer(QRhiBuffer *buf, QByteArray data);
1973 void readBackBuffer(QRhiBuffer *buf, quint32 offset, quint32 size, QRhiReadbackResult *result);
1974 void copyBuffer(QRhiBuffer *dst, QRhiBuffer *src,
const QRhiBufferCopyDescription &desc = QRhiBufferCopyDescription());
1975 void clearStorageBuffer(QRhiBuffer *buf, quint32 offset, quint32 size, quint8 value);
1976 void clearStorageBuffer(QRhiBuffer *buf, quint8 value);
1977 void uploadTexture(QRhiTexture *tex,
const QRhiTextureUploadDescription &desc);
1978 void uploadTexture(QRhiTexture *tex,
const QImage &image);
1979 void copyTexture(QRhiTexture *dst, QRhiTexture *src,
const QRhiTextureCopyDescription &desc = QRhiTextureCopyDescription());
1980 void readBackTexture(
const QRhiReadbackDescription &rb, QRhiReadbackResult *result);
1981 void generateMips(QRhiTexture *tex);
1982 void commitIndirectCommandBuffer(QRhiIndirectCommandBuffer *icb);
1985 QRhiResourceUpdateBatch(QRhiImplementation *rhi);
1986 Q_DISABLE_COPY(QRhiResourceUpdateBatch)
1987 QRhiResourceUpdateBatchPrivate *d;
1988 friend class QRhiResourceUpdateBatchPrivate;
2003 QByteArray deviceName;
2004 quint64 deviceId = 0;
2005 quint64 vendorId = 0;
2006 DeviceType deviceType = UnknownDevice;
2011#ifndef QT_NO_DEBUG_STREAM
2012Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiDriverInfo &);
2017 qint64 totalPipelineCreationTime = 0;
2019 quint32 blockCount = 0;
2020 quint32 allocCount = 0;
2021 quint64 usedBytes = 0;
2022 quint64 unusedBytes = 0;
2024 quint64 totalUsageBytes = 0;
2029#ifndef QT_NO_DEBUG_STREAM
2030Q_GUI_EXPORT
QDebug operator<<(QDebug,
const QRhiStats &);
2036 virtual ~QRhiAdapter();
2037 virtual QRhiDriverInfo info()
const = 0;
2047 enum Implementation {
2057 EnableDebugMarkers = 1 << 0,
2058 PreferSoftwareRenderer = 1 << 1,
2059 EnablePipelineCacheDataSave = 1 << 2,
2060 EnableTimestamps = 1 << 3,
2061 SuppressSmokeTestWarnings = 1 << 4
2063 Q_DECLARE_FLAGS(Flags, Flag)
2065 enum FrameOpResult {
2068 FrameOpSwapChainOutOfDate,
2073 MultisampleTexture = 1,
2074 MultisampleRenderBuffer,
2078 CustomInstanceStepRate,
2080 NonDynamicUniformBuffers,
2081 NonFourAlignedEffectiveIndexBufferOffset,
2087 VertexShaderPointSize,
2090 TriangleFanTopology,
2091 ReadBackNonUniformBuffer,
2092 ReadBackNonBaseMipLevel,
2094 RenderToNonBaseMipLevel,
2096 ScreenSpaceDerivatives,
2097 ReadBackAnyTextureFormat,
2098 PipelineCacheDataLoadSave,
2101 ThreeDimensionalTextures,
2102 RenderTo3DTextureSlice,
2108 OneDimensionalTextures,
2109 OneDimensionalTextureMipmaps,
2111 RenderToOneDimensionalTexture,
2112 ThreeDimensionalTextureMipmaps,
2115 ResolveDepthStencil,
2116 VariableRateShading,
2117 VariableRateShadingMap,
2118 VariableRateShadingMapWithTexture,
2119 PerRenderTargetBlending,
2121 InstanceIndexIncludesBaseInstance,
2125 ShaderDrawParameters,
2130 StaticBuffersOnGpuTimeline,
2131 FragmentStoresAndAtomics
2134 enum BeginFrameFlag {
2136 Q_DECLARE_FLAGS(BeginFrameFlags, BeginFrameFlag)
2139 SkipPresent = 1 << 0
2141 Q_DECLARE_FLAGS(EndFrameFlags, EndFrameFlag)
2143 enum ResourceLimit {
2146 MaxColorAttachments,
2148 MaxAsyncReadbackFrames,
2149 MaxThreadGroupsPerDimension,
2150 MaxThreadsPerThreadGroup,
2154 TextureArraySizeMax,
2155 MaxUniformBufferRange,
2158 ShadingRateImageTileSize,
2159 MaxVertexStorageBuffers,
2160 MaxFragmentStorageBuffers,
2161 MaxPushConstantsSize
2166 static QRhi *create(Implementation impl,
2167 QRhiInitParams *params,
2169 QRhiNativeHandles *importDevice =
nullptr);
2170 static QRhi *create(Implementation impl,
2171 QRhiInitParams *params,
2173 QRhiNativeHandles *importDevice,
2174 QRhiAdapter *adapter);
2175 static bool probe(Implementation impl, QRhiInitParams *params);
2176 using AdapterList = QVector<QRhiAdapter *>;
2177 static AdapterList enumerateAdapters(Implementation impl,
2178 QRhiInitParams *params,
2179 QRhiNativeHandles *nativeHandles =
nullptr);
2181 Implementation backend()
const;
2182 const char *backendName()
const;
2183 static const char *backendName(Implementation impl);
2184 QRhiDriverInfo driverInfo()
const;
2185 QThread *thread()
const;
2187 using CleanupCallback = std::function<
void(QRhi *)>;
2188 void addCleanupCallback(
const CleanupCallback &callback);
2189 void addCleanupCallback(
const void *key,
const CleanupCallback &callback);
2190 void removeCleanupCallback(
const void *key);
2192 QRhiGraphicsPipeline *newGraphicsPipeline();
2193 QRhiComputePipeline *newComputePipeline();
2194 QRhiShaderResourceBindings *newShaderResourceBindings();
2196 QRhiBuffer *newBuffer(QRhiBuffer::Type type,
2197 QRhiBuffer::UsageFlags usage,
2200 QRhiRenderBuffer *newRenderBuffer(QRhiRenderBuffer::Type type,
2201 const QSize &pixelSize,
2202 int sampleCount = 1,
2203 QRhiRenderBuffer::Flags flags = {},
2204 QRhiTexture::Format backingFormatHint = QRhiTexture::UnknownFormat);
2206 QRhiTexture *newTexture(QRhiTexture::Format format,
2207 const QSize &pixelSize,
2208 int sampleCount = 1,
2209 QRhiTexture::Flags flags = {});
2211 QRhiTexture *newTexture(QRhiTexture::Format format,
2212 int width,
int height,
int depth,
2213 int sampleCount = 1,
2214 QRhiTexture::Flags flags = {});
2216 QRhiTexture *newTextureArray(QRhiTexture::Format format,
2218 const QSize &pixelSize,
2219 int sampleCount = 1,
2220 QRhiTexture::Flags flags = {});
2222 QRhiSampler *newSampler(QRhiSampler::Filter magFilter,
2223 QRhiSampler::Filter minFilter,
2224 QRhiSampler::Filter mipmapMode,
2225 QRhiSampler::AddressMode addressU,
2226 QRhiSampler::AddressMode addressV,
2227 QRhiSampler::AddressMode addressW = QRhiSampler::Repeat);
2229 QRhiShadingRateMap *newShadingRateMap();
2231 QRhiIndirectCommandBuffer *newIndirectCommandBuffer(QRhiIndirectCommandBuffer::Type type,
2232 quint32 maxCommandCount);
2234 QRhiTextureRenderTarget *newTextureRenderTarget(
const QRhiTextureRenderTargetDescription &desc,
2235 QRhiTextureRenderTarget::Flags flags = {});
2237 QRhiSwapChain *newSwapChain();
2238 FrameOpResult beginFrame(QRhiSwapChain *swapChain, BeginFrameFlags flags = {});
2239 FrameOpResult endFrame(QRhiSwapChain *swapChain, EndFrameFlags flags = {});
2240 bool isRecordingFrame()
const;
2241 int currentFrameSlot()
const;
2243 FrameOpResult beginOffscreenFrame(QRhiCommandBuffer **cb, BeginFrameFlags flags = {});
2244 FrameOpResult endOffscreenFrame(EndFrameFlags flags = {});
2246 QRhi::FrameOpResult finish();
2248 QRhiResourceUpdateBatch *nextResourceUpdateBatch();
2250 QList<
int> supportedSampleCounts()
const;
2252 int ubufAlignment()
const;
2253 int ubufAligned(
int v)
const;
2255 static int mipLevelsForSize(
const QSize &size);
2256 static QSize sizeForMipLevel(
int mipLevel,
const QSize &baseLevelSize);
2258 bool isYUpInFramebuffer()
const;
2259 bool isYUpInNDC()
const;
2260 bool isClipDepthZeroToOne()
const;
2262 QMatrix4x4 clipSpaceCorrMatrix()
const;
2264 bool isTextureFormatSupported(QRhiTexture::Format format, QRhiTexture::Flags flags = {})
const;
2265 bool isFeatureSupported(QRhi::Feature feature)
const;
2266 int resourceLimit(ResourceLimit limit)
const;
2268 const QRhiNativeHandles *nativeHandles();
2269 bool makeThreadLocalNativeContextCurrent();
2270 void setQueueSubmitParams(QRhiNativeHandles *params);
2272 static constexpr int MAX_MIP_LEVELS = 16;
2274 void releaseCachedResources();
2276 bool isDeviceLost()
const;
2278 QByteArray pipelineCacheData();
2279 void setPipelineCacheData(
const QByteArray &data);
2281 QRhiStats statistics()
const;
2283 static QRhiSwapChainProxyData updateSwapChainProxyData(Implementation impl, QWindow *window);
2285 QList<QSize> supportedShadingRates(
int sampleCount)
const;
2291 Q_DISABLE_COPY(QRhi)
2292 QRhiImplementation *d =
nullptr;
2295Q_DECLARE_OPERATORS_FOR_FLAGS(QRhi::Flags)
2296Q_DECLARE_OPERATORS_FOR_FLAGS(QRhi::BeginFrameFlags)
2297Q_DECLARE_OPERATORS_FOR_FLAGS(QRhi::EndFrameFlags)
2301#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.
LimitsType
\value LuminanceInNits Indicates that the \l limits union has its luminanceInNits struct set
LuminanceBehavior luminanceBehavior
\inmodule QtGuiPrivate \inheaderfile rhi/qrhi.h