in projects/hvvr_samples/modelviewer/modelviewer.cpp [263:317]
void GApp::endFrame() {
if (m_settings.outputMode == OUTPUT_3D_API) {
uint32_t syncInterval = m_settings.vSync;
m_window->copyAndPresent(syncInterval);
}
// collect some overall perf statistics
{
struct FrameStats {
float deltaTime;
uint32_t rayCount;
};
enum { frameStatsWindowSize = 64 };
static FrameStats frameStats[frameStatsWindowSize] = {};
static int frameStatsPos = 0;
uint32_t rayCount = m_camera->getSampleCount();
frameStats[frameStatsPos].deltaTime = (float)m_deltaTime;
frameStats[frameStatsPos].rayCount = rayCount;
// let it run for a bit before collecting numbers
if (frameStatsPos == 0 && m_frameID > frameStatsWindowSize * 4) {
static double frameTimeAvgTotal = 0.0;
static uint64_t frameTimeAvgCount = 0;
// search for the fastest frame in the history window which matches the current state of the raycaster
int fastestMatchingFrame = -1;
for (int n = 0; n < frameStatsWindowSize; n++) {
frameTimeAvgTotal += frameStats[n].deltaTime;
frameTimeAvgCount++;
if (fastestMatchingFrame == -1 ||
frameStats[n].deltaTime < frameStats[fastestMatchingFrame].deltaTime) {
fastestMatchingFrame = n;
}
}
assert(fastestMatchingFrame >= 0 && fastestMatchingFrame < frameStatsWindowSize);
const FrameStats& fastestFrame = frameStats[fastestMatchingFrame];
float frameTimeAvg = float(frameTimeAvgTotal / double(frameTimeAvgCount));
printf("%.0f (%.0f) mrays/s"
", %.2f (%.2f) ms frametime"
", %u x %u rays"
"\n",
fastestFrame.rayCount / fastestFrame.deltaTime / 1000000.0f * hvvr::COLOR_MODE_MSAA_RATE,
fastestFrame.rayCount / frameTimeAvg / 1000000.0f * hvvr::COLOR_MODE_MSAA_RATE,
fastestFrame.deltaTime * 1000, frameTimeAvg * 1000, fastestFrame.rayCount,
hvvr::COLOR_MODE_MSAA_RATE);
}
frameStatsPos = (frameStatsPos + 1) % frameStatsWindowSize;
}
m_frameID++;
}