From 0c12bb5a4ea613697599d77ad3970cdb0390596f Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Mon, 2 Nov 2015 18:47:18 -0800 Subject: [PATCH 1/3] Remove idleTimer and call idle directly from paintGL. --- interface/src/Application.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 6d41679bea..4c55e05b01 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -160,7 +160,6 @@ static QTimer balanceUpdateTimer; static QTimer identityPacketTimer; static QTimer billboardPacketTimer; static QTimer checkFPStimer; -static QTimer idleTimer; static const QString SNAPSHOT_EXTENSION = ".jpg"; static const QString SVO_EXTENSION = ".svo"; @@ -844,7 +843,6 @@ void Application::cleanupBeforeQuit() { identityPacketTimer.stop(); billboardPacketTimer.stop(); checkFPStimer.stop(); - idleTimer.stop(); QMetaObject::invokeMethod(&_settingsTimer, "stop", Qt::BlockingQueuedConnection); // save state @@ -982,9 +980,6 @@ void Application::initializeGL() { connect(&checkFPStimer, &QTimer::timeout, this, &Application::checkFPS); checkFPStimer.start(1000); - // call our idle function whenever we can - connect(&idleTimer, &QTimer::timeout, this, &Application::idle); - idleTimer.start(TARGET_SIM_FRAME_PERIOD_MS); _idleLoopStdev.reset(); // update before the first render @@ -1048,6 +1043,9 @@ void Application::initializeUi() { } void Application::paintGL() { + + idle(); + PROFILE_RANGE(__FUNCTION__); PerformanceTimer perfTimer("paintGL"); From c139b62217742ce96ee43c712db6e5c40f0cc012 Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Tue, 3 Nov 2015 11:19:49 -0800 Subject: [PATCH 2/3] fps calculation now based on moving average fps stat is now calcualted the same way as simRate and avatarRate are calculated, based on a moving average that is sampled once a second. Also, Removed unused constants and renamed Application::checkFPS to Application::ping --- interface/src/Application.cpp | 39 +++++++++++++++++++++-------------- interface/src/Application.h | 4 +++- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 4c55e05b01..1f04338f99 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -159,7 +159,7 @@ static QTimer locationUpdateTimer; static QTimer balanceUpdateTimer; static QTimer identityPacketTimer; static QTimer billboardPacketTimer; -static QTimer checkFPStimer; +static QTimer pingTimer; static const QString SNAPSHOT_EXTENSION = ".jpg"; static const QString SVO_EXTENSION = ".svo"; @@ -183,9 +183,7 @@ static const quint64 TOO_LONG_SINCE_LAST_SEND_DOWNSTREAM_AUDIO_STATS = 1 * USECS static const QString INFO_HELP_PATH = "html/interface-welcome.html"; static const QString INFO_EDIT_ENTITIES_PATH = "html/edit-commands.html"; -static const unsigned int TARGET_SIM_FRAMERATE = 60; static const unsigned int THROTTLED_SIM_FRAMERATE = 15; -static const int TARGET_SIM_FRAME_PERIOD_MS = MSECS_PER_SECOND / TARGET_SIM_FRAMERATE; static const int THROTTLED_SIM_FRAME_PERIOD_MS = MSECS_PER_SECOND / THROTTLED_SIM_FRAMERATE; #ifndef __APPLE__ @@ -842,7 +840,7 @@ void Application::cleanupBeforeQuit() { balanceUpdateTimer.stop(); identityPacketTimer.stop(); billboardPacketTimer.stop(); - checkFPStimer.stop(); + pingTimer.stop(); QMetaObject::invokeMethod(&_settingsTimer, "stop", Qt::BlockingQueuedConnection); // save state @@ -977,8 +975,8 @@ void Application::initializeGL() { _entityEditSender.initialize(_enableProcessOctreeThread); // call our timer function every second - connect(&checkFPStimer, &QTimer::timeout, this, &Application::checkFPS); - checkFPStimer.start(1000); + connect(&pingTimer, &QTimer::timeout, this, &Application::ping); + pingTimer.start(1000); _idleLoopStdev.reset(); @@ -1312,7 +1310,6 @@ void Application::paintGL() { { PerformanceTimer perfTimer("makeCurrent"); _offscreenContext->makeCurrent(); - _frameCount++; Stats::getInstance()->setRenderDetails(renderArgs._details); // Reset the gpu::Context Stages @@ -1321,6 +1318,24 @@ void Application::paintGL() { batch.resetStages(); }); } + + // update fps moving average + { + uint64_t now = usecTimestampNow(); + static uint64_t lastPaintEnd{ now }; + uint64_t diff = now - lastPaintEnd; + if (diff != 0) { + _framesPerSecond.updateAverage((float)USECS_PER_SECOND / (float)diff); + } + lastPaintEnd = now; + + // update fps once a second + if (now - _lastFramesPerSecondUpdate > USECS_PER_SECOND) { + _fps = _framesPerSecond.getAverage(); + _lastFramesPerSecondUpdate = now; + } + _frameCount++; + } } void Application::runTests() { @@ -2085,17 +2100,11 @@ bool Application::acceptSnapshot(const QString& urlString) { return true; } -// Every second, check the frame rates and other stuff -void Application::checkFPS() { +// Every second, send a ping, if menu item is checked. +void Application::ping() { if (Menu::getInstance()->isOptionChecked(MenuOption::TestPing)) { DependencyManager::get()->sendPingPackets(); } - - float diffTime = (float)_timerStart.nsecsElapsed() / 1000000000.0f; - - _fps = (float)_frameCount / diffTime; - _frameCount = 0; - _timerStart.start(); } void Application::idle() { diff --git a/interface/src/Application.h b/interface/src/Application.h index dfc904e0ef..0fd8c74494 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -306,7 +306,7 @@ public slots: private slots: void clearDomainOctreeDetails(); - void checkFPS(); + void ping(); void idle(); void aboutToQuit(); @@ -541,6 +541,8 @@ private: EntityItemID _keyboardFocusedItem; quint64 _lastAcceptedKeyPress = 0; + SimpleMovingAverage _framesPerSecond{10}; + quint64 _lastFramesPerSecondUpdate = 0; SimpleMovingAverage _simsPerSecond{10}; int _simsPerSecondReport = 0; quint64 _lastSimsPerSecondUpdate = 0; From 31f361d49ca445ce84ca7c0a3ca8875554f42a7a Mon Sep 17 00:00:00 2001 From: "Anthony J. Thibault" Date: Tue, 3 Nov 2015 15:51:18 -0800 Subject: [PATCH 3/3] Moved fps timing to beginning of paintGL This should improve accuracy. However the fps displayed can still sometimes be slightly greater then the vsync, this is either due to timer accuracy problems or QTimer delay within OpenGLDisplayPlugin. --- interface/src/Application.cpp | 40 +++++++++++++++++------------------ interface/src/Application.h | 2 +- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 1f04338f99..d31d9de4a0 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1041,8 +1041,25 @@ void Application::initializeUi() { } void Application::paintGL() { + _frameCount++; - idle(); + // update fps moving average + uint64_t now = usecTimestampNow(); + static uint64_t lastPaintBegin{ now }; + uint64_t diff = now - lastPaintBegin; + if (diff != 0) { + _framesPerSecond.updateAverage((float)USECS_PER_SECOND / (float)diff); + } + + lastPaintBegin = now; + + // update fps once a second + if (now - _lastFramesPerSecondUpdate > USECS_PER_SECOND) { + _fps = _framesPerSecond.getAverage(); + _lastFramesPerSecondUpdate = now; + } + + idle(now); PROFILE_RANGE(__FUNCTION__); PerformanceTimer perfTimer("paintGL"); @@ -1318,24 +1335,6 @@ void Application::paintGL() { batch.resetStages(); }); } - - // update fps moving average - { - uint64_t now = usecTimestampNow(); - static uint64_t lastPaintEnd{ now }; - uint64_t diff = now - lastPaintEnd; - if (diff != 0) { - _framesPerSecond.updateAverage((float)USECS_PER_SECOND / (float)diff); - } - lastPaintEnd = now; - - // update fps once a second - if (now - _lastFramesPerSecondUpdate > USECS_PER_SECOND) { - _fps = _framesPerSecond.getAverage(); - _lastFramesPerSecondUpdate = now; - } - _frameCount++; - } } void Application::runTests() { @@ -2107,7 +2106,7 @@ void Application::ping() { } } -void Application::idle() { +void Application::idle(uint64_t now) { if (_aboutToQuit) { return; // bail early, nothing to do here. } @@ -2130,7 +2129,6 @@ void Application::idle() { { PROFILE_RANGE(__FUNCTION__); - uint64_t now = usecTimestampNow(); static uint64_t lastIdleStart{ now }; uint64_t idleStartToStartDuration = now - lastIdleStart; if (idleStartToStartDuration != 0) { diff --git a/interface/src/Application.h b/interface/src/Application.h index 0fd8c74494..212687c11e 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -307,7 +307,7 @@ public slots: private slots: void clearDomainOctreeDetails(); void ping(); - void idle(); + void idle(uint64_t now); void aboutToQuit(); void handleScriptEngineLoaded(const QString& scriptFilename);