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)
410 for (
const QRhiShaderStage &s : m_stages) {
411 if (s.type() == QRhiShaderStage::Compute)
487 } commonUniformIndices;
502 void setUniformValue(
char *ubufData,
const char *name,
const QVariant &value, QSSGRenderShaderValue::Type type);
503 void setUniform(
char *ubufData,
const char *name,
const void *data, size_t size,
int *storeIndex =
nullptr, UniformFlags flags = {});
504 void setUniformArray(
char *ubufData,
const char *name,
const void *data, size_t itemCount, QSSGRenderShaderValue::Type type,
int *storeIndex =
nullptr);
510 QSSGBufferManager &theBufferManager,
511 const QByteArray &inPropertyName,
512 const QVariant &propertyValue,
513 QSSGRenderShaderValue::Type inPropertyType);
521 void setLightProbeTexture(QRhiTexture *texture,
522 QSSGRenderTextureCoordOp hTile = QSSGRenderTextureCoordOp::ClampToEdge,
523 QSSGRenderTextureCoordOp vTile = QSSGRenderTextureCoordOp::ClampToEdge)
525 m_lightProbeTexture = texture; m_lightProbeHorzTile = hTile; m_lightProbeVertTile = vTile;
530 return {m_lightProbeHorzTile, m_lightProbeVertTile};
533 void setScreenTexture(QRhiTexture *texture) { m_screenTexture = texture; }
536 void setDepthTexture(QRhiTexture *texture) { m_depthTexture = texture; }
539 void setNormalTexture(QRhiTexture *texture) { m_normalTexture = texture; }
542 void setSsaoTexture(QRhiTexture *texture) { m_ssaoTexture = texture; }
545 void setLightmapTexture(QRhiTexture *texture) { m_lightmapTexture = texture; }
548 void setMotionVectorTexture(QRhiTexture *texture) { m_motionVectorTexture = texture; }
550 void setShadowMapAtlasTexture(QRhiTexture *texture) { m_shadowMapAtlasTexture = texture; }
553 void setShadowMapBlueNoiseTexture(QRhiTexture *texture) { m_shadowMapBlueNoiseTexture = texture; }
556 void setOITImages(QRhiTexture *accumulator, QRhiTexture *auxiliary, QRhiTexture *counter)
558 m_oitImages[0] = accumulator;
559 m_oitImages[1] = auxiliary;
560 m_oitImages[2] = counter;
583 using StorageBindingMap = QMap<
int, StorageResourceBinding>;
585 void addStorageBufferBinding(
const QByteArray &name, QRhiShaderResourceBinding::Type type, QRhiBuffer *buffer,
int binding);
586 void addStorageImageBinding(
const QByteArray &name, QRhiShaderResourceBinding::Type type, QRhiTexture *texture,
int binding);
598 QSSGRhiContext &m_context;
599 QVarLengthArray<QRhiShaderStage, 2> m_stages;
601 int m_ub0NextUBufOffset = 0;
602 QHash<QByteArray, QShaderDescription::BlockVariable> m_ub0;
603 QHash<QSSGRhiInputAssemblerState::InputSemantic, QShaderDescription::InOutVariable> m_vertexInputs;
604 QHash<QByteArray, QShaderDescription::InOutVariable> m_combinedImageSamplers;
605 QHash<QByteArray, QShaderDescription::InOutVariable> m_storageImages;
606 QHash<QByteArray, QShaderDescription::StorageBlock> m_storageBuffers;
609 QVarLengthArray<QSSGRhiShaderUniform, 32> m_uniforms;
610 QVarLengthArray<QSSGRhiShaderUniformArray, 8> m_uniformArrays;
611 QHash<QByteArray, size_t> m_uniformIndex;
614 bool m_lightsEnabled =
false;
617 QRhiTexture *m_shadowMapAtlasTexture =
nullptr;
618 QRhiTexture *m_shadowMapBlueNoiseTexture =
nullptr;
619 QRhiTexture *m_lightProbeTexture =
nullptr;
620 QSSGRenderTextureCoordOp m_lightProbeHorzTile = QSSGRenderTextureCoordOp::ClampToEdge;
621 QSSGRenderTextureCoordOp m_lightProbeVertTile = QSSGRenderTextureCoordOp::ClampToEdge;
622 QRhiTexture *m_screenTexture =
nullptr;
623 QRhiTexture *m_depthTexture =
nullptr;
624 QRhiTexture *m_normalTexture =
nullptr;
625 QRhiTexture *m_ssaoTexture =
nullptr;
626 QRhiTexture *m_lightmapTexture =
nullptr;
627 QRhiTexture *m_oitImages[3] = {
nullptr};
628 QRhiTexture *m_motionVectorTexture =
nullptr;
629 QVarLengthArray<QSSGRhiTexture, 8> m_extraTextures;
631 QMap<
int, StorageResourceBinding> m_storageImageBindings;
632 QMap<
int, StorageResourceBinding> m_storageBufferBindings;
635Q_DECLARE_OPERATORS_FOR_FLAGS(QSSGRhiShaderPipeline::StageFlags)
636Q_DECLARE_OPERATORS_FOR_FLAGS(QSSGRhiShaderPipeline::UniformFlags)
638using QSSGRhiShaderPipelinePtr = std::shared_ptr<QSSGRhiShaderPipeline>;
643 static const int MAX_SIZE = 32;
647 QRhiShaderResourceBinding v[MAX_SIZE];
649 void clear() { p = 0; h = 0; }
651 QSSGRhiShaderResourceBindingList() { }
653 QSSGRhiShaderResourceBindingList(
const QSSGRhiShaderResourceBindingList &other)
657 for (
int i = 0; i < p; ++i)
661 QSSGRhiShaderResourceBindingList &operator=(
const QSSGRhiShaderResourceBindingList &other) Q_DECL_NOTHROW
663 if (
this != &other) {
666 for (
int i = 0; i < p; ++i)
672 void addUniformBuffer(
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiBuffer *buf,
int offset = 0 ,
int size = 0,
bool hasDynamicOffset =
false);
673 void addTexture(
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiTexture *tex, QRhiSampler *sampler);
674 void addImageLoad(
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiTexture *tex,
int level);
675 void addImageStore(
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiTexture *tex,
int level);
676 void addImageLoadStore(
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiTexture *tex,
int level);
677 void addStorageBufferLoad(
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiBuffer *buf,
int offset = 0 ,
int size = 0);
678 void addStorageBufferStore(
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiBuffer *buf,
int offset = 0 ,
int size = 0);
679 void addStorageBufferLoadStore(
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiBuffer *buf,
int offset = 0 ,
int size = 0);
681 template<QRhiShaderResourceBinding::Type T>
682 void fillImage(QRhiShaderResourceBinding::Data *d,
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiTexture *tex,
int level);
683 template<QRhiShaderResourceBinding::Type T>
684 void fillStorageBuffer(QRhiShaderResourceBinding::Data *d,
int binding, QRhiShaderResourceBinding::StageFlags stage, QRhiBuffer *buf,
int offset,
int size);
685 QRhiShaderResourceBinding::Data *newBinding();
688inline bool operator==(
const QSSGRhiShaderResourceBindingList &a,
const QSSGRhiShaderResourceBindingList &b) Q_DECL_NOTHROW
694 for (
int i = 0; i < a.p; ++i) {
695 if (a.v[i] != b.v[i])
701inline bool operator!=(
const QSSGRhiShaderResourceBindingList &a,
const QSSGRhiShaderResourceBindingList &b) Q_DECL_NOTHROW
706inline size_t qHash(
const QSSGRhiShaderResourceBindingList &bl, size_t seed) Q_DECL_NOTHROW
711struct QSSGRhiDrawCallData
713 QRhiBuffer *ubuf =
nullptr;
714 QRhiShaderResourceBindings *srb =
nullptr;
715 QSSGRhiShaderResourceBindingList bindings;
716 QRhiGraphicsPipeline *pipeline =
nullptr;
717 size_t renderTargetDescriptionHash = 0;
718 QVector<quint32> renderTargetDescription;
719 QSSGRhiGraphicsPipelineState ps;
732 enum class Private { Initialize };
733 Q_DISABLE_COPY(QSSGManagedRhiTexture)
735 using Ptr = std::unique_ptr<QSSGManagedRhiTexture>;
737 const std::unique_ptr<QRhiTexture> &texture()
const {
return m_texture; }
739 [[nodiscard]]
bool isValid()
const {
return m_texture !=
nullptr; }
741 QSSGManagedRhiTexture() =
default;
742 QSSGManagedRhiTexture(
const std::shared_ptr<QSSGUserRenderPassManager> &manager, QRhiTexture *texture, Private);
743 QSSGManagedRhiTexture(
const std::shared_ptr<QSSGUserRenderPassManager> &manager, std::unique_ptr<QRhiTexture> texture);
744 ~QSSGManagedRhiTexture();
746 [[nodiscard]]
static Ptr make_copy(
const Ptr &other)
748 return std::make_unique<QSSGManagedRhiTexture>(other->m_manager, other->m_texture.get(), Private::Initialize);
752 friend class QSSGRhiRenderableTextureV2;
753 friend class QSSGUserRenderPassManager;
757 std::shared_ptr<QSSGUserRenderPassManager> m_manager;
758 std::unique_ptr<QRhiTexture> m_texture;
761using QSSGManagedRhiTexturePtr = QSSGManagedRhiTexture::Ptr;
765 enum class Private { Initialize };
767 QSSGRhiRenderableTextureV2(
const std::shared_ptr<QSSGUserRenderPassManager> &manager, Private)
773 void setDescription(QRhi *rhi, QRhiTextureRenderTargetDescription rtDesc, QRhiTextureRenderTarget::Flags = {});
775 void setName(
const QByteArray &name) { rtName = name; }
786 bool isValid()
const {
return (textures.size() > 0) && rt && rpDesc; }
788 void finialize(QRhi *rhi);
794 friend class QSSGUserRenderPassManager;
798 ColorTextureDirty = 0x1,
799 DepthStencilDirty = 0x2,
800 DepthTextureDirty = 0x4,
807 std::shared_ptr<QSSGUserRenderPassManager> m_manager;
809 QVarLengthArray<QSSGManagedRhiTexturePtr, 4> textures {};
810 std::unique_ptr<QRhiRenderBuffer> depthStencil;
811 QSSGManagedRhiTexturePtr depthTexture;
813 std::unique_ptr<QRhiRenderPassDescriptor> rpDesc;
814 std::unique_ptr<QRhiTextureRenderTarget> rt;
828 bool isValid()
const {
return texture && rpDesc && rt; }
880 size_t srbLayoutDescriptionHash;
883 const QRhiShaderResourceBindings *srb)
885 const QVector<quint32> srbDesc = srb->serializedLayoutDescription();
886 return { shader, srbDesc, { qHash(srbDesc) } };
890inline bool operator==(
const QSSGComputePipelineStateKey &a,
const QSSGComputePipelineStateKey &b) Q_DECL_NOTHROW
892 return a.shader == b.shader && a.srbLayoutDescription == b.srbLayoutDescription;
895inline bool operator!=(
const QSSGComputePipelineStateKey &a,
const QSSGComputePipelineStateKey &b) Q_DECL_NOTHROW
900inline size_t qHash(
const QSSGComputePipelineStateKey &k, size_t seed = 0) Q_DECL_NOTHROW
902 return qHash(k.shader, seed) ^ k.extra.srbLayoutDescriptionHash;
905struct QSSGRhiDummyTextureKey
907 QRhiTexture::Flags flags;
913inline size_t qHash(
const QSSGRhiDummyTextureKey &k, size_t seed) Q_DECL_NOTHROW
915 return qHash(k.flags, seed)
916 ^ qHash(k.size.width() ^ k.size.height() ^ k.color.red() ^ k.color.green()
917 ^ k.color.blue() ^ k.color.alpha() ^ k.arraySize);
920inline bool operator==(
const QSSGRhiDummyTextureKey &a,
const QSSGRhiDummyTextureKey &b) Q_DECL_NOTHROW
922 return a.flags == b.flags && a.size == b.size && a.color == b.color && a.arraySize == b.arraySize;
925inline bool operator!=(
const QSSGRhiDummyTextureKey &a,
const QSSGRhiDummyTextureKey &b) Q_DECL_NOTHROW
930class QSSGGraphicsPipelineStateKey
933 QSSGRhiGraphicsPipelineState state;
934 QVector<quint32> renderTargetDescription;
935 QVector<quint32> srbLayoutDescription;
937 size_t renderTargetDescriptionHash;
938 size_t srbLayoutDescriptionHash;
940 static QSSGGraphicsPipelineStateKey create(
const QSSGRhiGraphicsPipelineState &state,
941 const QRhiRenderPassDescriptor *rpDesc,
942 const QRhiShaderResourceBindings *srb)
944 const QVector<quint32> rtDesc = rpDesc->serializedFormat();
945 const QVector<quint32> srbDesc = srb->serializedLayoutDescription();
946 return { state, rtDesc, srbDesc, { qHash(rtDesc), qHash(srbDesc) } };
950inline bool operator==(
const QSSGGraphicsPipelineStateKey &a,
const QSSGGraphicsPipelineStateKey &b) Q_DECL_NOTHROW
952 return a.state == b.state
953 && a.renderTargetDescription == b.renderTargetDescription
954 && a.srbLayoutDescription == b.srbLayoutDescription;
957inline bool operator!=(
const QSSGGraphicsPipelineStateKey &a,
const QSSGGraphicsPipelineStateKey &b) Q_DECL_NOTHROW
962inline size_t qHash(
const QSSGGraphicsPipelineStateKey &k, size_t seed) Q_DECL_NOTHROW
964 return qHash(k.state, seed)
965 ^ k.extra.renderTargetDescriptionHash
966 ^ k.extra.srbLayoutDescriptionHash;
969#define QSSGRHICTX_STAT(ctx, f)
970 for (bool qssgrhictxlog_enabled = QSSGRhiContextStats::get(*ctx).isEnabled(); qssgrhictxlog_enabled; qssgrhictxlog_enabled = false)
971 QSSGRhiContextStats::get(*ctx).f
973class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRhiContextStats
976 [[nodiscard]]
static QSSGRhiContextStats &get(QSSGRhiContext &rhiCtx);
977 [[nodiscard]]
static const QSSGRhiContextStats &get(
const QSSGRhiContext &rhiCtx);
980 quint64 callCount = 0;
981 quint64 vertexOrIndexCount = 0;
983 struct InstancedDrawInfo {
984 quint64 callCount = 0;
985 quint64 vertexOrIndexCount = 0;
986 quint64 instanceCount = 0;
988 struct RenderPassInfo {
991 DrawInfo indexedDraws;
993 InstancedDrawInfo instancedIndexedDraws;
994 InstancedDrawInfo instancedDraws;
996 struct PerLayerInfo {
999 externalRenderPass.rtName = QByteArrayLiteral(
"Qt Quick");
1004 QVector<RenderPassInfo> renderPasses;
1009 RenderPassInfo externalRenderPass;
1011 int currentRenderPassIndex = -1;
1014 quint64 meshDataSize = 0;
1015 quint64 imageDataSize = 0;
1016 qint64 materialGenerationTime = 0;
1017 qint64 effectGenerationTime = 0;
1020 QHash<QSSGRenderLayer *, PerLayerInfo> perLayerInfo;
1021 GlobalInfo globalInfo;
1023 QSSGRhiContextStats(QSSGRhiContext &context)
1041 static bool profilingEnabled();
1042 static bool rendererDebugEnabled();
1044 bool isEnabled()
const;
1045 void drawIndexed(quint32 indexCount, quint32 instanceCount);
1046 void draw(quint32 vertexCount, quint32 instanceCount);
1048 void meshDataSizeChanges(quint64 newSize)
1050 globalInfo.meshDataSize = newSize;
1053 void imageDataSizeChanges(quint64 newSize)
1055 globalInfo.imageDataSize = newSize;
1058 void registerMaterialShaderGenerationTime(qint64 ms)
1060 globalInfo.materialGenerationTime += ms;
1063 void registerEffectShaderGenerationTime(qint64 ms)
1065 globalInfo.effectGenerationTime += ms;
1068 static quint64 totalDrawCallCountForPass(
const QSSGRhiContextStats::RenderPassInfo &pass)
1070 return pass.draws.callCount
1071 + pass.indexedDraws.callCount
1072 + pass.instancedDraws.callCount
1073 + pass.instancedIndexedDraws.callCount;
1076 static quint64 totalVertexCountForPass(
const QSSGRhiContextStats::RenderPassInfo &pass)
1078 return pass.draws.vertexOrIndexCount
1079 + pass.indexedDraws.vertexOrIndexCount
1080 + pass.instancedDraws.vertexOrIndexCount
1081 + pass.instancedIndexedDraws.vertexOrIndexCount;
1084 void start(QSSGRenderLayer *layer);
1085 void stop(QSSGRenderLayer *layer);
1086 void beginRenderPass(QRhiTextureRenderTarget *rt);
1087 void endRenderPass();
1088 void printRenderPass(
const RenderPassInfo &rp);
1089 void cleanupLayerInfo(QSSGRenderLayer *layer);
1091 QSSGRhiContext *rhiCtx;
1092 QSSGRenderLayer *layerKey =
nullptr;
1093 QSet<QSSGRenderLayer *> dynamicDataSources;
1098 Q_DECLARE_PUBLIC(QSSGRhiContext)
1100 explicit QSSGRhiContextPrivate(QSSGRhiContext &rhiCtx, QRhi *rhi_)
1107 using Textures = QSet<QRhiTexture *>;
1108 using Meshes = QSet<QSSGRenderMesh *>;
1110 [[nodiscard]]
static QSSGRhiContextPrivate *get(QSSGRhiContext *q) {
return q->d_ptr.get(); }
1111 [[nodiscard]]
static const QSSGRhiContextPrivate *get(
const QSSGRhiContext *q) {
return q->d_ptr.get(); }
1122 void releaseCachedResources();
1124 void registerTexture(QRhiTexture *texture);
1125 void releaseTexture(QRhiTexture *texture);
1134 QRhiRenderPassDescriptor *rpDesc,
1135 QRhiShaderResourceBindings *srb);
1138 QRhiRenderPassDescriptor *rpDesc,
1139 QRhiShaderResourceBindings *srb);
1142 QRhiShaderResourceBindings *srb);
1145 QRhiShaderResourceBindings *srb);
1167 Textures m_textures;
1185inline bool operator==(
const QSSGRhiDrawCallDataKey &a,
const QSSGRhiDrawCallDataKey &b)
noexcept
1187 return a.cid == b.cid && a.model == b.model && a.resource == b.resource && a.mapEntry == b.mapEntry
1188 && a.resourceIdx == b.resourceIdx;
1191inline bool operator!=(
const QSSGRhiDrawCallDataKey &a,
const QSSGRhiDrawCallDataKey &b)
noexcept
1196inline size_t qHash(
const QSSGRhiDrawCallDataKey &k, size_t seed = 0)
noexcept
1198 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
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
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)
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