History

use full 'present' time for FPS calculation

also, refactor LOD adjust logic

Andrew Meadows committed 8 years ago

Commit 8e0d3671 parent 5c84c5f3 files · +67 −166Browse files

Showing the changes to interface/src/LODManager.cpp (1 of 3 files). Show all

Unified · Split

interface/src/LODManager.cpp+55−132
@@ -19,6 +19,11 @@ · 18 unmodified lines
1919
2020 #include "LODManager.h"
2121
22+const uint64_t LOD_AUTO_ADJUST_PERIOD = 500 * USECS_PER_MSEC;
23+const float LOD_AUTO_ADJUST_DECREMENT_FACTOR = 0.8f;
24+const float LOD_AUTO_ADJUST_INCREMENT_FACTOR = 1.2f;
25+
26+
2227 Setting::Handle<float> desktopLODDecreaseFPS("desktopLODDecreaseFPS", DEFAULT_DESKTOP_LOD_DOWN_FPS);
2328 Setting::Handle<float> hmdLODDecreaseFPS("hmdLODDecreaseFPS", DEFAULT_HMD_LOD_DOWN_FPS);
2429
@@ -39,156 +44,74 @@ float LODManager::getLODIncreaseFPS() { · 14 unmodified lines
3944 return getDesktopLODIncreaseFPS();
4045 }
4146
42−void LODManager::autoAdjustLOD(float batchTime, float engineRunTime, float deltaTimeSec) {
43−
44− // NOTE: our first ~100 samples at app startup are completely all over the place, and we don't
45− // really want to count them in our average, so we will ignore the real frame rates and stuff
46− // our moving average with simulated good data
47− const int IGNORE_THESE_SAMPLES = 100;
48− if (_fpsAverageUpWindow.getSampleCount() < IGNORE_THESE_SAMPLES) {
49− _lastStable = _lastUpShift = _lastDownShift = usecTimestampNow();
50− }
51−
47+void LODManager::autoAdjustLOD(float presentTime, float engineRunTime, float deltaTimeSec) {
5248 // compute time-weighted running average renderTime
53− const float OVERLAY_AND_SWAP_TIME_BUDGET = 2.0f; // msec
54− float renderTime = batchTime + OVERLAY_AND_SWAP_TIME_BUDGET;
55− float maxTime = glm::max(renderTime, engineRunTime);
56− const float BLEND_TIMESCALE = 0.3f; // sec
57− const float MIN_DELTA_TIME = 0.001f;
58− const float safeDeltaTime = glm::max(deltaTimeSec, MIN_DELTA_TIME);
59− float blend = BLEND_TIMESCALE / safeDeltaTime;
60− if (blend > 1.0f) {
61− blend = 1.0f;
62− }
49+ float maxTime = glm::max(presentTime, engineRunTime);
50+ const float LOD_ADJUST_TIMESCALE = 0.1f; // sec
51+ float blend = (deltaTimeSec < LOD_ADJUST_TIMESCALE) ? deltaTimeSec / LOD_ADJUST_TIMESCALE : 1.0f;
6352 _avgRenderTime = (1.0f - blend) * _avgRenderTime + blend * maxTime; // msec
53+ if (!_automaticLODAdjust) {
54+ // early exit
55+ return;
56+ }
6457
65− // translate into fps for legacy implementation
58+ float oldOctreeSizeScale = _octreeSizeScale;
6659 float currentFPS = (float)MSECS_PER_SECOND / _avgRenderTime;
67−
68− _fpsAverageStartWindow.updateAverage(currentFPS);
69− _fpsAverageDownWindow.updateAverage(currentFPS);
70− _fpsAverageUpWindow.updateAverage(currentFPS);
71−
72− quint64 now = usecTimestampNow();
73−
74− quint64 elapsedSinceDownShift = now - _lastDownShift;
75− quint64 elapsedSinceUpShift = now - _lastUpShift;
76−
77− quint64 lastStableOrUpshift = glm::max(_lastUpShift, _lastStable);
78− quint64 elapsedSinceStableOrUpShift = now - lastStableOrUpshift;
79−
80− if (_automaticLODAdjust) {
81− bool changed = false;
82−
83− // LOD Downward adjustment
84− // If we've been downshifting, we watch a shorter downshift window so that we will quickly move toward our
85− // target frame rate. But if we haven't just done a downshift (either because our last shift was an upshift,
86− // or because we've just started out) then we look at a much longer window to consider whether or not to start
87− // downshifting.
88− bool doDownShift = false;
89−
90− if (_isDownshifting) {
91− // only consider things if our DOWN_SHIFT time has elapsed...
92− if (elapsedSinceDownShift > DOWN_SHIFT_ELPASED) {
93− doDownShift = _fpsAverageDownWindow.getAverage() < getLODDecreaseFPS();
94−
95− if (!doDownShift) {
96− qCDebug(interfaceapp) << "---- WE APPEAR TO BE DONE DOWN SHIFTING -----";
97− _isDownshifting = false;
98− _lastStable = now;
99− }
100− }
101− } else {
102− doDownShift = (elapsedSinceStableOrUpShift > START_SHIFT_ELPASED
103− && _fpsAverageStartWindow.getAverage() < getLODDecreaseFPS());
104− }
105−
106− if (doDownShift) {
107−
108− // Octree items... stepwise adjustment
60+ uint64_t now = usecTimestampNow();
61+ if (currentFPS < getLODDecreaseFPS()) {
62+ if (now > _decreaseFPSExpiry) {
63+ _decreaseFPSExpiry = now + LOD_AUTO_ADJUST_PERIOD;
10964 if (_octreeSizeScale > ADJUST_LOD_MIN_SIZE_SCALE) {
110− _octreeSizeScale *= ADJUST_LOD_DOWN_BY;
65+ _octreeSizeScale *= LOD_AUTO_ADJUST_DECREMENT_FACTOR;
11166 if (_octreeSizeScale < ADJUST_LOD_MIN_SIZE_SCALE) {
11267 _octreeSizeScale = ADJUST_LOD_MIN_SIZE_SCALE;
11368 }
114− changed = true;
69+ qCDebug(interfaceapp) << "adjusting LOD UP"
70+ << "fps =" << currentFPS
71+ << "targetFPS =" << getLODDecreaseFPS();
11572 }
116−
117− if (changed) {
118− if (_isDownshifting) {
119− // subsequent downshift
120− qCDebug(interfaceapp) << "adjusting LOD DOWN..."
121− << "average fps for last "<< DOWN_SHIFT_WINDOW_IN_SECS <<"seconds was "
122− << _fpsAverageDownWindow.getAverage()
123− << "minimum is:" << getLODDecreaseFPS()
124− << "elapsedSinceDownShift:" << elapsedSinceDownShift
125− << " NEW _octreeSizeScale=" << _octreeSizeScale;
73+ _decreaseFPSExpiry = now + LOD_AUTO_ADJUST_PERIOD;
74+ }
75+ _increaseFPSExpiry = now + LOD_AUTO_ADJUST_PERIOD;
76+ } else if (currentFPS > getLODIncreaseFPS()) {
77+ if (now > _increaseFPSExpiry) {
78+ _increaseFPSExpiry = now + LOD_AUTO_ADJUST_PERIOD;
79+ if (_octreeSizeScale < ADJUST_LOD_MAX_SIZE_SCALE) {
80+ if (_octreeSizeScale < ADJUST_LOD_MIN_SIZE_SCALE) {
81+ _octreeSizeScale = ADJUST_LOD_MIN_SIZE_SCALE;
12682 } else {
127− // first downshift
128− qCDebug(interfaceapp) << "adjusting LOD DOWN after initial delay..."
129− << "average fps for last "<< START_DELAY_WINDOW_IN_SECS <<"seconds was "
130− << _fpsAverageStartWindow.getAverage()
131− << "minimum is:" << getLODDecreaseFPS()
132− << "elapsedSinceUpShift:" << elapsedSinceUpShift
133− << " NEW _octreeSizeScale=" << _octreeSizeScale;
134− }
135−
136− _lastDownShift = now;
137− _isDownshifting = true;
138−
139− emit LODDecreased();
140− }
141− } else {
142−
143− // LOD Upward adjustment
144− if (elapsedSinceUpShift > UP_SHIFT_ELPASED) {
145−
146− if (_fpsAverageUpWindow.getAverage() > getLODIncreaseFPS()) {
147−
148− // Octee items... stepwise adjustment
149− if (_octreeSizeScale < ADJUST_LOD_MAX_SIZE_SCALE) {
150− if (_octreeSizeScale < ADJUST_LOD_MIN_SIZE_SCALE) {
151− _octreeSizeScale = ADJUST_LOD_MIN_SIZE_SCALE;
152− } else {
153− _octreeSizeScale *= ADJUST_LOD_UP_BY;
154− }
155− if (_octreeSizeScale > ADJUST_LOD_MAX_SIZE_SCALE) {
156− _octreeSizeScale = ADJUST_LOD_MAX_SIZE_SCALE;
157− }
158− changed = true;
159− }
83+ _octreeSizeScale *= LOD_AUTO_ADJUST_INCREMENT_FACTOR;
16084 }
161−
162− if (changed) {
163− qCDebug(interfaceapp) << "adjusting LOD UP... average fps for last "<< UP_SHIFT_WINDOW_IN_SECS <<"seconds was "
164− << _fpsAverageUpWindow.getAverage()
165− << "upshift point is:" << getLODIncreaseFPS()
166− << "elapsedSinceUpShift:" << elapsedSinceUpShift
167− << " NEW _octreeSizeScale=" << _octreeSizeScale;
168−
169− _lastUpShift = now;
170− _isDownshifting = false;
171−
172− emit LODIncreased();
85+ if (_octreeSizeScale > ADJUST_LOD_MAX_SIZE_SCALE) {
86+ _octreeSizeScale = ADJUST_LOD_MAX_SIZE_SCALE;
17387 }
88+ qCDebug(interfaceapp) << "adjusting LOD DOWN"
89+ << "fps =" << currentFPS
90+ << "targetFPS =" << getLODDecreaseFPS();
17491 }
92+ _increaseFPSExpiry = now + LOD_AUTO_ADJUST_PERIOD;
17593 }
94+ _decreaseFPSExpiry = now + LOD_AUTO_ADJUST_PERIOD;
95+ } else {
96+ _increaseFPSExpiry = now + LOD_AUTO_ADJUST_PERIOD;
97+ _decreaseFPSExpiry = _increaseFPSExpiry;
98+ }
17699
177− if (changed) {
178− auto lodToolsDialog = DependencyManager::get<DialogsManager>()->getLodToolsDialog();
179− if (lodToolsDialog) {
180− lodToolsDialog->reloadSliders();
181− }
100+ if (oldOctreeSizeScale != _octreeSizeScale) {
101+ auto lodToolsDialog = DependencyManager::get<DialogsManager>()->getLodToolsDialog();
102+ if (lodToolsDialog) {
103+ lodToolsDialog->reloadSliders();
182104 }
105+ // Assuming the LOD adjustment will work: we optimistically reset _avgRenderTime
106+ // to be at middle of target zone. It will drift close to its true value within
107+ // about three few LOD_ADJUST_TIMESCALEs and we'll adjust again as necessary.
108+ float expectedFPS = 0.5f * (getLODIncreaseFPS() + getLODDecreaseFPS());
109+ _avgRenderTime = MSECS_PER_SECOND / expectedFPS;
183110 }
184111 }
185112
186113 void LODManager::resetLODAdjust() {
187− _fpsAverageStartWindow.reset();
188− _fpsAverageDownWindow.reset();
189− _fpsAverageUpWindow.reset();
190− _lastUpShift = _lastDownShift = usecTimestampNow();
191− _isDownshifting = false;
114+ _decreaseFPSExpiry = _increaseFPSExpiry = usecTimestampNow() + LOD_AUTO_ADJUST_PERIOD;
192115 }
193116
194117 const float MIN_DECREASE_FPS = 0.5f;
@@ -206,7 +129,7 @@ float LODManager::getDesktopLODDecreaseFPS() const { · 11 unmodified lines
206129 }
207130
208131 float LODManager::getDesktopLODIncreaseFPS() const {
209− return glm::max(((float)MSECS_PER_SECOND / _desktopMaxRenderTime) + INCREASE_LOD_GAP, MAX_LIKELY_DESKTOP_FPS);
132+ return glm::max(((float)MSECS_PER_SECOND / _desktopMaxRenderTime) + INCREASE_LOD_GAP_FPS, MAX_LIKELY_DESKTOP_FPS);
210133 }
211134
212135 void LODManager::setHMDLODDecreaseFPS(float fps) {
@@ -222,7 +145,7 @@ float LODManager::getHMDLODDecreaseFPS() const { · 9 unmodified lines
222145 }
223146
224147 float LODManager::getHMDLODIncreaseFPS() const {
225− return glm::max(((float)MSECS_PER_SECOND / _hmdMaxRenderTime) + INCREASE_LOD_GAP, MAX_LIKELY_HMD_FPS);
148+ return glm::max(((float)MSECS_PER_SECOND / _hmdMaxRenderTime) + INCREASE_LOD_GAP_FPS, MAX_LIKELY_HMD_FPS);
226149 }
227150
228151 QString LODManager::getLODFeedbackText() {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t