diff options
| author | Jonathan "Geenz" Goodman <geenz@geenzo.com> | 2026-07-07 04:59:59 -0400 |
|---|---|---|
| committer | Jonathan "Geenz" Goodman <geenz@geenzo.com> | 2026-07-07 04:59:59 -0400 |
| commit | 6622a5694b5ccd1da77e1564c6475eaf81095f5b (patch) | |
| tree | 3e2e3242a3f0d81843972e253e219a3208ba325d /indra/llrender | |
| parent | 3e756b57f42e61f6aad3991c7bfa0a581c894244 (diff) | |
Get some more wins for overall downrezzing and minimizing thrashing.
Also make sure that probes don't stamp - that creates thrashing when distant probes render. We're at a low enough resolution on those things that higher mips are likely to go unnoticed, and we bake them frequently enough that we can pick up lower mips when we actually need them.
Diffstat (limited to 'indra/llrender')
| -rw-r--r-- | indra/llrender/llimagegl.cpp | 56 | ||||
| -rw-r--r-- | indra/llrender/llimagegl.h | 32 | ||||
| -rw-r--r-- | indra/llrender/llrender.cpp | 7 |
3 files changed, 82 insertions, 13 deletions
diff --git a/indra/llrender/llimagegl.cpp b/indra/llrender/llimagegl.cpp index 6bcc34938c..95575c009b 100644 --- a/indra/llrender/llimagegl.cpp +++ b/indra/llrender/llimagegl.cpp @@ -166,6 +166,8 @@ U64 LLImageGL::getTextureBytesAllocated() //statics U32 LLImageGL::sUniqueCount = 0; +std::atomic<U32> LLImageGL::sOOMErrorCount(0); +thread_local bool LLImageGL::sStampBindFrame = true; U32 LLImageGL::sBindCount = 0; S32 LLImageGL::sCount = 0; @@ -777,6 +779,7 @@ void LLImageGL::setImage(const LLImageRaw* imageraw) bool LLImageGL::setImage(const U8* data_in, bool data_hasmips /* = false */, S32 usename /* = 0 */) { LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE; + LLImageGLStampBypass no_stamp; // upload binds are not visibility const bool is_compressed = isCompressed(); @@ -1502,6 +1505,12 @@ void LLImageGL::setManualImage(U32 target, S32 miplevel, S32 intformat, S32 widt { free_cur_tex_image(); } + + // Drain stale GL errors so an OOM detected below belongs to this alloc. + // Otherwise a failed glTexImage2D is swallowed in release while + // alloc_tex_image still counts the bytes, inflating the used-VRAM figure. + while (glGetError() != GL_NO_ERROR) {} + const bool use_sub_image = should_stagger_image_set(compress); if (!use_sub_image) { @@ -1511,19 +1520,30 @@ void LLImageGL::setManualImage(U32 target, S32 miplevel, S32 intformat, S32 widt else { // break up calls to a manageable size for the GL command buffer - { - LL_PROFILE_ZONE_NAMED("glTexImage2D alloc"); - glTexImage2D(target, miplevel, intformat, width, height, 0, pixformat, pixtype, nullptr); - } + LL_PROFILE_ZONE_NAMED("glTexImage2D alloc"); + glTexImage2D(target, miplevel, intformat, width, height, 0, pixformat, pixtype, nullptr); + } - U8* src = (U8*)(pixels); - if (src) + if (glGetError() == GL_OUT_OF_MEMORY) + { + ++sOOMErrorCount; + LL_WARNS_ONCE("Texture") << "glTexImage2D failed with GL_OUT_OF_MEMORY (" + << width << "x" << height << " mip " << miplevel + << ") - not counting bytes" << LL_ENDL; + } + else + { + if (use_sub_image) { - LL_PROFILE_ZONE_NAMED("glTexImage2D copy"); - sub_image_lines(target, miplevel, 0, 0, width, height, pixformat, pixtype, src, width); + U8* src = (U8*)(pixels); + if (src) + { + LL_PROFILE_ZONE_NAMED("glTexImage2D copy"); + sub_image_lines(target, miplevel, 0, 0, width, height, pixformat, pixtype, src, width); + } } + alloc_tex_image(width, height, intformat, 1); } - alloc_tex_image(width, height, intformat, 1); } stop_glerror(); } @@ -1668,6 +1688,7 @@ bool LLImageGL::createGLTexture(S32 discard_level, const U8* data_in, bool data_ LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE; LL_PROFILE_GPU_ZONE("createGLTexture"); checkActiveThread(); + LLImageGLStampBypass no_stamp; // creation binds are not visibility bool main_thread = on_main_thread(); @@ -2090,12 +2111,21 @@ S32 LLImageGL::dimDerivedMaxDiscard(S32 width, S32 height) void LLImageGL::stampBound() const { - // Skip the store on same-frame re-binds - bindFast is per-draw and - // would dirty this cache line per bind per texture otherwise. + // Both stamps skip same-frame re-binds (bindFast runs per draw). They dedupe + // separately, so a non-camera pass touching the time stamp first doesn't stop + // a real camera bind from setting the frame stamp later the same frame. if (mLastBindTime != sLastFrameTime) { mLastBindTime = sLastFrameTime; } + if (sStampBindFrame) + { + const U32 frame = LLFrameTimer::getFrameCount(); + if (mLastBindFrame != frame) + { + mLastBindFrame = frame; + } + } } S64 LLImageGL::getBytes(S32 discard_level) const @@ -2520,6 +2550,10 @@ bool LLImageGL::scaleDown(S32 desired_discard) { LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE; + // Don't let eviction re-arm visibility: the glGenerateMipmap re-bind below + // would otherwise stamp mLastBindFrame and keep the texture fetch-eligible. + LLImageGLStampBypass no_stamp; + if (mTarget != GL_TEXTURE_2D || mFormatInternal == -1 // not initialized ) diff --git a/indra/llrender/llimagegl.h b/indra/llrender/llimagegl.h index 0869ae54fe..57ca79b3dd 100644 --- a/indra/llrender/llimagegl.h +++ b/indra/llrender/llimagegl.h @@ -39,6 +39,7 @@ #include "llrender.h" #include "threadpool.h" #include "workqueue.h" +#include <atomic> #include <unordered_set> #define LL_IMAGEGL_THREAD_CHECK 0 //set to 1 to enable thread debugging for ImageGL @@ -238,8 +239,17 @@ public: public: // Various GL/Rendering options S64Bytes mTextureMemory; - mutable F32 mLastBindTime = 0.f; // wall-clock time at last stampBound; drives the streaming cooldown - F32 mGLCreateTime = 0.f; // wall-clock time the GL texture was created; cooldown fallback for never-bound textures + mutable F32 mLastBindTime = 0.f; // wall-clock time at last stampBound (bind or bind-attempt) + mutable U32 mLastBindFrame = 0; // frame index (LLFrameTimer::getFrameCount) at last CAMERA-pass + // stampBound; 0 = never. Drives visibility GC + fetch gating. + F32 mGLCreateTime = 0.f; // wall-clock time the GL texture was created + + // When false, stampBound skips the mLastBindFrame stamp (mLastBindTime still + // updates). Set false around non-camera passes (probes, shadows, impostors) + // and administrative binds (upload, scaleDown - via LLImageGLStampBypass) so + // those binds don't count as camera visibility. Thread-local so a GL upload + // thread can't flip it on the render thread mid-frame. + static thread_local bool sStampBindFrame; private: U32 createPickMask(S32 pWidth, S32 pHeight); @@ -300,6 +310,11 @@ public: // Global memory statistics static U32 sBindCount; // Tracks number of texture binds for current frame static U32 sUniqueCount; // Tracks number of unique texture binds for current frame + // glTexImage2D GL_OUT_OF_MEMORY failures detected (bytes NOT counted for + // these). Written from whichever thread runs texture creation; read by + // the streaming 1Hz pressure log. Nonzero = the driver is refusing + // allocations and the VRAM budget is unreliable. + static std::atomic<U32> sOOMErrorCount; static bool sGlobalUseAnisotropic; static LLImageGL* sDefaultGLTexture ; static bool sAutomatedTest; @@ -355,6 +370,19 @@ public: }; +// RAII: suppress the mLastBindFrame stamp for the current scope. Use around +// administrative binds (upload, create, scaleDown) so they don't count as +// camera visibility - otherwise the GC's own scaleDown re-stamps what it just +// aged out and oscillates. Saves/restores, so it nests correctly. +class LLImageGLStampBypass +{ +public: + LLImageGLStampBypass() : mPrev(LLImageGL::sStampBindFrame) { LLImageGL::sStampBindFrame = false; } + ~LLImageGLStampBypass() { LLImageGL::sStampBindFrame = mPrev; } +private: + bool mPrev; +}; + class LLImageGLThread : public LLSimpleton<LLImageGLThread>, LL::ThreadPool { public: diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index 5e845fbcce..f0a1c44507 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -245,6 +245,11 @@ bool LLTexUnit::bind(LLTexture* texture, bool for_rendering, bool forceBind) texture->setActive() ; texture->updateBindStatsForTester() ; } + // updateBindStats only stamps time; the GC and fetch gate use + // the frame stamp, so stamp it here too or bind()-drawn faces + // (bump/material/media) oscillate. Admin/non-camera binds are + // already suppressed via LLImageGLStampBypass / sStampBindFrame. + gl_tex->stampBound(); mHasMipMaps = gl_tex->mHasMipMaps; if (gl_tex->mTexOptionsDirty) { @@ -325,6 +330,8 @@ bool LLTexUnit::bind(LLImageGL* texture, bool for_rendering, bool forceBind, S32 glBindTexture(sGLTextureType[texture->getTarget()], mCurrTexture); stop_glerror(); texture->updateBindStats(); + // Frame-stamp fresh binds too - see bind(LLTexture*) above. + texture->stampBound(); mHasMipMaps = texture->mHasMipMaps; if (texture->mTexOptionsDirty) { |
