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
qssgrenderdata_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 QSSGRENDERDATA_P_H
7#define QSSGRENDERDATA_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 <QtGui/qmatrix4x4.h>
21
23
24#include <vector>
25#include <unordered_map>
26#include <memory>
27#if QT_CONFIG(thread) && !defined(Q_OS_WASM)
28#include <mutex>
29#include <condition_variable>
30#endif
31
32class tst_NodeIndexing;
33
34QT_BEGIN_NAMESPACE
35
36struct QSSGRenderNode;
37class QSSGRenderRoot;
38
39class QThreadPool;
40
41class QSGRenderContext;
42class QSGRenderer;
43
44// Per window node data
45class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGGlobalRenderNodeData
46{
47 Q_DISABLE_COPY_MOVE(QSSGGlobalRenderNodeData)
48public:
49 struct InstanceTransforms
50 {
51 QMatrix4x4 local;
52 QMatrix4x4 global;
53 };
54
56 {
59 };
60
61 using VersionType = QSSGRenderNodeVersionType;
62
63 using LayerNodeView = QSSGDataView<QSSGRenderNode *>;
64
65 using GlobalTransformStore = std::vector<QMatrix4x4>;
66 using GlobalOpacityStore = std::vector<float>;
67 using InstanceTransformStore = std::vector<InstanceTransforms>;
68 using NodeStore = std::vector<QSSGRenderNode *>;
69 using LayerNodeViewStore = std::vector<LayerNodeSection>;
70
71 using NormalMatrixStore = std::vector<QMatrix3x3>;
72 using MeshStore = std::vector<QSSGRenderMesh *>;
73 using MaterialList = QVector<QSSGRenderGraphObject *>;
74 using MaterialStore = std::vector<MaterialList>;
75
76 explicit QSSGGlobalRenderNodeData(QSSGRenderRoot *root);
77 ~QSSGGlobalRenderNodeData();
78
79 void reindex();
80
81 // Once this is called we expect teardown as bugn and no further
82 // updates will be made. We do however keep the data around in case
83 // anyone holding a reference to us decides to query something.
84 void invalidate();
85
86 [[nodiscard]] VersionType version() const { return m_version; }
87
88 // The state generation is bumped whenever a layer consumes an active or tag change on a
89 // node that is shared between layers (imported scene). The node's dirty flags are cleared by
90 // the first layer that sees them, so the other layers sharing the node compare the generation
91 // they last saw against this one to know that they need to redo their filtered node lists.
92 [[nodiscard]] VersionType stateGeneration() const { return m_stateGeneration; }
93 void bumpStateGeneration() { ++m_stateGeneration; }
94
95 // NOTE: The node count is the number of nodes in the "world" tree.
96 // This is not the the same as the storage size. as some nodes
97 // may not be stored in the data or use the same storage location!
98 [[nodiscard]] size_t nodeCount() const { return m_nodeCount; }
99 [[nodiscard]] size_t storageSize() const { return m_size; }
100
101 [[nodiscard]] QMatrix4x4 getGlobalTransform(QSSGRenderNodeHandle h, const QMatrix4x4 &defaultValue) const;
102 [[nodiscard]] QMatrix4x4 getGlobalTransform(QSSGRenderNodeHandle h) const;
103 [[nodiscard]] QMatrix4x4 getGlobalTransform(const QSSGRenderNode &node) const;
104 [[nodiscard]] float getGlobalOpacity(QSSGRenderNodeHandle h, float defaultValue = 1.0f) const;
105 [[nodiscard]] float getGlobalOpacity(const QSSGRenderNode &node) const;
106 [[nodiscard]] InstanceTransforms getInstanceTransforms(QSSGRenderNodeHandle h) const;
107 [[nodiscard]] InstanceTransforms getInstanceTransforms(const QSSGRenderNode &node) const;
108
109 [[nodiscard]] LayerNodeView getLayerNodeView(QSSGRenderLayerHandle h) const;
110 [[nodiscard]] LayerNodeView getLayerNodeView(const QSSGRenderLayer &layer) const;
111
120
121#if QT_CONFIG(thread)
122 // NOTE: Thread pool for parallel processing of render data.
123 // This thread pool is not intended for async calls.
124 // For long running tasks use the global thread pool instead.
125 // (Threads executed here are expected to be done before the sync has ended).
126 QThreadPool *threadPool() const;
127#endif // QT_CONFIG(thread)
128
129private:
130 friend class ::tst_NodeIndexing;
131
132 void collectNodes(QSSGRenderRoot *rootNode);
133 void updateGlobalState();
134
135#if QT_CONFIG(thread) && !defined(Q_OS_WASM)
136 std::unique_ptr<QThreadPool> m_threadPool;
137#endif // QT_CONFIG(thread)
138
139 QSSGRenderRoot *m_rootNode = nullptr;
140 size_t m_size = 0;
141 size_t m_nodeCount = 0;
142 VersionType m_version = 0;
143 VersionType m_stateGeneration = 0;
144};
145
146using QSSGGlobalRenderNodeDataPtr = std::shared_ptr<QSSGGlobalRenderNodeData>;
147
149{
150 QSSGRenderDataHelpers() = delete;
151public:
152 enum class Strategy
153 {
154 Initial, // Initial calculation of ALL global variables
155 Update, // Update calculation of ONLY changed global variables
156 };
157
159 {
163 TagChanged = 0x4, // a node's content layer tag changed; the layer filter needs a rerun
164 };
165
168
169 /*!
170 \brief calcGlobalNodeData
171 \param node The node to calculate the global data for.
172 \param version The version of the node current node tree.
173 \param globalTransforms The global transforms store.
174 \param globalOpacities The global opacities store.
175 \return true if the data was updated, false otherwise.
176
177 The function is used to calculate the global node data for the given node.
178 It will use the given strategy to determine if it should calculate
179 the initial values or update the existing values based on the node's dirty state.
180
181 NOTE: This function assumes the output data is already allocated and can be directly
182 indexed!!!
183 */
184 template <Strategy strategy>
185 static bool calcGlobalNodeData(QSSGRenderNode *node,
186 const VersionType version,
187 QSSGGlobalRenderNodeData::GlobalTransformStore &globalTransforms,
188 QSSGGlobalRenderNodeData::GlobalOpacityStore &globalOpacities)
189 {
190 if constexpr (strategy == Strategy::Initial)
191 return calcGlobalVariablesIndexed(node, version, globalTransforms, globalOpacities);
192 else
193 return updateGlobalNodeDataIndexed(node, version, globalTransforms, globalOpacities);
194 }
195
196 /*!
197 \brief calcInstanceTransforms
198 \param node The node to calculate the instance transforms for.
199 \param version The version of the node current node tree.
200 \param globalTransforms The global transforms store.
201 \param instanceTransforms The instance transforms store.
202 \return true if the data was updated, false otherwise.
203
204 The function is used to calculate the instance transforms for the given node.
205
206 NOTE: This function assumes the output data is already allocated and can be directly
207 indexed!!!
208 */
209 static bool calcInstanceTransforms(QSSGRenderNode *node,
210 const VersionType version,
211 QSSGGlobalRenderNodeData::GlobalTransformStore &globalTransforms,
212 QSSGGlobalRenderNodeData::InstanceTransformStore &instanceTransforms);
213
214
215 /*!
216 \brief updateGlobalNodeState
217 \param node The node to update the global state for.
218 \param version The version of the node current node tree.
219 \return The result of the update.
220
221 The function is used to update the global state flagsfor the given node,
222 meaning the global active and pickable state of the node.
223 */
224 static GlobalStateResult updateGlobalNodeState(QSSGRenderNode *node, const VersionType version);
225private:
226 static bool updateGlobalNodeDataIndexed(QSSGRenderNode *node,
227 const VersionType version,
228 QSSGGlobalRenderNodeData::GlobalTransformStore &globalTransforms,
229 QSSGGlobalRenderNodeData::GlobalOpacityStore &globalOpacities);
230 static bool calcGlobalVariablesIndexed(QSSGRenderNode *node,
231 const VersionType version,
232 QSSGGlobalRenderNodeData::GlobalTransformStore &globalTransforms,
233 QSSGGlobalRenderNodeData::GlobalOpacityStore &globalOpacities);
234};
235
236// Per layer model data
238{
240public:
242
245
247
248 [[nodiscard]] ModelViewProjections getModelViewProjection(QSSGRenderNodeHandle h) const;
249 [[nodiscard]] ModelViewProjections getModelViewProjection(const QSSGRenderModel &model) const;
250
251 [[nodiscard]] QMatrix3x3 getNormalMatrix(QSSGRenderNodeHandle h, QMatrix3x3 defaultValue) const;
252 [[nodiscard]] QMatrix3x3 getNormalMatrix(const QSSGRenderModel &model) const;
253
254 [[nodiscard]] QSSGRenderMesh *getMesh(const QSSGRenderModel &model) const;
255
256 [[nodiscard]] MaterialList getMaterials(const QSSGRenderModel &model) const;
257
258 [[nodiscard]] const QSSGGlobalRenderNodeDataPtr &globalNodeData() const { return m_gnd; }
259
260 void updateModelData(QSSGModelsView &models, QSSGRenderer *renderer, const QSSGRenderCameraDataList &renderCameraData);
261
262private:
263 static quint32 getThreadPoolThreshold();
264
265 ModelViewProjectionStore modelViewProjections;
266
267 void prepareMeshData(const QSSGModelsView &models, QSSGRenderer *renderer);
268 void prepareMaterials(const QSSGModelsView &models);
269
270 QSSGGlobalRenderNodeDataPtr m_gnd;
271
272 quint32 m_version = 0;
273 const quint32 m_threadPoolThreshold = getThreadPoolThreshold();
274#if QT_CONFIG(thread) && !defined(Q_OS_WASM)
277#endif
278};
279
281{
283public:
286
289
291
292 [[nodiscard]] ModelViewProjections getModelViewProjection(QSSGRenderNodeHandle h) const;
293 [[nodiscard]] ModelViewProjections getModelViewProjection(const QSSGRenderItem2D &item) const;
294
295 [[nodiscard]] Item2DRenderer getItem2DRenderer(const QSSGRenderItem2D &item) const;
296
297 [[nodiscard]] const QSSGGlobalRenderNodeDataPtr &globalNodeData() const { return m_gnd; }
298
299 void updateItem2DData(QSSGItem2DsView &items, QSSGRenderer *renderer, const QSSGRenderCameraDataList &renderCameraData);
300
301 void releaseRenderData(const QSSGRenderItem2D &item);
302 void releaseAll();
303
304private:
305 // The association between the 2D item and its renderer and render pass descriptor, is cached and has
306 // a strong connection to the item itself. We therefore use a map here. The other stores are
307 // indexed stores as those are pure data.
309
310 QSSGGlobalRenderNodeDataPtr m_gnd;
311
312 QPointer<QSGRenderContext> item2DRenderContext;
313 Item2DRendererStore item2DRenderers;
314 ModelViewProjectionStore modelViewProjections;
315
316 const QMatrix4x4 flipMatrix { 1.0f, 0.0f, 0.0f, 0.0f,
317 0.0f, -1.0f, 0.0f, 0.0f,
318 0.0f, 0.0f, 1.0f, 0.0f,
319 0.0f, 0.0f, 0.0f, 1.0f };
320
321
322 quint32 m_version = 0;
323};
324
325QT_END_NAMESPACE
326
327#endif // QSSGRENDERDATA_P_H
QSSGRhiShaderPipelinePtr debugObjectShader
QSSGRhiGraphicsPipelineState ps
Type passType() const final
void resetForFrame() final
QSSGRhiGraphicsPipelineState ps
QSSGRenderLayer * layer
QSSGRhiShaderPipelinePtr gridShader
void resetForFrame() final
Type passType() const final
Type passType() const final
std::vector< QSGRenderer * > prepdItem2DRenderers
void resetForFrame() final
static constexpr int MaxBuckets
QSSGRhiGraphicsPipelineState ps
QSSGRenderMotionVectorMapPtr motionVectorMapManager
QSSGRenderableObjectList motionVectorPassObjects[MaxBuckets]
Type passType() const final
QSSGRhiRenderableTexture * rhiMotionVectorTexture
QSSGRenderCamera * camera
QSSGShaderFeatures shaderFeatures
QSSGRhiRenderableTexture * rhiABufferImage
QSSGRhiRenderableTexture * rhiAccumTexture
QRhiShaderResourceBindings * compositeSrb
QSSGRhiShaderPipelinePtr compositeShaderPipeline
QRhiBuffer * rhiAuxBuffer
QSSGRhiRenderableTexture * rhiAuxiliaryImage
QSSGRenderLayer::OITMethod method
QRhiBuffer * rhiABuffer
void resetForFrame() final
Type passType() const final
QSSGRhiRenderableTexture * rhiRevealageTexture
QSSGRhiGraphicsPipelineState ps
void setMethod(QSSGRenderLayer::OITMethod m)
QSSGRhiRenderableTexture * rhiRevealageTexture
QRhiResourceUpdateBatch * rub
void setMethod(QSSGRenderLayer::OITMethod m)
QSSGRhiRenderableTexture * rhiABufferImage
QList< QRhiReadbackResult * > results
QRhiBuffer * rhiABuffer
quint32 reportedNodeCount
QSSGShaderFeatures shaderFeatures
QSSGRenderLayer::OITMethod method
QRhiShaderResourceBindings * clearSrb
QSSGRenderableObjectList sortedTransparentObjects
QSSGRhiRenderableTexture * rhiAuxiliaryImage
QSSGRhiRenderableTexture * rhiCounterImage
QRhiTextureRenderTarget * renderTarget
QRhiBuffer * rhiAuxBuffer
void resetForFrame() final
QSSGRhiShaderPipelinePtr clearPipeline
QSSGRhiRenderableTexture * rhiDepthTexture
QSSGRhiGraphicsPipelineState ps
QRhiTexture * readbackImage
bool linkedListRequiresResize(QSize dim)
Type passType() const final
QRhiBuffer * rhiCounterBuffer
QSSGRhiRenderableTexture * rhiAccumTexture
static void prep(const QSSGRenderContextInterface &ctx, QSSGLayerRenderData &data, QSSGPassKey passKey, QSSGRhiGraphicsPipelineState &ps, QSSGShaderFeatures shaderFeatures, QRhiRenderPassDescriptor *rpDesc, const QSSGRenderableObjectList &sortedOpaqueObjects)
void resetForFrame() final
Type passType() const final
QSSGShaderFeatures shaderFeatures
QSSGRhiGraphicsPipelineState ps
static void render(const QSSGRenderContextInterface &ctx, const QSSGRhiGraphicsPipelineState &ps, const QSSGRenderableObjectList &sortedOpaqueObjects)
QSSGRenderableObjectList sortedOpaqueObjects
QRect viewport() const
Returns the viewport rectangle.
InstanceTransforms getInstanceTransforms(QSSGRenderNodeHandle h) const
float getGlobalOpacity(const QSSGRenderNode &node) const
LayerNodeView getLayerNodeView(const QSSGRenderLayer &layer) const
float getGlobalOpacity(QSSGRenderNodeHandle h, float defaultValue=1.0f) const
InstanceTransformStore instanceTransforms
GlobalOpacityStore globalOpacities
QMatrix4x4 getGlobalTransform(QSSGRenderNodeHandle h) const
QMatrix4x4 getGlobalTransform(const QSSGRenderNode &node) const
LayerNodeView getLayerNodeView(QSSGRenderLayerHandle h) const
QMatrix4x4 getGlobalTransform(QSSGRenderNodeHandle h, const QMatrix4x4 &defaultValue) const
VersionType stateGeneration() const
InstanceTransforms getInstanceTransforms(const QSSGRenderNode &node) const
VersionType version() const
GlobalTransformStore globalTransforms
NormalMatrixStore normalMatrices
LayerNodeViewStore layerNodes
QSSGLayerRenderPreparationResult(const QRectF &inViewport, QSSGRenderLayer &inLayer)
const QSSGLayerRenderPreparationResultFlags & getFlags() const
static GlobalStateResult updateGlobalNodeState(QSSGRenderNode *node, const VersionType version)
updateGlobalNodeState
static bool calcInstanceTransforms(QSSGRenderNode *node, const VersionType version, QSSGGlobalRenderNodeData::GlobalTransformStore &globalTransforms, QSSGGlobalRenderNodeData::InstanceTransformStore &instanceTransforms)
calcInstanceTransforms
void releaseRenderData(const QSSGRenderItem2D &item)
void updateItem2DData(QSSGItem2DsView &items, QSSGRenderer *renderer, const QSSGRenderCameraDataList &renderCameraData)
Item2DRenderer getItem2DRenderer(const QSSGRenderItem2D &item) const
const QSSGGlobalRenderNodeDataPtr & globalNodeData() const
ModelViewProjections getModelViewProjection(const QSSGRenderItem2D &item) const
ModelViewProjections getModelViewProjection(QSSGRenderNodeHandle h) const
ModelViewProjections getModelViewProjection(QSSGRenderNodeHandle h) const
void updateModelData(QSSGModelsView &models, QSSGRenderer *renderer, const QSSGRenderCameraDataList &renderCameraData)
QMatrix3x3 getNormalMatrix(const QSSGRenderModel &model) const
const QSSGGlobalRenderNodeDataPtr & globalNodeData() const
QSSGRenderMesh * getMesh(const QSSGRenderModel &model) const
ModelViewProjections getModelViewProjection(const QSSGRenderModel &model) const
MaterialList getMaterials(const QSSGRenderModel &model) const
QMatrix3x3 getNormalMatrix(QSSGRenderNodeHandle h, QMatrix3x3 defaultValue) const
virtual ~QSSGRenderPass()
virtual void resetForFrame()=0
virtual Type passType() const =0
friend class QSSGParticleRenderer
void releaseItem2DData(const QSSGRenderItem2D &item2D)
const std::unique_ptr< QSSGRhiQuadRenderer > & rhiQuadRenderer() const
quint32 frameDepth() const
float dpr() const
friend class QSSGRenderContextInterface
QRect scissorRect() const
void cleanupResources(QSet< QSSGRenderGraphObject * > &resources)
void setViewport(QRect inViewport)
void beginSubLayerRender(QSSGLayerRenderData &inLayer)
const std::unique_ptr< QSSGRhiCubeRenderer > & rhiCubeRenderer() const
void setDpr(float dpr)
void setScissorRect(QRect inScissorRect)
void endSubLayerRender(QSSGLayerRenderData &inLayer)
QSSGRenderContextInterface * contextInterface() const
void resetForFrame() final
std::shared_ptr< QSSGRenderReflectionMap > reflectionMapManager
QSSGRenderableObjectList reflectionPassObjects
std::vector< QSSGRenderReflectionProbe * > reflectionProbes
QSSGRhiGraphicsPipelineState ps
Type passType() const final
Type passType() const final
QSSGRhiRenderableTexture * rhiAoTexture
const QSSGRhiRenderableTexture * rhiDepthTexture
void resetForFrame() final
QSSGRhiShaderPipelinePtr ssaoShaderPipeline
QSSGAmbientOcclusionSettings aoSettings
const QSSGRenderCamera * camera
QSSGRhiGraphicsPipelineState ps
void resetForFrame() final
QSSGRhiGraphicsPipelineState ps
Type passType() const final
std::optional< SkyboxPass > skyboxPass
QSSGShaderFeatures shaderFeatures
QSSGRenderableObjectList sortedOpaqueObjects
std::optional< SkyboxCubeMapPass > skyboxCubeMapPass
QSSGRhiRenderableTexture * rhiScreenTexture
QSSGRenderableObjectList sortedScreenTextureObjects
const QSSGRhiRenderableTexture * rhiScreenTexture
QSSGRhiGraphicsPipelineState ps
Type passType() const final
QSSGRenderCamera * camera
QSSGBounds3 castingObjectsBox
QSSGShaderLightList globalLights
QSSGRenderableObjectList shadowPassObjects
QSSGRhiGraphicsPipelineState ps
QSSGBounds3 receivingObjectsBox
void resetForFrame() final
std::unique_ptr< QSSGRenderCamera > debugCamera
Type passType() const final
std::shared_ptr< QSSGRenderShadowMap > shadowMapManager
QSSGRhiRenderableTexture * offscreenTexture
QRhiShaderResourceBindings * backgroundSrb
Type passType() const final
QSSGRhiShaderPipelinePtr pipeline
QSSGRhiGraphicsPipelineState ps
QRhiRenderPassDescriptor * rpDesc
void resetForFrame() final
Type passType() const final
QRhiRenderPassDescriptor * rpDesc
QSSGRenderLayer * layer
QSSGRhiShaderPipelinePtr skyBoxCubeShader
QSSGRhiGraphicsPipelineState ps
void resetForFrame() final
Type passType() const final
void resetForFrame() final
QRhiRenderPassDescriptor * rpDesc
Type passType() const final
QSSGRenderLayer * layer
QSSGRhiGraphicsPipelineState ps
static void prep(const QSSGRenderContextInterface &ctx, QSSGLayerRenderData &data, QSSGPassKey passKey, QSSGRhiGraphicsPipelineState &ps, QSSGShaderFeatures shaderFeatures, QRhiRenderPassDescriptor *rpDesc, const QSSGRenderableObjectList &sortedTransparentObjects, bool oit=false)
QSSGRenderableObjectList sortedTransparentObjects
static void render(const QSSGRenderContextInterface &ctx, const QSSGRhiGraphicsPipelineState &ps, const QSSGRenderableObjectList &sortedTransparentObjects)
QSSGShaderFeatures shaderFeatures
QSSGRhiGraphicsPipelineState ps
void resetForFrame() final
Type passType() const final
Type passType() const final
QList< QSSGRenderExtension * > extensions
void resetForFrame() final
bool hasData() const
void resetForFrame() final
static constexpr size_t MAX_SUBPASS_DEPTH
QList< QSSGRenderUserPass * > userPasses
std::vector< UserPassData > userPassData
Type passType() const final
std::set< QSSGResourceId > visitedPasses
void resetForFrame() final
QSSGRenderableObjectList renderedOpaqueDepthPrepassObjects
Type passType() const final
QSSGRhiGraphicsPipelineState ps
QSSGRenderableObjectList renderedDepthWriteObjects
QSSGRenderResult::Key toInternalRenderResultKey(QSSGFrameData::RenderResult id)
Combined button and popup list for selecting options.
QSSGLayerRenderPreparationResultFlag
static const char * effect_fragment_main_with_tonemapping
static const char * effect_vertex_main_post
static const char * effect_vertex_main_pre
static const char * effect_vertex_main_position
static const char * effect_fragment_main
QVector< QSSGRenderableObjectHandle > renderables
QSSGBakedLightingModel(const QSSGRenderModel *model, const QVector< QSSGRenderableObjectHandle > &renderables)
const QSSGRenderModel * model
QSSGDefaultMaterialPreparationResult(QSSGShaderDefaultMaterialKey inMaterialKey)
QSSGShaderDefaultMaterialKey materialKey
QRhiTextureRenderTarget * oitRenderTarget
QRhiRenderPassDescriptor * renderPassDescriptor
QSSGRhiRenderableTextureV2Ptr renderableTexture
std::optional< SkyboxCubeMapPass > skyboxCubeMapPass
std::vector< UserPassData > subPassData
QSSGRhiGraphicsPipelineState ps
QSSGShaderDefineList shaderDefines
QRhiDepthStencilClearValue depthStencilClearValue
QSSGRenderableObjectList renderables
std::optional< SkyboxPass > skyboxPass
std::optional< Item2DPass > item2DPass