1/****************************************************************************
2**
3** Copyright (C) 2019 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the Qt Gui module
7**
8** $QT_BEGIN_LICENSE:LGPL3$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPLv3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or later as published by the Free
28** Software Foundation and appearing in the file LICENSE.GPL included in
29** the packaging of this file. Please review the following information to
30** ensure the GNU General Public License version 2.0 requirements will be
31** met: http://www.gnu.org/licenses/gpl-2.0.html.
32**
33** $QT_END_LICENSE$
34**
35****************************************************************************/
36
37#ifndef QRHIPROFILER_P_H
38#define QRHIPROFILER_P_H
39
40//
41// W A R N I N G
42// -------------
43//
44// This file is not part of the Qt API. It exists purely as an
45// implementation detail. This header file may change from version to
46// version without notice, or even be removed.
47//
48// We mean it.
49//
50
51#include "qrhiprofiler_p.h"
52#include <QElapsedTimer>
53#include <QHash>
54
55QT_BEGIN_NAMESPACE
56
57class QRhiProfilerPrivate
58{
59public:
60 static QRhiProfilerPrivate *get(QRhiProfiler *p) { return p->d; }
61
62 void newBuffer(QRhiBuffer *buf, quint32 realSize, int backingGpuBufCount, int backingCpuBufCount);
63 void releaseBuffer(QRhiBuffer *buf);
64 void newBufferStagingArea(QRhiBuffer *buf, int slot, quint32 size);
65 void releaseBufferStagingArea(QRhiBuffer *buf, int slot);
66
67 void newRenderBuffer(QRhiRenderBuffer *rb, bool transientBacking, bool winSysBacking, int sampleCount);
68 void releaseRenderBuffer(QRhiRenderBuffer *rb);
69
70 void newTexture(QRhiTexture *tex, bool owns, int mipCount, int layerCount, int sampleCount);
71 void releaseTexture(QRhiTexture *tex);
72 void newTextureStagingArea(QRhiTexture *tex, int slot, quint32 size);
73 void releaseTextureStagingArea(QRhiTexture *tex, int slot);
74
75 void resizeSwapChain(QRhiSwapChain *sc, int bufferCount, int msaaBufferCount, int sampleCount);
76 void releaseSwapChain(QRhiSwapChain *sc);
77
78 void beginSwapChainFrame(QRhiSwapChain *sc);
79 void endSwapChainFrame(QRhiSwapChain *sc, int frameCount);
80 void swapChainFrameGpuTime(QRhiSwapChain *sc, float gpuTimeMs);
81
82 void newReadbackBuffer(qint64 id, QRhiResource *src, quint32 size);
83 void releaseReadbackBuffer(qint64 id);
84
85 void vmemStat(uint realAllocCount, uint subAllocCount, quint32 totalSize, quint32 unusedSize);
86
87 void startEntry(QRhiProfiler::StreamOp op, qint64 timestamp, QRhiResource *res);
88 void writeInt(const char *key, qint64 v);
89 void writeFloat(const char *key, float f);
90 void endEntry();
91
92 QRhiImplementation *rhiDWhenEnabled = nullptr;
93 QIODevice *outputDevice = nullptr;
94 QElapsedTimer ts;
95 QByteArray buf;
96 static const int DEFAULT_FRAME_TIMING_WRITE_INTERVAL = 120; // frames
97 int frameTimingWriteInterval = DEFAULT_FRAME_TIMING_WRITE_INTERVAL;
98 struct Sc {
99 Sc() {
100 frameToFrameSamples.reserve(asize: DEFAULT_FRAME_TIMING_WRITE_INTERVAL);
101 beginToEndSamples.reserve(asize: DEFAULT_FRAME_TIMING_WRITE_INTERVAL);
102 gpuFrameSamples.reserve(asize: DEFAULT_FRAME_TIMING_WRITE_INTERVAL);
103 }
104 QElapsedTimer frameToFrameTimer;
105 bool frameToFrameRunning = false;
106 QElapsedTimer beginToEndTimer;
107 QVector<qint64> frameToFrameSamples;
108 QVector<qint64> beginToEndSamples;
109 QVector<float> gpuFrameSamples;
110 QRhiProfiler::CpuTime frameToFrameTime;
111 QRhiProfiler::CpuTime beginToEndFrameTime;
112 QRhiProfiler::GpuTime gpuFrameTime;
113 };
114 QHash<QRhiSwapChain *, Sc> swapchains;
115};
116
117Q_DECLARE_TYPEINFO(QRhiProfilerPrivate::Sc, Q_MOVABLE_TYPE);
118
119QT_END_NAMESPACE
120
121#endif
122

source code of qtbase/src/gui/rhi/qrhiprofiler_p_p.h