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
29
30struct QSSGRenderNode;
31class QSSGRenderRoot;
32
33class QThreadPool;
34
35class QSGRenderContext;
36class QSGRenderer;
37
38// Per window node data
39class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGGlobalRenderNodeData
40{
41 Q_DISABLE_COPY_MOVE(QSSGGlobalRenderNodeData)
42public:
43 struct InstanceTransforms
44 {
45 QMatrix4x4 local;
46 QMatrix4x4 global;
47 };
48
50 {
53 };
54
55 using LayerNodeView = QSSGDataView<QSSGRenderNode *>;
56
57 using GlobalTransformStore = std::vector<QMatrix4x4>;
58 using GlobalOpacityStore = std::vector<float>;
59 using InstanceTransformStore = std::vector<InstanceTransforms>;
60 using NodeStore = std::vector<QSSGRenderNode *>;
61 using LayerNodeViewStore = std::vector<LayerNodeSection>;
62
63 explicit QSSGGlobalRenderNodeData(QSSGRenderRoot *root);
64 ~QSSGGlobalRenderNodeData();
65
66 void reindex();
67
68 // Once this is called we expect teardown as bugn and no further
69 // updates will be made. We do however keep the data around in case
70 // anyone holding a reference to us decides to query something.
71 void invalidate();
72
73 [[nodiscard]] quint32 version() const { return m_version; }
74
75 // NOTE: The node count is the number of nodes in the "world" tree.
76 // This is not the the same as the storage size. as some nodes
77 // may not be stored in the data or use the same storage location!
78 [[nodiscard]] size_t nodeCount() const { return m_nodeCount; }
79 [[nodiscard]] size_t storageSize() const { return m_size; }
80
81 [[nodiscard]] QMatrix4x4 getGlobalTransform(QSSGRenderNodeHandle h, QMatrix4x4 defaultValue) const;
82 [[nodiscard]] QMatrix4x4 getGlobalTransform(QSSGRenderNodeHandle h) const;
83 [[nodiscard]] QMatrix4x4 getGlobalTransform(const QSSGRenderNode &node) const;
84 [[nodiscard]] float getGlobalOpacity(QSSGRenderNodeHandle h, float defaultValue = 1.0f) const;
85 [[nodiscard]] float getGlobalOpacity(const QSSGRenderNode &node) const;
86 [[nodiscard]] InstanceTransforms getInstanceTransforms(QSSGRenderNodeHandle h) const;
87 [[nodiscard]] InstanceTransforms getInstanceTransforms(const QSSGRenderNode &node) const;
88
89 [[nodiscard]] LayerNodeView getLayerNodeView(QSSGRenderLayerHandle h) const;
90 [[nodiscard]] LayerNodeView getLayerNodeView(const QSSGRenderLayer &layer) const;
91
97
98#if QT_CONFIG(thread)
99 // NOTE: Thread pool for parallel processing of render data.
100 // This thread pool is not intended for async calls.
101 // For long running tasks use the global thread pool instead.
102 // (Threads executed here are expected to be done before the sync has ended).
103 const std::unique_ptr<QThreadPool> &threadPool() const;
104#endif // QT_CONFIG(thread)
105
106private:
107 void collectNodes(QSSGRenderRoot *rootNode);
108 void updateGlobalState();
109
110#if QT_CONFIG(thread)
111 std::unique_ptr<QThreadPool> m_threadPool;
112#endif // QT_CONFIG(thread)
113
114 QSSGRenderRoot *m_rootNode = nullptr;
115 size_t m_size = 0;
116 size_t m_nodeCount = 0;
117 quint32 m_version = 0;
118};
119
120using QSSGGlobalRenderNodeDataPtr = std::shared_ptr<QSSGGlobalRenderNodeData>;
121
123{
124 QSSGRenderDataHelpers() = delete;
125public:
126 enum class Strategy
127 {
128 Initial, // Initial calculation of ALL global variables
129 Update, // Update calculation of ONLY changed global variables
130 };
131
138
140
141 /*!
142 \brief calcGlobalNodeData
143 \param node The node to calculate the global data for.
144 \param version The version of the node current node tree.
145 \param globalTransforms The global transforms store.
146 \param globalOpacities The global opacities store.
147 \return true if the data was updated, false otherwise.
148
149 The function is used to calculate the global node data for the given node.
150 It will use the given strategy to determine if it should calculate
151 the initial values or update the existing values based on the node's dirty state.
152
153 NOTE: This function assumes the output data is already allocated and can be directly
154 indexed!!!
155 */
156 template <Strategy strategy>
157 static bool calcGlobalNodeData(QSSGRenderNode *node,
158 const quint32 version,
159 QSSGGlobalRenderNodeData::GlobalTransformStore &globalTransforms,
160 QSSGGlobalRenderNodeData::GlobalOpacityStore &globalOpacities)
161 {
162 if constexpr (strategy == Strategy::Initial)
163 return calcGlobalVariablesIndexed(node, version, globalTransforms, globalOpacities);
164 else
165 return updateGlobalNodeDataIndexed(node, version, globalTransforms, globalOpacities);
166 }
167
168 /*!
169 \brief calcInstanceTransforms
170 \param node The node to calculate the instance transforms for.
171 \param version The version of the node current node tree.
172 \param globalTransforms The global transforms store.
173 \param instanceTransforms The instance transforms store.
174 \return true if the data was updated, false otherwise.
175
176 The function is used to calculate the instance transforms for the given node.
177
178 NOTE: This function assumes the output data is already allocated and can be directly
179 indexed!!!
180 */
181 static bool calcInstanceTransforms(QSSGRenderNode *node,
182 const quint32 version,
183 QSSGGlobalRenderNodeData::GlobalTransformStore &globalTransforms,
184 QSSGGlobalRenderNodeData::InstanceTransformStore &instanceTransforms);
185
186
187 /*!
188 \brief updateGlobalNodeState
189 \param node The node to update the global state for.
190 \param version The version of the node current node tree.
191 \return The result of the update.
192
193 The function is used to update the global state flagsfor the given node,
194 meaning the global active and pickable state of the node.
195 */
196 static GlobalStateResult updateGlobalNodeState(QSSGRenderNode *node, const quint32 version);
197private:
198 static bool updateGlobalNodeDataIndexed(QSSGRenderNode *node,
199 const quint32 version,
200 QSSGGlobalRenderNodeData::GlobalTransformStore &globalTransforms,
201 QSSGGlobalRenderNodeData::GlobalOpacityStore &globalOpacities);
202 static bool calcGlobalVariablesIndexed(QSSGRenderNode *node,
203 const quint32 version,
204 QSSGGlobalRenderNodeData::GlobalTransformStore &globalTransforms,
205 QSSGGlobalRenderNodeData::GlobalOpacityStore &globalOpacities);
206};
207
208// Per layer model data
210{
212public:
214
217
222
223 [[nodiscard]] ModelViewProjections getModelViewProjection(QSSGRenderModelHandle h) const;
224 [[nodiscard]] ModelViewProjections getModelViewProjection(const QSSGRenderModel &model) const;
225
226 [[nodiscard]] QMatrix3x3 getNormalMatrix(QSSGRenderModelHandle h, QMatrix3x3 defaultValue) const;
227 [[nodiscard]] QMatrix3x3 getNormalMatrix(const QSSGRenderModel &model) const;
228
229 [[nodiscard]] QSSGRenderMesh *getMesh(QSSGRenderModelHandle h) const;
230 [[nodiscard]] QSSGRenderMesh *getMesh(const QSSGRenderModel &model) const;
231
232 [[nodiscard]] MaterialList getMaterials(QSSGRenderModelHandle h) const;
233 [[nodiscard]] MaterialList getMaterials(const QSSGRenderModel &model) const;
234
235 [[nodiscard]] const QSSGGlobalRenderNodeDataPtr &globalNodeData() const { return m_gnd; }
236
237 void updateModelData(QSSGModelsView &models, QSSGRenderer *renderer, const QSSGRenderCameraDataList &renderCameraData);
238
239private:
240 ModelViewProjectionStore modelViewProjections;
241 NormalMatrixStore normalMatrices;
242 MeshStore meshes;
243 MaterialStore materials;
244
245 void prepareMeshData(const QSSGModelsView &models, QSSGRenderer *renderer);
246 void prepareMaterials(const QSSGModelsView &models);
247
248 QSSGGlobalRenderNodeDataPtr m_gnd;
249
250 quint32 m_version = 0;
251};
252
254{
256public:
259
262
264
265 [[nodiscard]] ModelViewProjections getModelViewProjection(QSSGRenderItem2DHandle h) const;
266 [[nodiscard]] ModelViewProjections getModelViewProjection(const QSSGRenderItem2D &item) const;
267
268 [[nodiscard]] Item2DRenderer getItem2DRenderer(const QSSGRenderItem2D &item) const;
269
270 [[nodiscard]] const QSSGGlobalRenderNodeDataPtr &globalNodeData() const { return m_gnd; }
271
272 void updateItem2DData(QSSGItem2DsView &items, QSSGRenderer *renderer, const QSSGRenderCameraDataList &renderCameraData);
273
274 void releaseRenderData(const QSSGRenderItem2D &item);
275 void releaseAll();
276
277private:
278 // The association between the 2D item and its renderer and render pass descriptor, is cached and has
279 // a strong connection to the item itself. We therefore use a map here. The other stores are
280 // indexed stores as those are pure data.
282
283 QSSGGlobalRenderNodeDataPtr m_gnd;
284
285 QPointer<QSGRenderContext> item2DRenderContext;
286 Item2DRendererStore item2DRenderers;
287 ModelViewProjectionStore modelViewProjections;
288
289 const QMatrix4x4 flipMatrix { 1.0f, 0.0f, 0.0f, 0.0f,
290 0.0f, -1.0f, 0.0f, 0.0f,
291 0.0f, 0.0f, 1.0f, 0.0f,
292 0.0f, 0.0f, 0.0f, 1.0f };
293
294
295 quint32 m_version = 0;
296};
297
298QT_END_NAMESPACE
299
300#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
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, QMatrix4x4 defaultValue) const
InstanceTransforms getInstanceTransforms(const QSSGRenderNode &node) const
GlobalTransformStore globalTransforms
LayerNodeViewStore layerNodes
QSSGLayerRenderPreparationResult(const QRectF &inViewport, QSSGRenderLayer &inLayer)
const QSSGLayerRenderPreparationResultFlags & getFlags() const
static bool calcInstanceTransforms(QSSGRenderNode *node, const quint32 version, QSSGGlobalRenderNodeData::GlobalTransformStore &globalTransforms, QSSGGlobalRenderNodeData::InstanceTransformStore &instanceTransforms)
calcInstanceTransforms
static GlobalStateResult updateGlobalNodeState(QSSGRenderNode *node, const quint32 version)
updateGlobalNodeState
void releaseRenderData(const QSSGRenderItem2D &item)
void updateItem2DData(QSSGItem2DsView &items, QSSGRenderer *renderer, const QSSGRenderCameraDataList &renderCameraData)
Item2DRenderer getItem2DRenderer(const QSSGRenderItem2D &item) const
ModelViewProjections getModelViewProjection(QSSGRenderItem2DHandle h) const
const QSSGGlobalRenderNodeDataPtr & globalNodeData() const
ModelViewProjections getModelViewProjection(const QSSGRenderItem2D &item) const
void updateModelData(QSSGModelsView &models, QSSGRenderer *renderer, const QSSGRenderCameraDataList &renderCameraData)
QMatrix3x3 getNormalMatrix(QSSGRenderModelHandle h, QMatrix3x3 defaultValue) const
QMatrix3x3 getNormalMatrix(const QSSGRenderModel &model) const
QSSGRenderMesh * getMesh(QSSGRenderModelHandle h) const
const QSSGGlobalRenderNodeDataPtr & globalNodeData() const
MaterialList getMaterials(QSSGRenderModelHandle h) const
ModelViewProjections getModelViewProjection(QSSGRenderModelHandle h) const
QSSGRenderMesh * getMesh(const QSSGRenderModel &model) const
ModelViewProjections getModelViewProjection(const QSSGRenderModel &model) const
MaterialList getMaterials(const QSSGRenderModel &model) 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
QSSGRhiGraphicsPipelineState ps
QList< QSSGRenderReflectionProbe * > reflectionProbes
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
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