Skip to content

Commit 0edf6e2

Browse files
#2388 Texture downrezzing tune up. (#2414)
- Hold onto unreferenced textures for 30 seconds. - Don't downres unless memory is low - Downres when viewer is backgrounded.
1 parent 1adf2d0 commit 0edf6e2

File tree

4 files changed

+78
-26
lines changed

4 files changed

+78
-26
lines changed

indra/newview/llface.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,13 +2212,6 @@ bool LLFace::calcPixelArea(F32& cos_angle_to_view_dir, F32& radius)
22122212

22132213
F32 dist = lookAt.getLength3().getF32();
22142214
dist = llmax(dist-size.getLength3().getF32(), 0.001f);
2215-
//ramp down distance for nearby objects
2216-
if (dist < 16.f)
2217-
{
2218-
dist /= 16.f;
2219-
dist *= dist;
2220-
dist *= 16.f;
2221-
}
22222215

22232216
lookAt.normalize3fast() ;
22242217

indra/newview/llviewertexture.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,37 @@ void LLViewerTexture::updateClass()
548548

549549
was_low = is_low;
550550

551-
sDesiredDiscardBias = llclamp(sDesiredDiscardBias, 1.f, 3.f);
551+
552+
// set to max discard bias if the window has been backgrounded for a while
553+
static bool was_backgrounded = false;
554+
static LLFrameTimer backgrounded_timer;
555+
556+
bool in_background = (gViewerWindow && !gViewerWindow->getWindow()->getVisible()) || !gFocusMgr.getAppHasFocus();
557+
558+
if (in_background)
559+
{
560+
if (backgrounded_timer.getElapsedTimeF32() > 10.f)
561+
{
562+
if (!was_backgrounded)
563+
{
564+
LL_INFOS() << "Viewer is backgrounded, freeing up video memory." << LL_ENDL;
565+
}
566+
was_backgrounded = true;
567+
sDesiredDiscardBias = 4.f;
568+
}
569+
}
570+
else
571+
{
572+
backgrounded_timer.reset();
573+
if (was_backgrounded)
574+
{ // if the viewer was backgrounded
575+
LL_INFOS() << "Viewer is no longer backgrounded, resuming normal texture usage." << LL_ENDL;
576+
was_backgrounded = false;
577+
sDesiredDiscardBias = 1.f;
578+
}
579+
}
580+
581+
sDesiredDiscardBias = llclamp(sDesiredDiscardBias, 1.f, 4.f);
552582

553583
LLViewerTexture::sFreezeImageUpdates = false;
554584
}

indra/newview/llviewertexture.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ class LLViewerTexture : public LLGLTexture
146146

147147
virtual F32 getMaxVirtualSize() ;
148148

149+
LLFrameTimer* getLastReferencedTimer() { return &mLastReferencedTimer; }
150+
149151
S32 getFullWidth() const { return mFullWidth; }
150152
S32 getFullHeight() const { return mFullHeight; }
151153
/*virtual*/ void setKnownDrawSize(S32 width, S32 height);
@@ -195,6 +197,7 @@ class LLViewerTexture : public LLGLTexture
195197
mutable F32 mMaxVirtualSize = 0.f; // The largest virtual size of the image, in pixels - how much data to we need?
196198
mutable S32 mMaxVirtualSizeResetCounter;
197199
mutable S32 mMaxVirtualSizeResetInterval;
200+
LLFrameTimer mLastReferencedTimer;
198201

199202
ll_face_list_t mFaceList[LLRender::NUM_TEXTURE_CHANNELS]; //reverse pointer pointing to the faces using this image as texture
200203
U32 mNumFaces[LLRender::NUM_TEXTURE_CHANNELS];
@@ -571,10 +574,7 @@ class LLViewerMediaTexture : public LLViewerTexture
571574
/*virtual*/ void addFace(U32 ch, LLFace* facep) ;
572575
/*virtual*/ void removeFace(U32 ch, LLFace* facep) ;
573576

574-
/*virtual*/ F32 getMaxVirtualSize() ;
575-
576-
// get the timer that tracks the last time reinit was called
577-
LLFrameTimer* getLastReferencedTimer() { return &mLastReferencedTimer; }
577+
/*virtual*/ F32 getMaxVirtualSize();
578578

579579
private:
580580
void switchTexture(U32 ch, LLFace* facep) ;
@@ -596,9 +596,6 @@ class LLViewerMediaTexture : public LLViewerTexture
596596
bool mIsPlaying ;
597597
U32 mUpdateVirtualSizeTime ;
598598

599-
// tracks last time reinit was called
600-
LLFrameTimer mLastReferencedTimer;
601-
602599
public:
603600
static void updateClass() ;
604601
static void cleanUpClass() ;

indra/newview/llviewertexturelist.cpp

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -889,12 +889,9 @@ void LLViewerTextureList::updateImageDecodePriority(LLViewerFetchedTexture* imag
889889
static LLCachedControl<F32> texture_scale_min(gSavedSettings, "TextureScaleMinAreaFactor", 0.04f);
890890
static LLCachedControl<F32> texture_scale_max(gSavedSettings, "TextureScaleMaxAreaFactor", 25.f);
891891

892-
if (imagep->getType() == LLViewerTexture::LOD_TEXTURE && imagep->getBoostLevel() == LLViewerTexture::BOOST_NONE)
893-
{ // reset max virtual size for unboosted LOD_TEXTURES
894-
// this is an alternative to decaying mMaxVirtualSize over time
895-
// that keeps textures from continously downrezzing and uprezzing in the background
896-
imagep->mMaxVirtualSize = 0.f;
897-
}
892+
893+
F32 max_vsize = 0.f;
894+
bool on_screen = false;
898895

899896
LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
900897
for (U32 i = 0; i < LLRender::NUM_TEXTURE_CHANNELS; ++i)
@@ -911,6 +908,8 @@ void LLViewerTextureList::updateImageDecodePriority(LLViewerFetchedTexture* imag
911908
F32 vsize = face->getPixelArea();
912909
bool in_frustum = face->calcPixelArea(cos_angle_to_view_dir, radius);
913910

911+
on_screen = in_frustum;
912+
914913
// Scale desired texture resolution higher or lower depending on texture scale
915914
//
916915
// Minimum usage examples: a 1024x1024 texture with aplhabet, runing string
@@ -936,15 +935,40 @@ void LLViewerTextureList::updateImageDecodePriority(LLViewerFetchedTexture* imag
936935
if (apply_bias)
937936
{
938937
F32 bias = powf(4, LLViewerTexture::sDesiredDiscardBias - 1.f);
939-
bias = (F32)llround(bias);
938+
bias = (F32) llround(bias);
940939
vsize /= bias;
941940
}
942941

943-
imagep->addTextureStats(vsize);
942+
max_vsize = llmax(max_vsize, vsize);
944943
}
945944
}
946945
}
947946

947+
if (imagep->getType() == LLViewerTexture::LOD_TEXTURE && imagep->getBoostLevel() == LLViewerTexture::BOOST_NONE)
948+
{ // conditionally reset max virtual size for unboosted LOD_TEXTURES
949+
// this is an alternative to decaying mMaxVirtualSize over time
950+
// that keeps textures from continously downrezzing and uprezzing in the background
951+
952+
if (LLViewerTexture::sDesiredDiscardBias > 2.f ||
953+
(!on_screen && LLViewerTexture::sDesiredDiscardBias > 1.f))
954+
{
955+
imagep->mMaxVirtualSize = 0.f;
956+
}
957+
}
958+
959+
960+
imagep->addTextureStats(max_vsize);
961+
962+
#if 0
963+
imagep->setDebugText(llformat("%d/%d - %d/%d -- %d/%d",
964+
(S32)sqrtf(max_vsize),
965+
(S32)sqrtf(imagep->mMaxVirtualSize),
966+
imagep->getDiscardLevel(),
967+
imagep->getDesiredDiscardLevel(),
968+
imagep->getWidth(),
969+
imagep->getFullWidth()));
970+
#endif
971+
948972
// make sure to addTextureStats for any spotlights that are using this texture
949973
for (S32 vi = 0; vi < imagep->getNumVolumes(LLRender::LIGHT_TEX); ++vi)
950974
{
@@ -955,18 +979,26 @@ void LLViewerTextureList::updateImageDecodePriority(LLViewerFetchedTexture* imag
955979
F32 max_inactive_time = 20.f; // inactive time before deleting saved raw image
956980
S32 min_refs = 3; // 1 for mImageList, 1 for mUUIDMap, and 1 for "entries" in updateImagesFetchTextures
957981

982+
F32 lazy_flush_timeout = 30.f; // delete unused images after 30 seconds
983+
958984
//
959985
// Flush formatted images using a lazy flush
960986
//
961987
S32 num_refs = imagep->getNumRefs();
962988
if (num_refs <= min_refs && flush_images)
963989
{
964-
// Remove the unused image from the image list
965-
deleteImage(imagep);
966-
return;
990+
if (imagep->getLastReferencedTimer()->getElapsedTimeF32() > lazy_flush_timeout)
991+
{
992+
// Remove the unused image from the image list
993+
deleteImage(imagep);
994+
return;
995+
}
967996
}
968997
else
969998
{
999+
// still referenced outside of image list, reset timer
1000+
imagep->getLastReferencedTimer()->reset();
1001+
9701002
if (imagep->hasSavedRawImage())
9711003
{
9721004
if (imagep->getElapsedLastReferencedSavedRawImageTime() > max_inactive_time)

0 commit comments

Comments
 (0)