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) ...@@ -582,6 +582,10 @@ QRhi::FrameOpResult QRhiD3D11::endFrame(QRhiSwapChain *swapChain)
swapChainD->currentFrameSlot = (swapChainD->currentFrameSlot + 1) % QD3D11SwapChain::BUFFER_COUNT; swapChainD->currentFrameSlot = (swapChainD->currentFrameSlot + 1) % QD3D11SwapChain::BUFFER_COUNT;
swapChainD->frameCount += 1; swapChainD->frameCount += 1;
QRhiProfilerPrivate *rhiP = profilerPrivateOrNull();
QRHI_PROF_F(endSwapChainFrame(swapChain, swapChainD->frameCount));
contextState.currentSwapChain = nullptr; contextState.currentSwapChain = nullptr;
return QRhi::FrameOpSuccess; return QRhi::FrameOpSuccess;
......
...@@ -524,14 +524,18 @@ QRhi::FrameOpResult QRhiGles2::endFrame(QRhiSwapChain *swapChain) ...@@ -524,14 +524,18 @@ QRhi::FrameOpResult QRhiGles2::endFrame(QRhiSwapChain *swapChain)
executeCommandBuffer(&swapChainD->cb); executeCommandBuffer(&swapChainD->cb);
swapChainD->frameCount += 1;
currentSwapChain = nullptr;
if (swapChainD->surface) { if (swapChainD->surface) {
ctx->swapBuffers(swapChainD->surface); ctx->swapBuffers(swapChainD->surface);
buffersSwapped = true; buffersSwapped = true;
} }
swapChainD->frameCount += 1;
QRhiProfilerPrivate *rhiP = profilerPrivateOrNull();
QRHI_PROF_F(endSwapChainFrame(swapChain, swapChainD->frameCount));
currentSwapChain = nullptr;
return QRhi::FrameOpSuccess; return QRhi::FrameOpSuccess;
} }
......
...@@ -729,6 +729,10 @@ QRhi::FrameOpResult QRhiMetal::endFrame(QRhiSwapChain *swapChain) ...@@ -729,6 +729,10 @@ QRhi::FrameOpResult QRhiMetal::endFrame(QRhiSwapChain *swapChain)
swapChainD->currentFrameSlot = (swapChainD->currentFrameSlot + 1) % QMTL_FRAMES_IN_FLIGHT; swapChainD->currentFrameSlot = (swapChainD->currentFrameSlot + 1) % QMTL_FRAMES_IN_FLIGHT;
swapChainD->frameCount += 1; swapChainD->frameCount += 1;
QRhiProfilerPrivate *rhiP = profilerPrivateOrNull();
QRHI_PROF_F(endSwapChainFrame(swapChain, swapChainD->frameCount));
currentSwapChain = nullptr; currentSwapChain = nullptr;
return QRhi::FrameOpSuccess; return QRhi::FrameOpSuccess;
......
...@@ -304,6 +304,33 @@ void QRhiProfilerPrivate::releaseSwapChain(QRhiSwapChain *sc) ...@@ -304,6 +304,33 @@ void QRhiProfilerPrivate::releaseSwapChain(QRhiSwapChain *sc)
writer->endMap(); 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) void QRhiProfilerPrivate::vmemStat(int realAllocCount, int subAllocCount, quint32 totalSize, quint32 unusedSize)
{ {
if (!ensureStream()) if (!ensureStream())
......
...@@ -60,7 +60,8 @@ public: ...@@ -60,7 +60,8 @@ public:
ReleaseTextureStagingArea, ReleaseTextureStagingArea,
ResizeSwapChain, ResizeSwapChain,
ReleaseSwapChain, ReleaseSwapChain,
VMemAllocStats VMemAllocStats,
FrameTime
}; };
QRhiProfiler(); QRhiProfiler();
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#include "qtrhiglobal_p.h" #include "qtrhiglobal_p.h"
#include "qrhiprofiler.h" #include "qrhiprofiler.h"
#include <QElapsedTimer> #include <QElapsedTimer>
#include <QHash>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
...@@ -72,6 +73,8 @@ public: ...@@ -72,6 +73,8 @@ public:
void resizeSwapChain(QRhiSwapChain *sc, int bufferCount, int msaaBufferCount, int sampleCount); void resizeSwapChain(QRhiSwapChain *sc, int bufferCount, int msaaBufferCount, int sampleCount);
void releaseSwapChain(QRhiSwapChain *sc); void releaseSwapChain(QRhiSwapChain *sc);
void endSwapChainFrame(QRhiSwapChain *sc, int frameCount);
void vmemStat(int realAllocCount, int subAllocCount, quint32 totalSize, quint32 unusedSize); void vmemStat(int realAllocCount, int subAllocCount, quint32 totalSize, quint32 unusedSize);
bool ensureStream(); bool ensureStream();
...@@ -83,8 +86,17 @@ public: ...@@ -83,8 +86,17 @@ public:
QCborStreamWriter *writer = nullptr; QCborStreamWriter *writer = nullptr;
bool active = false; bool active = false;
QElapsedTimer ts; 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 QT_END_NAMESPACE
#endif #endif
...@@ -1244,6 +1244,10 @@ QRhi::FrameOpResult QRhiVulkan::endWrapperFrame(QRhiSwapChain *swapChain) ...@@ -1244,6 +1244,10 @@ QRhi::FrameOpResult QRhiVulkan::endWrapperFrame(QRhiSwapChain *swapChain)
Q_ASSERT(currentSwapChain == swapChainD); Q_ASSERT(currentSwapChain == swapChainD);
swapChainD->frameCount += 1; swapChainD->frameCount += 1;
QRhiProfilerPrivate *rhiP = profilerPrivateOrNull();
QRHI_PROF_F(endSwapChainFrame(swapChain, swapChainD->frameCount));
currentSwapChain = nullptr; currentSwapChain = nullptr;
return QRhi::FrameOpSuccess; return QRhi::FrameOpSuccess;
...@@ -1474,6 +1478,10 @@ QRhi::FrameOpResult QRhiVulkan::endNonWrapperFrame(QRhiSwapChain *swapChain) ...@@ -1474,6 +1478,10 @@ QRhi::FrameOpResult QRhiVulkan::endNonWrapperFrame(QRhiSwapChain *swapChain)
swapChainD->currentFrameSlot = (swapChainD->currentFrameSlot + 1) % QVK_FRAMES_IN_FLIGHT; swapChainD->currentFrameSlot = (swapChainD->currentFrameSlot + 1) % QVK_FRAMES_IN_FLIGHT;
swapChainD->frameCount += 1; swapChainD->frameCount += 1;
QRhiProfilerPrivate *rhiP = profilerPrivateOrNull();
QRHI_PROF_F(endSwapChainFrame(swapChain, swapChainD->frameCount));
currentSwapChain = nullptr; currentSwapChain = nullptr;
return QRhi::FrameOpSuccess; 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