From 37c501b131aa6c3bab3ab2a96d9a8bbc50506367 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Mon, 25 Sep 2017 13:17:21 -0700 Subject: [PATCH 1/3] LODManager uses renderTime instead of main loop fps --- interface/src/Application.cpp | 8 +++-- interface/src/Application.h | 2 +- interface/src/LODManager.cpp | 57 +++++++++++++++++++++++++++++++---- interface/src/LODManager.h | 23 ++++++++------ 4 files changed, 71 insertions(+), 19 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index e1c3af1939..4380db0e4f 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -4470,11 +4470,13 @@ void Application::init() { }, Qt::QueuedConnection); } -void Application::updateLOD() const { +void Application::updateLOD(float deltaTime) const { PerformanceTimer perfTimer("LOD"); // adjust it unless we were asked to disable this feature, or if we're currently in throttleRendering mode if (!isThrottleRendering()) { - DependencyManager::get()->autoAdjustLOD(_frameCounter.rate()); + float batchTime = (float)_gpuContext->getFrameTimerBatchAverage(); + float engineRunTime = (float)(_renderEngine->getConfiguration().get()->getCPURunTime()); + DependencyManager::get()->autoAdjustLOD(batchTime, engineRunTime, deltaTime); } else { DependencyManager::get()->resetLODAdjust(); } @@ -4851,7 +4853,7 @@ void Application::update(float deltaTime) { bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); PerformanceWarning warn(showWarnings, "Application::update()"); - updateLOD(); + updateLOD(deltaTime); if (!_physicsEnabled) { if (!domainLoadingInProgress) { diff --git a/interface/src/Application.h b/interface/src/Application.h index 86e4f94917..be9d0e6171 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -464,7 +464,7 @@ private: void update(float deltaTime); // Various helper functions called during update() - void updateLOD() const; + void updateLOD(float deltaTime) const; void updateThreads(float deltaTime); void updateDialogs(float deltaTime) const; diff --git a/interface/src/LODManager.cpp b/interface/src/LODManager.cpp index bf756a55a5..7fd266c45d 100644 --- a/interface/src/LODManager.cpp +++ b/interface/src/LODManager.cpp @@ -39,16 +39,29 @@ float LODManager::getLODIncreaseFPS() { return getDesktopLODIncreaseFPS(); } -void LODManager::autoAdjustLOD(float currentFPS) { - +void LODManager::autoAdjustLOD(float batchTime, float engineRunTime, float deltaTimeSec) { + // NOTE: our first ~100 samples at app startup are completely all over the place, and we don't // really want to count them in our average, so we will ignore the real frame rates and stuff // our moving average with simulated good data const int IGNORE_THESE_SAMPLES = 100; if (_fpsAverageUpWindow.getSampleCount() < IGNORE_THESE_SAMPLES) { - currentFPS = ASSUMED_FPS; _lastStable = _lastUpShift = _lastDownShift = usecTimestampNow(); } + + // compute time-weighted running average renderTime + const float SYNC_AND_SWAP_TIME_BUDGET = 2.0f; // msec + float renderTime = batchTime + SYNC_AND_SWAP_TIME_BUDGET; + float maxTime = glm::max(renderTime, engineRunTime); + const float BLEND_TIMESCALE = 0.3f; // sec + float blend = BLEND_TIMESCALE / deltaTimeSec; + if (blend > 1.0f) { + blend = 1.0f; + } + _avgRenderTime = (1.0f - blend) * _avgRenderTime + blend * maxTime; // msec + + // translate into fps for legacy implementation + float currentFPS = (float)MSECS_PER_SECOND / _avgRenderTime; _fpsAverageStartWindow.updateAverage(currentFPS); _fpsAverageDownWindow.updateAverage(currentFPS); @@ -56,7 +69,6 @@ void LODManager::autoAdjustLOD(float currentFPS) { quint64 now = usecTimestampNow(); - bool changed = false; quint64 elapsedSinceDownShift = now - _lastDownShift; quint64 elapsedSinceUpShift = now - _lastUpShift; @@ -64,6 +76,7 @@ void LODManager::autoAdjustLOD(float currentFPS) { quint64 elapsedSinceStableOrUpShift = now - lastStableOrUpshift; if (_automaticLODAdjust) { + bool changed = false; // LOD Downward adjustment // If we've been downshifting, we watch a shorter downshift window so that we will quickly move toward our @@ -176,11 +189,44 @@ void LODManager::resetLODAdjust() { _isDownshifting = false; } +const float MIN_SENSIBLE_FPS = 1.0f; + +void LODManager::setDesktopLODDecreaseFPS(float fps) { + if (fps < MIN_SENSIBLE_FPS) { + // avoid divide by zero + fps = MIN_SENSIBLE_FPS; + } + _desktopMaxRenderTime = (float)MSECS_PER_SECOND / fps; +} + +float LODManager::getDesktopLODDecreaseFPS() const { + return (float)MSECS_PER_SECOND / _desktopMaxRenderTime; +} + +float LODManager::getDesktopLODIncreaseFPS() const { + return glm::max(((float)MSECS_PER_SECOND / _desktopMaxRenderTime) + INCREASE_LOD_GAP, MAX_LIKELY_DESKTOP_FPS); +} + +void LODManager::setHMDLODDecreaseFPS(float fps) { + if (fps < MIN_SENSIBLE_FPS) { + // avoid divide by zero + fps = MIN_SENSIBLE_FPS; + } + _hmdMaxRenderTime = (float)MSECS_PER_SECOND / fps; +} + +float LODManager::getHMDLODDecreaseFPS() const { + return (float)MSECS_PER_SECOND / _hmdMaxRenderTime; +} + +float LODManager::getHMDLODIncreaseFPS() const { + return glm::max(((float)MSECS_PER_SECOND / _hmdMaxRenderTime) + INCREASE_LOD_GAP, MAX_LIKELY_HMD_FPS); +} + QString LODManager::getLODFeedbackText() { // determine granularity feedback int boundaryLevelAdjust = getBoundaryLevelAdjust(); QString granularityFeedback; - switch (boundaryLevelAdjust) { case 0: { granularityFeedback = QString("."); @@ -195,7 +241,6 @@ QString LODManager::getLODFeedbackText() { granularityFeedback = QString(" at 1/%1th of standard granularity.").arg(boundaryLevelAdjust + 1); } break; } - // distance feedback float octreeSizeScale = getOctreeSizeScale(); float relativeToDefault = octreeSizeScale / DEFAULT_OCTREE_SIZE_SCALE; diff --git a/interface/src/LODManager.h b/interface/src/LODManager.h index 3d5161298d..11fd28a4e9 100644 --- a/interface/src/LODManager.h +++ b/interface/src/LODManager.h @@ -21,6 +21,8 @@ const float DEFAULT_DESKTOP_LOD_DOWN_FPS = 20.0; const float DEFAULT_HMD_LOD_DOWN_FPS = 20.0; +const float DEFAULT_DESKTOP_MAX_RENDER_TIME = (float)MSECS_PER_SECOND / DEFAULT_DESKTOP_LOD_DOWN_FPS; // msec +const float DEFAULT_HMD_MAX_RENDER_TIME = (float)MSECS_PER_SECOND / DEFAULT_HMD_LOD_DOWN_FPS; // msec const float MAX_LIKELY_DESKTOP_FPS = 59.0; // this is essentially, V-synch - 1 fps const float MAX_LIKELY_HMD_FPS = 74.0; // this is essentially, V-synch - 1 fps const float INCREASE_LOD_GAP = 15.0f; @@ -56,13 +58,13 @@ public: Q_INVOKABLE void setAutomaticLODAdjust(bool value) { _automaticLODAdjust = value; } Q_INVOKABLE bool getAutomaticLODAdjust() const { return _automaticLODAdjust; } - Q_INVOKABLE void setDesktopLODDecreaseFPS(float value) { _desktopLODDecreaseFPS = value; } - Q_INVOKABLE float getDesktopLODDecreaseFPS() const { return _desktopLODDecreaseFPS; } - Q_INVOKABLE float getDesktopLODIncreaseFPS() const { return glm::min(_desktopLODDecreaseFPS + INCREASE_LOD_GAP, MAX_LIKELY_DESKTOP_FPS); } + Q_INVOKABLE void setDesktopLODDecreaseFPS(float value); + Q_INVOKABLE float getDesktopLODDecreaseFPS() const; + Q_INVOKABLE float getDesktopLODIncreaseFPS() const; - Q_INVOKABLE void setHMDLODDecreaseFPS(float value) { _hmdLODDecreaseFPS = value; } - Q_INVOKABLE float getHMDLODDecreaseFPS() const { return _hmdLODDecreaseFPS; } - Q_INVOKABLE float getHMDLODIncreaseFPS() const { return glm::min(_hmdLODDecreaseFPS + INCREASE_LOD_GAP, MAX_LIKELY_HMD_FPS); } + Q_INVOKABLE void setHMDLODDecreaseFPS(float value); + Q_INVOKABLE float getHMDLODDecreaseFPS() const; + Q_INVOKABLE float getHMDLODIncreaseFPS() const; // User Tweakable LOD Items Q_INVOKABLE QString getLODFeedbackText(); @@ -76,7 +78,7 @@ public: Q_INVOKABLE float getLODIncreaseFPS(); static bool shouldRender(const RenderArgs* args, const AABox& bounds); - void autoAdjustLOD(float currentFPS); + void autoAdjustLOD(float batchTime, float engineRunTime, float deltaTimeSec); void loadSettings(); void saveSettings(); @@ -90,8 +92,11 @@ private: LODManager(); bool _automaticLODAdjust = true; - float _desktopLODDecreaseFPS = DEFAULT_DESKTOP_LOD_DOWN_FPS; - float _hmdLODDecreaseFPS = DEFAULT_HMD_LOD_DOWN_FPS; + //float _desktopLODDecreaseFPS = DEFAULT_DESKTOP_LOD_DOWN_FPS; + //float _hmdLODDecreaseFPS = DEFAULT_HMD_LOD_DOWN_FPS; + float _avgRenderTime { 0.0 }; + float _desktopMaxRenderTime { DEFAULT_DESKTOP_MAX_RENDER_TIME }; + float _hmdMaxRenderTime { DEFAULT_HMD_MAX_RENDER_TIME }; float _octreeSizeScale = DEFAULT_OCTREE_SIZE_SCALE; int _boundaryLevelAdjust = 0; From a3ac20d9615f7f7402b6ad295382775fc11389b3 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Mon, 25 Sep 2017 15:10:14 -0700 Subject: [PATCH 2/3] minor cleanup --- interface/src/LODManager.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/interface/src/LODManager.cpp b/interface/src/LODManager.cpp index 7fd266c45d..d3c8746e16 100644 --- a/interface/src/LODManager.cpp +++ b/interface/src/LODManager.cpp @@ -50,8 +50,8 @@ void LODManager::autoAdjustLOD(float batchTime, float engineRunTime, float delta } // compute time-weighted running average renderTime - const float SYNC_AND_SWAP_TIME_BUDGET = 2.0f; // msec - float renderTime = batchTime + SYNC_AND_SWAP_TIME_BUDGET; + const float OVERLAY_AND_SWAP_TIME_BUDGET = 2.0f; // msec + float renderTime = batchTime + OVERLAY_AND_SWAP_TIME_BUDGET; float maxTime = glm::max(renderTime, engineRunTime); const float BLEND_TIMESCALE = 0.3f; // sec float blend = BLEND_TIMESCALE / deltaTimeSec; @@ -189,12 +189,12 @@ void LODManager::resetLODAdjust() { _isDownshifting = false; } -const float MIN_SENSIBLE_FPS = 1.0f; +const float MIN_DECREASE_FPS = 0.5f; void LODManager::setDesktopLODDecreaseFPS(float fps) { - if (fps < MIN_SENSIBLE_FPS) { + if (fps < MIN_DECREASE_FPS) { // avoid divide by zero - fps = MIN_SENSIBLE_FPS; + fps = MIN_DECREASE_FPS; } _desktopMaxRenderTime = (float)MSECS_PER_SECOND / fps; } @@ -208,9 +208,9 @@ float LODManager::getDesktopLODIncreaseFPS() const { } void LODManager::setHMDLODDecreaseFPS(float fps) { - if (fps < MIN_SENSIBLE_FPS) { + if (fps < MIN_DECREASE_FPS) { // avoid divide by zero - fps = MIN_SENSIBLE_FPS; + fps = MIN_DECREASE_FPS; } _hmdMaxRenderTime = (float)MSECS_PER_SECOND / fps; } From cc8e618bc0379f3ec4dc8f8332e67b0531721aa7 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Mon, 25 Sep 2017 15:52:14 -0700 Subject: [PATCH 3/3] remove cruft --- interface/src/LODManager.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/interface/src/LODManager.h b/interface/src/LODManager.h index 11fd28a4e9..1b3797a0ca 100644 --- a/interface/src/LODManager.h +++ b/interface/src/LODManager.h @@ -92,8 +92,6 @@ private: LODManager(); bool _automaticLODAdjust = true; - //float _desktopLODDecreaseFPS = DEFAULT_DESKTOP_LOD_DOWN_FPS; - //float _hmdLODDecreaseFPS = DEFAULT_HMD_LOD_DOWN_FPS; float _avgRenderTime { 0.0 }; float _desktopMaxRenderTime { DEFAULT_DESKTOP_MAX_RENDER_TIME }; float _hmdMaxRenderTime { DEFAULT_HMD_MAX_RENDER_TIME };