diff options
| author | Jonathan "Geenz" Goodman <geenz@geenzo.com> | 2026-05-29 05:29:27 -0400 |
|---|---|---|
| committer | Jonathan "Geenz" Goodman <geenz@geenzo.com> | 2026-05-29 05:29:27 -0400 |
| commit | c299c8038e73e541cafe3c8df135752cb48b903c (patch) | |
| tree | 288c2848f2f4da4bbf2c3acc500e5a29818700f9 | |
| parent | 375ade3df2930cdc6087e1b4e4c31851ed5be762 (diff) | |
Add watermark driven discards.
Does a much better job of staying within the memory budget.
| -rw-r--r-- | indra/llprimitive/lltextureentry.cpp | 15 | ||||
| -rw-r--r-- | indra/llprimitive/lltextureentry.h | 14 | ||||
| -rw-r--r-- | indra/newview/app_settings/settings.xml | 120 | ||||
| -rw-r--r-- | indra/newview/lltextureview.cpp | 6 | ||||
| -rw-r--r-- | indra/newview/llviewercontrol.cpp | 113 | ||||
| -rw-r--r-- | indra/newview/llviewertexture.cpp | 538 | ||||
| -rw-r--r-- | indra/newview/llviewertexture.h | 41 | ||||
| -rw-r--r-- | indra/newview/llviewertexturelist.cpp | 24 |
8 files changed, 458 insertions, 413 deletions
diff --git a/indra/llprimitive/lltextureentry.cpp b/indra/llprimitive/lltextureentry.cpp index ac482ffbf9..5296e86a69 100644 --- a/indra/llprimitive/lltextureentry.cpp +++ b/indra/llprimitive/lltextureentry.cpp @@ -356,6 +356,7 @@ S32 LLTextureEntry::setScale(F32 s, F32 t) { mScaleS = s; mScaleT = t; + mMinScaleSq = -1.f; // invalidate cache for getMinScaleSq() retval = TEM_CHANGE_TEXTURE; } @@ -368,6 +369,7 @@ S32 LLTextureEntry::setScaleS(F32 s) if (mScaleS != s) { mScaleS = s; + mMinScaleSq = -1.f; // invalidate cache for getMinScaleSq() retval = TEM_CHANGE_TEXTURE; } return retval; @@ -379,11 +381,22 @@ S32 LLTextureEntry::setScaleT(F32 t) if (mScaleT != t) { mScaleT = t; + mMinScaleSq = -1.f; // invalidate cache for getMinScaleSq() retval = TEM_CHANGE_TEXTURE; } return retval; } +F32 LLTextureEntry::getMinScaleSq() const +{ + if (mMinScaleSq < 0.f) + { + F32 m = llmin(fabsf(mScaleS), fabsf(mScaleT)); + mMinScaleSq = m * m; + } + return mMinScaleSq; +} + S32 LLTextureEntry::setColor(const LLColor4 &color) { if (mColor != color) @@ -600,7 +613,7 @@ LLGLTFMaterial* LLTextureEntry::getGLTFRenderMaterial() const return mGLTFRenderMaterial; } - llassert(getGLTFMaterialOverride() == nullptr || getGLTFMaterialOverride()->isClearedForBaseMaterial()); + //llassert(getGLTFMaterialOverride() == nullptr || getGLTFMaterialOverride()->isClearedForBaseMaterial()); return getGLTFMaterial(); } diff --git a/indra/llprimitive/lltextureentry.h b/indra/llprimitive/lltextureentry.h index 78c61b4d65..765a5f5fdc 100644 --- a/indra/llprimitive/lltextureentry.h +++ b/indra/llprimitive/lltextureentry.h @@ -143,6 +143,13 @@ public: F32 getScaleS() const { return mScaleS; } F32 getScaleT() const { return mScaleT; } + // Cached min(|mScaleS|, |mScaleT|)^2, lazily computed and invalidated + // in setScale/setScaleS/setScaleT. Used by the texture streaming face + // loop (updateImageDecodePriority) to avoid the per-face per-frame + // sqrt/abs/min/multiply chain. Returns the raw (unclamped) value; + // callers still apply TextureScaleMin/MaxAreaFactor clamps. + F32 getMinScaleSq() const; + void getOffset(F32 *s, F32 *t) const { *s = mOffsetS; *t = mOffsetT; } F32 getOffsetS() const { return mOffsetS; } F32 getOffsetT() const { return mOffsetT; } @@ -218,6 +225,13 @@ public: F32 mOffsetT; // S, T offset F32 mRotation; // anti-clockwise rotation in rad about the bottom left corner +private: + // Cache for getMinScaleSq(). -1.f sentinel = stale. Invalidated by + // setScale/setScaleS/setScaleT. Mutable so getMinScaleSq() can fill it + // on first read without breaking const correctness for read-only callers. + mutable F32 mMinScaleSq = -1.f; +public: + static const LLTextureEntry null; // LLSD key defines diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index e4f5f0b6d4..6e25d2e835 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -8060,7 +8060,7 @@ <key>RenderTextureQuality</key> <map> <key>Comment</key> - <string>Texture quality preset: 0=Low, 1=Medium, 2=High, 3=Ultra. Drives RenderMaxTextureResolution, the four TextureChannel* exponents, TextureDistanceDiscardPower, and TextureScreenSizeOversample.</string> + <string>Texture quality preset: 0=Low, 1=Medium, 2=High, 3=Ultra. Drives RenderMaxTextureResolution, TextureDiscardBiasMax, TextureCloseBubbleMeters/MinMeters/ShrinkThreshold, TextureChannelOffset* (four), TexturePressureDiscardScale, TextureMinCapPressureRelaxScale, TextureUpdateCountPressureMaxMultiplier, TextureScreenSizeOversample/UnderPressure, TextureAgentAvatarOversampleMultiplier, TextureBackgroundFactorRatePerSec, TextureDiscardBackgroundedTime. Watermarks (TextureWatermarkHigh/Low) are constant across tiers.</string> <key>Persist</key> <integer>1</integer> <key>Type</key> @@ -11871,49 +11871,49 @@ <key>Value</key> <real>20.0</real> </map> - <key>TextureChannelNormal</key> + <key>TextureChannelOffsetNormal</key> <map> <key>Comment</key> - <string>Per-channel discard exponent for normal maps. 1.0 = baseline; lower = more aggressive. Driven by the RenderTextureQuality preset.</string> + <string>Additive discard offset for normal maps (integer mip levels). 0 = no shift; positive = N more discard levels (worse quality). Driven by the RenderTextureQuality preset.</string> <key>Persist</key> <integer>1</integer> <key>Type</key> - <string>F32</string> + <string>S32</string> <key>Value</key> - <real>1.0</real> + <integer>0</integer> </map> - <key>TextureChannelBaseColor</key> + <key>TextureChannelOffsetBaseColor</key> <map> <key>Comment</key> - <string>Per-channel discard exponent for base color / diffuse. 1.0 = baseline; lower = more aggressive. Driven by the RenderTextureQuality preset.</string> + <string>Additive discard offset for base color / diffuse (integer mip levels). 0 = no shift; positive = N more discard levels. Driven by the RenderTextureQuality preset.</string> <key>Persist</key> <integer>1</integer> <key>Type</key> - <string>F32</string> + <string>S32</string> <key>Value</key> - <real>0.75</real> + <integer>0</integer> </map> - <key>TextureChannelSpecular</key> + <key>TextureChannelOffsetSpecular</key> <map> <key>Comment</key> - <string>Per-channel discard exponent for specular / metallic-roughness. 1.0 = baseline; lower = more aggressive. Driven by the RenderTextureQuality preset.</string> + <string>Additive discard offset for specular / metallic-roughness (integer mip levels). Higher = more aggressive (specular detail is usually less perceptible than diffuse). Driven by the RenderTextureQuality preset.</string> <key>Persist</key> <integer>1</integer> <key>Type</key> - <string>F32</string> + <string>S32</string> <key>Value</key> - <real>0.5</real> + <integer>1</integer> </map> - <key>TextureChannelEmissive</key> + <key>TextureChannelOffsetEmissive</key> <map> <key>Comment</key> - <string>Per-channel discard exponent for emissive. 1.0 = baseline; lower = more aggressive. Driven by the RenderTextureQuality preset.</string> + <string>Additive discard offset for emissive (integer mip levels). Higher = more aggressive. Driven by the RenderTextureQuality preset.</string> <key>Persist</key> <integer>1</integer> <key>Type</key> - <string>F32</string> + <string>S32</string> <key>Value</key> - <real>0.75</real> + <integer>1</integer> </map> <key>TextureMaxDiscardOverride</key> <map> @@ -11926,104 +11926,104 @@ <key>Value</key> <integer>0</integer> </map> - <key>TextureMemoryHighWaterMark</key> + <key>TextureWatermarkHigh</key> <map> <key>Comment</key> - <string>Fraction of budget (0..1) at which the pressure controller bypasses smoothing and slams to cap. Last-ditch min-discard also creeps without waiting for mult_progress.</string> + <string>High watermark as a fraction of the VRAM budget. When used VRAM crosses this, the global discard bias climbs (backs off detail). Held at 0.90 across quality tiers - it's a physical "crossed the budget" threshold, not a tier preference.</string> <key>Persist</key> <integer>1</integer> <key>Type</key> <string>F32</string> <key>Value</key> - <real>0.8</real> + <real>0.90</real> </map> - <key>TextureMemoryPressureBackoffStart</key> + <key>TextureWatermarkLow</key> <map> <key>Comment</key> - <string>Fraction of the VRAM target at which the pressure ramp starts (0..1). Lower = earlier headroom-building; 1.0 disables backoff (ramp only above target).</string> + <string>Low watermark as a fraction of the VRAM budget. When used VRAM drops below this, the global discard bias relaxes (restores detail). The band between low and high is the hysteresis zone where the bias holds steady - wide enough to prevent sawtooth without prediction/smoothing.</string> <key>Persist</key> <integer>1</integer> <key>Type</key> <string>F32</string> <key>Value</key> - <real>0.85</real> + <real>0.70</real> </map> - <key>TextureMemoryPressureMaxMultiplier</key> + <key>TextureDiscardBiasMax</key> <map> <key>Comment</key> - <string>Upper bound on the VRAM-pressure distance multiplier (>= 1). Mostly defensive -- at mult=64 the streaming ramp collapses to ~ramp_range/64, already extreme. Higher allows even more aggressive compression in tight-budget scenes.</string> + <string>Upper bound on the watermark-driven global discard bias. Caps how steep the distance-floor ramp can get under sustained pressure: at the cap with TexturePressureDiscardScale=1.0 the floor forces max discard at ~1/(1+max) of draw distance. Also the denominator for getMemoryPressureProgress.</string> <key>Persist</key> <integer>1</integer> <key>Type</key> <string>F32</string> <key>Value</key> - <real>64.0</real> + <real>12.0</real> </map> - <key>TextureLastDitchEngageProgress</key> + <key>TextureDiscardBiasRampRate</key> <map> <key>Comment</key> - <string>mult_progress (0..1) at which the last-ditch floor starts creeping up. The floor only advances when mult is at or above this fraction of its cap AND prediction is still over budget. Decays back toward 0 whenever prediction is under budget.</string> + <string>Rate (bias units/sec) at which the global discard bias climbs while used VRAM is above the high watermark. Deliberately slow so eviction (scaleDown draining) catches up before the next step - prevents over-shoot / thrash.</string> <key>Persist</key> <integer>1</integer> <key>Type</key> <string>F32</string> <key>Value</key> - <real>0.95</real> + <real>2.0</real> </map> - <key>TextureLastDitchRampRate</key> + <key>TextureDiscardBiasDecayRate</key> <map> <key>Comment</key> - <string>Rate (discard levels/sec) at which sLastDitchMinDiscard creeps up while engaged. 0.5 = takes ~2 sec to add one discard level. Mirrors sDesiredDiscardBias ramp shape.</string> + <string>Rate (bias units/sec) at which the global discard bias relaxes while used VRAM is below the low watermark. Typically slower than the ramp so detail returns gradually as headroom appears.</string> <key>Persist</key> <integer>1</integer> <key>Type</key> <string>F32</string> <key>Value</key> - <real>0.5</real> + <real>1.0</real> </map> - <key>TextureLastDitchDecayRate</key> + <key>TexturePressureDiscardScale</key> <map> <key>Comment</key> - <string>Rate (discard levels/sec) at which sLastDitchMinDiscard decays back to 0 when prediction is under budget.</string> + <string>Modulates the distance-floor pressure response. compression = 1 + sDiscardBias * scale; the floor forces max discard at ~1/compression of draw distance. At scale=1.0 with bias=12, max discard is forced at ~8% of draw distance; higher scale = steeper / closer. Driven by the RenderTextureQuality preset.</string> <key>Persist</key> <integer>1</integer> <key>Type</key> <string>F32</string> <key>Value</key> - <real>0.5</real> + <real>1.0</real> </map> - <key>TextureLastDitchMinDiscardMax</key> + <key>TextureMinCapPressureRelaxScale</key> <map> <key>Comment</key> - <string>Hard ceiling on sLastDitchMinDiscard. At 13 the floor can climb all the way to the deepest meaningful mip; lower values cap how aggressive the last-ditch escalation can get before we are simply out of discards.</string> + <string>Modulates the relaxation of mMinDesiredDiscardLevel under pressure. add = floor(progress * room * scale), where room is the gap to max discard and progress is sDiscardBias/TextureDiscardBiasMax. At 0 disables relaxation entirely.</string> <key>Persist</key> <integer>1</integer> <key>Type</key> <string>F32</string> <key>Value</key> - <real>13.0</real> + <real>1.0</real> </map> - <key>TextureMemoryPressurePredictionGain</key> + <key>TextureUpdateCountPressureMaxMultiplier</key> <map> <key>Comment</key> - <string>Power exponent mapping predicted-over-budget ratio to target multiplier. target_mult = pred_over^gain. Higher gain saturates faster.</string> + <string>Hard cap on per-frame update_count scale-up factor in updateImagesFetchTextures under pressure. Replaces unbounded max(bias, mult) blow-up. At default 6, the full-list sweep takes at minimum mUUIDMap.size()/6 frames per round-trip under high pressure - bounded CPU cost even at peak.</string> <key>Persist</key> <integer>1</integer> <key>Type</key> <string>F32</string> <key>Value</key> - <real>10.0</real> + <real>6.0</real> </map> - <key>TextureMemoryPressureSmoothingRate</key> + <key>TextureFetchBiasTrackRate</key> <map> <key>Comment</key> - <string>Lerp rate (1/sec) at which the pressure multiplier converges to its prediction-driven target. Higher = faster response, lower = smoother. Default 4 reaches ~63% in 0.25s.</string> + <string>First-order low-pass rate for the fetch-pressure bias contribution (1/sec). The bias floor decays independently of VRAM headroom, so queue-driven bias releases naturally as fetches drain. Default ~1s convergence.</string> <key>Persist</key> <integer>1</integer> <key>Type</key> <string>F32</string> <key>Value</key> - <real>4.0</real> + <real>1.0</real> </map> <key>TextureTerrainDistanceFloor</key> <map> @@ -12047,16 +12047,16 @@ <key>Value</key> <real>0.99</real> </map> - <key>TextureAgentAvatarBoost</key> + <key>TextureAgentAvatarOversampleMultiplier</key> <map> <key>Comment</key> - <string>Quality boost (0..1) for textures on the agent's avatar (rigged mesh / animated objects). Lower = higher quality. Preference, not exemption - pressure can still evict.</string> + <string>Oversample multiplier for textures on the agent's avatar (rigged mesh / animated objects). 1.0 = no boost; 2.0 = 4x texels per pixel = exactly -1 discard level. Preference, not exemption - pressure can still evict via the distance floor.</string> <key>Persist</key> <integer>1</integer> <key>Type</key> <string>F32</string> <key>Value</key> - <real>0.5</real> + <real>2.0</real> </map> <key>TextureBackgroundFactorRatePerSec</key> <map> @@ -12095,7 +12095,7 @@ <key>TextureCloseBubbleMinMeters</key> <map> <key>Comment</key> - <string>Floor (meters) for the close-camera bubble under maximum VRAM pressure. At sMemoryPressureMultiplier = TextureMemoryPressureMaxMultiplier the bubble collapses to this value, allowing eviction of even close textures when nothing else fits.</string> + <string>Floor (meters) for the close-camera bubble under maximum VRAM pressure. As the discard bias approaches TextureDiscardBiasMax the bubble collapses toward this value, allowing eviction of even close textures when nothing else fits.</string> <key>Persist</key> <integer>1</integer> <key>Type</key> @@ -12125,28 +12125,6 @@ <key>Value</key> <real>0.5</real> </map> - <key>TextureDistanceDiscardPower</key> - <map> - <key>Comment</key> - <string>Exponent on the distance factor (face_distance / draw_distance). 1.0 = linear; lower = textures hit max discard sooner with distance. Default 0.5 = sqrt.</string> - <key>Persist</key> - <integer>1</integer> - <key>Type</key> - <string>F32</string> - <key>Value</key> - <real>0.5</real> - </map> - <key>TextureSizeDiscardPower</key> - <map> - <key>Comment</key> - <string>Exponent on the on-screen size factor (1 - coverage). 1.0 = linear; lower = small-on-screen textures attenuate sooner.</string> - <key>Persist</key> - <integer>1</integer> - <key>Type</key> - <string>F32</string> - <key>Value</key> - <real>1.0</real> - </map> <key>TextureScreenSizeOversample</key> <map> <key>Comment</key> @@ -12161,7 +12139,7 @@ <key>TextureScreenSizeOversampleUnderPressure</key> <map> <key>Comment</key> - <string>Floor that TextureScreenSizeOversample collapses toward as the pressure multiplier walks up. Pinned to this value above TextureMemoryHighWaterMark. Lower = allow distant textures to drop below their on-screen contribution under pressure.</string> + <string>Floor that TextureScreenSizeOversample collapses toward as the discard bias walks up toward TextureDiscardBiasMax. Lower = allow distant textures to drop below their on-screen contribution under pressure.</string> <key>Persist</key> <integer>1</integer> <key>Type</key> diff --git a/indra/newview/lltextureview.cpp b/indra/newview/lltextureview.cpp index 4534db958f..1cc26896b1 100644 --- a/indra/newview/lltextureview.cpp +++ b/indra/newview/lltextureview.cpp @@ -572,13 +572,13 @@ void LLGLTexMemBar::draw() LLFontGL::getFontMonospace()->renderUTF8(text, 0, 0, v_offset + line_height*8, text_color, LLFontGL::LEFT, LLFontGL::TOP); - text = llformat("Images: %d Raw: %d (%.2f MB) Saved: %d (%.2f MB) Aux: %d (%.2f MB) Bubble: %.1fm PressMult: %.1fx LDMin: %.1f", + text = llformat("Images: %d Raw: %d (%.2f MB) Saved: %d (%.2f MB) Aux: %d (%.2f MB) Bubble: %.1fm DiscardBias: %.2f Progress: %.2f", image_count, raw_image_count, raw_image_bytes_MB, saved_raw_image_count, saved_raw_image_bytes_MB, aux_raw_image_count, aux_raw_image_bytes_MB, LLViewerTextureList::sCurrentBubbleMeters, - LLViewerTexture::sMemoryPressureMultiplier, - LLViewerTexture::sLastDitchMinDiscard); + LLViewerTexture::sDiscardBias, + LLViewerTexture::getMemoryPressureProgress()); LLFontGL::getFontMonospace()->renderUTF8(text, 0, 0, v_offset + line_height * 7, text_color, LLFontGL::LEFT, LLFontGL::TOP); diff --git a/indra/newview/llviewercontrol.cpp b/indra/newview/llviewercontrol.cpp index bb868b950b..19c28b12f1 100644 --- a/indra/newview/llviewercontrol.cpp +++ b/indra/newview/llviewercontrol.cpp @@ -112,51 +112,80 @@ static bool handleRenderAvatarMouselookChanged(const LLSD& newvalue) return true; } +// Per-tier texture quality preset. Data-driven so adding a setting is +// "add a column", and the tier values are visible side-by-side. Index is +// RenderTextureQuality: 0=Low, 1=Medium, 2=High, 3=Ultra. +namespace +{ + struct TexturePreset + { + const char* name; + U32 max_resolution; + F32 discard_bias_max; // TextureDiscardBiasMax: ceiling on the watermark bias + F32 close_bubble_meters; + F32 close_bubble_min_meters; + F32 close_bubble_shrink_threshold; + F32 screen_size_oversample; + F32 screen_size_oversample_under_pressure; + F32 background_factor_rate_per_sec; + F32 discard_backgrounded_time; + F32 pressure_discard_scale; + F32 min_cap_relax_scale; + F32 update_count_max_mult; + F32 avatar_oversample_mult; + S32 channel_off_normal; + S32 channel_off_basecolor; + S32 channel_off_specular; + S32 channel_off_emissive; + }; + + // Tier values: Low (2-4GB), Medium (4-8GB), High (8-16GB), Ultra (16+GB). + // Pressure-aggression ladder: Low burns hot, Ultra barely sweats. + // + // The watermarks (TextureWatermarkHigh/Low) are NOT tiered - they're a + // physical "crossed the budget" threshold (0.90 / 0.70), constant across + // tiers. Tier aggression is expressed via discard_bias_max (how steep the + // ramp can get) and pressure_discard_scale (how fast it steepens). At the + // cap, compression = 1 + bias_max*scale; the floor forces max discard at + // ~1/compression of draw distance: + // Low: 1+16*1.5 = 25 -> ~4% of draw distance + // Medium: 1+12*1.2 = 15 -> ~7% + // High: 1+10*1.0 = 11 -> ~9% + // Ultra: 1+ 8*0.75 = 7 -> ~14% (the old "mult 8" feel) + // max_res biasMax bub bub_min sh_th oS oSp bgRt bgT pScl relax uMul avO N BC S E + static constexpr TexturePreset TEXTURE_PRESETS[4] = { + /* 0 Low */ { "Low", 1024, 16.0f, 3.0f, 0.0f, 0.70f, 0.75f, 0.50f, 0.020f, 30.0f, 1.5f, 1.5f, 8.0f, 1.5f, 7, 0, 4, 1 }, + /* 1 Medium */ { "Medium", 2048, 12.0f, 5.0f, 1.0f, 0.80f, 1.00f, 0.50f, 0.011f, 60.0f, 1.2f, 1.2f, 6.0f, 1.75f, 0, 0, 1, 1 }, + /* 2 High */ { "High", 2048, 10.0f, 8.0f, 2.0f, 0.90f, 1.50f, 0.75f, 0.005f, 120.0f, 1.0f, 1.0f, 4.0f, 2.0f, 0, 0, 1, 0 }, + /* 3 Ultra */ { "Ultra", 2048, 8.0f, 12.0f, 4.0f, 0.95f, 2.00f, 1.00f, 0.002f, 300.0f, 0.75f, 0.75f, 2.0f, 2.0f, 0, 0, 0, 0 }, + }; +} + static bool handleRenderTextureQualityChanged(const LLSD& newvalue) { - // 0=Low, 1=Medium, 2=High, 3=Ultra. Drives RenderMaxTextureResolution, - // the four TextureChannel* exponents (Normal/BaseColor/Spec/Emissive), - // and TextureDistanceDiscardPower. U32 quality = (U32)newvalue.asInteger(); - U32 max_res = 2048; - F32 ch_normal = 1.0f; - F32 ch_basecolor = 0.75f; - F32 ch_specular = 0.5f; - F32 ch_emissive = 0.75f; - F32 distance_power = 0.5f; - F32 screen_oversample = 1.5f; - switch (quality) - { - case 0: // Low - max_res = 1024; - ch_normal = 0.5f; ch_basecolor = 0.75f; ch_specular = 0.1f; ch_emissive = 0.5f; - distance_power = 0.15f; - screen_oversample = 0.75f; - break; - case 1: // Medium - ch_normal = 0.75f; ch_basecolor = 0.75f; ch_specular = 0.3f; ch_emissive = 0.75f; - distance_power = 0.25f; - screen_oversample = 1.0f; - break; - case 2: // High - // channel defaults above - distance_power = 0.35f; - screen_oversample = 1.5f; - break; - case 3: // Ultra - default: - ch_normal = 1.f; ch_basecolor = 1.f; ch_specular = 1.f; ch_emissive = 1.f; - distance_power = 0.5f; - screen_oversample = 2.0f; - break; - } - gSavedSettings.setU32("RenderMaxTextureResolution", max_res); - gSavedSettings.setF32("TextureChannelNormal", ch_normal); - gSavedSettings.setF32("TextureChannelBaseColor", ch_basecolor); - gSavedSettings.setF32("TextureChannelSpecular", ch_specular); - gSavedSettings.setF32("TextureChannelEmissive", ch_emissive); - gSavedSettings.setF32("TextureDistanceDiscardPower", distance_power); - gSavedSettings.setF32("TextureScreenSizeOversample", screen_oversample); + if (quality > 3) quality = 3; + const TexturePreset& p = TEXTURE_PRESETS[quality]; + + gSavedSettings.setU32("RenderMaxTextureResolution", p.max_resolution); + gSavedSettings.setF32("TextureDiscardBiasMax", p.discard_bias_max); + gSavedSettings.setF32("TextureCloseBubbleMeters", p.close_bubble_meters); + gSavedSettings.setF32("TextureCloseBubbleMinMeters", p.close_bubble_min_meters); + gSavedSettings.setF32("TextureCloseBubbleShrinkThreshold", p.close_bubble_shrink_threshold); + gSavedSettings.setF32("TextureScreenSizeOversample", p.screen_size_oversample); + gSavedSettings.setF32("TextureScreenSizeOversampleUnderPressure", p.screen_size_oversample_under_pressure); + gSavedSettings.setF32("TextureBackgroundFactorRatePerSec", p.background_factor_rate_per_sec); + gSavedSettings.setF32("TextureDiscardBackgroundedTime", p.discard_backgrounded_time); + gSavedSettings.setF32("TexturePressureDiscardScale", p.pressure_discard_scale); + gSavedSettings.setF32("TextureMinCapPressureRelaxScale", p.min_cap_relax_scale); + gSavedSettings.setF32("TextureUpdateCountPressureMaxMultiplier", p.update_count_max_mult); + gSavedSettings.setF32("TextureAgentAvatarOversampleMultiplier", p.avatar_oversample_mult); + gSavedSettings.setS32("TextureChannelOffsetNormal", p.channel_off_normal); + gSavedSettings.setS32("TextureChannelOffsetBaseColor", p.channel_off_basecolor); + gSavedSettings.setS32("TextureChannelOffsetSpecular", p.channel_off_specular); + gSavedSettings.setS32("TextureChannelOffsetEmissive", p.channel_off_emissive); + + LL_INFOS("TextureStream") << "Applied texture quality preset: " << p.name << LL_ENDL; return true; } diff --git a/indra/newview/llviewertexture.cpp b/indra/newview/llviewertexture.cpp index fa29ffdf2d..c2cdd54910 100644 --- a/indra/newview/llviewertexture.cpp +++ b/indra/newview/llviewertexture.cpp @@ -88,15 +88,14 @@ S32 LLViewerTexture::sAuxCount = 0; LLFrameTimer LLViewerTexture::sEvaluationTimer; F32 LLViewerTexture::sDesiredDiscardBias = 0.f; F32 LLViewerTexture::sBackgroundFactor = 0.f; -F32 LLViewerTexture::sMemoryPressureMultiplier = 1.f; -F32 LLViewerTexture::sLastDitchMinDiscard = 0.f; +F32 LLViewerTexture::sDiscardBias = 0.f; //static F32 LLViewerTexture::getMemoryPressureProgress() { - static LLCachedControl<F32> max_mult(gSavedSettings, "TextureMemoryPressureMaxMultiplier", 64.f); - F32 cap = llmax((F32)max_mult, 1.0001f); - return llclampf((sMemoryPressureMultiplier - 1.f) / (cap - 1.f)); + static LLCachedControl<F32> bias_max(gSavedSettings, "TextureDiscardBiasMax", 12.f); + F32 cap = llmax((F32)bias_max, 0.0001f); + return llclampf(sDiscardBias / cap); } // Effective oversample factor for the per-texture pixel-area discard cap. @@ -556,128 +555,56 @@ void LLViewerTexture::updateClass() F32 over_pct = (used - target) / target; - // Predicted-VRAM pressure controller. Eviction is fast, refetch is slow, - // so feedback on instantaneous `used` sawtooths; feeding `used + - // in_flight_delta` lets mult converge to equilibrium instead of cycling. + // Watermark-driven discard-bias controller. One clean signal: the bias + // climbs while used VRAM is above the high watermark, relaxes below the + // low watermark, and holds steady in the hysteresis band between. The + // band is what prevents sawtooth - no prediction scan or smoothing + // needed (the prediction apparatus existed only to damp the old + // multiplier's oscillation). The dt-based ramp is deliberately slow so + // eviction (scaleDown draining mDownScaleQueue) has time to actually + // free bytes before the next step, matching the id/Granite "back off + // without thrashing" pattern. Subsumes the old last-ditch floor: when + // the bias saturates, the distance-weighted floor in processTextureStats + // forces everything outside the bubble to its deepest mip. { - static LLCachedControl<F32> backoff_start(gSavedSettings, "TextureMemoryPressureBackoffStart", 0.85f); - static LLCachedControl<F32> max_mult(gSavedSettings, "TextureMemoryPressureMaxMultiplier", 64.f); - static LLCachedControl<F32> prediction_gain(gSavedSettings, "TextureMemoryPressurePredictionGain", 10.f); - static LLCachedControl<F32> smoothing_rate(gSavedSettings, "TextureMemoryPressureSmoothingRate", 4.f); + static LLCachedControl<F32> wm_high(gSavedSettings, "TextureWatermarkHigh", 0.90f); + static LLCachedControl<F32> wm_low(gSavedSettings, "TextureWatermarkLow", 0.70f); + static LLCachedControl<F32> bias_max(gSavedSettings, "TextureDiscardBiasMax", 12.f); + static LLCachedControl<F32> bias_ramp(gSavedSettings, "TextureDiscardBiasRampRate", 2.0f); + static LLCachedControl<F32> bias_decay(gSavedSettings, "TextureDiscardBiasDecayRate", 1.0f); - F32 backoff_target = target * llclamp((F32)backoff_start, 0.05f, 1.f); - F32 cap = llmax((F32)max_mult, 1.0001f); - F32 dt = (F32)gFrameIntervalSeconds; - - // Skip the full-list iteration when there is no pressure to react to: - // mult already at baseline, last-ditch at zero, and used well clear of - // the backoff target. Worst case the controller picks up the spike one - // frame later, from `used` alone. - bool need_predict = sMemoryPressureMultiplier > 1.001f - || sLastDitchMinDiscard > 0.f - || used > backoff_target * 0.5f; - - S64 pending_bytes_increase = 0; - S64 pending_bytes_decrease = 0; - if (need_predict) - { - LL_PROFILE_ZONE_NAMED_CATEGORY_TEXTURE("vt - in-flight predict"); - for (auto& imagep : gTextureList) - { - if (imagep.isNull()) continue; - // Cheap inline checks first so the virtual getDiscardLevel() - // call only fires when there is a real chance of contribution. - S32 desired = imagep->getDesiredDiscardLevel(); - if (desired < 0) continue; - S32 fw = imagep->getFullWidth(); - S32 fh = imagep->getFullHeight(); - if (fw <= 0 || fh <= 0) continue; - S32 current = imagep->getDiscardLevel(); - if (current < 0 || desired == current) continue; - - S32 wd = llmax(1, fw >> desired); - S32 hd = llmax(1, fh >> desired); - S32 wc = llmax(1, fw >> current); - S32 hc = llmax(1, fh >> current); - // bpp=4, mip pyramid overhead 4/3 - S64 size_d = (S64)wd * hd * 4 * 4 / 3; - S64 size_c = (S64)wc * hc * 4 * 4 / 3; - - if (desired < current) - pending_bytes_increase += (size_d - size_c); - else - pending_bytes_decrease += (size_c - size_d); - } - } - - // 1024 * 512 = 524288: matches the unit reduction at line 513. - constexpr F32 BYTES_TO_USED_UNITS = 1.f / 524288.f; - F32 predicted_used = used - + (F32)pending_bytes_increase * BYTES_TO_USED_UNITS - - (F32)pending_bytes_decrease * BYTES_TO_USED_UNITS; - F32 predicted_over = predicted_used / llmax(backoff_target, 1.f); + F32 high_frac = llclamp((F32)wm_high, 0.1f, 1.f); + F32 low_frac = llclamp((F32)wm_low, 0.05f, high_frac); + F32 high = budget * high_frac; + F32 low = budget * low_frac; + F32 cap = llmax((F32)bias_max, 0.f); + F32 dt = (F32)gFrameIntervalSeconds; - // High water mark: when used crosses budget * high_water, skip the - // smoothed convergence and slam the controller into hard-cap state. - // Recovers the historical 90% behavior - immediate aggressive - // response instead of waiting for the lerp to chase the target. - static LLCachedControl<F32> high_water(gSavedSettings, "TextureMemoryHighWaterMark", 0.8f); - bool above_high_water = used >= budget * llclamp((F32)high_water, 0.5f, 1.f); - - F32 target_mult = llclamp(powf(llmax(predicted_over, 1.f), llmax((F32)prediction_gain, 0.0001f)), 1.f, cap); - if (above_high_water) + if (used > high) { - target_mult = cap; - sMemoryPressureMultiplier = cap; + sDiscardBias += llmax((F32)bias_ramp, 0.f) * dt; } - else + else if (used < low) { - // ~63% convergence in 1/smoothing_rate seconds (default 0.25s). - F32 alpha = 1.f - expf(-llmax(dt, 0.f) * llmax((F32)smoothing_rate, 0.f)); - sMemoryPressureMultiplier += (target_mult - sMemoryPressureMultiplier) * alpha; - } - sMemoryPressureMultiplier = llclamp(sMemoryPressureMultiplier, 1.f, cap); - - F32 progress = getMemoryPressureProgress(); - - { - static LLCachedControl<F32> ld_engage(gSavedSettings, "TextureLastDitchEngageProgress", 0.95f); - static LLCachedControl<F32> ld_ramp(gSavedSettings, "TextureLastDitchRampRate", 0.5f); - static LLCachedControl<F32> ld_decay(gSavedSettings, "TextureLastDitchDecayRate", 0.5f); - static LLCachedControl<F32> ld_max(gSavedSettings, "TextureLastDitchMinDiscardMax", 13.f); - // Above the high water mark, last-ditch creeps regardless of - // mult_progress: by definition we are out of normal headroom. - bool engage = above_high_water || progress >= llclampf((F32)ld_engage); - if (engage && predicted_over > 1.f) - { - sLastDitchMinDiscard += llmax((F32)ld_ramp, 0.f) * dt; - } - else if (!above_high_water && predicted_over < 1.f) - { - sLastDitchMinDiscard -= llmax((F32)ld_decay, 0.f) * dt; - } - sLastDitchMinDiscard = llclamp(sLastDitchMinDiscard, 0.f, llmax((F32)ld_max, 0.f)); + sDiscardBias -= llmax((F32)bias_decay, 0.f) * dt; } + // In the hysteresis band [low, high]: hold steady. + sDiscardBias = llclamp(sDiscardBias, 0.f, cap); // 1 Hz pressure log. static LLFrameTimer s_pressure_log_timer; if (s_pressure_log_timer.getElapsedTimeF32() > 1.f) { s_pressure_log_timer.reset(); - F32 over = used / llmax(backoff_target, 1.f); LL_INFOS("TextureStream") << "pressure" - << " mult=" << sMemoryPressureMultiplier - << " target_mult=" << target_mult - << " progress=" << progress + << " discard_bias=" << sDiscardBias + << " progress=" << getMemoryPressureProgress() << " used=" << used - << " predicted=" << predicted_used - << " target=" << target - << " over=" << over - << " pred_over=" << predicted_over - << " in+=" << (S32)(pending_bytes_increase / 1024 / 1024) - << "MB in-=" << (S32)(pending_bytes_decrease / 1024 / 1024) - << "MB bias=" << sDesiredDiscardBias - << " ldmin=" << sLastDitchMinDiscard + << " budget=" << budget + << " high=" << high + << " low=" << low + << " over_pct=" << over_pct + << " legacy_bias=" << sDesiredDiscardBias << " dsq=" << (S32)gTextureList.mDownScaleQueue.size() << LL_ENDL; } @@ -802,17 +729,23 @@ void LLViewerTexture::updateClass() } } - // Fetch-queue depth as a one-way bias floor (decay path still drops - // bias when the queue drains). Pushes bias up before VRAM overflows - // during teleport/scene-change floods. + // Fetch-queue depth as a smoothed bias floor. First-order low-pass so the + // contribution decays naturally as the queue drains - the old one-way max + // floor would latch bias high in busy regions even after VRAM came back + // (the unrelated bias-decay path required VRAM-comfortable AND no eviction + // in flight, which often never coincided during sustained fetch floods). + static F32 s_fetch_bias = 0.f; if (LLTextureFetch* fetcher = LLAppViewer::getTextureFetch()) { - S32 pending = fetcher->getNumRequests(); static LLCachedControl<F32> fetch_pressure_scale(gSavedSettings, "TextureFetchPressureScale", 1000.f); + static LLCachedControl<F32> fetch_bias_track_rate(gSavedSettings, "TextureFetchBiasTrackRate", 1.0f); F32 scale = llmax((F32)fetch_pressure_scale, 1.f); - F32 fetch_pressure = llclamp((F32)pending / scale, 0.f, 3.f); - sDesiredDiscardBias = llmax(sDesiredDiscardBias, 1.f + fetch_pressure); + F32 target = llclamp((F32)fetcher->getNumRequests() / scale, 0.f, 3.f); + F32 dt = (F32)gFrameIntervalSeconds; + F32 alpha = 1.f - expf(-llmax(dt, 0.f) * llmax((F32)fetch_bias_track_rate, 0.f)); + s_fetch_bias += (target - s_fetch_bias) * alpha; } + sDesiredDiscardBias = llmax(sDesiredDiscardBias, 1.f + s_fetch_bias); sDesiredDiscardBias = llclamp(sDesiredDiscardBias, 1.f, 4.f); if (last_texture_update_count_bias < sDesiredDiscardBias) @@ -830,6 +763,20 @@ void LLViewerTexture::updateClass() // a problem. last_texture_update_count_bias = sDesiredDiscardBias; } + + // Quartile-pressure crossing resets the update counter so eviction + // candidates get re-evaluated when pressure escalates - parallel to + // the bias-rise reset above. The legacy bias term doesn't see fast + // VRAM-pressure changes (sDiscardBias ramps independently of it), so + // without this, a sudden VRAM pressure spike would wait for the + // round-trip through the whole mUUIDMap before re-evaluating. + static S32 last_pressure_quartile = 0; + S32 pressure_quartile = (S32)floorf(getMemoryPressureProgress() * 4.f); + if (pressure_quartile > last_pressure_quartile) + { + sBiasTexturesUpdated = 0; + } + last_pressure_quartile = pressure_quartile; } //static @@ -3224,6 +3171,157 @@ S8 LLViewerLODTexture::getType() const return LLViewerTexture::LOD_TEXTURE; } +// ---- processTextureStats discard pipeline helpers ---------------------- +// Each takes the working discard level and returns the updated value, +// reading per-texture member state directly. Pure functions of state (they +// never write members); the orchestrator in processTextureStats owns +// mDesiredDiscardLevel. See the header for the execution-order overview. + +// Canonical "1 texel per screen pixel" base discard. For UI-pinned textures +// (mKnownDrawWidth/Height) it uses the known render size; otherwise the +// on-screen pixel coverage with an oversample factor (sharper when we have +// headroom, plus the own-avatar boost) and the close-camera bubble clamp. +S32 LLViewerLODTexture::computeBaseDiscard(S32 dim_max_i) const +{ + static const F64 log_4 = log(4.0); + + if (mKnownDrawWidth && mKnownDrawHeight) + { + // UI-pinned target dimensions - pixel-area against the known render + // size, not the on-screen coverage. + S32 draw_texels = mKnownDrawWidth * mKnownDrawHeight; + draw_texels = llclamp(draw_texels, MIN_IMAGE_AREA, MAX_IMAGE_AREA); + return (S32)floor(log((F64)mTexelsPerImage / (F64)draw_texels) / log_4); + } + + // Oversample: >1 = sharper than 1:1; <1 = allow under-sampling. Pressure + // shrinks it via pixelCapOversampleForPressure. Own-avatar boost doubles + // it (4x texels = exactly -1 discard) - a preference, not an exemption. + F32 oversample = pixelCapOversampleForPressure(); + if (mOnAgentAvatar) + { + static LLCachedControl<F32> avatar_over_mult(gSavedSettings, "TextureAgentAvatarOversampleMultiplier", 2.0f); + oversample *= llmax((F32)avatar_over_mult, 1.f); + } + + // Bubble clamp: any face inside the close-camera bubble + // (mMinDistanceFactor == 0) is treated as filling the screen, so the + // base saturates at 0 (full res) for bubble-resident content. + F32 effective_screen = mMaxOnScreenSize; + if (mMinDistanceFactor <= 0.f) + { + effective_screen = llmax(effective_screen, sWindowPixelArea); + } + + F32 visible_texels = effective_screen * oversample * oversample; + visible_texels = llclamp(visible_texels, (F32)MIN_IMAGE_AREA, (F32)mTexelsPerImage); + + S32 base_discard; + if ((F32)mTexelsPerImage <= visible_texels || mMaxOnScreenSize <= 0.f) + { + // Already at-or-below 1:1 with on-screen pixels; no discard needed. + // Also the fallback for never-measured textures (mMaxOnScreenSize==0) + // - keep full res until a measurement arrives. + base_discard = 0; + } + else + { + base_discard = (S32)floor(log((F64)mTexelsPerImage / (F64)visible_texels) / log_4); + } + return llclamp(base_discard, 0, dim_max_i); +} + +// Per-channel additive offset. Channel-priority order: +// 0=Normal, 1=BaseColor, 2=Specular, 3=Emissive. +// Defaults push specular/emissive +1 (one mip coarser) - users frequently +// put 2048 spec/emissive maps on tiny prims where the detail is invisible. +// Tier presets crank these further (e.g. Low pushes normals hard). +S32 LLViewerLODTexture::applyChannelOffset(S32 discard) const +{ + if (mPriorityChannel >= 0 && mPriorityChannel < 4) + { + static LLCachedControl<S32> off_normal (gSavedSettings, "TextureChannelOffsetNormal", 0); + static LLCachedControl<S32> off_basecolor(gSavedSettings, "TextureChannelOffsetBaseColor", 0); + static LLCachedControl<S32> off_specular (gSavedSettings, "TextureChannelOffsetSpecular", 1); + static LLCachedControl<S32> off_emissive (gSavedSettings, "TextureChannelOffsetEmissive", 1); + const S32 offsets[4] = { + (S32)off_normal, + (S32)off_basecolor, + (S32)off_specular, + (S32)off_emissive, + }; + discard += offsets[mPriorityChannel]; + } + return discard; +} + +// VRAM pressure distance floor. Forces a minimum discard that ramps with +// distance; the ramp steepens as the watermark-driven sDiscardBias climbs, +// so the "force max discard" distance moves inward from draw distance toward +// the bubble. compression = 1 + bias*scale; the floor reaches dim_max at +// ~1/compression of draw distance. Bubble residents (mMinDistanceFactor==0) +// stay at floor 0 - protected. Subsumes the old last-ditch mechanism: at +// saturated bias every non-bubble texture is forced to its deepest mip. +// Avatar bakes exempt. +S32 LLViewerLODTexture::applyPressureFloor(S32 discard, F32 dim_max, bool avatar_bake) const +{ + if (!avatar_bake && sDiscardBias > 0.f) + { + static LLCachedControl<F32> press_scale(gSavedSettings, "TexturePressureDiscardScale", 1.0f); + F32 ramp_compression = 1.f + sDiscardBias * llmax((F32)press_scale, 0.f); + F32 effective_dist = llmin(mMinDistanceFactor * ramp_compression, 1.f); + S32 pressure_floor = (S32)floorf(effective_dist * dim_max); + discard = llmax(discard, pressure_floor); + } + return discard; +} + +// Staleness + background max-floors. Both are authored 0..1 elsewhere +// (updateImageDecodePriority / updateClass) and translated to discard space +// here. They only raise discard (worse quality), never reduce it. Background +// floor is capped at (dim_max - offset) so we keep some baseline quality +// while backgrounded; avatar bakes are exempt from the background floor. +S32 LLViewerLODTexture::applyStalenessBackgroundFloors(S32 discard, F32 dim_max, bool avatar_bake) const +{ + const S32 stale_floor = (S32)floorf(mStalenessFactor * dim_max); + discard = llmax(discard, stale_floor); + + if (!avatar_bake) + { + static LLCachedControl<S32> bg_offset(gSavedSettings, "TextureBackgroundDiscardOffset", 2); + F32 bg_norm = sBackgroundFactor; + if ((S32)bg_offset > 0 && dim_max > 0.f) + { + F32 cap = llmax(dim_max - (F32)(S32)bg_offset, 0.f) / dim_max; + bg_norm = llmin(bg_norm, cap); + } + const S32 bg_floor = (S32)floorf(bg_norm * dim_max); + discard = llmax(discard, bg_floor); + } + return discard; +} + +// Caller-set min-discard cap (setMinDiscardLevel: terrain / avatar-self / +// thumbnails), relaxed under pressure. add = floor(progress * room * scale), +// where room is the gap to dim_max and progress is sDiscardBias normalized - +// mirrors the original cap_relax = (1 - 1/mult)*room shape. Caps of 0 +// (thumbnails) and avatar bakes are preserved. Returns the capped discard. +S32 LLViewerLODTexture::applyMinDesiredCap(S32 discard, S32 dim_max_i, bool avatar_bake) const +{ + S32 effective_min_cap = mMinDesiredDiscardLevel; + if (sDiscardBias > 0.f && + mMinDesiredDiscardLevel > 0 && mMinDesiredDiscardLevel < S8_MAX && + !avatar_bake) + { + static LLCachedControl<F32> cap_relax_scale(gSavedSettings, "TextureMinCapPressureRelaxScale", 1.0f); + F32 progress = getMemoryPressureProgress(); + F32 room = (F32)dim_max_i - (F32)mMinDesiredDiscardLevel; + S32 add = (S32)floorf(progress * room * llmax((F32)cap_relax_scale, 0.f)); + effective_min_cap = llmin(effective_min_cap + add, dim_max_i); + } + return llmin(effective_min_cap, discard); +} + // This is gauranteed to get called periodically for every texture //virtual void LLViewerLODTexture::processTextureStats() @@ -3231,7 +3329,13 @@ void LLViewerLODTexture::processTextureStats() LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE; updateVirtualSize(); - bool did_downscale = false; + // Hoisted once: avatar bake textures are exempt from several pressure + // mechanisms below (anti-cloud-bug protection). Reads of `avatar_bake` + // replace inline isAgentAvatarBoost(mBoostLevel) calls; each site keeps + // its own intent comment explaining *why* the exemption applies. See + // also LLViewerFetchedTexture::isAgentAvatarBoost() in the header for + // the canonical list of exemption sites. + const bool avatar_bake = isAgentAvatarBoost(mBoostLevel); static LLCachedControl<bool> textures_fullres(gSavedSettings,"TextureLoadFullRes", false); @@ -3266,183 +3370,59 @@ void LLViewerLODTexture::processTextureStats() } else { - F32 discard_level = 0.f; + // Pixel-area-primary discard pipeline. The canonical "1 texel per + // screen pixel" base means distance falls out for free (pixel + // coverage ~ 1/D^2 => +1 discard per doubling of distance). The + // per-stage math lives in the helpers (computeBaseDiscard etc.); + // this just orchestrates them. Every modifier after the base is + // monotone non-decreasing in discard. - // floor(log2(max(w, h))) - both the multiplier on the normalized - // factor and the cap clamp at the bottom of this function. + // Per-texture max discard (smallest meaningful mip): floor(log2(max(w,h))). S32 dim_max_for_image_i = (mFullWidth > 0 && mFullHeight > 0) ? LLImageGL::dimDerivedMaxDiscard(mFullWidth, mFullHeight) : (S32)mCodecMaxDiscardLevel; F32 dim_max_for_image = (F32)dim_max_for_image_i; - if (mKnownDrawWidth && mKnownDrawHeight) - { - // UI-pinned target dimensions - use pixel-area math. - static const F64 log_4 = log(4.0); - S32 draw_texels = mKnownDrawWidth * mKnownDrawHeight; - draw_texels = llclamp(draw_texels, MIN_IMAGE_AREA, MAX_IMAGE_AREA); - discard_level = (F32)(log(mTexelsPerImage / draw_texels) / log_4); - } - else - { - // Two 0..1 signals composed multiplicatively: - // discard = distance_factor * size_factor * max_discard - // distance_factor: face_dist / draw_dist, shaped by - // TextureDistanceDiscardPower (default 0.5 = sqrt). - // size_factor: 1 - (mMaxOnScreenSize / window_pixels), shaped - // by TextureSizeDiscardPower. - // Either factor near 0 keeps the result fine - both have to - // be high for the texture to go deep. - static LLCachedControl<F32> distance_power(gSavedSettings, "TextureDistanceDiscardPower", 0.5f); - F32 power = llmax((F32)distance_power, 0.0001f); - F32 distance_factor = (power == 1.f) ? mMinDistanceFactor : powf(mMinDistanceFactor, power); - - static LLCachedControl<F32> size_power(gSavedSettings, "TextureSizeDiscardPower", 1.f); - F32 sz_power = llmax((F32)size_power, 0.0001f); - F32 coverage = llclampf(mMaxOnScreenSize / sWindowPixelArea); - F32 inv_cov = 1.f - coverage; - F32 size_factor = (sz_power == 1.f) ? inv_cov : powf(inv_cov, sz_power); - - F32 combined = distance_factor * size_factor; - - // VRAM pressure: multiply the combined signal and clamp to 0..1. - // Compresses the effective draw range and picks up close-coverage - // textures (small combined) too. Applied before the channel - // exponent so subsequent transforms see a normalized 0..1 value. - // Avatar bakes exempt. - if (!isAgentAvatarBoost(mBoostLevel) && sMemoryPressureMultiplier > 1.f) - { - combined = llmin(combined * sMemoryPressureMultiplier, 1.f); - } - - // Per-channel exponent. 1.0 = baseline; <1.0 pushes combined - // toward 1 (max attenuation) faster. Edges are preserved: - // pow(0, p) = 0, pow(1, p) = 1. - // mPriorityChannel order: 0=Normal, 1=BaseColor, 2=Specular, 3=Emissive. - S32 priority_channel = (mPriorityChannel >= 0 && mPriorityChannel < 4) ? (S32)mPriorityChannel : 1; - static LLCachedControl<F32> channel_normal (gSavedSettings, "TextureChannelNormal", 1.0f); - static LLCachedControl<F32> channel_basecolor(gSavedSettings, "TextureChannelBaseColor", 0.75f); - static LLCachedControl<F32> channel_specular (gSavedSettings, "TextureChannelSpecular", 0.5f); - static LLCachedControl<F32> channel_emissive (gSavedSettings, "TextureChannelEmissive", 0.75f); - const F32 channels[4] = { - (F32)channel_normal, - (F32)channel_basecolor, - (F32)channel_specular, - (F32)channel_emissive, - }; - F32 channel_power = llmax(channels[priority_channel], 0.0001f); - if (channel_power != 1.f) - { - combined = powf(combined, channel_power); - } - - // Own-avatar boost: shave combined for rigged/animated faces - // on gAgentAvatarp. Preference, not exemption - applied - // before the staleness/background/pressure floors so heavy - // pressure can still evict. - if (mOnAgentAvatar) - { - static LLCachedControl<F32> agent_avatar_boost(gSavedSettings, "TextureAgentAvatarBoost", 0.5f); - combined *= llclampf((F32)agent_avatar_boost); - } - - // Staleness / background floors. Avatar bakes exempt from - // background to avoid the universal-cloud bug when re-foregrounding. - combined = llmax(combined, mStalenessFactor); - if (!isAgentAvatarBoost(mBoostLevel)) - { - // Background floor capped at (dim_max - offset) so we can - // keep some baseline quality while backgrounded. - static LLCachedControl<S32> bg_offset(gSavedSettings, "TextureBackgroundDiscardOffset", 2); - F32 bg = sBackgroundFactor; - if ((S32)bg_offset > 0 && dim_max_for_image > 0.f) - { - F32 cap = llmax(dim_max_for_image - (F32)(S32)bg_offset, 0.f) / dim_max_for_image; - bg = llmin(bg, cap); - } - combined = llmax(combined, bg); - } + S32 discard = computeBaseDiscard(dim_max_for_image_i); - discard_level = combined * dim_max_for_image; + // Channel / pressure / staleness+background floors apply only to the + // coverage-driven path; UI-pinned (mKnownDrawWidth/Height) textures + // take the base verbatim. + if (!(mKnownDrawWidth && mKnownDrawHeight)) + { + discard = applyChannelOffset(discard); + discard = applyPressureFloor(discard, dim_max_for_image, avatar_bake); + discard = applyStalenessBackgroundFloors(discard, dim_max_for_image, avatar_bake); } - discard_level = floorf(discard_level); - - F32 min_discard = 0.f; + // Per-texture caps: min_discard forces 1 for sources over the + // resolution cap; effective_cap is the per-texture max (debug + // override or dim-derived). + S32 min_discard = 0; if (mFullWidth > max_tex_res || mFullHeight > max_tex_res) - min_discard = 1.f; + min_discard = 1; - // dim_max_for_image_i is the per-texture cap. TextureMaxDiscardOverride - // raises it (debug). Codec_max applies only to fetches, not here. static LLCachedControl<S32> max_discard_override(gSavedSettings, "TextureMaxDiscardOverride", 0); - S32 effective_cap = (max_discard_override > 0) ? (S32)max_discard_override : dim_max_for_image_i; - discard_level = llclamp(discard_level, min_discard, (F32)effective_cap); + const S32 effective_cap = (max_discard_override > 0) ? (S32)max_discard_override : dim_max_for_image_i; + discard = llclamp(discard, min_discard, effective_cap); + mDesiredDiscardLevel = (S8)discard; - mDesiredDiscardLevel = llmin(effective_cap, (S32)discard_level); + // Caller-set min-discard cap (terrain / avatar-self / thumbnails), + // relaxed under pressure. + mDesiredDiscardLevel = (S8)applyMinDesiredCap(mDesiredDiscardLevel, dim_max_for_image_i, avatar_bake); - // Pixel-area discard cap. Don't let mDesiredDiscardLevel push the - // GL resolution below the texture's largest on-screen contribution - // x an oversample factor (sharper when we have memory headroom, - // looser under pressure). Avatar bakes exempt. - if (!isAgentAvatarBoost(mBoostLevel) && mMaxOnScreenSize > 0.f && mTexelsPerImage > 0) - { - static const F64 log_4 = log(4.0); - F32 oversample = pixelCapOversampleForPressure(); - F32 visible_texels = mMaxOnScreenSize * oversample * oversample; - visible_texels = llclamp(visible_texels, (F32)MIN_IMAGE_AREA, (F32)mTexelsPerImage); - if ((F32)mTexelsPerImage > visible_texels) - { - S32 d_pixel_cap = (S32)floor(log((F32)mTexelsPerImage / visible_texels) / log_4); - d_pixel_cap = llclamp(d_pixel_cap, 0, dim_max_for_image_i); - mDesiredDiscardLevel = llmin((S32)mDesiredDiscardLevel, d_pixel_cap); - } - } - - // Apply the setMinDiscardLevel cap, relaxed under VRAM pressure - // (cap_relax = 1 - 1/mult: 0 at mult=1, ~0.5 at mult=2, ~0.9 at - // mult=10). Caps of 0 (thumbnails) and avatar bakes are preserved. - S32 effective_min_cap = mMinDesiredDiscardLevel; - if (sMemoryPressureMultiplier > 1.f && - mMinDesiredDiscardLevel > 0 && mMinDesiredDiscardLevel < S8_MAX && - !isAgentAvatarBoost(mBoostLevel)) - { - F32 cap_relax = 1.f - 1.f / sMemoryPressureMultiplier; - F32 room = (F32)dim_max_for_image_i - (F32)mMinDesiredDiscardLevel; - effective_min_cap += (S32)(cap_relax * room); - effective_min_cap = llmin(effective_min_cap, dim_max_for_image_i); - } - mDesiredDiscardLevel = llmin((S8)effective_min_cap, mDesiredDiscardLevel); - - // Halve the floor for bubble-resident textures (mMinDistanceFactor == 0 - // = at least one face inside the bubble) so the close-vs-far gradient - // is preserved at every pressure level. - if (!isAgentAvatarBoost(mBoostLevel)) - { - S32 forced = (S32)floorf(sLastDitchMinDiscard); - if (mMinDistanceFactor <= 0.f) forced /= 2; - forced = llclamp(forced, 0, dim_max_for_image_i); - if (forced > mDesiredDiscardLevel) - { - mDesiredDiscardLevel = (S8)forced; - } - } - - - // - // At this point we've calculated the quality level that we want, - // if possible. Now we check to see if we have it, and take the - // proper action if we don't. - // + // (There is no separate last-ditch floor - applyPressureFloor + // subsumes it. At saturated sDiscardBias the distance floor forces + // every non-bubble texture to its deepest mip, and in-bubble content + // stays protected, which is exactly the intended behavior.) + // If the GPU already holds finer data than we now want, schedule a + // downscale. Avatar bakes exempt: shrinking mid-bake can leave the + // avatar stuck as a cloud until the next bake completes. S32 current_discard = getDiscardLevel(); - // Avatar bakes exempt: shrinking mid-bake can leave the avatar - // stuck as a cloud until the next bake completes. - if (!isAgentAvatarBoost(mBoostLevel)) + if (!avatar_bake && current_discard < mDesiredDiscardLevel && !mForceToSaveRawImage) { - if (current_discard < mDesiredDiscardLevel && !mForceToSaveRawImage) - { // should scale down - scaleDown(); - } + scaleDown(); } mDesiredDiscardLevel = llmin(mDesiredDiscardLevel, (S32)mLoadedCallbackDesiredDiscardLevel); diff --git a/indra/newview/llviewertexture.h b/indra/newview/llviewertexture.h index 991bb638a1..390a6caa58 100644 --- a/indra/newview/llviewertexture.h +++ b/indra/newview/llviewertexture.h @@ -247,17 +247,21 @@ public: // snaps to 0 in foreground. Avatar bakes exempt. static F32 sBackgroundFactor; - // VRAM-pressure distance multiplier, >= 1. Compresses the distance - // signal: dist_factor = clamp(mMinDistanceFactor * mult, 0, 1). - // Grows geometrically while over budget; decays back to 1 when fitting. - static F32 sMemoryPressureMultiplier; - // Last-ditch global discard floor. Mirrors sDesiredDiscardBias once the - // multiplier is exhausted. - static F32 sLastDitchMinDiscard; + // Watermark-driven global discard bias, [0, TextureDiscardBiasMax]. + // The single VRAM-pressure controller: climbs while used VRAM is above + // the high watermark, relaxes below the low watermark, holds in the + // hysteresis band between. Replaces the old sMemoryPressureMultiplier + + // sLastDitchMinDiscard pair (and the predict-scan apparatus). Feeds the + // distance-weighted pressure floor in processTextureStats: close content + // is protected, distant content is evicted first, and as the bias climbs + // the "force max discard" distance moves inward from draw distance toward + // the bubble. Subsumes last-ditch - at max bias the distance floor forces + // everything outside the bubble to its deepest mip. + static F32 sDiscardBias; - // 0..1 progress of the pressure multiplier from baseline (1) to its - // configured cap (TextureMemoryPressureMaxMultiplier). Used to gate - // bubble shrink and last-ditch engagement. + // 0..1 progress of sDiscardBias from baseline (0) to its configured cap + // (TextureDiscardBiasMax). Gates bubble shrink, pixel-area oversample + // collapse, the per-frame update count, and the min-cap relax. static F32 getMemoryPressureProgress(); static U32 sBiasTexturesUpdated; static S32 sMaxSculptRez ; @@ -599,6 +603,23 @@ public: private: void init(bool firstinit) ; + + // Streaming discard pipeline, factored out of processTextureStats so each + // stage is individually readable and testable. Execution order: + // base = computeBaseDiscard() // canonical texels/pixel (or UI-pinned) + // if not UI-pinned: + // base = applyChannelOffset(base) // per-channel additive bias + // base = applyPressureFloor(base) // distance-weighted VRAM floor + // base = applyStalenessBackgroundFloors(base) + // ... per-texture caps ... + // final = applyMinDesiredCap(final) // caller-set min, relaxed under pressure + // Each reads per-texture member state directly; avatar_bake and the + // dim-max values are computed once by the caller and threaded through. + S32 computeBaseDiscard(S32 dim_max_i) const; + S32 applyChannelOffset(S32 discard) const; + S32 applyPressureFloor(S32 discard, F32 dim_max, bool avatar_bake) const; + S32 applyStalenessBackgroundFloors(S32 discard, F32 dim_max, bool avatar_bake) const; + S32 applyMinDesiredCap(S32 discard, S32 dim_max_i, bool avatar_bake) const; }; // diff --git a/indra/newview/llviewertexturelist.cpp b/indra/newview/llviewertexturelist.cpp index 4d09eff74e..780dda6ef7 100644 --- a/indra/newview/llviewertexturelist.cpp +++ b/indra/newview/llviewertexturelist.cpp @@ -1043,8 +1043,11 @@ void LLViewerTextureList::updateImageDecodePriority(LLViewerFetchedTexture* imag S32 te_offset = face->getTEOffset(); // offset is -1 if not inited LLViewerObject* objp = face->getViewerObject(); const LLTextureEntry* te = (te_offset < 0 || te_offset >= objp->getNumTEs()) ? nullptr : objp->getTE(te_offset); - F32 min_scale = te ? llmin(fabsf(te->getScaleS()), fabsf(te->getScaleT())) : 1.f; - min_scale = llclamp(min_scale * min_scale, texture_scale_min(), texture_scale_max()); + // getMinScaleSq() returns cached min(|scaleS|,|scaleT|)^2; + // invalidated by setScale*. Saves the abs/min/multiply per + // face per frame. Clamp against the user-tunable LLCachedControl + // values still happens here. + F32 min_scale = te ? llclamp(te->getMinScaleSq(), texture_scale_min(), texture_scale_max()) : 1.f; vsize /= min_scale; // Raw screen-space coverage - taken before the bias / @@ -1410,10 +1413,17 @@ F32 LLViewerTextureList::updateImagesFetchTextures(F32 max_time) //update MIN_UPDATE_COUNT or 5% of other textures, whichever is greater update_count = llmax((U32) MIN_UPDATE_COUNT, (U32) mUUIDMap.size()/20); // Scale up the per-frame update window under VRAM pressure so eviction - // candidates get re-evaluated quickly. Both the legacy bias and the - // new pressure multiplier widen the window. - F32 pressure_scale = llmax(LLViewerTexture::sDesiredDiscardBias, - LLViewerTexture::sMemoryPressureMultiplier); + // candidates get re-evaluated quickly. Use memory-pressure *progress* + // (0..1) rather than the raw multiplier so the cap can't blow up by 64x + // at peak pressure - the old code processed the entire mUUIDMap every + // frame at peak, inflating non-avatar frame time and tripping AutoFPS + // to walk RenderFarClip down. Legacy bias term is preserved (it's + // small-ranged 1..4) so behavior unchanged at moderate pressure. + static LLCachedControl<F32> update_cap(gSavedSettings, "TextureUpdateCountPressureMaxMultiplier", 6.f); + F32 cap_minus_1 = llmax((F32)update_cap - 1.f, 0.f); + F32 progress = LLViewerTexture::getMemoryPressureProgress(); + F32 bias_term = llmax(0.f, LLViewerTexture::sDesiredDiscardBias - 1.f); + F32 pressure_scale = 1.f + llmin(cap_minus_1, llmax(bias_term, progress * cap_minus_1)); if (pressure_scale > 1.f && LLViewerTexture::sBiasTexturesUpdated < (U32)mUUIDMap.size()) { @@ -1421,7 +1431,7 @@ F32 LLViewerTextureList::updateImagesFetchTextures(F32 max_time) // This isn't particularly precise and can overshoot, but it doesn't need // to be, just making sure it did a full circle and doesn't get stuck updating - // at bias = 4 with 4 times the rate permanently. + // at the scaled rate permanently. LLViewerTexture::sBiasTexturesUpdated += update_count; } update_count = llmin(update_count, (U32) mUUIDMap.size()); |
