Skip to content

Commit 1120a7c

Browse files
#3210 Fix for "Texture will be downscaled" happening too often. (#3212)
1 parent 396b97a commit 1120a7c

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

indra/newview/app_settings/settings.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7808,7 +7808,18 @@
78087808
<key>RenderLowMemMinDiscardIncrement</key>
78097809
<map>
78107810
<key>Comment</key>
7811-
<string>Minimum increment of discard level if system memory gets low</string>
7811+
<string>Minimum increment of discard bias if available texture memory gets low</string>
7812+
<key>Persist</key>
7813+
<integer>1</integer>
7814+
<key>Type</key>
7815+
<string>F32</string>
7816+
<key>Value</key>
7817+
<real>0.1</real>
7818+
</map>
7819+
<key>RenderHighMemMinDiscardDecrement</key>
7820+
<map>
7821+
<key>Comment</key>
7822+
<string>Minimum decrement of discard bias if excess texture memory is available</string>
78127823
<key>Persist</key>
78137824
<integer>1</integer>
78147825
<key>Type</key>

indra/newview/lltexturefetch.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,10 @@ bool LLTextureFetchWorker::doWork(S32 param)
17611761
mRawImage = NULL;
17621762
mAuxImage = NULL;
17631763
llassert_always(mFormattedImage.notNull());
1764-
S32 discard = mHaveAllData ? 0 : mLoadedDiscard;
1764+
1765+
// if we have the entire image data (and the image is not J2C), decode the full res image
1766+
// DO NOT decode a higher res j2c than was requested. This is a waste of time and memory.
1767+
S32 discard = mHaveAllData && mFormattedImage->getCodec() != IMG_CODEC_J2C ? 0 : mLoadedDiscard;
17651768
mDecoded = false;
17661769
setState(DECODE_IMAGE_UPDATE);
17671770
LL_DEBUGS(LOG_TXT) << mID << ": Decoding. Bytes: " << mFormattedImage->getDataSize() << " Discard: " << discard
@@ -2318,6 +2321,10 @@ void LLTextureFetchWorker::callbackDecoded(bool success, const std::string &erro
23182321
mRawImage = raw;
23192322
mAuxImage = aux;
23202323
mDecodedDiscard = mFormattedImage->getDiscardLevel();
2324+
if (mDecodedDiscard < mDesiredDiscard)
2325+
{
2326+
LL_WARNS_ONCE(LOG_TXT) << "Decoded higher resolution than requested" << LL_ENDL;
2327+
}
23212328
LL_DEBUGS(LOG_TXT) << mID << ": Decode Finished. Discard: " << mDecodedDiscard
23222329
<< " Raw Image: " << llformat("%dx%d",mRawImage->getWidth(),mRawImage->getHeight()) << LL_ENDL;
23232330
}

indra/newview/llviewertexture.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,10 @@ void LLViewerTexture::updateClass()
559559
// lower discard bias over time when free memory is available
560560
if (sDesiredDiscardBias > 1.f && over_pct < 0.f)
561561
{
562-
sDesiredDiscardBias -= gFrameIntervalSeconds * 0.01f;
562+
static LLCachedControl<F32> high_mem_discard_decrement(gSavedSettings, "RenderHighMemMinDiscardDecrement", .1f);
563+
564+
F32 decrement = high_mem_discard_decrement - llmin(over_pct, 0.f);
565+
sDesiredDiscardBias -= decrement * gFrameIntervalSeconds;
563566
}
564567
}
565568

indra/newview/llviewertexturelist.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,13 +1066,26 @@ F32 LLViewerTextureList::updateImagesCreateTextures(F32 max_time)
10661066
{
10671067
LLViewerFetchedTexture* imagep = mCreateTextureList.front();
10681068
llassert(imagep->mCreatePending);
1069-
imagep->createTexture();
1069+
1070+
// desired discard may change while an image is being decoded. If the texture in VRAM is sufficient
1071+
// for the current desired discard level, skip the texture creation. This happens more often than it probably
1072+
// should
1073+
bool redundant_load = imagep->hasGLTexture() && imagep->getDiscardLevel() <= imagep->getDesiredDiscardLevel();
1074+
1075+
if (!redundant_load)
1076+
{
1077+
imagep->createTexture();
1078+
}
1079+
10701080
imagep->postCreateTexture();
10711081
imagep->mCreatePending = false;
10721082
mCreateTextureList.pop();
10731083

10741084
if (imagep->hasGLTexture() && imagep->getDiscardLevel() < imagep->getDesiredDiscardLevel())
10751085
{
1086+
// NOTE: this may happen if the desired discard reduces while a decode is in progress and does not
1087+
// necessarily indicate a problem, but if log occurrences excede that of dsiplay_stats: FPS,
1088+
// something has probably gone wrong.
10761089
LL_WARNS_ONCE("Texture") << "Texture will be downscaled immediately after loading." << LL_ENDL;
10771090
imagep->scaleDown();
10781091
}

0 commit comments

Comments
 (0)