Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qssgrenderuserpass_p.h
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5
6#ifndef QSSGRENDERUSERPASS_P_H
7#define QSSGRENDERUSERPASS_P_H
8
9//
10// W A R N I N G
11// -------------
12//
13// This file is not part of the Qt API. It exists purely as an
14// implementation detail. This header file may change from version to
15// version without notice, or even be removed.
16//
17// We mean it.
18//
19
20#include <QtQuick3DRuntimeRender/private/qssgrendergraphobject_p.h>
21#include <QtQuick3DRuntimeRender/private/qssgrendershadercache_p.h>
22
23#include <QtCore/QVariant>
24
25QT_BEGIN_NAMESPACE
26
27class QSSGCommand;
28
29class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRenderUserPassBase : public QSSGRenderGraphObject
30{
31public:
32 enum class DirtyFlag : quint8
33 {
34 ShaderDirty = 0x1
35 };
36 using FlagT = std::underlying_type_t<DirtyFlag>;
37
38 enum class State : quint8
39 {
40 None,
41 Ready,
42 Error,
43 };
44
45 enum class ExecutionStage : quint8
46 {
47 StartOfFrame,
48 PreColor,
49 };
50
51 static constexpr DirtyFlag DirtyMask { std::numeric_limits<FlagT>::max() };
52
53 bool isDirty(DirtyFlag flag = DirtyMask) const
54 {
55 return (m_dirtyFlags & FlagT(flag)) != 0;
56 }
57 void markDirty(DirtyFlag flag)
58 {
59 m_dirtyFlags |= FlagT(flag);
60 }
61 void clearDirty(DirtyFlag flag)
62 {
63 m_dirtyFlags &= ~FlagT(flag);
64 }
65
66 bool isReady() const { return (m_state == State::Ready); }
67
68 // True for a RenderPass used as a sub-pass. Only render passes can be sub-passes.
69 bool isSubPass() const;
70
71 QVector<QSSGCommand *> commands;
72
73 FlagT m_dirtyFlags = 0;
74 State m_state = State::None;
75
76 // Number of RenderPass ancestors of the frontend item. Deeper-nested passes
77 // render first ("children before parents"), so a pass declared inside its
78 // consumer renders before it. Derived at sync when the scene manager's pass
79 // set is dirty.
80 quint32 m_nestingDepth = 0;
81 // Registration order in the scene manager's userRenderPasses list. Used as a
82 // stable tiebreak when ordering scheduled passes with equal nesting depth,
83 // so the render order does not depend on when a provider scheduled a pass.
84 quint32 m_declarationOrder = 0;
85 ExecutionStage m_executionStage = ExecutionStage::PreColor;
86
87 ~QSSGRenderUserPassBase() override;
88
89 virtual void finalizeShaders(const QSSGRenderContextInterface &ctx)
90 {
91 Q_UNUSED(ctx);
92 }
93 void resetCommands();
94
95protected:
96 explicit QSSGRenderUserPassBase(Type type)
97 : QSSGRenderGraphObject(type, FlagT(Flags::HasGraphicsResources))
98 {
99 }
100};
101
102class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRenderUserPass : public QSSGRenderUserPassBase
103{
104public:
105 enum MaterialModes {
106 OriginalMaterial,
107 AugmentMaterial,
108 OverrideMaterial
109 };
110
111 enum PassModes {
112 UserPass,
113 SkyboxPass,
114 Item2DPass,
115 InfiniteGridPass
116 };
117
118 enum class Role : quint8 {
119 TopLevel,
120 SubPass
121 };
122
123 QSSGRenderUserPass();
124 ~QSSGRenderUserPass();
125
126 // Replaces the augment macros (e.g. BASE_COLOR) in \a shaderCode in-place with their
127 // built-in variable names, setting the corresponding feature flags on \a augmentation.
128 // Exposed for testing; normally called via finalizeShaders().
129 static void replaceAugmentMacros(QByteArray &shaderCode, QSSGUserShaderAugmentation &augmentation);
130
131 void finalizeShaders(const QSSGRenderContextInterface &ctx) override;
132
133 QColor clearColor = Qt::black;
134 QRhiTextureRenderTarget::Flags renderTargetFlags = {};
135
136 // Material Mode
137 MaterialModes materialMode = OriginalMaterial;
138 QSSGRenderGraphObject *overrideMaterial = nullptr;
139 QSSGUserShaderAugmentation shaderAugmentation;
140 QRhiDepthStencilClearValue depthStencilClearValue = { };
141 PassModes passMode = UserPass;
142 Role role = Role::TopLevel;
143};
144
145inline bool QSSGRenderUserPassBase::isSubPass() const
146{
147 return type == Type::RenderPass
148 && static_cast<const QSSGRenderUserPass *>(this)->role == QSSGRenderUserPass::Role::SubPass;
149}
150
151using QSSGRenderUserPassPtr = std::shared_ptr<QSSGRenderUserPass>;
152
153QT_END_NAMESPACE
154
155#endif // QSSGRENDERUSERPASS_P_H
constexpr QByteArrayView augmentMacroReplacement(AugmentMacro macro)
static constexpr MacroPair augmentMacroPairs[]
static constexpr QSSGUserShaderAugmentation::FeatureFlags featureForMacro(AugmentMacro macro)
constexpr QByteArrayView augmentMacroName(AugmentMacro macro)
constexpr size_t QSSGMaxReplacementLength
constexpr size_t QSSGMaxMacroLength
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)
const char replacement[QSSGMaxReplacementLength]
const char macroName[QSSGMaxMacroLength]