diff options
author | Mnikolenko Productengine <mnikolenko@productengine.com> | 2022-01-24 16:33:44 +0200 |
---|---|---|
committer | Mnikolenko Productengine <mnikolenko@productengine.com> | 2022-01-24 16:33:44 +0200 |
commit | d7603ffc9c94a6cdab94bc23745903c7fff25ff1 (patch) | |
tree | 7cdc77fc087a6d7442d52e7e0faa0f7823245693 /indra/newview/pipeline.cpp | |
parent | 5b04123aec281de30fb8b6473600f6b1e9d16909 (diff) |
SL-16627 AutoFPS first pass
Diffstat (limited to 'indra/newview/pipeline.cpp')
-rw-r--r-- | indra/newview/pipeline.cpp | 120 |
1 files changed, 118 insertions, 2 deletions
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index dd9999d73a..96dd0b895d 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -43,6 +43,7 @@ #include "llui.h" #include "llglheaders.h" #include "llrender.h" +#include "llstartup.h" #include "llwindow.h" // swapBuffers() // newview includes @@ -405,7 +406,8 @@ LLPipeline::LLPipeline() : mLightMovingMask(0), mLightingDetail(0), mScreenWidth(0), - mScreenHeight(0) + mScreenHeight(0), + mUpdateTimer(new LLTimer()) { mNoiseMap = 0; mTrueNoiseMap = 0; @@ -613,7 +615,7 @@ void LLPipeline::init() LLPipeline::~LLPipeline() { - + delete mUpdateTimer; } void LLPipeline::cleanup() @@ -11428,3 +11430,117 @@ void LLPipeline::restoreHiddenObject( const LLUUID& id ) } } +const F32 MIN_DRAW_DISTANCE = 64; +const F32 MAX_DRAW_DISTANCE = 256; + +void update_far_clip(F32 fps_dif) +{ + F32 DIST_PER_FRAME_DIF = 16; + + F32 new_far_clip = llclamp(LLPipeline::RenderFarClip - llmin(fps_dif * DIST_PER_FRAME_DIF, (F32)128), MIN_DRAW_DISTANCE, MAX_DRAW_DISTANCE); + gSavedSettings.setF32("RenderFarClip", new_far_clip); +} + +void update_max_non_impostors(F32 fps_dif, S32 max_avatars) +{ + const F32 IMPOSTORS_PER_FRAME_DIF = 0.5; + + U32 new_non_imp = (U32)llclamp((S32)(LLVOAvatar::sMaxNonImpostors - llmin((S32)(fps_dif / IMPOSTORS_PER_FRAME_DIF), 10)), 1, max_avatars); + gSavedSettings.setU32("RenderAvatarMaxNonImpostors", new_non_imp); +} + +void LLPipeline::autoAdjustSettings() +{ + static LLCachedControl<bool> use_auto_adjustment(gSavedSettings,"AutoFPS"); + if (!use_auto_adjustment) + { + return; + } + + if (LLStartUp::getStartupState() < STATE_STARTED || LLApp::isExiting()) + { + return; + } + + static LLCachedControl<F32> adjustment_timeout(gSavedSettings, "AutoAdjustmentTimeout"); + static LLCachedControl<F32> initial_adjustment_timeout(gSavedSettings, "InitialAdjustmentTimeout"); + + static LLCachedControl<S32> fps_lower_boundary(gSavedSettings, "AutoFPSLowerBoundary"); + static LLCachedControl<S32> fps_upper_boundary(gSavedSettings, "AutoFPSUpperBoundary"); + + if (gViewerWindow && gViewerWindow->getWindow()->getVisible() + && gFocusMgr.getAppHasFocus() && !gTeleportDisplay) + { + static bool is_init = false; + if (!is_init) + { + //wait for FPS to stabilize after login in-world + mUpdateTimer->setTimerExpirySec((F32)initial_adjustment_timeout); + is_init = true; + } + if (mUpdateTimer->hasExpired()) + { + mUpdateTimer->setTimerExpirySec((F32)adjustment_timeout); + + const S32 FPS_STAT_PERIODS = 50; + S32 fps = (S32)llround(LLTrace::get_frame_recording().getPeriodMedianPerSec(LLStatViewer::FPS, FPS_STAT_PERIODS)); + if (fps < fps_lower_boundary) + { + S32 fps_dif = fps_lower_boundary - fps; + + if (LLPipeline::sRenderDeferred && RenderShadowDetail > 0) + { + S32 shadow_detail = RenderShadowDetail - 1; + gSavedSettings.setS32("RenderShadowDetail", shadow_detail); + return; + } + + if (RenderFarClip > MIN_DRAW_DISTANCE) + { + update_far_clip(fps_dif); + } + + std::vector<LLCharacter*> valid_nearby_avs; + LLWorld::getInstance()->getNearbyAvatarsAndCompl(valid_nearby_avs); + + if (valid_nearby_avs.size() > 1 && LLVOAvatar::sMaxNonImpostors > 1) + { + update_max_non_impostors(fps_dif, valid_nearby_avs.size()); + } + } + else if (fps > fps_upper_boundary) + { + S32 fps_dif = fps_upper_boundary - fps; + + std::vector<LLCharacter*> valid_nearby_avs; + LLWorld::getInstance()->getNearbyAvatarsAndCompl(valid_nearby_avs); + if (valid_nearby_avs.size() > 1 && (LLVOAvatar::sMaxNonImpostors < valid_nearby_avs.size())) + { + update_max_non_impostors(fps_dif, valid_nearby_avs.size()); + return; + } + + if (RenderFarClip < MAX_DRAW_DISTANCE) + { + update_far_clip(fps_dif); + } + + if (LLPipeline::sRenderDeferred && RenderShadowDetail < 2) + { + S32 shadow_detail = RenderShadowDetail + 1; + gSavedSettings.setS32("RenderShadowDetail", shadow_detail); + } + } + } + } + else + { + //wait for FPS to stabilize if the window was minimized or not focused before + mUpdateTimer->setTimerExpirySec((F32)initial_adjustment_timeout); + } +} + +void LLPipeline::setAdjustmentTimerExpiry(F32 expiration) +{ + mUpdateTimer->setTimerExpirySec(expiration); +} |