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>
29struct QSSGRenderLayer;
30struct QSSGRenderSkyMaterial;
31struct QSSGRenderInstanceTable;
32struct QSSGRenderModel;
34class QSSGRenderGraphObject;
35class QSSGBufferManager;
36class QSSGUserRenderPassManager;
45using QSSGRhiInputAssemblerState = QSSGRhiInputAssemblerStatePrivate::InputAssemblerState;
49 static void setShaderPipeline(QSSGRhiGraphicsPipelineState &ps,
const QSSGRhiShaderPipeline *pipeline)
51 ps.shaderPipeline = pipeline;
54 static constexpr const QSSGRhiShaderPipeline *
getShaderPipeline(
const QSSGRhiGraphicsPipelineState &ps)
56 return ps.shaderPipeline;
66 case QSSGRenderTextureFilterOp::Nearest:
67 return QRhiSampler::Nearest;
68 case QSSGRenderTextureFilterOp::Linear:
69 return QRhiSampler::Linear;
70 case QSSGRenderTextureFilterOp::None:
71 return QRhiSampler::Linear;
74 Q_UNREACHABLE_RETURN(QRhiSampler::Linear);
80 case QSSGRenderTextureCoordOp::Repeat:
81 return QRhiSampler::Repeat;
82 case QSSGRenderTextureCoordOp::MirroredRepeat:
83 return QRhiSampler::Mirror;
84 case QSSGRenderTextureCoordOp::ClampToEdge:
85 return QRhiSampler::ClampToEdge;
86 case QSSGRenderTextureCoordOp::Unknown:
87 return QRhiSampler::ClampToEdge;
90 Q_UNREACHABLE_RETURN(QRhiSampler::ClampToEdge);
95 switch (cullFaceMode) {
96 case QSSGCullFaceMode::Back:
97 return QRhiGraphicsPipeline::Back;
98 case QSSGCullFaceMode::Front:
99 return QRhiGraphicsPipeline::Front;
100 case QSSGCullFaceMode::Disabled:
101 return QRhiGraphicsPipeline::None;
102 case QSSGCullFaceMode::FrontAndBack:
103 qWarning(
"FrontAndBack cull mode not supported");
104 return QRhiGraphicsPipeline::None;
105 case QSSGCullFaceMode::Unknown:
106 return QRhiGraphicsPipeline::None;
109 Q_UNREACHABLE_RETURN(QRhiGraphicsPipeline::None);
116void bakeVertexInputLocations(QSSGRhiInputAssemblerState *ia,
const QSSGRhiShaderPipeline &shaders,
int instanceBufferBinding = 0);
120inline bool operator==(
const QSSGRhiGraphicsPipelineState &a,
const QSSGRhiGraphicsPipelineState &b) Q_DECL_NOTHROW
122 const auto &ia_a = QSSGRhiInputAssemblerStatePrivate::get(a);
123 const auto &ia_b = QSSGRhiInputAssemblerStatePrivate::get(b);
124 const auto compareTargetBlend = [](
const std::array<QRhiGraphicsPipeline::TargetBlend, 8> &a,
125 const std::array<QRhiGraphicsPipeline::TargetBlend, 8> &b,
126 const int count) ->
bool {
127 for (
int i = 0; i < count; i++) {
128 if (a[i].colorWrite != b[i].colorWrite
129 || a[i].srcColor != b[i].srcColor
130 || a[i].dstColor != b[i].dstColor
131 || a[i].opColor != b[i].opColor
132 || a[i].srcAlpha != b[i].srcAlpha
133 || a[i].dstAlpha != b[i].dstAlpha
134 || a[i].opAlpha != b[i].opAlpha) {
144 return QSSGRhiGraphicsPipelineStatePrivate::getShaderPipeline(a) == QSSGRhiGraphicsPipelineStatePrivate::getShaderPipeline(b)
145 && a.samples == b.samples
146 && a.flags == b.flags
147 && a.stencilRef == b.stencilRef
148 && (std::memcmp(&a.stencilOpFrontState, &b.stencilOpFrontState,
sizeof(QRhiGraphicsPipeline::StencilOpState)) == 0)
149 && a.stencilWriteMask == b.stencilWriteMask
150 && a.depthFunc == b.depthFunc
151 && a.cullMode == b.cullMode
152 && a.depthBias == b.depthBias
153 && a.slopeScaledDepthBias == b.slopeScaledDepthBias
154 && ia_a.topology == ia_b.topology
155 && ia_a.inputLayout == ia_b.inputLayout
156 && a.colorAttachmentCount == b.colorAttachmentCount
157 && compareTargetBlend(a.targetBlend, b.targetBlend, a.colorAttachmentCount)
158 && a.lineWidth == b.lineWidth
159 && a.polygonMode == b.polygonMode
160 && a.viewCount == b.viewCount;
163inline bool operator!=(
const QSSGRhiGraphicsPipelineState &a,
const QSSGRhiGraphicsPipelineState &b) Q_DECL_NOTHROW
168inline size_t qHash(
const QSSGRhiGraphicsPipelineState &s, size_t seed) Q_DECL_NOTHROW
171 return qHash(QSSGRhiGraphicsPipelineStatePrivate::getShaderPipeline(s), seed)
174 ^ qHash(s.targetBlend[0].dstColor)
177 ^ qHash(s.colorAttachmentCount)
179 ^ qHash(s.polygonMode)
180 ^ qHashBits(&s.stencilOpFrontState,
sizeof(QRhiGraphicsPipeline::StencilOpState))
182 ^ (s.stencilRef << 6)
183 ^ (s.stencilWriteMask << 7);
200struct QSSGRhiDrawCallDataKey
202 const void *cid =
nullptr;
203 const void *model =
nullptr;
204 const void *resource =
nullptr;
205 const void *mapEntry =
nullptr;
206 quintptr resourceIdx = 0;
211 Q_DISABLE_COPY(QSSGRhiBuffer)
213 QSSGRhiBuffer(QSSGRhiContext &context,
214 QRhiBuffer::Type type,
215 QRhiBuffer::UsageFlags usageMask,
218 QRhiCommandBuffer::IndexFormat indexFormat = QRhiCommandBuffer::IndexUInt16);
220 virtual ~QSSGRhiBuffer();
225 const quint32 sz = quint32(m_buffer->size());
226 Q_ASSERT((sz % m_stride) == 0);
227 return sz / m_stride;
232 QSSGRhiContext &m_context;
233 QRhiBuffer *m_buffer =
nullptr;
235 QRhiCommandBuffer::IndexFormat m_indexFormat;
245 bool maybeExists =
true;
246 friend class QSSGRhiShaderPipeline;
258 bool maybeExists =
true;
259 friend class QSSGRhiShaderPipeline;
262using QSSGRhiBufferPtr = std::shared_ptr<QSSGRhiBuffer>;
264inline bool operator==(
const QSSGRhiSamplerDescription &a,
const QSSGRhiSamplerDescription &b) Q_DECL_NOTHROW
266 return a.hTiling == b.hTiling && a.vTiling == b.vTiling && a.zTiling == b.zTiling
267 && a.minFilter == b.minFilter && a.magFilter == b.magFilter
268 && a.mipmap == b.mipmap;
271inline bool operator!=(
const QSSGRhiSamplerDescription &a,
const QSSGRhiSamplerDescription &b) Q_DECL_NOTHROW
279 QRhiTexture *texture =
nullptr;
280 QSSGRhiSamplerDescription samplerDesc;
300#define QSSG_MAX_NUM_LIGHTS 16
301#define QSSG_MAX_NUM_DIRECTIONAL_LIGHTS 4
302#define QSSG_REDUCED_MAX_NUM_LIGHTS 4
303#define QSSG_REDUCED_MAX_NUM_DIRECTIONAL_LIGHTS 1
373class QSSGRhiShaderResourceBindingList;
376 Q_DISABLE_COPY(QSSGRhiShaderPipeline)
378 explicit QSSGRhiShaderPipeline(QSSGRhiContext &context) : m_context(context) { }
380 QSSGRhiContext &context()
const {
return m_context; }
381 bool isNull()
const {
return m_stages.isEmpty(); }
391 void addStage(
const QRhiShaderStage &stage, StageFlags flags = {});
396 for (
const QRhiShaderStage &s : m_stages) {
397 if (s.type() == QRhiShaderStage::Vertex)
403 for (
const QRhiShaderStage &s : m_stages) {
404 if (s.type() == QRhiShaderStage::Fragment)
480 } commonUniformIndices;
495 void setUniformValue(
char *ubufData,
const char *name,
const QVariant &value, QSSGRenderShaderValue::Type type);
496 void setUniform(
char *ubufData,
const char *name,
const void *data, size_t size,
int *storeIndex =
nullptr, UniformFlags flags = {});
497 void setUniformArray(
char *ubufData,
const char *name,
const void *data, size_t itemCount, QSSGRenderShaderValue::Type type,
int *storeIndex =
nullptr);
503 QSSGBufferManager &theBufferManager,
504 const QByteArray &inPropertyName,
505 const QVariant &propertyValue,
506 QSSGRenderShaderValue::Type inPropertyType);
514 void setLightProbeTexture(QRhiTexture *texture,
515 QSSGRenderTextureCoordOp hTile = QSSGRenderTextureCoordOp::ClampToEdge,
516 QSSGRenderTextureCoordOp vTile = QSSGRenderTextureCoordOp::ClampToEdge)
518 m_lightProbeTexture = texture; m_lightProbeHorzTile = hTile; m_lightProbeVertTile = vTile;
523 return {m_lightProbeHorzTile, m_lightProbeVertTile};
526 void setScreenTexture(QRhiTexture *texture) { m_screenTexture = texture; }
529 void setDepthTexture(QRhiTexture *texture) { m_depthTexture = texture; }
532 void setNormalTexture(QRhiTexture *texture) { m_normalTexture = texture; }
535 void setSsaoTexture(QRhiTexture *texture) { m_ssaoTexture = texture; }
538 void setLightmapTexture(QRhiTexture *texture) { m_lightmapTexture = texture; }
541 void setMotionVectorTexture(QRhiTexture *texture) { m_motionVectorTexture = texture; }
543 void setShadowMapAtlasTexture(QRhiTexture *texture) { m_shadowMapAtlasTexture = texture; }
546 void setShadowMapBlueNoiseTexture(QRhiTexture *texture) { m_shadowMapBlueNoiseTexture = texture; }
549 void setOITImages(QRhiTexture *accumulator, QRhiTexture *auxiliary, QRhiTexture *counter)
551 m_oitImages[0] = accumulator;
552 m_oitImages[1] = auxiliary;
553 m_oitImages[2] = counter;
576 using StorageBindingMap = QMap<
int, StorageResourceBinding>;
578 void addStorageBufferBinding(
const QByteArray &name, QRhiShaderResourceBinding::Type type, QRhiBuffer *buffer,
int binding);
579 void addStorageImageBinding(
const QByteArray &name, QRhiShaderResourceBinding::Type type, QRhiTexture *texture,
int binding);
591 QSSGRhiContext &m_context;
592 QVarLengthArray<QRhiShaderStage, 2> m_stages;
594 int m_ub0NextUBufOffset = 0;
595 QHash<QByteArray, QShaderDescription::BlockVariable> m_ub0;
596 QHash<QSSGRhiInputAssemblerState::InputSemantic, QShaderDescription::InOutVariable> m_vertexInputs;
597 QHash<QByteArray, QShaderDescription::InOutVariable> m_combinedImageSamplers;
598 QHash<QByteArray, QShaderDescription::InOutVariable> m_storageImages;
599 QHash<QByteArray, QShaderDescription::StorageBlock> m_storageBuffers;
602 QVarLengthArray<QSSGRhiShaderUniform, 32> m_uniforms;
603 QVarLengthArray<QSSGRhiShaderUniformArray, 8> m_uniformArrays;
604 QHash<QByteArray, size_t> m_uniformIndex;
607 bool m_lightsEnabled =
false;
610 QRhiTexture *m_shadowMapAtlasTexture =
nullptr;
611 QRhiTexture *m_shadowMapBlueNoiseTexture =
nullptr;
612 QRhiTexture *m_lightProbeTexture =
nullptr;
613 QSSGRenderTextureCoordOp m_lightProbeHorzTile = QSSGRenderTextureCoordOp::ClampToEdge;
614 QSSGRenderTextureCoordOp m_lightProbeVertTile = QSSGRenderTextureCoordOp::ClampToEdge;
615 QRhiTexture *m_screenTexture =
nullptr;
616 QRhiTexture *m_depthTexture =
nullptr;
617 QRhiTexture *m_normalTexture =
nullptr;
618 QRhiTexture *m_ssaoTexture =
nullptr;
619 QRhiTexture *m_lightmapTexture =
nullptr;
620 QRhiTexture *m_oitImages[3] = {
nullptr};
621 QRhiTexture *m_motionVectorTexture =
nullptr;
622 QVarLengthArray<QSSGRhiTexture, 8> m_extraTextures;
624 QMap<
int, StorageResourceBinding> m_storageImageBindings;
625 QMap<
int, StorageResourceBinding> m_storageBufferBindings;
628Q_DECLARE_OPERATORS_FOR_FLAGS(QSSGRhiShaderPipeline::StageFlags)
629Q_DECLARE_OPERATORS_FOR_FLAGS(QSSGRhiShaderPipeline::UniformFlags)
631using QSSGRhiShaderPipelinePtr = std::shared_ptr<QSSGRhiShaderPipeline>;
636 static const int MAX_SIZE = 32;
640 QRhiShaderResourceBinding v[MAX_SIZE];
642 void clear() { p = 0; h = 0; }
644 QSSGRhiShaderResourceBindingList() { }
646 QSSGRhiShaderResourceBindingList(
const QSSGRhiShaderResourceBindingList &other)
650 for (
int i = 0; i < p; ++i)
654 QSSGRhiShaderResourceBindingList &operator=(
const QSSGRhiShaderResourceBindingList &other) Q_DECL_NOTHROW
656 if (
this != &other) {
659 for (
int i = 0; i < p; ++i)
665 void addUniformBuffer(
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiBuffer *buf,
int offset = 0 ,
int size = 0,
bool hasDynamicOffset =
false);
666 void addTexture(
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiTexture *tex, QRhiSampler *sampler);
667 void addImageLoad(
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiTexture *tex,
int level);
668 void addImageStore(
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiTexture *tex,
int level);
669 void addImageLoadStore(
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiTexture *tex,
int level);
670 void addStorageBufferLoad(
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiBuffer *buf,
int offset = 0 ,
int size = 0);
671 void addStorageBufferStore(
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiBuffer *buf,
int offset = 0 ,
int size = 0);
672 void addStorageBufferLoadStore(
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiBuffer *buf,
int offset = 0 ,
int size = 0);
674 void fillImage(QRhiShaderResourceBinding::Data *d, QRhiShaderResourceBinding::Type t,
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiTexture *tex,
int level);
675 void fillStorageBuffer(QRhiShaderResourceBinding::Data *d, QRhiShaderResourceBinding::Type t,
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiBuffer *buf,
int offset,
int size);
676 QRhiShaderResourceBinding::Data *newBinding();
679inline bool operator==(
const QSSGRhiShaderResourceBindingList &a,
const QSSGRhiShaderResourceBindingList &b) Q_DECL_NOTHROW
685 for (
int i = 0; i < a.p; ++i) {
686 if (a.v[i] != b.v[i])
692inline bool operator!=(
const QSSGRhiShaderResourceBindingList &a,
const QSSGRhiShaderResourceBindingList &b) Q_DECL_NOTHROW
697inline size_t qHash(
const QSSGRhiShaderResourceBindingList &bl, size_t seed) Q_DECL_NOTHROW
702struct QSSGRhiDrawCallData
704 QRhiBuffer *ubuf =
nullptr;
705 QRhiShaderResourceBindings *srb =
nullptr;
706 QSSGRhiShaderResourceBindingList bindings;
707 QRhiGraphicsPipeline *pipeline =
nullptr;
708 size_t renderTargetDescriptionHash = 0;
709 QVector<quint32> renderTargetDescription;
710 QSSGRhiGraphicsPipelineState ps;
723 enum class Private { Initialize };
724 Q_DISABLE_COPY(QSSGManagedRhiTexture)
726 using Ptr = std::unique_ptr<QSSGManagedRhiTexture>;
728 const std::unique_ptr<QRhiTexture> &texture()
const {
return m_texture; }
730 [[nodiscard]]
bool isValid()
const {
return m_texture !=
nullptr; }
732 QSSGManagedRhiTexture() =
default;
733 QSSGManagedRhiTexture(
const std::shared_ptr<QSSGUserRenderPassManager> &manager, QRhiTexture *texture, Private);
734 QSSGManagedRhiTexture(
const std::shared_ptr<QSSGUserRenderPassManager> &manager, std::unique_ptr<QRhiTexture> texture);
735 ~QSSGManagedRhiTexture();
737 [[nodiscard]]
static Ptr make_copy(
const Ptr &other)
739 return std::make_unique<QSSGManagedRhiTexture>(other->m_manager, other->m_texture.get(), Private::Initialize);
743 friend class QSSGRhiRenderableTextureV2;
744 friend class QSSGUserRenderPassManager;
748 std::shared_ptr<QSSGUserRenderPassManager> m_manager;
749 std::unique_ptr<QRhiTexture> m_texture;
752using QSSGManagedRhiTexturePtr = QSSGManagedRhiTexture::Ptr;
756 enum class Private { Initialize };
758 QSSGRhiRenderableTextureV2(
const std::shared_ptr<QSSGUserRenderPassManager> &manager, Private)
764 void setDescription(QRhi *rhi, QRhiTextureRenderTargetDescription rtDesc, QRhiTextureRenderTarget::Flags = {});
766 void setName(
const QByteArray &name) { rtName = name; }
777 bool isValid()
const {
return (textures.size() > 0) && rt && rpDesc; }
779 void finialize(QRhi *rhi);
785 friend class QSSGUserRenderPassManager;
789 ColorTextureDirty = 0x1,
790 DepthStencilDirty = 0x2,
791 DepthTextureDirty = 0x4,
798 std::shared_ptr<QSSGUserRenderPassManager> m_manager;
800 QVarLengthArray<QSSGManagedRhiTexturePtr, 4> textures {};
801 std::unique_ptr<QRhiRenderBuffer> depthStencil;
802 QSSGManagedRhiTexturePtr depthTexture;
804 std::unique_ptr<QRhiRenderPassDescriptor> rpDesc;
805 std::unique_ptr<QRhiTextureRenderTarget> rt;
819 bool isValid()
const {
return texture && rpDesc && rt; }
874 const QRhiShaderResourceBindings *srb)
876 const QVector<quint32> srbDesc = srb->serializedLayoutDescription();
877 return { shader, srbDesc, { qHash(srbDesc) } };
881inline bool operator==(
const QSSGComputePipelineStateKey &a,
const QSSGComputePipelineStateKey &b) Q_DECL_NOTHROW
883 return a.shader == b.shader && a.srbLayoutDescription == b.srbLayoutDescription;
886inline bool operator!=(
const QSSGComputePipelineStateKey &a,
const QSSGComputePipelineStateKey &b) Q_DECL_NOTHROW
891inline size_t qHash(
const QSSGComputePipelineStateKey &k, size_t seed = 0) Q_DECL_NOTHROW
893 return qHash(k.shader, seed) ^ k.extra.srbLayoutDescriptionHash;
896struct QSSGRhiDummyTextureKey
898 QRhiTexture::Flags flags;
904inline size_t qHash(
const QSSGRhiDummyTextureKey &k, size_t seed) Q_DECL_NOTHROW
906 return qHash(k.flags, seed)
907 ^ qHash(k.size.width() ^ k.size.height() ^ k.color.red() ^ k.color.green()
908 ^ k.color.blue() ^ k.color.alpha() ^ k.arraySize);
911inline bool operator==(
const QSSGRhiDummyTextureKey &a,
const QSSGRhiDummyTextureKey &b) Q_DECL_NOTHROW
913 return a.flags == b.flags && a.size == b.size && a.color == b.color && a.arraySize == b.arraySize;
916inline bool operator!=(
const QSSGRhiDummyTextureKey &a,
const QSSGRhiDummyTextureKey &b) Q_DECL_NOTHROW
921class QSSGGraphicsPipelineStateKey
924 QSSGRhiGraphicsPipelineState state;
925 QVector<quint32> renderTargetDescription;
926 QVector<quint32> srbLayoutDescription;
928 size_t renderTargetDescriptionHash;
929 size_t srbLayoutDescriptionHash;
931 static QSSGGraphicsPipelineStateKey create(
const QSSGRhiGraphicsPipelineState &state,
932 const QRhiRenderPassDescriptor *rpDesc,
933 const QRhiShaderResourceBindings *srb)
935 const QVector<quint32> rtDesc = rpDesc->serializedFormat();
936 const QVector<quint32> srbDesc = srb->serializedLayoutDescription();
937 return { state, rtDesc, srbDesc, { qHash(rtDesc), qHash(srbDesc) } };
941inline bool operator==(
const QSSGGraphicsPipelineStateKey &a,
const QSSGGraphicsPipelineStateKey &b) Q_DECL_NOTHROW
943 return a.state == b.state
944 && a.renderTargetDescription == b.renderTargetDescription
945 && a.srbLayoutDescription == b.srbLayoutDescription;
948inline bool operator!=(
const QSSGGraphicsPipelineStateKey &a,
const QSSGGraphicsPipelineStateKey &b) Q_DECL_NOTHROW
953inline size_t qHash(
const QSSGGraphicsPipelineStateKey &k, size_t seed) Q_DECL_NOTHROW
955 return qHash(k.state, seed)
956 ^ k.extra.renderTargetDescriptionHash
957 ^ k.extra.srbLayoutDescriptionHash;
960#define QSSGRHICTX_STAT(ctx, f)
961 for (bool qssgrhictxlog_enabled = QSSGRhiContextStats::get(*ctx).isEnabled(); qssgrhictxlog_enabled; qssgrhictxlog_enabled = false)
962 QSSGRhiContextStats::get(*ctx).f
964class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRhiContextStats
967 [[nodiscard]]
static QSSGRhiContextStats &get(QSSGRhiContext &rhiCtx);
968 [[nodiscard]]
static const QSSGRhiContextStats &get(
const QSSGRhiContext &rhiCtx);
971 quint64 callCount = 0;
972 quint64 vertexOrIndexCount = 0;
974 struct InstancedDrawInfo {
975 quint64 callCount = 0;
976 quint64 vertexOrIndexCount = 0;
977 quint64 instanceCount = 0;
979 struct RenderPassInfo {
982 DrawInfo indexedDraws;
984 InstancedDrawInfo instancedIndexedDraws;
985 InstancedDrawInfo instancedDraws;
987 struct PerLayerInfo {
990 externalRenderPass.rtName = QByteArrayLiteral(
"Qt Quick");
995 QVector<RenderPassInfo> renderPasses;
1000 RenderPassInfo externalRenderPass;
1002 int currentRenderPassIndex = -1;
1005 quint64 meshDataSize = 0;
1006 quint64 imageDataSize = 0;
1007 qint64 materialGenerationTime = 0;
1008 qint64 effectGenerationTime = 0;
1011 QHash<QSSGRenderLayer *, PerLayerInfo> perLayerInfo;
1012 GlobalInfo globalInfo;
1014 QSSGRhiContextStats(QSSGRhiContext &context)
1032 static bool profilingEnabled();
1033 static bool rendererDebugEnabled();
1035 bool isEnabled()
const;
1036 void drawIndexed(quint32 indexCount, quint32 instanceCount);
1037 void draw(quint32 vertexCount, quint32 instanceCount);
1039 void meshDataSizeChanges(quint64 newSize)
1041 globalInfo.meshDataSize = newSize;
1044 void imageDataSizeChanges(quint64 newSize)
1046 globalInfo.imageDataSize = newSize;
1049 void registerMaterialShaderGenerationTime(qint64 ms)
1051 globalInfo.materialGenerationTime += ms;
1054 void registerEffectShaderGenerationTime(qint64 ms)
1056 globalInfo.effectGenerationTime += ms;
1059 static quint64 totalDrawCallCountForPass(
const QSSGRhiContextStats::RenderPassInfo &pass)
1061 return pass.draws.callCount
1062 + pass.indexedDraws.callCount
1063 + pass.instancedDraws.callCount
1064 + pass.instancedIndexedDraws.callCount;
1067 static quint64 totalVertexCountForPass(
const QSSGRhiContextStats::RenderPassInfo &pass)
1069 return pass.draws.vertexOrIndexCount
1070 + pass.indexedDraws.vertexOrIndexCount
1071 + pass.instancedDraws.vertexOrIndexCount
1072 + pass.instancedIndexedDraws.vertexOrIndexCount;
1075 void start(QSSGRenderLayer *layer);
1076 void stop(QSSGRenderLayer *layer);
1077 void beginRenderPass(QRhiTextureRenderTarget *rt);
1078 void endRenderPass();
1079 void printRenderPass(
const RenderPassInfo &rp);
1080 void cleanupLayerInfo(QSSGRenderLayer *layer);
1082 QSSGRhiContext *rhiCtx;
1083 QSSGRenderLayer *layerKey =
nullptr;
1084 QSet<QSSGRenderLayer *> dynamicDataSources;
1089 Q_DECLARE_PUBLIC(QSSGRhiContext)
1091 explicit QSSGRhiContextPrivate(QSSGRhiContext &rhiCtx, QRhi *rhi_)
1098 using Textures = QSet<QRhiTexture *>;
1099 using Meshes = QSet<QSSGRenderMesh *>;
1101 [[nodiscard]]
static QSSGRhiContextPrivate *get(QSSGRhiContext *q) {
return q->d_ptr.get(); }
1102 [[nodiscard]]
static const QSSGRhiContextPrivate *get(
const QSSGRhiContext *q) {
return q->d_ptr.get(); }
1113 void releaseCachedResources();
1115 void registerTexture(QRhiTexture *texture);
1116 void releaseTexture(QRhiTexture *texture);
1125 QRhiRenderPassDescriptor *rpDesc,
1126 QRhiShaderResourceBindings *srb);
1129 QRhiRenderPassDescriptor *rpDesc,
1130 QRhiShaderResourceBindings *srb);
1133 QRhiShaderResourceBindings *srb);
1136 QRhiShaderResourceBindings *srb);
1176inline bool operator==(
const QSSGRhiDrawCallDataKey &a,
const QSSGRhiDrawCallDataKey &b)
noexcept
1178 return a.cid == b.cid && a.model == b.model && a.resource == b.resource && a.mapEntry == b.mapEntry
1179 && a.resourceIdx == b.resourceIdx;
1182inline bool operator!=(
const QSSGRhiDrawCallDataKey &a,
const QSSGRhiDrawCallDataKey &b)
noexcept
1187inline size_t qHash(
const QSSGRhiDrawCallDataKey &k, size_t seed = 0)
noexcept
1189 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)
size_t srbLayoutDescriptionHash
QVector< quint32 > srbLayoutDescription
QRhiBuffer * buffer() const
QRhiCommandBuffer::IndexFormat indexFormat() const
quint32 numVertices() const
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 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 setMainPassSampleCount(int samples)
void cleanupDrawCallData(const QSSGRenderModel *model)
QHash< const QSSGRenderGraphObject *, QSSGRhiParticleData > m_particleData
QSSGRhiContextStats m_stats
void cleanupDrawCallDataForResource(const void *resource)
QHash< const QSSGRenderModel *, QSSGRhiInstanceBufferData > m_instanceBuffersLod
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
QHash< QSSGRhiDrawCallDataKey, QSSGRhiDrawCallData > m_drawCallData
void setMainPassViewCount(int viewCount)
QRhiComputePipeline * computePipeline(const QShader &shader, QRhiShaderResourceBindings *srb)
QHash< QSSGComputePipelineStateKey, QRhiComputePipeline * > m_computePipelines
QHash< QSSGGraphicsPipelineStateKey, QRhiGraphicsPipeline * > m_pipelines
void cleanupDrawCallDataForSkyMaterial(QSSGRenderSkyMaterial *skyMaterial)
QSSGRhiInstanceBufferData & instanceBufferData(QSSGRenderInstanceTable *instanceTable)
const QSSGManagedRhiTexturePtr & getColorTexture(int index) const
const std::unique_ptr< QRhiRenderPassDescriptor > & getRenderPassDescriptor() const
void setName(const QByteArray &name)
const std::unique_ptr< QRhiTextureRenderTarget > & getRenderTarget() const
~QSSGRhiRenderableTextureV2()
const std::unique_ptr< QRhiRenderBuffer > & getDepthStencil() const
size_t colorAttachmentCount() const
const QByteArray & getName() const
const QSSGManagedRhiTexturePtr & getDepthTexture() const
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
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)
Combined button and popup list for selecting options.
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)
QList< QSSGRhiSortData > sortData
QVector3D sortedCameraDirection
QList< QSSGRhiSortData > sortData
QRhiTextureRenderTarget * rt
QRhiTexture * depthTexture
QRhiRenderPassDescriptor * rpDesc
QRhiRenderBuffer * depthStencil
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