1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QQUICK3DRENDERSTATS_H
5#define QQUICK3DRENDERSTATS_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuick3D/qtquick3dglobal.h>
19#include <QtCore/qobject.h>
20#include <QtQuick3DRuntimeRender/private/qssgrendercontextcore_p.h>
21#include <QtQuick3DRuntimeRender/private/qssgrhicontext_p.h>
22
23QT_BEGIN_NAMESPACE
24
25struct QSSGRenderLayer;
26class QQuickItem;
27
28class Q_QUICK3D_EXPORT QQuick3DRenderStats : public QObject
29{
30 Q_OBJECT
31 Q_PROPERTY(int fps READ fps NOTIFY fpsChanged)
32 Q_PROPERTY(float frameTime READ frameTime NOTIFY frameTimeChanged)
33 Q_PROPERTY(float renderTime READ renderTime NOTIFY renderTimeChanged)
34 Q_PROPERTY(float renderPrepareTime READ renderPrepareTime NOTIFY renderTimeChanged)
35 Q_PROPERTY(float syncTime READ syncTime NOTIFY syncTimeChanged)
36 Q_PROPERTY(float maxFrameTime READ maxFrameTime NOTIFY maxFrameTimeChanged)
37
38 Q_PROPERTY(bool extendedDataCollectionEnabled READ extendedDataCollectionEnabled WRITE setExtendedDataCollectionEnabled NOTIFY extendedDataCollectionEnabledChanged)
39 Q_PROPERTY(quint64 drawCallCount READ drawCallCount NOTIFY drawCallCountChanged)
40 Q_PROPERTY(quint64 drawVertexCount READ drawVertexCount NOTIFY drawVertexCountChanged)
41 Q_PROPERTY(quint64 imageDataSize READ imageDataSize NOTIFY imageDataSizeChanged)
42 Q_PROPERTY(quint64 meshDataSize READ meshDataSize NOTIFY meshDataSizeChanged)
43 Q_PROPERTY(int renderPassCount READ renderPassCount NOTIFY renderPassCountChanged)
44 Q_PROPERTY(QString renderPassDetails READ renderPassDetails NOTIFY renderPassDetailsChanged)
45 Q_PROPERTY(QString textureDetails READ textureDetails NOTIFY textureDetailsChanged)
46 Q_PROPERTY(QString meshDetails READ meshDetails NOTIFY meshDetailsChanged)
47 Q_PROPERTY(int pipelineCount READ pipelineCount NOTIFY pipelineCountChanged)
48 Q_PROPERTY(qint64 materialGenerationTime READ materialGenerationTime NOTIFY materialGenerationTimeChanged)
49 Q_PROPERTY(qint64 effectGenerationTime READ effectGenerationTime NOTIFY effectGenerationTimeChanged)
50 Q_PROPERTY(qint64 pipelineCreationTime READ pipelineCreationTime NOTIFY pipelineCreationTimeChanged)
51 Q_PROPERTY(quint32 vmemAllocCount READ vmemAllocCount NOTIFY vmemAllocCountChanged)
52 Q_PROPERTY(quint64 vmemUsedBytes READ vmemUsedBytes NOTIFY vmemUsedBytesChanged)
53 Q_PROPERTY(QString graphicsApiName READ graphicsApiName NOTIFY graphicsApiNameChanged)
54 Q_PROPERTY(float lastCompletedGpuTime READ lastCompletedGpuTime NOTIFY lastCompletedGpuTimeChanged)
55
56public:
57 QQuick3DRenderStats(QObject *parent = nullptr);
58
59 int fps() const;
60 float frameTime() const;
61 float renderTime() const;
62 float renderPrepareTime() const;
63 float syncTime() const;
64 float maxFrameTime() const;
65
66 void startSync();
67 void endSync(bool dump = false);
68
69 void startRender();
70 void startRenderPrepare();
71 void endRenderPrepare();
72 void endRender(bool dump = false);
73
74 void setRhiContext(QSSGRhiContext *ctx, QSSGRenderLayer *layer);
75
76 bool extendedDataCollectionEnabled() const;
77 void setExtendedDataCollectionEnabled(bool enable);
78
79 quint64 drawCallCount() const;
80 quint64 drawVertexCount() const;
81 quint64 imageDataSize() const;
82 quint64 meshDataSize() const;
83 int renderPassCount() const;
84 QString renderPassDetails() const;
85 QString textureDetails() const;
86 QString meshDetails() const;
87 int pipelineCount() const;
88 qint64 materialGenerationTime() const;
89 qint64 effectGenerationTime() const;
90 qint64 pipelineCreationTime() const;
91 quint32 vmemAllocCount() const;
92 quint64 vmemUsedBytes() const;
93 QString graphicsApiName() const;
94 float lastCompletedGpuTime() const;
95
96 Q_INVOKABLE void releaseCachedResources();
97
98 void setWindow(QQuickWindow *window);
99
100Q_SIGNALS:
101 void fpsChanged();
102 void frameTimeChanged();
103 void renderTimeChanged();
104 void syncTimeChanged();
105 void maxFrameTimeChanged();
106 void extendedDataCollectionEnabledChanged();
107 void drawCallCountChanged();
108 void drawVertexCountChanged();
109 void imageDataSizeChanged();
110 void meshDataSizeChanged();
111 void renderPassCountChanged();
112 void renderPassDetailsChanged();
113 void textureDetailsChanged();
114 void meshDetailsChanged();
115 void pipelineCountChanged();
116 void materialGenerationTimeChanged();
117 void effectGenerationTimeChanged();
118 void pipelineCreationTimeChanged();
119 void vmemAllocCountChanged();
120 void vmemUsedBytesChanged();
121 void graphicsApiNameChanged();
122 void lastCompletedGpuTimeChanged();
123
124private Q_SLOTS:
125 void onFrameSwapped();
126
127private:
128 float timestamp() const;
129 void processRhiContextStats();
130 void notifyRhiContextStats();
131
132 QElapsedTimer m_frameTimer;
133 int m_frameCount = 0;
134 float m_secTimer = 0;
135 float m_notifyTimer = 0;
136 float m_renderStartTime = 0;
137 float m_renderPrepareStartTime = 0;
138 float m_syncStartTime = 0;
139
140 float m_internalMaxFrameTime = 0;
141 float m_maxFrameTime = 0;
142
143 int m_fps = 0;
144
145 struct Results {
146 float frameTime = 0;
147 float renderTime = 0;
148 float renderPrepareTime = 0;
149 float syncTime = 0;
150 float lastCompletedGpuTime = 0;
151 quint64 drawCallCount = 0;
152 quint64 drawVertexCount = 0;
153 quint64 imageDataSize = 0;
154 quint64 meshDataSize = 0;
155 int renderPassCount = 0;
156 QString renderPassDetails;
157 QString textureDetails;
158 QString meshDetails;
159 QSet<QRhiTexture *> activeTextures;
160 QSet<QSSGRenderMesh *> activeMeshes;
161 int pipelineCount = 0;
162 qint64 materialGenerationTime = 0;
163 qint64 effectGenerationTime = 0;
164 QRhiStats rhiStats;
165 };
166
167 Results m_results;
168 Results m_notifiedResults;
169 QSSGRhiContextStats *m_contextStats = nullptr;
170 bool m_extendedDataCollectionEnabled = false;
171 QSSGRenderLayer *m_layer = nullptr;
172 QMetaObject::Connection m_frameSwappedConnection;
173 QQuickWindow *m_window = nullptr;
174 bool m_renderingThisFrame = false;
175 QString m_graphicsApiName;
176};
177
178QT_END_NAMESPACE
179
180Q_DECLARE_METATYPE(QQuick3DRenderStats *)
181
182#endif // QQUICK3DRENDERSTATS_H
183

source code of qtquick3d/src/quick3d/qquick3drenderstats_p.h