From 32d766cb3af0b79a722b838dcebffef29a755cfe Mon Sep 17 00:00:00 2001 From: Brad Linden Date: Tue, 15 Oct 2024 15:20:16 -0700 Subject: Provide affordances to disable automatic downrezing of textures when SL is in background secondlife/viewer#2549 --- indra/newview/app_settings/settings.xml | 11 ++++++++++ indra/newview/llviewertexture.cpp | 24 +++++++++++++++++++--- .../newview/skins/default/xui/en/notifications.xml | 15 ++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index 0d194288e8..25e6fac0ad 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -11413,6 +11413,17 @@ Value 0 + TextureDiscardBackgroundedTime + + Comment + Specify how long to wait before discarding texture data after viewer is backgrounded. (zero or negative to disable) + Persist + 1 + Type + F32 + Value + 60.0 + TextureFetchConcurrency Comment diff --git a/indra/newview/llviewertexture.cpp b/indra/newview/llviewertexture.cpp index 99f8db00f2..ab0ea1ec93 100644 --- a/indra/newview/llviewertexture.cpp +++ b/indra/newview/llviewertexture.cpp @@ -43,6 +43,7 @@ #include "message.h" #include "lltimer.h" #include "v4coloru.h" +#include "llnotificationsutil.h" // viewer includes #include "llimagegl.h" @@ -111,6 +112,18 @@ const U32 DESIRED_NORMAL_TEXTURE_SIZE = (U32)LLViewerFetchedTexture::MAX_IMAGE_S const U32 DESIRED_NORMAL_TEXTURE_SIZE = (U32)LLViewerFetchedTexture::MAX_IMAGE_SIZE_DEFAULT; #endif +namespace +{ +void onClickDisableDiscard(const LLSD& notification, const LLSD& response) +{ + if (response["Cancel_okcancelignore"].asBoolean()) + { + LL_INFOS() << "User chose to disable texture discard on backgrounding." << LL_ENDL; + gSavedSettings.setF32("TextureDiscardBackgroundedTime", -1.f); + } +} +} // namespace + //---------------------------------------------------------------------------------------------- //namespace: LLViewerTextureAccess //---------------------------------------------------------------------------------------------- @@ -560,16 +573,21 @@ void LLViewerTexture::updateClass() // set to max discard bias if the window has been backgrounded for a while static bool was_backgrounded = false; static LLFrameTimer backgrounded_timer; + static F32 last_desired_discard_bias = 1.f; + static LLCachedControl backgrounded_discard_time(gSavedSettings, "TextureDiscardBackgroundedTime", 60.f); bool in_background = (gViewerWindow && !gViewerWindow->getWindow()->getVisible()) || !gFocusMgr.getAppHasFocus(); if (in_background) { - if (backgrounded_timer.getElapsedTimeF32() > 10.f) + F32 background_elapsed = backgrounded_timer.getElapsedTimeF32(); + if (backgrounded_discard_time > 0.f && background_elapsed > backgrounded_discard_time) { if (!was_backgrounded) { - LL_INFOS() << "Viewer is backgrounded, freeing up video memory." << LL_ENDL; + LL_INFOS() << "Viewer is backgrounded for " << backgrounded_discard_time << "s, freeing up video memory." << LL_ENDL; + LLNotificationsUtil::add("TextureDiscardBackgrounded", llsd::map("DELAY", backgrounded_discard_time), LLSD(), &onClickDisableDiscard); + last_desired_discard_bias = sDesiredDiscardBias; } was_backgrounded = true; sDesiredDiscardBias = 4.f; @@ -582,7 +600,7 @@ void LLViewerTexture::updateClass() { // if the viewer was backgrounded LL_INFOS() << "Viewer is no longer backgrounded, resuming normal texture usage." << LL_ENDL; was_backgrounded = false; - sDesiredDiscardBias = 1.f; + sDesiredDiscardBias = last_desired_discard_bias; } } diff --git a/indra/newview/skins/default/xui/en/notifications.xml b/indra/newview/skins/default/xui/en/notifications.xml index 5ce73b2cfa..40a8557bb8 100644 --- a/indra/newview/skins/default/xui/en/notifications.xml +++ b/indra/newview/skins/default/xui/en/notifications.xml @@ -12583,4 +12583,19 @@ are wearing now. yestext="OK"/> + + + DELAY + + To improve system performance, [SECOND_LIFE] has reduced texture memory usage after being in the background for [DELAY] seconds. It may take some time for texture image quality to return to normal. + + + -- cgit v1.2.3 From 7827f66caefe358f050caf4d1215d5e956192114 Mon Sep 17 00:00:00 2001 From: Rye Date: Tue, 29 Oct 2024 02:30:52 -0700 Subject: Add handling for downrezzing textures when viewer is minimized, fix downrezzing textures when minimized due to texture system not processesing --- indra/newview/app_settings/settings.xml | 11 +++++ indra/newview/llviewerdisplay.cpp | 29 ++++++++++++ indra/newview/llviewertexture.cpp | 52 +++++++++++++--------- .../newview/skins/default/xui/en/notifications.xml | 15 +++++++ 4 files changed, 87 insertions(+), 20 deletions(-) diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index 25e6fac0ad..01df915af3 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -11424,6 +11424,17 @@ Value 60.0 + TextureDiscardMinimizedTime + + Comment + Specify how long to wait before discarding texture data after viewer is minimized. (zero or negative to disable) + Persist + 1 + Type + F32 + Value + 1.0 + TextureFetchConcurrency Comment diff --git a/indra/newview/llviewerdisplay.cpp b/indra/newview/llviewerdisplay.cpp index 8c6a38876a..3642c2a339 100644 --- a/indra/newview/llviewerdisplay.cpp +++ b/indra/newview/llviewerdisplay.cpp @@ -455,6 +455,35 @@ void display(bool rebuild, F32 zoom_factor, int subfield, bool for_snapshot) // true = minimized, do not show/update the TP screen. HB update_tp_display(true); } + + // Run texture subsystem to discard memory while backgrounded + if (!gNonInteractive) + { + LL_PROFILE_ZONE_NAMED("Update Images"); + + { + LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("Class"); + LLViewerTexture::updateClass(); + } + + { + LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("Image Update Bump"); + gBumpImageList.updateImages(); // must be called before gTextureList version so that it's textures are thrown out first. + } + + { + LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("List"); + F32 max_image_decode_time = 0.050f * gFrameIntervalSeconds.value(); // 50 ms/second decode time + max_image_decode_time = llclamp(max_image_decode_time, 0.002f, 0.005f); // min 2ms/frame, max 5ms/frame) + gTextureList.updateImages(max_image_decode_time); + } + + { + LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("GLTF Materials Cleanup"); + // remove dead gltf materials + gGLTFMaterialList.flushMaterials(); + } + } return; } diff --git a/indra/newview/llviewertexture.cpp b/indra/newview/llviewertexture.cpp index ab0ea1ec93..a4b76d0ae9 100644 --- a/indra/newview/llviewertexture.cpp +++ b/indra/newview/llviewertexture.cpp @@ -112,18 +112,6 @@ const U32 DESIRED_NORMAL_TEXTURE_SIZE = (U32)LLViewerFetchedTexture::MAX_IMAGE_S const U32 DESIRED_NORMAL_TEXTURE_SIZE = (U32)LLViewerFetchedTexture::MAX_IMAGE_SIZE_DEFAULT; #endif -namespace -{ -void onClickDisableDiscard(const LLSD& notification, const LLSD& response) -{ - if (response["Cancel_okcancelignore"].asBoolean()) - { - LL_INFOS() << "User chose to disable texture discard on backgrounding." << LL_ENDL; - gSavedSettings.setF32("TextureDiscardBackgroundedTime", -1.f); - } -} -} // namespace - //---------------------------------------------------------------------------------------------- //namespace: LLViewerTextureAccess //---------------------------------------------------------------------------------------------- @@ -571,25 +559,49 @@ void LLViewerTexture::updateClass() } // set to max discard bias if the window has been backgrounded for a while + static F32 last_desired_discard_bias = 1.f; static bool was_backgrounded = false; static LLFrameTimer backgrounded_timer; - static F32 last_desired_discard_bias = 1.f; + static LLCachedControl minimized_discard_time(gSavedSettings, "TextureDiscardMinimizedTime", 1.f); static LLCachedControl backgrounded_discard_time(gSavedSettings, "TextureDiscardBackgroundedTime", 60.f); bool in_background = (gViewerWindow && !gViewerWindow->getWindow()->getVisible()) || !gFocusMgr.getAppHasFocus(); - + bool is_minimized = gViewerWindow && gViewerWindow->getWindow()->getMinimized() && in_background; if (in_background) { - F32 background_elapsed = backgrounded_timer.getElapsedTimeF32(); - if (backgrounded_discard_time > 0.f && background_elapsed > backgrounded_discard_time) + F32 discard_time = is_minimized ? minimized_discard_time : backgrounded_discard_time; + if (discard_time > 0.f && backgrounded_timer.getElapsedTimeF32() > discard_time) { if (!was_backgrounded) { - LL_INFOS() << "Viewer is backgrounded for " << backgrounded_discard_time << "s, freeing up video memory." << LL_ENDL; - LLNotificationsUtil::add("TextureDiscardBackgrounded", llsd::map("DELAY", backgrounded_discard_time), LLSD(), &onClickDisableDiscard); + std::string notification_name; + std::string setting; + if (is_minimized) + { + notification_name = "TextureDiscardMinimized"; + setting = "TextureDiscardMinimizedTime"; + } + else + { + notification_name = "TextureDiscardBackgrounded"; + setting = "TextureDiscardBackgroundedTime"; + } + + LL_INFOS() << "Viewer was " << (is_minimized ? "minimized" : "backgrounded") << " for " << discard_time + << "s, freeing up video memory." << LL_ENDL; + + LLNotificationsUtil::add(notification_name, llsd::map("DELAY", discard_time), LLSD(), + [=](const LLSD& notification, const LLSD& response) + { + if (response["Cancel_okcancelignore"].asBoolean()) + { + LL_INFOS() << "User chose to disable texture discard on " << (is_minimized ? "minimizing." : "backgrounding.") << LL_ENDL; + gSavedSettings.setF32(setting, -1.f); + } + }); last_desired_discard_bias = sDesiredDiscardBias; + was_backgrounded = true; } - was_backgrounded = true; sDesiredDiscardBias = 4.f; } } @@ -598,7 +610,7 @@ void LLViewerTexture::updateClass() backgrounded_timer.reset(); if (was_backgrounded) { // if the viewer was backgrounded - LL_INFOS() << "Viewer is no longer backgrounded, resuming normal texture usage." << LL_ENDL; + LL_INFOS() << "Viewer is no longer backgrounded or minimized, resuming normal texture usage." << LL_ENDL; was_backgrounded = false; sDesiredDiscardBias = last_desired_discard_bias; } diff --git a/indra/newview/skins/default/xui/en/notifications.xml b/indra/newview/skins/default/xui/en/notifications.xml index 40a8557bb8..509e6e9766 100644 --- a/indra/newview/skins/default/xui/en/notifications.xml +++ b/indra/newview/skins/default/xui/en/notifications.xml @@ -12598,4 +12598,19 @@ are wearing now. notext="Disable"/> + + + DELAY + + To improve system performance, [SECOND_LIFE] has reduced texture memory usage after being minimized for [DELAY] seconds. It may take some time for texture image quality to return to normal. + + + -- cgit v1.2.3 From 9598e2f4cedd3dc36d447086273e0ed97967bbf9 Mon Sep 17 00:00:00 2001 From: Rye Date: Tue, 29 Oct 2024 10:16:53 -0700 Subject: Fix texture discard bias not incrementing correctly due to being limited by frame interval and a timer at the same time --- indra/newview/llviewertexture.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/indra/newview/llviewertexture.cpp b/indra/newview/llviewertexture.cpp index a4b76d0ae9..5b4efc9ecc 100644 --- a/indra/newview/llviewertexture.cpp +++ b/indra/newview/llviewertexture.cpp @@ -543,7 +543,6 @@ void LLViewerTexture::updateClass() { static LLCachedControl low_mem_min_discard_increment(gSavedSettings, "RenderLowMemMinDiscardIncrement", .1f); sDesiredDiscardBias += (F32)low_mem_min_discard_increment * (F32)gFrameIntervalSeconds; - sEvaluationTimer.reset(); } } else -- cgit v1.2.3