summaryrefslogtreecommitdiff
path: root/indra/newview/llviewertexture.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llviewertexture.cpp')
-rw-r--r--indra/newview/llviewertexture.cpp133
1 files changed, 73 insertions, 60 deletions
diff --git a/indra/newview/llviewertexture.cpp b/indra/newview/llviewertexture.cpp
index 99f8db00f2..c10e28d688 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"
@@ -70,6 +71,7 @@ LLPointer<LLViewerTexture> LLViewerTexture::sBlackImagep = nullptr;
LLPointer<LLViewerTexture> LLViewerTexture::sCheckerBoardImagep = nullptr;
LLPointer<LLViewerFetchedTexture> LLViewerFetchedTexture::sMissingAssetImagep = nullptr;
LLPointer<LLViewerFetchedTexture> LLViewerFetchedTexture::sWhiteImagep = nullptr;
+LLPointer<LLViewerFetchedTexture> LLViewerFetchedTexture::sDefaultParticleImagep = nullptr;
LLPointer<LLViewerFetchedTexture> LLViewerFetchedTexture::sDefaultImagep = nullptr;
LLPointer<LLViewerFetchedTexture> LLViewerFetchedTexture::sSmokeImagep = nullptr;
LLPointer<LLViewerFetchedTexture> LLViewerFetchedTexture::sFlatNormalImagep = nullptr;
@@ -497,16 +499,19 @@ void LLViewerTexture::updateClass()
F64 texture_bytes_alloc = LLImageGL::getTextureBytesAllocated() / 1024.0 / 512.0;
F64 vertex_bytes_alloc = LLVertexBuffer::getBytesAllocated() / 1024.0 / 512.0;
- F64 render_bytes_alloc = LLRenderTarget::sBytesAllocated / 1024.0 / 512.0;
// get an estimate of how much video memory we're using
// NOTE: our metrics miss about half the vram we use, so this biases high but turns out to typically be within 5% of the real number
- F32 used = (F32)ll_round(texture_bytes_alloc + vertex_bytes_alloc + render_bytes_alloc);
+ F32 used = (F32)ll_round(texture_bytes_alloc + vertex_bytes_alloc);
F32 budget = max_vram_budget == 0 ? (F32)gGLManager.mVRAM : (F32)max_vram_budget;
- // try to leave half a GB for everyone else, but keep at least 768MB for ourselves
- F32 target = llmax(budget - 512.f, MIN_VRAM_BUDGET);
+ // Try to leave at least half a GB for everyone else and for bias,
+ // but keep at least 768MB for ourselves
+ // Viewer can 'overshoot' target when scene changes, if viewer goes over budget it
+ // can negatively impact performance, so leave 20% of a breathing room for
+ // 'bias' calculation to kick in.
+ F32 target = llmax(llmin(budget - 512.f, budget * 0.8f), MIN_VRAM_BUDGET);
sFreeVRAMMegabytes = target - used;
F32 over_pct = (used - target) / target;
@@ -522,7 +527,7 @@ void LLViewerTexture::updateClass()
// slam to 1.5 bias the moment we hit low memory (discards off screen textures immediately)
sDesiredDiscardBias = llmax(sDesiredDiscardBias, 1.5f);
- if (is_sys_low)
+ if (is_sys_low || over_pct > 2.f)
{ // if we're low on system memory, emergency purge off screen textures to avoid a death spiral
LL_WARNS() << "Low system memory detected, emergency downrezzing off screen textures" << LL_ENDL;
for (auto& image : gTextureList)
@@ -541,8 +546,9 @@ void LLViewerTexture::updateClass()
if (sEvaluationTimer.getElapsedTimeF32() > MEMORY_CHECK_WAIT_TIME)
{
static LLCachedControl<F32> low_mem_min_discard_increment(gSavedSettings, "RenderLowMemMinDiscardIncrement", .1f);
- sDesiredDiscardBias += (F32)low_mem_min_discard_increment * (F32)gFrameIntervalSeconds;
- sEvaluationTimer.reset();
+
+ F32 increment = low_mem_min_discard_increment + llmax(over_pct, 0.f);
+ sDesiredDiscardBias += increment * gFrameIntervalSeconds;
}
}
else
@@ -558,21 +564,50 @@ 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 LLCachedControl<F32> minimized_discard_time(gSavedSettings, "TextureDiscardMinimizedTime", 1.f);
+ static LLCachedControl<F32> 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)
{
- if (backgrounded_timer.getElapsedTimeF32() > 10.f)
+ 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, freeing up video memory." << LL_ENDL;
+ 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;
+ sDesiredDiscardBias = 5.f;
}
}
else
@@ -580,13 +615,13 @@ 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 = 1.f;
+ sDesiredDiscardBias = last_desired_discard_bias;
}
}
- sDesiredDiscardBias = llclamp(sDesiredDiscardBias, 1.f, 4.f);
+ sDesiredDiscardBias = llclamp(sDesiredDiscardBias, 1.f, 5.f);
LLViewerTexture::sFreezeImageUpdates = false;
}
@@ -1361,51 +1396,6 @@ void LLViewerFetchedTexture::addToCreateTexture()
}
else
{
- LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-#if 1
- //
- //if mRequestedDiscardLevel > mDesiredDiscardLevel, we assume the required image res keep going up,
- //so do not scale down the over qualified image.
- //Note: scaling down image is expensensive. Do it only when very necessary.
- //
- if(mRequestedDiscardLevel <= mDesiredDiscardLevel && !mForceToSaveRawImage)
- {
- U32 w = mFullWidth >> mRawDiscardLevel;
- U32 h = mFullHeight >> mRawDiscardLevel;
-
- //if big image, do not load extra data
- //scale it down to size >= LLViewerTexture::sMinLargeImageSize
- if(w * h > LLViewerTexture::sMinLargeImageSize)
- {
- S32 d_level = llmin(mRequestedDiscardLevel, (S32)mDesiredDiscardLevel) - mRawDiscardLevel;
-
- if(d_level > 0)
- {
- S32 i = 0;
- while((d_level > 0) && ((w >> i) * (h >> i) > LLViewerTexture::sMinLargeImageSize))
- {
- i++;
- d_level--;
- }
- if(i > 0)
- {
- mRawDiscardLevel += i;
- if(mRawDiscardLevel >= getDiscardLevel() && getDiscardLevel() > 0)
- {
- mNeedsCreateTexture = false;
- destroyRawImage();
- return;
- }
-
- {
- //make a duplicate in case somebody else is using this raw image
- mRawImage = mRawImage->scaled(w >> i, h >> i);
- }
- }
- }
- }
- }
-#endif
scheduleCreateTexture();
}
return;
@@ -1703,6 +1693,7 @@ void LLViewerFetchedTexture::processTextureStats()
if(mDesiredDiscardLevel > mMinDesiredDiscardLevel)//need to load more
{
mDesiredDiscardLevel = llmin(mDesiredDiscardLevel, mMinDesiredDiscardLevel);
+ mDesiredDiscardLevel = llmin(mDesiredDiscardLevel, (S32)mLoadedCallbackDesiredDiscardLevel);
mFullyLoaded = false;
}
//setDebugText("fully loaded");
@@ -1752,6 +1743,7 @@ void LLViewerFetchedTexture::processTextureStats()
log((F32)mFullHeight / mKnownDrawHeight) / log_2);
mDesiredDiscardLevel = llclamp(mDesiredDiscardLevel, (S8)0, (S8)getMaxDiscardLevel());
mDesiredDiscardLevel = llmin(mDesiredDiscardLevel, mMinDesiredDiscardLevel);
+ mDesiredDiscardLevel = llmin(mDesiredDiscardLevel, (S32)mLoadedCallbackDesiredDiscardLevel);
}
mKnownDrawSizeChanged = false;
@@ -2476,6 +2468,7 @@ bool LLViewerFetchedTexture::doLoadedCallbacks()
if (mIsRawImageValid)
{
// If we have an existing raw image, we have a baseline for the raw and auxiliary quality levels.
+ current_raw_discard = mRawDiscardLevel;
best_raw_discard = llmin(best_raw_discard, mRawDiscardLevel);
best_aux_discard = llmin(best_aux_discard, mRawDiscardLevel); // We always decode the aux when we decode the base raw
current_aux_discard = llmin(current_aux_discard, best_aux_discard);
@@ -2540,6 +2533,11 @@ bool LLViewerFetchedTexture::doLoadedCallbacks()
}
}
+ if (need_readback)
+ {
+ readbackRawImage();
+ }
+
//
// Run raw/auxiliary data callbacks
//
@@ -2789,10 +2787,22 @@ void LLViewerFetchedTexture::readbackRawImage()
if (mGLTexturep.notNull() && mGLTexturep->getTexName() != 0 &&
(mRawImage.isNull() || mRawImage->getWidth() < mGLTexturep->getWidth() || mRawImage->getHeight() < mGLTexturep->getHeight() ))
{
+ if (mRawImage.isNull())
+ {
+ sRawCount++;
+ }
mRawImage = new LLImageRaw();
if (!mGLTexturep->readBackRaw(-1, mRawImage, false))
{
mRawImage = nullptr;
+ mIsRawImageValid = false;
+ mRawDiscardLevel = INVALID_DISCARD_LEVEL;
+ sRawCount--;
+ }
+ else
+ {
+ mIsRawImageValid = true;
+ mRawDiscardLevel = mGLTexturep->getDiscardLevel();
}
}
}
@@ -2917,10 +2927,12 @@ void LLViewerLODTexture::processTextureStats()
{
// If the image has not been significantly visible in a while, we don't want it
mDesiredDiscardLevel = llmin(mMinDesiredDiscardLevel, (S8)(MAX_DISCARD_LEVEL + 1));
+ mDesiredDiscardLevel = llmin(mDesiredDiscardLevel, (S32)mLoadedCallbackDesiredDiscardLevel);
}
else if (!mFullWidth || !mFullHeight)
{
mDesiredDiscardLevel = getMaxDiscardLevel();
+ mDesiredDiscardLevel = llmin(mDesiredDiscardLevel, (S32)mLoadedCallbackDesiredDiscardLevel);
}
else
{
@@ -2990,6 +3002,7 @@ void LLViewerLODTexture::processTextureStats()
// stop requesting more
mDesiredDiscardLevel = current_discard;
}
+ mDesiredDiscardLevel = llmin(mDesiredDiscardLevel, (S32)mLoadedCallbackDesiredDiscardLevel);
}
if(mForceToSaveRawImage && mDesiredSavedRawDiscardLevel >= 0)