Commit 05fe449b authored by Laszlo Agocs's avatar Laszlo Agocs

prof: Write out frame timings from time to time

Every 120 frames atm. This becomes more interesting once
timestamp queries are implemented...
parent fbb992e4
......@@ -582,6 +582,10 @@ QRhi::FrameOpResult QRhiD3D11::endFrame(QRhiSwapChain *swapChain)
swapChainD->currentFrameSlot = (swapChainD->currentFrameSlot + 1) % QD3D11SwapChain::BUFFER_COUNT;
swapChainD->frameCount += 1;
QRhiProfilerPrivate *rhiP = profilerPrivateOrNull();
QRHI_PROF_F(endSwapChainFrame(swapChain, swapChainD->frameCount));
contextState.currentSwapChain = nullptr;
return QRhi::FrameOpSuccess;
......
......@@ -524,14 +524,18 @@ QRhi::FrameOpResult QRhiGles2::endFrame(QRhiSwapChain *swapChain)
executeCommandBuffer(&swapChainD->cb);
swapChainD->frameCount += 1;
currentSwapChain = nullptr;
if (swapChainD->surface) {
ctx->swapBuffers(swapChainD->surface);
buffersSwapped = true;
}
swapChainD->frameCount += 1;
QRhiProfilerPrivate *rhiP = profilerPrivateOrNull();
QRHI_PROF_F(endSwapChainFrame(swapChain, swapChainD->frameCount));
currentSwapChain = nullptr;
return QRhi::FrameOpSuccess;
}
......
......@@ -729,6 +729,10 @@ QRhi::FrameOpResult QRhiMetal::endFrame(QRhiSwapChain *swapChain)
swapChainD->currentFrameSlot = (swapChainD->currentFrameSlot + 1) % QMTL_FRAMES_IN_FLIGHT;
swapChainD->frameCount += 1;
QRhiProfilerPrivate *rhiP = profilerPrivateOrNull();
QRHI_PROF_F(endSwapChainFrame(swapChain, swapChainD->frameCount));
currentSwapChain = nullptr;
return QRhi::FrameOpSuccess;
......
......@@ -304,6 +304,33 @@ void QRhiProfilerPrivate::releaseSwapChain(QRhiSwapChain *sc)
writer->endMap();
}
void QRhiProfilerPrivate::endSwapChainFrame(QRhiSwapChain *sc, int frameCount)
{
if (!swapchains.contains(sc)) {
swapchains[sc].t.start();
return;
}
Sc &scd(swapchains[sc]);
scd.frameDelta[scd.n++] = scd.t.restart();
if (scd.n == Sc::FRAME_SAMPLE_SIZE) {
scd.n = 0;
float totalDelta = 0;
for (int i = 0; i < Sc::FRAME_SAMPLE_SIZE; ++i)
totalDelta += scd.frameDelta[i];
const float avgDelta = totalDelta / Sc::FRAME_SAMPLE_SIZE;
if (ensureStream()) {
writer->startMap();
WRITE_OP(FrameTime);
WRITE_TIMESTAMP;
WRITE_PAIR(QLatin1String("swapchain"), quint64(quintptr(sc)));
WRITE_PAIR(QLatin1String("frames_since_resize"), frameCount);
WRITE_PAIR(QLatin1String("avg_ms_between_frames"), avgDelta);
writer->endMap();
}
}
}
void QRhiProfilerPrivate::vmemStat(int realAllocCount, int subAllocCount, quint32 totalSize, quint32 unusedSize)
{
if (!ensureStream())
......
......@@ -60,7 +60,8 @@ public:
ReleaseTextureStagingArea,
ResizeSwapChain,
ReleaseSwapChain,
VMemAllocStats
VMemAllocStats,
FrameTime
};
QRhiProfiler();
......
......@@ -44,6 +44,7 @@
#include "qtrhiglobal_p.h"
#include "qrhiprofiler.h"
#include <QElapsedTimer>
#include <QHash>
QT_BEGIN_NAMESPACE
......@@ -72,6 +73,8 @@ public:
void resizeSwapChain(QRhiSwapChain *sc, int bufferCount, int msaaBufferCount, int sampleCount);
void releaseSwapChain(QRhiSwapChain *sc);
void endSwapChainFrame(QRhiSwapChain *sc, int frameCount);
void vmemStat(int realAllocCount, int subAllocCount, quint32 totalSize, quint32 unusedSize);
bool ensureStream();
......@@ -83,8 +86,17 @@ public:
QCborStreamWriter *writer = nullptr;
bool active = false;
QElapsedTimer ts;
struct Sc {
QElapsedTimer t;
int n = 0;
static const int FRAME_SAMPLE_SIZE = 120;
qint64 frameDelta[FRAME_SAMPLE_SIZE];
};
QHash<QRhiSwapChain *, Sc> swapchains;
};
Q_DECLARE_TYPEINFO(QRhiProfilerPrivate::Sc, Q_MOVABLE_TYPE);
QT_END_NAMESPACE
#endif
......@@ -1244,6 +1244,10 @@ QRhi::FrameOpResult QRhiVulkan::endWrapperFrame(QRhiSwapChain *swapChain)
Q_ASSERT(currentSwapChain == swapChainD);
swapChainD->frameCount += 1;
QRhiProfilerPrivate *rhiP = profilerPrivateOrNull();
QRHI_PROF_F(endSwapChainFrame(swapChain, swapChainD->frameCount));
currentSwapChain = nullptr;
return QRhi::FrameOpSuccess;
......@@ -1474,6 +1478,10 @@ QRhi::FrameOpResult QRhiVulkan::endNonWrapperFrame(QRhiSwapChain *swapChain)
swapChainD->currentFrameSlot = (swapChainD->currentFrameSlot + 1) % QVK_FRAMES_IN_FLIGHT;
swapChainD->frameCount += 1;
QRhiProfilerPrivate *rhiP = profilerPrivateOrNull();
QRHI_PROF_F(endSwapChainFrame(swapChain, swapChainD->frameCount));
currentSwapChain = nullptr;
return QRhi::FrameOpSuccess;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment