6#ifndef QSSGRHICONTEXT_P_H
7#define QSSGRHICONTEXT_P_H
20#include <QtGui/rhi/qrhi.h>
22#include <QtQuick3DRuntimeRender/qtquick3druntimerenderexports.h>
23#include <QtQuick3DUtils/private/qssgrenderbasetypes_p.h>
24#include <QtQuick3DUtils/private/qssgutils_p.h>
25#include <ssg/qssgrhicontext.h>
26#include <QtQuick3DRuntimeRender/private/qssgrhiresourcehandle_p.h>
28#include <QtCore/qhash.h>
29#include <QtCore/qvarlengtharray.h>
35struct QSSGRenderLayer;
36struct QSSGRenderSkyMaterial;
37struct QSSGRenderInstanceTable;
38struct QSSGRenderModel;
40class QSSGRenderGraphObject;
41class QSSGBufferManager;
42class QSSGRenderUserPassBase;
51using QSSGRhiInputAssemblerState = QSSGRhiInputAssemblerStatePrivate::InputAssemblerState;
55 static void setShaderPipeline(QSSGRhiGraphicsPipelineState &ps,
const QSSGRhiShaderPipeline *pipeline)
57 ps.shaderPipeline = pipeline;
60 static constexpr const QSSGRhiShaderPipeline *
getShaderPipeline(
const QSSGRhiGraphicsPipelineState &ps)
62 return ps.shaderPipeline;
72 case QSSGRenderTextureFilterOp::Nearest:
73 return QRhiSampler::Nearest;
74 case QSSGRenderTextureFilterOp::Linear:
75 return QRhiSampler::Linear;
76 case QSSGRenderTextureFilterOp::None:
77 return QRhiSampler::Linear;
80 Q_UNREACHABLE_RETURN(QRhiSampler::Linear);
86 case QSSGRenderTextureCoordOp::Repeat:
87 return QRhiSampler::Repeat;
88 case QSSGRenderTextureCoordOp::MirroredRepeat:
89 return QRhiSampler::Mirror;
90 case QSSGRenderTextureCoordOp::ClampToEdge:
91 return QRhiSampler::ClampToEdge;
92 case QSSGRenderTextureCoordOp::Unknown:
93 return QRhiSampler::ClampToEdge;
96 Q_UNREACHABLE_RETURN(QRhiSampler::ClampToEdge);
101 switch (cullFaceMode) {
102 case QSSGCullFaceMode::Back:
103 return QRhiGraphicsPipeline::Back;
104 case QSSGCullFaceMode::Front:
105 return QRhiGraphicsPipeline::Front;
106 case QSSGCullFaceMode::Disabled:
107 return QRhiGraphicsPipeline::None;
108 case QSSGCullFaceMode::FrontAndBack:
109 qWarning(
"FrontAndBack cull mode not supported");
110 return QRhiGraphicsPipeline::None;
111 case QSSGCullFaceMode::Unknown:
112 return QRhiGraphicsPipeline::None;
115 Q_UNREACHABLE_RETURN(QRhiGraphicsPipeline::None);
122void bakeVertexInputLocations(QSSGRhiInputAssemblerState *ia,
const QSSGRhiShaderPipeline &shaders,
int instanceBufferBinding = -1);
124QShaderDescription::VariableType samplerType(
const QSSGRhiShaderPipeline &shaders,
const QByteArray &name);
127QRhiTexture *dummyTextureForSampler(QSSGRhiContext *rhiCtx, QShaderDescription::VariableType samplerType,
128 QRhiResourceUpdateBatch *rub,
int arraySize = 2,
129 const QSize &size = QSize(64, 64),
const QColor &fillColor = Qt::black);
133inline bool operator==(
const QSSGRhiGraphicsPipelineState &a,
const QSSGRhiGraphicsPipelineState &b) Q_DECL_NOTHROW
135 const auto &ia_a = QSSGRhiInputAssemblerStatePrivate::get(a);
136 const auto &ia_b = QSSGRhiInputAssemblerStatePrivate::get(b);
137 const auto compareTargetBlend = [](
const std::array<QRhiGraphicsPipeline::TargetBlend, 8> &a,
138 const std::array<QRhiGraphicsPipeline::TargetBlend, 8> &b,
139 const int count) ->
bool {
140 for (
int i = 0; i < count; i++) {
141 if (a[i].colorWrite != b[i].colorWrite
142 || a[i].srcColor != b[i].srcColor
143 || a[i].dstColor != b[i].dstColor
144 || a[i].opColor != b[i].opColor
145 || a[i].srcAlpha != b[i].srcAlpha
146 || a[i].dstAlpha != b[i].dstAlpha
147 || a[i].opAlpha != b[i].opAlpha) {
157 return QSSGRhiGraphicsPipelineStatePrivate::getShaderPipeline(a) == QSSGRhiGraphicsPipelineStatePrivate::getShaderPipeline(b)
158 && a.samples == b.samples
159 && a.flags == b.flags
160 && a.stencilRef == b.stencilRef
161 && (std::memcmp(&a.stencilOpFrontState, &b.stencilOpFrontState,
sizeof(QRhiGraphicsPipeline::StencilOpState)) == 0)
162 && a.stencilWriteMask == b.stencilWriteMask
163 && a.depthFunc == b.depthFunc
164 && a.cullMode == b.cullMode
165 && a.depthBias == b.depthBias
166 && a.slopeScaledDepthBias == b.slopeScaledDepthBias
167 && ia_a.topology == ia_b.topology
168 && ia_a.inputLayout == ia_b.inputLayout
169 && a.colorAttachmentCount == b.colorAttachmentCount
170 && compareTargetBlend(a.targetBlend, b.targetBlend, a.colorAttachmentCount)
171 && a.lineWidth == b.lineWidth
172 && a.polygonMode == b.polygonMode
173 && a.viewCount == b.viewCount;
176inline bool operator!=(
const QSSGRhiGraphicsPipelineState &a,
const QSSGRhiGraphicsPipelineState &b) Q_DECL_NOTHROW
181inline size_t qHash(
const QSSGRhiGraphicsPipelineState &s, size_t seed) Q_DECL_NOTHROW
184 return qHash(QSSGRhiGraphicsPipelineStatePrivate::getShaderPipeline(s), seed)
187 ^ qHash(s.targetBlend[0].dstColor)
190 ^ qHash(s.colorAttachmentCount)
192 ^ qHash(s.polygonMode)
193 ^ qHashBits(&s.stencilOpFrontState,
sizeof(QRhiGraphicsPipeline::StencilOpState))
195 ^ (s.stencilRef << 6)
196 ^ (s.stencilWriteMask << 7);
213struct QSSGRhiDrawCallDataKey
215 const void *cid =
nullptr;
216 const void *model =
nullptr;
217 const void *resource =
nullptr;
218 const void *mapEntry =
nullptr;
219 quintptr resourceIdx = 0;
224 Q_DISABLE_COPY(QSSGRhiBuffer)
226 QSSGRhiBuffer(QSSGRhiContext &context,
227 QRhiBuffer::Type type,
228 QRhiBuffer::UsageFlags usageMask,
231 QRhiCommandBuffer::IndexFormat indexFormat = QRhiCommandBuffer::IndexUInt16);
233 virtual ~QSSGRhiBuffer();
238 const quint32 sz = quint32(m_buffer->size());
239 Q_ASSERT((sz % m_stride) == 0);
240 return sz / m_stride;
245 QSSGRhiContext &m_context;
246 QRhiBuffer *m_buffer =
nullptr;
248 QRhiCommandBuffer::IndexFormat m_indexFormat;
258 bool maybeExists =
true;
259 friend class QSSGRhiShaderPipeline;
271 bool maybeExists =
true;
272 friend class QSSGRhiShaderPipeline;
275using QSSGRhiBufferPtr = std::shared_ptr<QSSGRhiBuffer>;
277inline bool operator==(
const QSSGRhiSamplerDescription &a,
const QSSGRhiSamplerDescription &b) Q_DECL_NOTHROW
279 return a.hTiling == b.hTiling && a.vTiling == b.vTiling && a.zTiling == b.zTiling
280 && a.minFilter == b.minFilter && a.magFilter == b.magFilter
281 && a.mipmap == b.mipmap;
284inline bool operator!=(
const QSSGRhiSamplerDescription &a,
const QSSGRhiSamplerDescription &b) Q_DECL_NOTHROW
292 QRhiTexture *texture =
nullptr;
293 QSSGRhiSamplerDescription samplerDesc;
313#define QSSG_MAX_NUM_LIGHTS 16
314#define QSSG_MAX_NUM_DIRECTIONAL_LIGHTS 4
315#define QSSG_REDUCED_MAX_NUM_LIGHTS 4
316#define QSSG_REDUCED_MAX_NUM_DIRECTIONAL_LIGHTS 1
386class QSSGRhiShaderResourceBindingList;
389 Q_DISABLE_COPY(QSSGRhiShaderPipeline)
391 explicit QSSGRhiShaderPipeline(QSSGRhiContext &context) : m_context(context) { }
393 QSSGRhiContext &context()
const {
return m_context; }
394 bool isNull()
const {
return m_stages.isEmpty(); }
404 void addStage(
const QRhiShaderStage &stage, StageFlags flags = {});
409 for (
const QRhiShaderStage &s : m_stages) {
410 if (s.type() == QRhiShaderStage::Vertex)
416 for (
const QRhiShaderStage &s : m_stages) {
417 if (s.type() == QRhiShaderStage::Fragment)
423 for (
const QRhiShaderStage &s : m_stages) {
424 if (s.type() == QRhiShaderStage::Compute)
501 } commonUniformIndices;
517 void setUniformValue(
char *ubufData,
const char *name,
const QVariant &value, QSSGRenderShaderValue::Type type);
518 void setUniform(
char *ubufData,
const char *name,
const void *data, size_t size,
int *storeIndex =
nullptr, UniformFlags flags = {});
519 void setUniformArray(
char *ubufData,
const char *name,
const void *data, size_t itemCount, QSSGRenderShaderValue::Type type,
int *storeIndex =
nullptr);
525 QSSGBufferManager &theBufferManager,
526 const QByteArray &inPropertyName,
527 const QVariant &propertyValue,
528 QSSGRenderShaderValue::Type inPropertyType);
536 void setLightProbeTexture(QRhiTexture *texture,
537 QSSGRenderTextureCoordOp hTile = QSSGRenderTextureCoordOp::ClampToEdge,
538 QSSGRenderTextureCoordOp vTile = QSSGRenderTextureCoordOp::ClampToEdge)
540 m_lightProbeTexture = texture; m_lightProbeHorzTile = hTile; m_lightProbeVertTile = vTile;
545 return {m_lightProbeHorzTile, m_lightProbeVertTile};
548 void setScreenTexture(QRhiTexture *texture) { m_screenTexture = texture; }
551 void setDepthTexture(QRhiTexture *texture) { m_depthTexture = texture; }
554 void setNormalTexture(QRhiTexture *texture) { m_normalTexture = texture; }
557 void setSsaoTexture(QRhiTexture *texture) { m_ssaoTexture = texture; }
560 void setLightmapTexture(QRhiTexture *texture) { m_lightmapTexture = texture; }
563 void setMotionVectorTexture(QRhiTexture *texture) { m_motionVectorTexture = texture; }
565 void setShadowMapAtlasTexture(QRhiTexture *texture) { m_shadowMapAtlasTexture = texture; }
568 void setShadowMapBlueNoiseTexture(QRhiTexture *texture) { m_shadowMapBlueNoiseTexture = texture; }
571 void setOITImages(QRhiTexture *accumulator, QRhiTexture *auxiliary, QRhiTexture *counter)
573 m_oitImages[0] = accumulator;
574 m_oitImages[1] = auxiliary;
575 m_oitImages[2] = counter;
598 using StorageBindingMap = QMap<
int, StorageResourceBinding>;
600 void addStorageBufferBinding(
const QByteArray &name, QRhiShaderResourceBinding::Type type, QRhiBuffer *buffer,
int binding);
601 void addStorageImageBinding(
const QByteArray &name, QRhiShaderResourceBinding::Type type, QRhiTexture *texture,
int binding);
613 QSSGRhiContext &m_context;
614 QVarLengthArray<QRhiShaderStage, 2> m_stages;
616 int m_ub0NextUBufOffset = 0;
617 QHash<QByteArray, QShaderDescription::BlockVariable> m_ub0;
618 QHash<QSSGRhiInputAssemblerState::InputSemantic, QShaderDescription::InOutVariable> m_vertexInputs;
619 QHash<QByteArray, QShaderDescription::InOutVariable> m_combinedImageSamplers;
620 QHash<QByteArray, QShaderDescription::InOutVariable> m_storageImages;
621 QHash<QByteArray, QShaderDescription::StorageBlock> m_storageBuffers;
624 QVarLengthArray<QSSGRhiShaderUniform, 32> m_uniforms;
625 QVarLengthArray<QSSGRhiShaderUniformArray, 8> m_uniformArrays;
626 QHash<QByteArray, size_t> m_uniformIndex;
629 bool m_lightsEnabled =
false;
632 QRhiTexture *m_shadowMapAtlasTexture =
nullptr;
633 QRhiTexture *m_shadowMapBlueNoiseTexture =
nullptr;
634 QRhiTexture *m_lightProbeTexture =
nullptr;
635 QSSGRenderTextureCoordOp m_lightProbeHorzTile = QSSGRenderTextureCoordOp::ClampToEdge;
636 QSSGRenderTextureCoordOp m_lightProbeVertTile = QSSGRenderTextureCoordOp::ClampToEdge;
637 QRhiTexture *m_screenTexture =
nullptr;
638 QRhiTexture *m_depthTexture =
nullptr;
639 QRhiTexture *m_normalTexture =
nullptr;
640 QRhiTexture *m_ssaoTexture =
nullptr;
641 QRhiTexture *m_lightmapTexture =
nullptr;
642 QRhiTexture *m_oitImages[3] = {
nullptr};
643 QRhiTexture *m_motionVectorTexture =
nullptr;
644 QVarLengthArray<QSSGRhiTexture, 8> m_extraTextures;
646 QMap<
int, StorageResourceBinding> m_storageImageBindings;
647 QMap<
int, StorageResourceBinding> m_storageBufferBindings;
650Q_DECLARE_OPERATORS_FOR_FLAGS(QSSGRhiShaderPipeline::StageFlags)
651Q_DECLARE_OPERATORS_FOR_FLAGS(QSSGRhiShaderPipeline::UniformFlags)
653using QSSGRhiShaderPipelinePtr = std::shared_ptr<QSSGRhiShaderPipeline>;
658 static const int MAX_SIZE = 32;
662 QRhiShaderResourceBinding v[MAX_SIZE];
664 void clear() { p = 0; h = 0; }
666 QSSGRhiShaderResourceBindingList() { }
668 QSSGRhiShaderResourceBindingList(
const QSSGRhiShaderResourceBindingList &other)
672 for (
int i = 0; i < p; ++i)
676 QSSGRhiShaderResourceBindingList &operator=(
const QSSGRhiShaderResourceBindingList &other) Q_DECL_NOTHROW
678 if (
this != &other) {
681 for (
int i = 0; i < p; ++i)
687 void addUniformBuffer(
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiBuffer *buf,
int offset = 0 ,
int size = 0,
bool hasDynamicOffset =
false);
688 void addTexture(
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiTexture *tex, QRhiSampler *sampler);
689 void addImageLoad(
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiTexture *tex,
int level);
690 void addImageStore(
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiTexture *tex,
int level);
691 void addImageLoadStore(
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiTexture *tex,
int level);
692 void addStorageBufferLoad(
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiBuffer *buf,
int offset = 0 ,
int size = 0);
693 void addStorageBufferStore(
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiBuffer *buf,
int offset = 0 ,
int size = 0);
694 void addStorageBufferLoadStore(
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiBuffer *buf,
int offset = 0 ,
int size = 0);
696 template<QRhiShaderResourceBinding::Type T>
697 void fillImage(QRhiShaderResourceBinding::Data *d,
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiTexture *tex,
int level);
698 template<QRhiShaderResourceBinding::Type T>
699 void fillStorageBuffer(QRhiShaderResourceBinding::Data *d,
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiBuffer *buf,
int offset,
int size);
700 QRhiShaderResourceBinding::Data *newBinding();
703inline bool operator==(
const QSSGRhiShaderResourceBindingList &a,
const QSSGRhiShaderResourceBindingList &b) Q_DECL_NOTHROW
709 for (
int i = 0; i < a.p; ++i) {
710 if (a.v[i] != b.v[i])
716inline bool operator!=(
const QSSGRhiShaderResourceBindingList &a,
const QSSGRhiShaderResourceBindingList &b) Q_DECL_NOTHROW
721inline size_t qHash(
const QSSGRhiShaderResourceBindingList &bl, size_t seed) Q_DECL_NOTHROW
726struct QSSGRhiDrawCallData
728 QRhiBuffer *ubuf =
nullptr;
729 QRhiShaderResourceBindings *srb =
nullptr;
730 QSSGRhiShaderResourceBindingList bindings;
731 QRhiGraphicsPipeline *pipeline =
nullptr;
732 size_t renderTargetDescriptionHash = 0;
733 QVector<quint32> renderTargetDescription;
734 QSSGRhiGraphicsPipelineState ps;
749 enum class Private { Initialize };
752 QRhiTexture *texture()
const {
return m_texture; }
754 [[nodiscard]]
bool isValid()
const {
return m_texture !=
nullptr; }
756 QSSGManagedRhiTexture() =
default;
757 QSSGManagedRhiTexture(QSSGRhiContextPrivate &rhiCtxD, QRhiTexture *texture, Private);
758 ~QSSGManagedRhiTexture();
760 QSSGManagedRhiTexture(
const QSSGManagedRhiTexture &other);
761 QSSGManagedRhiTexture &operator=(
const QSSGManagedRhiTexture &other);
763 QSSGManagedRhiTexture(QSSGManagedRhiTexture &&other)
noexcept;
764 QSSGManagedRhiTexture &operator=(QSSGManagedRhiTexture &&other)
noexcept;
769 friend class QSSGRhiContextPrivate;
774 QSSGRhiContextPrivate *m_rhiCtxD =
nullptr;
775 QRhiTexture *m_texture =
nullptr;
784 void setDescription(QSSGRhiContext &rhiCtx, QRhiTextureRenderTargetDescription rtDesc, QRhiTextureRenderTarget::Flags = {});
786 void setName(
const QByteArray &name) { rtName = name; }
798 bool isValid()
const {
return (textures.size() > 0) && rt && rpDesc; }
802 void reset(QSSGRhiResourceRegistry *registry);
805 friend class QSSGUserRenderPassManager;
809 ColorTextureDirty = 0x1,
810 DepthStencilDirty = 0x2,
811 DepthTextureDirty = 0x4,
814 void invalidate(QSSGRhiResourceRegistry *registry);
815 void releaseDepthStencil(QSSGRhiResourceRegistry *registry);
819 QVarLengthArray<QSSGManagedRhiTexture, 4> textures {};
820 std::unique_ptr<QRhiRenderBuffer> depthStencil;
821 QSSGManagedRhiTexture depthTexture;
823 std::unique_ptr<QRhiRenderPassDescriptor> rpDesc;
824 std::unique_ptr<QRhiTextureRenderTarget> rt;
833 QRhiTexture *texture =
nullptr;
834 QRhiRenderBuffer *depthStencil =
nullptr;
835 QRhiTexture *depthTexture =
nullptr;
836 QRhiRenderPassDescriptor *rpDesc =
nullptr;
837 QRhiTextureRenderTarget *rt =
nullptr;
838 bool isValid()
const {
return texture && rpDesc && rt; }
839 void resetRenderTarget() {
847 void reset(QSSGRhiResourceRegistry *registry);
870 return a.global == b.global && a.localAxes == b.localAxes
871 && a.boundsCenter == b.boundsCenter
905 const QSSGRenderInstanceTable *
table =
nullptr;
935 const QSSGRenderInstanceTable *
table =
nullptr;
968 size_t srbLayoutDescriptionHash;
971 const QRhiShaderResourceBindings *srb)
973 const QVector<quint32> srbDesc = srb->serializedLayoutDescription();
974 return { shader, srbDesc, { qHash(srbDesc) } };
978inline bool operator==(
const QSSGComputePipelineStateKey &a,
const QSSGComputePipelineStateKey &b) Q_DECL_NOTHROW
980 return a.shader == b.shader && a.srbLayoutDescription == b.srbLayoutDescription;
983inline bool operator!=(
const QSSGComputePipelineStateKey &a,
const QSSGComputePipelineStateKey &b) Q_DECL_NOTHROW
988inline size_t qHash(
const QSSGComputePipelineStateKey &k, size_t seed = 0) Q_DECL_NOTHROW
990 return qHash(k.shader, seed) ^ k.extra.srbLayoutDescriptionHash;
993struct QSSGRhiDummyTextureKey
995 QRhiTexture::Flags flags;
1001inline size_t qHash(
const QSSGRhiDummyTextureKey &k, size_t seed) Q_DECL_NOTHROW
1003 return qHash(k.flags, seed)
1004 ^ qHash(k.size.width() ^ k.size.height() ^ k.color.red() ^ k.color.green()
1005 ^ k.color.blue() ^ k.color.alpha() ^ k.arraySize);
1008inline bool operator==(
const QSSGRhiDummyTextureKey &a,
const QSSGRhiDummyTextureKey &b) Q_DECL_NOTHROW
1010 return a.flags == b.flags && a.size == b.size && a.color == b.color && a.arraySize == b.arraySize;
1013inline bool operator!=(
const QSSGRhiDummyTextureKey &a,
const QSSGRhiDummyTextureKey &b) Q_DECL_NOTHROW
1018class QSSGGraphicsPipelineStateKey
1021 QSSGRhiGraphicsPipelineState state;
1022 QVector<quint32> renderTargetDescription;
1023 QVector<quint32> srbLayoutDescription;
1025 size_t renderTargetDescriptionHash;
1026 size_t srbLayoutDescriptionHash;
1028 static QSSGGraphicsPipelineStateKey create(
const QSSGRhiGraphicsPipelineState &state,
1029 const QRhiRenderPassDescriptor *rpDesc,
1030 const QRhiShaderResourceBindings *srb)
1032 const QVector<quint32> rtDesc = rpDesc->serializedFormat();
1033 const QVector<quint32> srbDesc = srb->serializedLayoutDescription();
1034 return { state, rtDesc, srbDesc, { qHash(rtDesc), qHash(srbDesc) } };
1038inline bool operator==(
const QSSGGraphicsPipelineStateKey &a,
const QSSGGraphicsPipelineStateKey &b) Q_DECL_NOTHROW
1040 return a.state == b.state
1041 && a.renderTargetDescription == b.renderTargetDescription
1042 && a.srbLayoutDescription == b.srbLayoutDescription;
1045inline bool operator!=(
const QSSGGraphicsPipelineStateKey &a,
const QSSGGraphicsPipelineStateKey &b) Q_DECL_NOTHROW
1050inline size_t qHash(
const QSSGGraphicsPipelineStateKey &k, size_t seed) Q_DECL_NOTHROW
1052 return qHash(k.state, seed)
1053 ^ k.extra.renderTargetDescriptionHash
1054 ^ k.extra.srbLayoutDescriptionHash;
1057#define QSSGRHICTX_STAT(ctx, f)
1058 for (bool qssgrhictxlog_enabled = QSSGRhiContextStats::get(*ctx).isEnabled(); qssgrhictxlog_enabled; qssgrhictxlog_enabled = false)
1059 QSSGRhiContextStats::get(*ctx).f
1061class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRhiContextStats
1064 [[nodiscard]]
static QSSGRhiContextStats &get(QSSGRhiContext &rhiCtx);
1065 [[nodiscard]]
static const QSSGRhiContextStats &get(
const QSSGRhiContext &rhiCtx);
1068 quint64 callCount = 0;
1069 quint64 vertexOrIndexCount = 0;
1071 struct InstancedDrawInfo {
1072 quint64 callCount = 0;
1073 quint64 vertexOrIndexCount = 0;
1074 quint64 instanceCount = 0;
1076 struct RenderPassInfo {
1079 DrawInfo indexedDraws;
1081 InstancedDrawInfo instancedIndexedDraws;
1082 InstancedDrawInfo instancedDraws;
1084 struct PerLayerInfo {
1087 externalRenderPass.rtName = QByteArrayLiteral(
"Qt Quick");
1092 QVector<RenderPassInfo> renderPasses;
1097 RenderPassInfo externalRenderPass;
1099 int currentRenderPassIndex = -1;
1102 quint64 meshDataSize = 0;
1103 quint64 imageDataSize = 0;
1104 qint64 materialGenerationTime = 0;
1105 qint64 effectGenerationTime = 0;
1108 QHash<QSSGRenderLayer *, PerLayerInfo> perLayerInfo;
1109 GlobalInfo globalInfo;
1111 QSSGRhiContextStats(QSSGRhiContext &context)
1129 static bool profilingEnabled();
1130 static bool rendererDebugEnabled();
1132 bool isEnabled()
const;
1133 void drawIndexed(quint32 indexCount, quint32 instanceCount);
1134 void draw(quint32 vertexCount, quint32 instanceCount);
1136 void meshDataSizeChanges(quint64 newSize)
1138 globalInfo.meshDataSize = newSize;
1141 void imageDataSizeChanges(quint64 newSize)
1143 globalInfo.imageDataSize = newSize;
1146 void registerMaterialShaderGenerationTime(qint64 ms)
1148 globalInfo.materialGenerationTime += ms;
1151 void registerEffectShaderGenerationTime(qint64 ms)
1153 globalInfo.effectGenerationTime += ms;
1156 static quint64 totalDrawCallCountForPass(
const QSSGRhiContextStats::RenderPassInfo &pass)
1158 return pass.draws.callCount
1159 + pass.indexedDraws.callCount
1160 + pass.instancedDraws.callCount
1161 + pass.instancedIndexedDraws.callCount;
1164 static quint64 totalVertexCountForPass(
const QSSGRhiContextStats::RenderPassInfo &pass)
1166 return pass.draws.vertexOrIndexCount
1167 + pass.indexedDraws.vertexOrIndexCount
1168 + pass.instancedDraws.vertexOrIndexCount
1169 + pass.instancedIndexedDraws.vertexOrIndexCount;
1172 void start(QSSGRenderLayer *layer);
1173 void stop(QSSGRenderLayer *layer);
1174 void beginRenderPass(QRhiTextureRenderTarget *rt);
1175 void endRenderPass();
1176 void printRenderPass(
const RenderPassInfo &rp);
1177 void cleanupLayerInfo(QSSGRenderLayer *layer);
1179 QSSGRhiContext *rhiCtx;
1180 QSSGRenderLayer *layerKey =
nullptr;
1181 QSet<QSSGRenderLayer *> dynamicDataSources;
1186 Q_DECLARE_PUBLIC(QSSGRhiContext)
1188 explicit QSSGRhiContextPrivate(QSSGRhiContext &rhiCtx, QRhi *rhi_)
1192 , m_resourceRegistry(rhi_)
1199 [[nodiscard]] QSSGRhiResourceRegistry &resourceRegistry() {
return m_resourceRegistry; }
1201 using Textures = QSet<QRhiTexture *>;
1202 using Meshes = QSet<QSSGRenderMesh *>;
1204 [[nodiscard]]
static QSSGRhiContextPrivate *get(QSSGRhiContext *q) {
return q->d_ptr.get(); }
1205 [[nodiscard]]
static const QSSGRhiContextPrivate *get(
const QSSGRhiContext *q) {
return q->d_ptr.get(); }
1216 void releaseCachedResources();
1218 void registerTexture(QRhiTexture *texture);
1219 void releaseTexture(QRhiTexture *texture);
1224 QSSGManagedRhiTexture create(QRhiTexture *texture);
1240 QRhiRenderPassDescriptor *rpDesc,
1241 QRhiShaderResourceBindings *srb);
1244 QRhiRenderPassDescriptor *rpDesc,
1245 QRhiShaderResourceBindings *srb);
1248 QRhiShaderResourceBindings *srb);
1251 QRhiShaderResourceBindings *srb);
1285 Textures m_textures;
1310 void refManagedTexture(QRhiTexture *texture);
1311 [[nodiscard]]
bool derefManagedTexture(QRhiTexture *texture);
1314inline bool operator==(
const QSSGRhiDrawCallDataKey &a,
const QSSGRhiDrawCallDataKey &b)
noexcept
1316 return a.cid == b.cid && a.model == b.model && a.resource == b.resource && a.mapEntry == b.mapEntry
1317 && a.resourceIdx == b.resourceIdx;
1320inline bool operator!=(
const QSSGRhiDrawCallDataKey &a,
const QSSGRhiDrawCallDataKey &b)
noexcept
1325inline size_t qHash(
const QSSGRhiDrawCallDataKey &k, size_t seed = 0)
noexcept
1327 return qHashMulti(seed, k.cid, k.model, k.resource, k.mapEntry, k.resourceIdx);
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.
Q_DECLARE_FLAGS(InitFlags, InitFlag)
static QSSGComputePipelineStateKey create(const QShader &shader, const QRhiShaderResourceBindings *srb)
QVector< quint32 > srbLayoutDescription
QRhiBuffer * buffer() const
QRhiCommandBuffer::IndexFormat indexFormat() const
quint32 numVertices() const
QHash< const QSSGRenderModel *, QSSGRhiInstanceBufferData > m_instanceBuffersPerModel
void setMainRenderPassDescriptor(QRhiRenderPassDescriptor *rpDesc)
void releaseInstanceBuffer(QSSGRenderInstanceTable *instanceTable)
QSSGRhiInstanceBufferData & instanceBufferData(const QSSGRenderModel *model)
void releaseDrawCallData(QSSGRhiDrawCallData &dcd)
QRhiRenderPassDescriptor * m_mainRpDesc
QRhiShaderResourceBindings * srb(const QSSGRhiShaderResourceBindingList &bindings)
QSSGRhiDrawCallData & drawCallData(const QSSGRhiDrawCallDataKey &key)
QRhiGraphicsPipeline * pipeline(const QSSGRhiGraphicsPipelineState &ps, QRhiRenderPassDescriptor *rpDesc, QRhiShaderResourceBindings *srb)
void cleanupDrawCallDataForCid(const void *cid)
void releaseCachedSrb(QSSGRhiShaderResourceBindingList &bindings)
void releaseAutoLodData(const QSSGRenderLayer *layer)
void releaseUnusedAutoLodData(const QSSGRenderLayer *layer, quint32 frame)
void releaseMesh(QSSGRenderMesh *mesh)
QRhiComputePipeline * computePipeline(const QSSGComputePipelineStateKey &key, QRhiShaderResourceBindings *srb)
QHash< QSSGRenderInstanceTable *, QSSGRhiInstanceBufferData > m_instanceBuffers
void setCommandBuffer(QRhiCommandBuffer *cb)
QVector< QPair< QSSGRhiSamplerDescription, QRhiSampler * > > m_samplers
void releaseModelInstanceCopy(const QSSGRenderModel *model)
void relocateManagedTexture(QSSGManagedRhiTexture *from, QSSGManagedRhiTexture *to)
void setMainPassSampleCount(int samples)
void unregisterManagedTexture(QSSGManagedRhiTexture *wrapper)
void cleanupDrawCallData(const QSSGRenderModel *model)
QHash< const QSSGRenderGraphObject *, QSSGRhiParticleData > m_particleData
QSSGRhiContextStats m_stats
void cleanupDrawCallDataForResource(const void *resource)
QHash< QSSGRhiDummyTextureKey, QRhiTexture * > m_dummyTextures
void registerMesh(QSSGRenderMesh *mesh)
static bool shaderDebuggingEnabled()
QSSGRhiParticleData & particleData(const QSSGRenderGraphObject *particlesOrModel)
void setRenderTarget(QRhiRenderTarget *rt)
QHash< QSSGRhiShaderResourceBindingList, QRhiShaderResourceBindings * > m_srbCache
QSet< QSSGManagedRhiTexture * > m_managedTextureWrappers
void cleanupDrawCallDataForUserPass(const QSSGRenderUserPassBase *userPass)
QHash< QSSGRhiDrawCallDataKey, QSSGRhiDrawCallData > m_drawCallData
void registerManagedTexture(QSSGManagedRhiTexture *wrapper)
void invalidateManagedTextures()
void setMainPassViewCount(int viewCount)
void releaseModelInstanceData(const QSSGRenderModel *model)
QRhiComputePipeline * computePipeline(const QShader &shader, QRhiShaderResourceBindings *srb)
QList< quint8 > m_autoLodLevelOfInstance
QHash< QSSGComputePipelineStateKey, QRhiComputePipeline * > m_computePipelines
QHash< QRhiTexture *, size_t > m_managedTextureRefs
QHash< QSSGGraphicsPipelineStateKey, QRhiGraphicsPipeline * > m_pipelines
QSSGRhiResourceRegistry m_resourceRegistry
void cleanupDrawCallDataForSkyMaterial(QSSGRenderSkyMaterial *skyMaterial)
QSSGRhiInstanceBufferData & instanceBufferData(QSSGRenderInstanceTable *instanceTable)
const std::unique_ptr< QRhiRenderPassDescriptor > & getRenderPassDescriptor() const
const QSSGManagedRhiTexture & getDepthTexture() const
void setName(const QByteArray &name)
void reset(QSSGRhiResourceRegistry *registry)
const std::unique_ptr< QRhiTextureRenderTarget > & getRenderTarget() const
const QSSGManagedRhiTexture & getColorTexture(int index) const
QSSGRhiRenderableTextureV2()=default
const std::unique_ptr< QRhiRenderBuffer > & getDepthStencil() const
size_t colorAttachmentCount() const
const QByteArray & getName() const
~QSSGRhiRenderableTextureV2()=default
void setUniformValue(char *ubufData, const char *name, const QVariant &value, QSSGRenderShaderValue::Type type)
const QRhiShaderStage * cendStages() const
QRhiTexture * ssaoTexture() const
const QHash< QSSGRhiInputAssemblerState::InputSemantic, QShaderDescription::InOutVariable > & vertexInputs() const
QRhiTexture * lightProbeTexture() const
QRhiTexture * shadowMapAtlasTexture() const
void applyAndClearStorageBindings(QRhiShaderResourceBinding::StageFlags stage, QSSGRhiShaderResourceBindingList &bindings)
int bindingForStorageImage(QByteArrayView name)
void resetExtraTextures()
QPair< QSSGRenderTextureCoordOp, QSSGRenderTextureCoordOp > lightProbeTiling() const
InstanceLocations instanceBufferLocations() const
const StorageBindingMap & storageImageBindings() const
int bindingForStorageBuffer(QByteArrayView name)
bool isLightingEnabled() const
void addStage(const QRhiShaderStage &stage, StageFlags flags={})
QRhiTexture * screenTexture() const
void ensureUniformBuffer(QRhiBuffer **ubuf)
QRhiTexture * MotionVectorTexture() const
QRhiTexture * shadowMapBlueNoiseTexture() const
const QRhiShaderStage * cbeginStages() const
const QRhiShaderStage * fragmentStage() const
QRhiTexture * depthTexture() const
void addExtraTexture(const QSSGRhiTexture &t)
int ub0LightDataOffset() const
void addStorageBufferBinding(const QByteArray &name, QRhiShaderResourceBinding::Type type, QRhiBuffer *buffer, int binding)
void setLightsEnabled(bool enable)
QSSGShaderDirectionalLightsUniformData & directionalLightsUniformData()
int offsetOfUniform(const QByteArray &name)
int bindingForTexture(const char *name, int hint=-1)
void ensureCombinedUniformBuffer(QRhiBuffer **ubuf)
void setShaderResources(char *ubufData, QSSGBufferManager &theBufferManager, const QByteArray &inPropertyName, const QVariant &propertyValue, QSSGRenderShaderValue::Type inPropertyType)
QRhiTexture ** oitImages()
void setUniformArray(char *ubufData, const char *name, const void *data, size_t itemCount, QSSGRenderShaderValue::Type type, int *storeIndex=nullptr)
QRhiTexture * normalTexture() const
const QRhiShaderStage * computeStage() const
int extraTextureCount() const
int ub0DirectionalLightDataOffset() const
const QRhiShaderStage * vertexStage() const
QSSGShaderLightsUniformData & lightsUniformData()
void setUniform(char *ubufData, const char *name, const void *data, size_t size, int *storeIndex=nullptr, UniformFlags flags={})
QRhiTexture * lightmapTexture() const
const QSSGRhiTexture & extraTextureAt(int index) const
const StorageBindingMap & storageBufferBindings() const
QRhiVertexInputAttribute::Format toVertexInputFormat(QSSGRenderComponentType compType, quint32 numComps)
QRhiGraphicsPipeline::CullMode toCullMode(QSSGCullFaceMode cullFaceMode)
QRhiGraphicsPipeline::Topology toTopology(QSSGRenderDrawMode drawMode)
QRhiSampler::Filter toRhi(QSSGRenderTextureFilterOp op)
static bool skyIblCreatePrefilterTargets(QRhi *rhi, QRhiTexture *texture, const QSize &environmentMapSize, const QByteArray &namePrefix, QSSGSkyIblPrefilterTargets *outTargets, bool preserveColorContents=false)
static constexpr QRhiTexture::Format cTextureFormat
static bool ensureSrb(QRhi *rhi, QRhiShaderResourceBindings *&dst, std::initializer_list< QRhiShaderResourceBinding > bindings, const char *errorMessage)
static bool skyIblCreateFaceTargets(QRhi *rhi, QRhiTexture *texture, const QByteArray &namePrefix, QSSGSkyIblFaceTargets *outTargets, bool preserveColorContents=false)
static QRhiGraphicsPipeline * createPrefilterPipeline(QRhi *rhi, const QRhiVertexInputLayout &inputLayout, const PrefilterPipelineConfig &cfg, const char *errorMessage)
static void drawCubeFace(QRhiCommandBuffer *cb, QSSGRhiContext *ctx, QRhiTextureRenderTarget *rt, QSize viewport, QRhiGraphicsPipeline *pipeline, QRhiShaderResourceBindings *srb, const QRhiCommandBuffer::VertexInput &vbufBinding, const QVector< QPair< int, quint32 > > &dynamicOffsets, const QByteArray &profilerLabel, const QByteArray &passDebugLabel, const QColor &clearColor=QColor(0, 0, 0, 1))
static void skyIblInitializeUnrenderedMips(QRhi *rhi, QRhiCommandBuffer *cb, QSSGRhiContext *context, QRhiTexture *texture, int firstMip, int mipCountExclusive, const QByteArray &debugObjectName)
static bool ensureDynamicUBuf(QRhi *rhi, QRhiBuffer *&dst, int size, const char *errorMessage)
static QVarLengthArray< QMatrix4x4, 6 > skyIblEnvironmentMapViews(QRhi *rhi)
static const float skyIblCubeVerts[]
static int nearestPowerOfTwo(int v)
constexpr size_t qHash(const QSize &s, size_t seed=0) noexcept
#define QSSGRHICTX_STAT(ctx, f)
#define QSSG_MAX_NUM_LIGHTS
#define QSSG_MAX_NUM_DIRECTIONAL_LIGHTS
QSSGRhiSamplerBindingHints
static constexpr const QSSGRhiShaderPipeline * getShaderPipeline(const QSSGRhiGraphicsPipelineState &ps)
bool instanceIndicesDirty
QList< qint32 > instanceIndices
QSSGRhiInstancePlacement placement
QVector3D cameraDirection
QRhiBuffer * instanceIndexBuffer
QMatrix4x4 cameraViewProjection
QVarLengthArray< float, MaxAutoLodLevels > lodDistancesSq
const QSSGRenderInstanceTable * table
std::array< int, MaxAutoLodLevels > counts
bool instanceIndicesDirty
QMatrix4x4 globalInstanceTransform
QRhiBuffer * instanceIndexBuffer
QHash< SubsetLodKey, SubsetLodData > subsetLodData
QList< QSSGRhiSortData > sortData
QVector3D sortedCameraDirection
std::pair< const QSSGRenderSubset *, const QSSGRenderLayer * > SubsetLodKey
QVector3D localInstanceTranslation
const QSSGRenderInstanceTable * table
QList< qint32 > lodInstanceIndices
static constexpr int MaxAutoLodLevels
std::array< QVector3D, 3 > localAxes
friend bool operator!=(const QSSGRhiInstancePlacement &a, const QSSGRhiInstancePlacement &b)
friend bool operator==(const QSSGRhiInstancePlacement &a, const QSSGRhiInstancePlacement &b)
QList< QSSGRhiSortData > sortData
StorageResourceBinding()=default
StorageResourceBinding(int binding, const QByteArray &name, QRhiShaderResourceBinding::Type type, QRhiBuffer *buffer)
QRhiShaderResourceBinding::Type type
float atlasLocations[4][4]
float dimensionsInverted[4][4]
float constantAttenuation
float quadraticAttenuation
QSSGRhiShaderPipeline * shader
QRhiRenderPassDescriptor * rpd
QRhiShaderResourceBindings * srb