diff options
| author | Jonathan "Geenz" Goodman <geenz@geenzo.com> | 2026-07-06 02:34:15 -0400 |
|---|---|---|
| committer | Jonathan "Geenz" Goodman <geenz@geenzo.com> | 2026-07-06 02:34:15 -0400 |
| commit | b55a7038511a6ed3d97e17b13c9d83bc2017ba61 (patch) | |
| tree | 1ef43d267a055f07b177b53d5a4fe23a00381822 /indra | |
| parent | cd62a49879374c84b66e1ee963e161c3e6109977 (diff) | |
Move over to a pixels to texels ratio to drive texture resolution.
Diffstat (limited to 'indra')
| -rw-r--r-- | indra/llrender/llimagegl.h | 4 | ||||
| -rw-r--r-- | indra/newview/app_settings/settings.xml | 270 | ||||
| -rw-r--r-- | indra/newview/lltextureview.cpp | 13 | ||||
| -rw-r--r-- | indra/newview/llviewercontrol.cpp | 76 | ||||
| -rw-r--r-- | indra/newview/llviewertexture.cpp | 564 | ||||
| -rw-r--r-- | indra/newview/llviewertexture.h | 104 | ||||
| -rw-r--r-- | indra/newview/llviewertexturelist.cpp | 290 | ||||
| -rw-r--r-- | indra/newview/llviewertexturelist.h | 4 |
8 files changed, 309 insertions, 1016 deletions
diff --git a/indra/llrender/llimagegl.h b/indra/llrender/llimagegl.h index 0c85446b84..0869ae54fe 100644 --- a/indra/llrender/llimagegl.h +++ b/indra/llrender/llimagegl.h @@ -238,8 +238,8 @@ public: public: // Various GL/Rendering options S64Bytes mTextureMemory; - mutable F32 mLastBindTime = 0.f; // wall-clock time at last stampBound; drives streaming staleness - F32 mGLCreateTime = 0.f; // wall-clock time the GL texture was created; staleness fallback for never-bound textures + 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 private: U32 createPickMask(S32 pWidth, S32 pHeight); diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index 519041bbeb..cfd92e03ca 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, TextureDiscardBiasMax, TextureCloseBubbleMeters/MinMeters/ShrinkThreshold, TextureChannelOffset* (four), TexturePressureDiscardScale, TextureMinCapPressureRelaxScale, TextureUpdateCountPressureMaxMultiplier, TextureScreenSizeOversample/UnderPressure, TextureAgentAvatarOversampleMultiplier, TextureBackgroundFactorRatePerSec, TextureDiscardBackgroundedTime. Watermarks (TextureWatermarkHigh/Low) are constant across tiers.</string> + <string>Texture quality preset: 0=Low, 1=Medium, 2=High, 3=Ultra. Drives RenderMaxTextureResolution, TexturePixelToTexelRatio, TexturePressureTightenRate, TexturePressureRelaxRate, and TextureChannelRatio* (Normal/BaseColor/Specular/Emissive). Watermarks (TextureWatermarkHigh/Low) are constant across tiers.</string> <key>Persist</key> <integer>1</integer> <key>Type</key> @@ -11871,131 +11871,10 @@ <key>Value</key> <real>20.0</real> </map> - <key>TextureChannelOffsetNormal</key> + <key>TextureChannelRatioNormal</key> <map> <key>Comment</key> - <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>S32</string> - <key>Value</key> - <integer>0</integer> - </map> - <key>TextureChannelOffsetBaseColor</key> - <map> - <key>Comment</key> - <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>S32</string> - <key>Value</key> - <integer>0</integer> - </map> - <key>TextureChannelOffsetSpecular</key> - <map> - <key>Comment</key> - <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>S32</string> - <key>Value</key> - <integer>1</integer> - </map> - <key>TextureChannelOffsetEmissive</key> - <map> - <key>Comment</key> - <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>S32</string> - <key>Value</key> - <integer>1</integer> - </map> - <key>TextureMaxDiscardOverride</key> - <map> - <key>Comment</key> - <string>When non-zero, overrides the per-texture codec-derived max discard cap. 0 = use codec-reported levels. Higher lets the streaming math push past the codec ceiling; scaleDown handles the GL side.</string> - <key>Persist</key> - <integer>1</integer> - <key>Type</key> - <string>S32</string> - <key>Value</key> - <integer>0</integer> - </map> - <key>TextureWatermarkHigh</key> - <map> - <key>Comment</key> - <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.90</real> - </map> - <key>TextureWatermarkLow</key> - <map> - <key>Comment</key> - <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.70</real> - </map> - <key>TextureDiscardBiasMax</key> - <map> - <key>Comment</key> - <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>12.0</real> - </map> - <key>TextureDiscardBiasRampRate</key> - <map> - <key>Comment</key> - <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>2.0</real> - </map> - <key>TextureDiscardBiasDecayRate</key> - <map> - <key>Comment</key> - <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>1.0</real> - </map> - <key>TexturePressureDiscardScale</key> - <map> - <key>Comment</key> - <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>1.0</real> - </map> - <key>TextureMinCapPressureRelaxScale</key> - <map> - <key>Comment</key> - <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> + <string>Per-channel pixel:texel ratio multiplier for normal maps (texels per pixel, applied on top of the global TexturePixelToTexelRatio). 1.0 = full quality; lower = coarser. Driven by the RenderTextureQuality preset.</string> <key>Persist</key> <integer>1</integer> <key>Type</key> @@ -12003,21 +11882,10 @@ <key>Value</key> <real>1.0</real> </map> - <key>TextureUpdateCountPressureMaxMultiplier</key> - <map> - <key>Comment</key> - <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>6.0</real> - </map> - <key>TextureFetchBiasTrackRate</key> + <key>TextureChannelRatioBaseColor</key> <map> <key>Comment</key> - <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> + <string>Per-channel pixel:texel ratio multiplier for base color / diffuse (texels per pixel, applied on top of the global TexturePixelToTexelRatio). 1.0 = full quality. Driven by the RenderTextureQuality preset.</string> <key>Persist</key> <integer>1</integer> <key>Type</key> @@ -12025,162 +11893,116 @@ <key>Value</key> <real>1.0</real> </map> - <key>TextureTerrainDistanceFloor</key> + <key>TextureChannelRatioSpecular</key> <map> <key>Comment</key> - <string>Minimum distance factor for BOOST_TERRAIN textures. Keeps combined > 0 so VRAM pressure can evict terrain. Lower = higher idle quality, less pressure response.</string> + <string>Per-channel pixel:texel ratio multiplier for specular / metallic-roughness (texels per pixel, applied on top of the global TexturePixelToTexelRatio). 0.5 = half resolution (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> <key>Value</key> - <real>0.01</real> - </map> - <key>TextureTerrainCoverageFraction</key> - <map> - <key>Comment</key> - <string>Synthetic on-screen coverage fraction for BOOST_TERRAIN textures (no faces are registered). Higher = higher idle quality, less pressure response.</string> - <key>Persist</key> - <integer>1</integer> - <key>Type</key> - <string>F32</string> - <key>Value</key> - <real>0.99</real> - </map> - <key>TextureAgentAvatarOversampleMultiplier</key> - <map> - <key>Comment</key> - <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>2.0</real> + <real>0.5</real> </map> - <key>TextureBackgroundFactorRatePerSec</key> + <key>TextureChannelRatioEmissive</key> <map> <key>Comment</key> - <string>Per-second ramp rate of the background-window discard floor (0..1). Snaps to 0 in foreground. Default 0.011 ~ 90s to saturate.</string> + <string>Per-channel pixel:texel ratio multiplier for emissive (texels per pixel, applied on top of the global TexturePixelToTexelRatio). 0.5 = half resolution. Driven by the RenderTextureQuality preset.</string> <key>Persist</key> <integer>1</integer> <key>Type</key> <string>F32</string> <key>Value</key> - <real>0.011</real> + <real>0.5</real> </map> - <key>TextureBackgroundDiscardOffset</key> + <key>TextureMaxDiscardOverride</key> <map> <key>Comment</key> - <string>Backgrounded textures will only discard up to (dim_max - offset). e.g. a 2048 texture (dim_max 11) with offset 2 caps the background floor at discard 9. 0 disables the cap (background can drive to max discard).</string> + <string>When non-zero, overrides the per-texture codec-derived max discard cap. 0 = use codec-reported levels. Higher lets the streaming math push past the codec ceiling; scaleDown handles the GL side.</string> <key>Persist</key> <integer>1</integer> <key>Type</key> <string>S32</string> <key>Value</key> - <integer>2</integer> - </map> - - <key>TextureCloseBubbleMeters</key> - <map> - <key>Comment</key> - <string>Close-camera bubble (meters). Faces inside this distance get dist_factor = 0 (no discard contribution); the ramp to 1 spans (bubble, draw_distance]. Shrinks toward TextureCloseBubbleMinMeters as VRAM pressure ramps the multiplier toward its cap.</string> - <key>Persist</key> - <integer>1</integer> - <key>Type</key> - <string>F32</string> - <key>Value</key> - <real>5.0</real> - </map> - <key>TextureCloseBubbleMinMeters</key> - <map> - <key>Comment</key> - <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> - <string>F32</string> - <key>Value</key> - <real>3.0</real> + <integer>0</integer> </map> - <key>TextureCloseBubbleShrinkThreshold</key> + <key>TexturePixelToTexelRatio</key> <map> <key>Comment</key> - <string>Bubble stays at full size until mult_progress exceeds this fraction (0..1) of its range to the cap. Above that, bubble lerps from full to TextureCloseBubbleMinMeters. Keeps the bubble out of the normal feedback loop.</string> + <string>Global maximum pixel:texel ratio, expressed as texels per screen pixel (the "R" in 1:R). 1.0 = one texel per pixel, the best quality the streamer will allocate. A texture is sized so its most-demanding on-screen face stays at or below this many texels per pixel; everything coarser falls out by distance. VRAM pressure walks the effective ratio down from here toward 0 (no floor).</string> <key>Persist</key> <integer>1</integer> <key>Type</key> <string>F32</string> <key>Value</key> - <real>0.8</real> + <real>1.0</real> </map> - <key>TextureCloseBubbleTrackRate</key> + <key>TextureWatermarkHigh</key> <map> <key>Comment</key> - <string>Rate (1/sec) at which the actual bubble tracks its target. Lower = smoother, slower to react. Damps short-term multiplier swings so close textures don't yo-yo.</string> + <string>High watermark as a fraction of the VRAM budget. When used VRAM crosses this, the global pixel:texel ratio tightens (backs off detail). Held at 0.90 - 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.5</real> + <real>0.90</real> </map> - <key>TextureScreenSizeOversample</key> + <key>TextureWatermarkLow</key> <map> <key>Comment</key> - <string>Texels per screen pixel kept by the per-texture pixel-area discard cap. 1.0 = 1:1 with on-screen contribution; higher = sharper distant textures, more VRAM. Driven by RenderTextureQuality.</string> + <string>Low watermark as a fraction of the VRAM budget. When used VRAM drops below this, the global pixel:texel ratio relaxes (restores detail). The band between low and high is the hysteresis zone where the ratio holds steady - wide enough to prevent sawtooth.</string> <key>Persist</key> <integer>1</integer> <key>Type</key> <string>F32</string> <key>Value</key> - <real>1.5</real> + <real>0.70</real> </map> - <key>TextureScreenSizeOversampleUnderPressure</key> + <key>TexturePressureTightenRate</key> <map> <key>Comment</key> - <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> + <string>Rate (ratio units/sec) at which the global pixel:texel ratio drops while used VRAM is above the high watermark. Deliberately slow so eviction (scaleDown draining) frees bytes 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.5</real> + <real>0.30</real> </map> - <key>TextureStalenessIntervalSeconds</key> + <key>TexturePressureRelaxRate</key> <map> <key>Comment</key> - <string>Seconds per staleness step. Per-interval increment is 1/max_discard so any texture saturates after interval * max_discard seconds idle.</string> + <string>Rate (ratio units/sec) at which the global pixel:texel ratio climbs back toward TexturePixelToTexelRatio while used VRAM is below the low watermark. Typically slower than the tighten rate so detail returns gradually as headroom appears.</string> <key>Persist</key> <integer>1</integer> <key>Type</key> <string>F32</string> <key>Value</key> - <real>5.0</real> + <real>0.10</real> </map> - <key>TextureBindDecaySeconds</key> + <key>TextureUpRezMargin</key> <map> <key>Comment</key> - <string>Grace seconds after a bind during which the staleness factor stays at 0. Prevents intermittently-bound textures from ramping. 0 disables the grace period.</string> + <string>Hysteresis dead-band (in mip levels) around a texture's current discard. A texture only fetches a finer mip when its ideal discard falls more than this below the current level, and only evicts when it rises more than this above - prevents fetch/scaleDown thrash at mip boundaries when an object slowly recedes.</string> <key>Persist</key> <integer>1</integer> <key>Type</key> <string>F32</string> <key>Value</key> - <real>5.0</real> + <real>0.2</real> </map> - <key>TextureFetchPressureScale</key> + <key>TextureCooldownStepSeconds</key> <map> <key>Comment</key> - <string>Pending-fetch divisor for the bias floor: bias floor = 1 + clamp(pending / scale, 0, 3). Lower = bias rises sooner under load floods.</string> + <string>Seconds an unseen texture waits per mip level before stepping down. When a texture stops being bound (occluded / off-screen) or the window is backgrounded, its discard rises one level every this many seconds until it reaches the deepest mip, instead of snapping there immediately - so briefly-unseen content isn't thrown away and refetched (cache thrash) if it reappears. Resets the moment the texture is bound again.</string> <key>Persist</key> <integer>1</integer> <key>Type</key> <string>F32</string> <key>Value</key> - <real>1000.0</real> + <real>1.0</real> </map> - <key>TextureDecodeDisabled</key> <map> <key>Comment</key> @@ -12214,28 +12036,6 @@ <key>Value</key> <integer>0</integer> </map> - <key>TextureDiscardBackgroundedTime</key> - <map> - <key>Comment</key> - <string>Specify how long to wait before discarding texture data after viewer is backgrounded. (zero or negative to disable)</string> - <key>Persist</key> - <integer>1</integer> - <key>Type</key> - <string>F32</string> - <key>Value</key> - <real>60.0</real> - </map> - <key>TextureDiscardMinimizedTime</key> - <map> - <key>Comment</key> - <string>Specify how long to wait before discarding texture data after viewer is minimized. (zero or negative to disable)</string> - <key>Persist</key> - <integer>1</integer> - <key>Type</key> - <string>F32</string> - <key>Value</key> - <real>1.0</real> - </map> <key>TextureFetchConcurrency</key> <map> <key>Comment</key> diff --git a/indra/newview/lltextureview.cpp b/indra/newview/lltextureview.cpp index 1c341a06cd..10b57f47da 100644 --- a/indra/newview/lltextureview.cpp +++ b/indra/newview/lltextureview.cpp @@ -476,7 +476,7 @@ private: void LLGLTexMemBar::draw() { - F32 discard_bias = LLViewerTexture::sDesiredDiscardBias; + F32 pixel_to_texel_ratio = LLViewerTexture::sPixelToTexelRatio; F32 cache_usage = (F32)LLAppViewer::getTextureCache()->getUsage().valueInUnits<LLUnits::Megabytes>(); F32 cache_max_usage = (F32)LLAppViewer::getTextureCache()->getMaxUsage().valueInUnits<LLUnits::Megabytes>(); S32 line_height = LLFontGL::getFontMonospace()->getLineHeight(); @@ -560,25 +560,22 @@ void LLGLTexMemBar::draw() gGL.color4f(0.f, 0.f, 0.f, 0.25f); gl_rect_2d(-10, getRect().getHeight() + line_height*2 + 1, getRect().getWidth()+2, getRect().getHeight()+2); - text = llformat("Est. Free: %d MB Sys Free: %d MB FBO: %d MB Probe#: %d Probe Mem: %d MB Bias: %.2f Cache: %.1f/%.1f MB", + text = llformat("Est. Free: %d MB Sys Free: %d MB FBO: %d MB Probe#: %d Probe Mem: %d MB Px:Texel 1:%.2f Cache: %.1f/%.1f MB", (S32)LLViewerTexture::sFreeVRAMMegabytes, LLMemory::getAvailableMemKB()/1024, LLRenderTarget::sBytesAllocated/(1024*1024), gPipeline.mReflectionMapManager.probeCount(), gPipeline.mReflectionMapManager.probeMemory(), - discard_bias, + pixel_to_texel_ratio, cache_usage, cache_max_usage); 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 DiscardBias: %.2f Progress: %.2f", + text = llformat("Images: %d Raw: %d (%.2f MB) Saved: %d (%.2f MB) Aux: %d (%.2f MB)", 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::sDiscardBias, - LLViewerTexture::getMemoryPressureProgress()); + aux_raw_image_count, aux_raw_image_bytes_MB); 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 19c28b12f1..e2af54539a 100644 --- a/indra/newview/llviewercontrol.cpp +++ b/indra/newview/llviewercontrol.cpp @@ -121,43 +121,32 @@ namespace { 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; + F32 pixel_to_texel_ratio; // TexturePixelToTexelRatio (R_max, texels per pixel) + F32 pressure_tighten_rate; // TexturePressureTightenRate (ratio units/sec) + F32 pressure_relax_rate; // TexturePressureRelaxRate (ratio units/sec) + F32 channel_ratio_normal; // TextureChannelRatioNormal + F32 channel_ratio_basecolor; // TextureChannelRatioBaseColor + F32 channel_ratio_specular; // TextureChannelRatioSpecular + F32 channel_ratio_emissive; // TextureChannelRatioEmissive }; // Tier values: Low (2-4GB), Medium (4-8GB), High (8-16GB), Ultra (16+GB). - // Pressure-aggression ladder: Low burns hot, Ultra barely sweats. - // + // Quality ladder, expressed in pixel:texel (texels per pixel): + // - pixel_to_texel_ratio is the baseline quality: how many texels per + // screen pixel the tier allocates when VRAM is comfortable (1.0 = 1:1). + // Under pressure the runtime drives the global ratio below this with no + // floor (down to 0 = deepest mips), so there is no per-tier minimum. + // - the channel ratios coarsen specular/emissive/normal relative to base + // color (each is a multiplier on the global ratio). // 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 + // tiers. Lower tiers start blurrier (lower R_max) and tighten faster. + // max_res Rmax tight relax 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 }, + /* 0 Low */ { "Low", 1024, 0.10f, 0.50f, 0.05f, 0.50f, 1.00f, 0.25f, 0.25f }, + /* 1 Medium */ { "Medium", 2048, 0.40f, 0.35f, 0.08f, 1.00f, 1.00f, 0.50f, 0.50f }, + /* 2 High */ { "High", 2048, 0.80f, 0.25f, 0.10f, 1.00f, 1.00f, 0.50f, 1.00f }, + /* 3 Ultra */ { "Ultra", 2048, 1.00f, 0.15f, 0.12f, 1.00f, 1.00f, 1.00f, 1.00f }, }; } @@ -167,23 +156,14 @@ static bool handleRenderTextureQualityChanged(const LLSD& newvalue) 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); + gSavedSettings.setU32("RenderMaxTextureResolution", p.max_resolution); + gSavedSettings.setF32("TexturePixelToTexelRatio", p.pixel_to_texel_ratio); + gSavedSettings.setF32("TexturePressureTightenRate", p.pressure_tighten_rate); + gSavedSettings.setF32("TexturePressureRelaxRate", p.pressure_relax_rate); + gSavedSettings.setF32("TextureChannelRatioNormal", p.channel_ratio_normal); + gSavedSettings.setF32("TextureChannelRatioBaseColor", p.channel_ratio_basecolor); + gSavedSettings.setF32("TextureChannelRatioSpecular", p.channel_ratio_specular); + gSavedSettings.setF32("TextureChannelRatioEmissive", p.channel_ratio_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 545264b980..ef49e0e67f 100644 --- a/indra/newview/llviewertexture.cpp +++ b/indra/newview/llviewertexture.cpp @@ -86,33 +86,8 @@ S32 LLViewerTexture::sImageCount = 0; S32 LLViewerTexture::sRawCount = 0; S32 LLViewerTexture::sAuxCount = 0; LLFrameTimer LLViewerTexture::sEvaluationTimer; -F32 LLViewerTexture::sDesiredDiscardBias = 0.f; -F32 LLViewerTexture::sBackgroundFactor = 0.f; -F32 LLViewerTexture::sDiscardBias = 0.f; - -//static -F32 LLViewerTexture::getMemoryPressureProgress() -{ - 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. -// Trends from TextureScreenSizeOversample toward -// TextureScreenSizeOversampleUnderPressure as the pressure multiplier -// walks its 0..1 range. Progress = 1 (mult at cap, including the high- -// water-mark slam in updateClass) lands on the floor. -static F32 pixelCapOversampleForPressure() -{ - static LLCachedControl<F32> over_base(gSavedSettings, "TextureScreenSizeOversample", 1.5f); - static LLCachedControl<F32> over_pressure(gSavedSettings, "TextureScreenSizeOversampleUnderPressure", 0.5f); - F32 base = llmax((F32)over_base, 0.1f); - F32 floor = llclamp((F32)over_pressure, 0.1f, base); - F32 progress = LLViewerTexture::getMemoryPressureProgress(); - return base + (floor - base) * progress; -} -U32 LLViewerTexture::sBiasTexturesUpdated = 0; +F32 LLViewerTexture::sPixelToTexelRatio = 1.f; +F32 LLViewerTexture::sBackgroundSeconds = 0.f; S32 LLViewerTexture::sMaxSculptRez = 128; //max sculpt image size constexpr S32 MAX_CACHED_RAW_IMAGE_AREA = 64 * 64; @@ -562,96 +537,71 @@ void LLViewerTexture::updateClass() sFreeVRAMMegabytes = vram_target - vram_used; const S32Megabytes free_sys_mem = getFreeSystemMemory(); - F32 over_pct = (vram_used - vram_target) / vram_target; - - // 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. + // Single VRAM-pressure knob: the global maximum pixel:texel ratio (texels + // per screen pixel, the "R" in 1:R). It tightens (drops toward 0, no floor) + // while used VRAM is above the high watermark, + // relaxes back toward TexturePixelToTexelRatio below the low watermark, and + // holds steady in the hysteresis band between - the band is what prevents + // sawtooth. The ramp is deliberately slow so eviction (scaleDown draining + // mDownScaleQueue) frees bytes before the next step. Lowering the ratio + // raises every texture's desired discard, which is what actually evicts. { + static LLCachedControl<F32> ratio_max(gSavedSettings, "TexturePixelToTexelRatio", 1.0f); 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 = vram_target * llclamp((F32)backoff_start, 0.05f, 1.f); - F32 cap = llmax((F32)max_mult, 1.0001f); - F32 dt = (F32)gFrameIntervalSeconds; + static LLCachedControl<F32> tighten_rate(gSavedSettings, "TexturePressureTightenRate", 0.30f); + static LLCachedControl<F32> relax_rate(gSavedSettings, "TexturePressureRelaxRate", 0.10f); - // 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 - || vram_used > backoff_target * 0.5f; + // Unbounded downward: pressure drives the ratio all the way to 0 if it + // has to. There is no quality floor - at 0 every texture resolves to + // its deepest mip (computeDesiredDiscard treats zero allowed texels as + // dim_max), and desired discard is clamped to dim_max anyway, so it + // saturates on its own. Only the top is bounded, by the configured max. + F32 r_max = llmax((F32)ratio_max, 0.f); + F32 high_frac = llclamp((F32)wm_high, 0.1f, 1.f); + F32 high = vram_budget * high_frac; + F32 low = vram_budget * llclamp((F32)wm_low, 0.05f, high_frac); + F32 dt = (F32)gFrameIntervalSeconds; - S64 pending_bytes_increase = 0; - S64 pending_bytes_decrease = 0; - if (need_predict) + if (vram_used > high) { - sDiscardBias += llmax((F32)bias_ramp, 0.f) * dt; + sPixelToTexelRatio -= llmax((F32)tighten_rate, 0.f) * dt; } - - // 1024 * 512 = 524288: matches the unit reduction at line 513. - constexpr F32 BYTES_TO_USED_UNITS = 1.f / 524288.f; - F32 predicted_used = vram_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); - - // 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 = vram_used >= vram_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) + else if (vram_used < low) { - sDiscardBias -= llmax((F32)bias_decay, 0.f) * dt; + sPixelToTexelRatio += llmax((F32)relax_rate, 0.f) * dt; } - // In the hysteresis band [low, high]: hold steady. - sDiscardBias = llclamp(sDiscardBias, 0.f, cap); + // else: hold in the hysteresis band. + sPixelToTexelRatio = llclamp(sPixelToTexelRatio, 0.f, r_max); + + // Background cooldown clock: grows while backgrounded/minimized, resets in + // foreground. Feeds the per-texture cooldown in computeDesiredDiscard so + // backgrounding steps every texture up its mip chain over time instead of + // snapping straight to the deepest mip. + bool in_background = (gViewerWindow && !gViewerWindow->getWindow()->getVisible()) || !gFocusMgr.getAppHasFocus(); + sBackgroundSeconds = in_background ? (sBackgroundSeconds + dt) : 0.f; // 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 = vram_used / llmax(backoff_target, 1.f); LL_INFOS("TextureStream") << "pressure" - << " mult=" << sMemoryPressureMultiplier - << " target_mult=" << target_mult - << " progress=" << progress + << " ratio=" << sPixelToTexelRatio << " used=" << vram_used - << " predicted=" << predicted_used - << " target=" << vram_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=" << vram_budget + << " high=" << high + << " low=" << low << " dsq=" << (S32)gTextureList.mDownScaleQueue.size() << LL_ENDL; } } - bool is_sys_low = isSystemMemoryLow(); + // System-memory -> draw-distance factor. Separate from the VRAM ratio above: + // this is a last-resort response to running low on *system* RAM and only + // affects draw distance (via getSystemMemoryBudgetFactor, consumed by + // llviewerdisplay). Textures were mostly moved to VRAM, so this rarely fires. bool is_sys_critically_low = isSystemMemoryCritical(); - bool is_low = is_sys_low || over_pct > 0.f; - - static bool was_low = false; static bool sys_was_low = false; // System memory factor @@ -706,169 +656,6 @@ void LLViewerTexture::updateClass() } } sys_was_low = is_sys_critically_low; - - // VRAM memory bias - if (is_low && !was_low) - { - if (is_sys_low) - { - // Not having system memory is more serious, so discard harder - sDesiredDiscardBias = llmax(sDesiredDiscardBias, 1.5f * getSystemMemoryBudgetFactor()); - } - else - { - // 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 || 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) - { - gTextureList.updateImageDecodePriority(image, false /*will modify gTextureList otherwise!*/); - } - } - } - - was_low = is_low; - - if (is_low) - { - // ramp up discard bias over time to free memory - if (sEvaluationTimer.getElapsedTimeF32() > MEMORY_CHECK_WAIT_TIME) - { - static LLCachedControl<F32> low_mem_min_discard_increment(gSavedSettings, "RenderLowMemMinDiscardIncrement", .1f); - - F32 increment = low_mem_min_discard_increment + llmax(over_pct, 0.f); - sDesiredDiscardBias += increment * gFrameIntervalSeconds; - } - } - else - { - // don't execute above until the slam to 1.5 has a chance to take effect - sEvaluationTimer.reset(); - - // Don't decay bias while downscale is still draining - those bytes - // are about to free and the loop would oscillate. - bool eviction_in_flight = !gTextureList.mDownScaleQueue.empty(); - - // lower discard bias over time when at least 10% of budget is free - constexpr F32 FREE_PERCENTAGE_TRESHOLD = -0.1f; - constexpr U32 FREE_SYS_MEM_THRESHOLD = 100; // 100MB more than isSystemMemoryLow to avoid fluctuations. - const S32Megabytes MIN_FREE_MAIN_MEMORY(get_render_free_main_memory_treshold() + S32Megabytes(FREE_SYS_MEM_THRESHOLD)); - if (sDesiredDiscardBias > 1.f - && over_pct < FREE_PERCENTAGE_TRESHOLD - && free_sys_mem > MIN_FREE_MAIN_MEMORY - && !eviction_in_flight) - { - static LLCachedControl<F32> high_mem_discard_decrement(gSavedSettings, "RenderHighMemMinDiscardDecrement", .1f); - - F32 decrement = high_mem_discard_decrement - llmin(over_pct - FREE_PERCENTAGE_TRESHOLD, 0.f); - sDesiredDiscardBias -= decrement * gFrameIntervalSeconds; - } - } - - // set to max discard bias if the window has been backgrounded for a while - static F32 last_desired_discard_bias = 1.f; - static F32 last_texture_update_count_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) - { - 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 was " << (is_minimized ? "minimized" : "backgrounded") << " for " << discard_time - << "s, freeing up video memory." << LL_ENDL; - - last_desired_discard_bias = sDesiredDiscardBias; - was_backgrounded = true; - } - sDesiredDiscardBias = 5.f; - } - } - else - { - backgrounded_timer.reset(); - if (was_backgrounded) - { // if the viewer was backgrounded - LL_INFOS() << "Viewer is no longer backgrounded or minimized, resuming normal texture usage." << LL_ENDL; - was_backgrounded = false; - sDesiredDiscardBias = last_desired_discard_bias; - } - } - - // Background-window ramp: 0 -> 1 at rate per second while backgrounded, - // snaps to 0 in foreground. Default 0.011 ~ 90s to saturate. - { - static LLCachedControl<F32> bg_factor_rate(gSavedSettings, "TextureBackgroundFactorRatePerSec", 0.011f); - if (in_background) - { - sBackgroundFactor += (F32)bg_factor_rate * gFrameIntervalSeconds; - sBackgroundFactor = llclampf(sBackgroundFactor); - } - else - { - sBackgroundFactor = 0.f; - } - } - - // 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()) - { - 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 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) - { - // bias increased, reset texture update counter to - // let updates happen at an increased rate. - last_texture_update_count_bias = sDesiredDiscardBias; - sBiasTexturesUpdated = 0; - } - else if (last_texture_update_count_bias > sDesiredDiscardBias + 0.1f) - { - // bias decreased, 0.1f is there to filter out small fluctuations - // and not reset sBiasTexturesUpdated too often. - // Bias jumps to 1.5 at low memory, so getting stuck at 1.1 is not - // 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 @@ -3248,155 +3035,128 @@ 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 +// Desired discard from the pixel:texel ratio - this is the entire streaming +// policy. For each channel bucket the texture is used in, the most-demanding +// (largest screen coverage) face sets that bucket's requirement at +// floor(log4(texels / (R_global * channelRatio[b] * coverage))); the sharpest +// requirement across buckets wins, since one GL image serves every channel it +// is used in. floor (not ceil) keeps content native up close - "1:1" is a +// target, not a hard cap that downrezzes anything slightly oversampled. A +// per-mip hysteresis dead-band against the current discard level prevents +// fetch/scaleDown thrash as an object slowly crosses a mip boundary. +S32 LLViewerLODTexture::computeDesiredDiscard(S32 dim_max_i, bool avatar_bake) const { static const F64 log_4 = log(4.0); + // UI-pinned (icons / thumbnails): size against the known draw size, with no + // ratio or pressure - these want exact native-for-their-slot resolution. 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); + S32 draw_texels = llclamp(mKnownDrawWidth * mKnownDrawHeight, MIN_IMAGE_AREA, MAX_IMAGE_AREA); + S32 d = (draw_texels >= (S32)mTexelsPerImage) + ? 0 + : (S32)floor(log((F64)mTexelsPerImage / (F64)draw_texels) / log_4); + return llclamp(d, 0, dim_max_i); } - // 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) + // Avatar bakes ignore the global pressure ramp (a blurred bake reads as a + // cloud avatar); they always size against the configured max ratio. + static LLCachedControl<F32> ratio_max(gSavedSettings, "TexturePixelToTexelRatio", 1.0f); + const F32 r_global = avatar_bake ? llmax((F32)ratio_max, 0.01f) : sPixelToTexelRatio; + + static LLCachedControl<F32> ch_normal (gSavedSettings, "TextureChannelRatioNormal", 1.0f); + static LLCachedControl<F32> ch_basecolor(gSavedSettings, "TextureChannelRatioBaseColor", 1.0f); + static LLCachedControl<F32> ch_specular (gSavedSettings, "TextureChannelRatioSpecular", 0.5f); + static LLCachedControl<F32> ch_emissive (gSavedSettings, "TextureChannelRatioEmissive", 0.5f); + const F32 channel_ratio[4] = { (F32)ch_normal, (F32)ch_basecolor, (F32)ch_specular, (F32)ch_emissive }; + + // Continuous ideal discard = sharpest (smallest) requirement across the + // channels this texture is actually used in. + F32 ideal = (F32)dim_max_i; // default: coarsest, until a measurement arrives + bool measured = false; + for (S32 b = 0; b < 4; ++b) { - static LLCachedControl<F32> avatar_over_mult(gSavedSettings, "TextureAgentAvatarOversampleMultiplier", 2.0f); - oversample *= llmax((F32)avatar_over_mult, 1.f); + F32 coverage = mChannelCoverage[b]; + if (coverage <= 0.f) + { + continue; + } + measured = true; + F32 allowed_texels = coverage * r_global * llmax(channel_ratio[b], 0.01f); + F32 d; + if (allowed_texels <= 0.f) // ratio driven to 0 -> deepest mip + d = (F32)dim_max_i; + else if (allowed_texels >= (F32)mTexelsPerImage) + d = 0.f; + else + d = (F32)(log((F64)mTexelsPerImage / (F64)allowed_texels) / log_4); + ideal = llmin(ideal, d); } - - // 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) + if (!measured) { - effective_screen = llmax(effective_screen, sWindowPixelArea); + return dim_max_i; // off-screen / never measured -> coarsest mip } - F32 visible_texels = effective_screen * oversample * oversample; - visible_texels = llclamp(visible_texels, (F32)MIN_IMAGE_AREA, (F32)mTexelsPerImage); + // Round toward sharper (floor): a texture stays at a mip level until its + // ideal is a full level past the boundary. This is what makes "1:1" mean + // "native up close" - ceil would downrez anything even slightly oversampled + // (a 2048 map can't hit its own resolution on a 1080p screen), which reads + // as everything being blurry. Pressure still evicts by lowering R_global. + ideal = llmax(ideal, 0.f); + const S32 target = (S32)floor(ideal); - S32 base_discard; - if ((F32)mTexelsPerImage <= visible_texels || mMaxOnScreenSize <= 0.f) + // Hysteresis: a texture at discard C is "happy" while floor(ideal) == C, + // i.e. ideal in [C, C+1). Only leave that band once ideal is past it by the + // margin, so coverage jitter at a boundary doesn't ping-pong fetch<->scaleDown. + static LLCachedControl<F32> uprez_margin(gSavedSettings, "TextureUpRezMargin", 0.2f); + const F32 margin = llclamp((F32)uprez_margin, 0.f, 0.9f); + const S32 current = getDiscardLevel(); + S32 desired; + if (current < 0) { - // 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; + desired = target; // nothing loaded yet } - else + else if (ideal >= (F32)current + 1.f + margin) { - base_discard = (S32)floor(log((F64)mTexelsPerImage / (F64)visible_texels) / log_4); + desired = target; // clearly coarser -> evict } - 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) + else if (ideal <= (F32)current - margin) { - 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]; + desired = target; // clearly finer -> uprez } - 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) + else { - 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); + desired = current; // inside the dead-band -> hold } - 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); + // Cooldown: don't snap an unseen texture straight to its deepest mip - step + // it up one level per TextureCooldownStepSeconds so briefly-occluded or + // backgrounded content isn't thrown away (and doesn't thrash the cache) when + // we look at it again. Driven by whichever is longer: time since last bind, + // or time backgrounded. It only raises discard and resets the moment the + // texture is bound again. One frame interval is subtracted so a + // continuously-visible texture (whose last bind is a frame old here, since + // this pass runs a frame ahead of its own render) reads as zero. Avatar + // bakes exempt. if (!avatar_bake) { - static LLCachedControl<S32> bg_offset(gSavedSettings, "TextureBackgroundDiscardOffset", 2); - F32 bg_norm = sBackgroundFactor; - if ((S32)bg_offset > 0 && dim_max > 0.f) + static LLCachedControl<F32> cooldown_step(gSavedSettings, "TextureCooldownStepSeconds", 1.f); + const F32 step = llmax((F32)cooldown_step, 0.01f); + F32 unbound = 0.f; + if (LLImageGL* gli = getGLTexture()) { - F32 cap = llmax(dim_max - (F32)(S32)bg_offset, 0.f) / dim_max; - bg_norm = llmin(bg_norm, cap); + const F32 ref = llmax(gli->mLastBindTime, gli->mGLCreateTime); + if (ref > 0.f) + { + unbound = llmax(0.f, LLImageGL::sLastFrameTime - ref - (F32)gFrameIntervalSeconds); + } } - const S32 bg_floor = (S32)floorf(bg_norm * dim_max); - discard = llmax(discard, bg_floor); + const F32 cooldown_seconds = llmax(unbound, sBackgroundSeconds); + const S32 cooldown_floor = llclamp((S32)floor(cooldown_seconds / step), 0, dim_max_i); + desired = llmax(desired, cooldown_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); + return llclamp(desired, 0, dim_max_i); } // This is gauranteed to get called periodically for every texture @@ -3431,7 +3191,7 @@ void LLViewerLODTexture::processTextureStats() mDesiredDiscardLevel = 0; } // HUD/UI/preview and mDontDiscard textures bypass streaming - no - // face_distance signal applies, they need native resolution. + // coverage signal applies, they need native resolution. else if (mBoostLevel >= LLGLTexture::BOOST_HIGH || mDontDiscard || !mUseMipMaps) @@ -3447,34 +3207,16 @@ void LLViewerLODTexture::processTextureStats() } else { - // 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. - // 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; - - S32 discard = computeBaseDiscard(dim_max_for_image_i); - // 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); - } + // The whole policy: pixel:texel ratio at the most-demanding face. + S32 discard = computeDesiredDiscard(dim_max_for_image_i, avatar_bake); - // 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). + // Per-texture caps: force >=1 for sources over the resolution cap; + // bound by the debug override or the dim-derived max. S32 min_discard = 0; if (mFullWidth > max_tex_res || mFullHeight > max_tex_res) min_discard = 1; @@ -3482,22 +3224,18 @@ void LLViewerLODTexture::processTextureStats() static LLCachedControl<S32> max_discard_override(gSavedSettings, "TextureMaxDiscardOverride", 0); 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; - // Caller-set min-discard cap (terrain / avatar-self / thumbnails), - // relaxed under pressure. - mDesiredDiscardLevel = (S8)applyMinDesiredCap(mDesiredDiscardLevel, dim_max_for_image_i, avatar_bake); + // Caller-set min-discard ceiling (terrain / avatar-self / thumbnails): + // never coarser than the caller explicitly asked for. + discard = llmin(discard, (S32)mMinDesiredDiscardLevel); - // (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.) + mDesiredDiscardLevel = (S8)discard; - // 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. + // If the GPU already holds finer data than we now want, evict it. + // Avatar bakes exempt: shrinking mid-bake can leave the avatar stuck + // as a cloud until the next bake completes. S32 current_discard = getDiscardLevel(); - if (!avatar_bake && current_discard < mDesiredDiscardLevel && !mForceToSaveRawImage) + if (!avatar_bake && current_discard >= 0 && current_discard < mDesiredDiscardLevel && !mForceToSaveRawImage) { scaleDown(); } diff --git a/indra/newview/llviewertexture.h b/indra/newview/llviewertexture.h index 51ef9f8206..6fc6ad72f9 100644 --- a/indra/newview/llviewertexture.h +++ b/indra/newview/llviewertexture.h @@ -205,24 +205,13 @@ protected: mutable S32 mMaxVirtualSizeResetInterval; LLFrameTimer mLastReferencedTimer; - // 0=Normal, 1=BaseColor, 2=Specular, 3=Emissive. -1 -> base color. - S8 mPriorityChannel = -1; - - // Bind-staleness floor, 0..1. Per-interval increment is 1/max_discard - // so any texture saturates after interval x max_discard seconds idle. - F32 mStalenessFactor = 0.f; - - // Closest face's face_distance / draw_distance, clamped 0..1. - // Defaults to 1 so never-measured textures resolve to deepest discard. - F32 mMinDistanceFactor = 1.f; - - // Largest per-face screen-space coverage in pixels. Raw - no bias or - // channel-priority contamination. - F32 mMaxOnScreenSize = 0.f; - - // Any face on the agent's avatar (rigged / animated). Drives the - // own-avatar quality boost in processTextureStats. - bool mOnAgentAvatar = false; + // Largest screen-space pixel coverage among the texture's faces, per + // priority bucket (0=Normal, 1=BaseColor, 2=Specular, 3=Emissive). 0 = the + // texture is not used in that channel (or hasn't been measured yet). + // Populated by LLViewerTextureList::updateImageDecodePriority; consumed by + // LLViewerLODTexture::computeDesiredDiscard. This is the only view-dependent + // streaming signal - distance, size, and channel role all collapse into it. + F32 mChannelCoverage[4] = { 0.f, 0.f, 0.f, 0.f }; ll_face_list_t mFaceList[LLRender::NUM_TEXTURE_CHANNELS]; //reverse pointer pointing to the faces using this image as texture U32 mNumFaces[LLRender::NUM_TEXTURE_CHANNELS]; @@ -244,28 +233,21 @@ public: static S32 sRawCount; static S32 sAuxCount; static LLFrameTimer sEvaluationTimer; - static F32 sDesiredDiscardBias; - // Backgrounded-window discard floor, 0..1. Ramps while backgrounded, - // snaps to 0 in foreground. Avatar bakes exempt. - static F32 sBackgroundFactor; - // 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; + // The single VRAM-pressure knob: the global maximum pixel:texel ratio, + // expressed as texels per screen pixel (the "R" in 1:R). Starts at + // TexturePixelToTexelRatio (1.0 = one texel per pixel) and the watermark + // controller in updateClass() walks it down toward 0 (no floor) + // while used VRAM is above the high watermark, back up below the low + // watermark, holding in the band between. Lowering it raises every + // texture's desired discard, which drives scaleDown eviction. Consumed by + // LLViewerLODTexture::computeDesiredDiscard. + static F32 sPixelToTexelRatio; + + // Seconds the app has been backgrounded/minimized (0 in foreground). Drives + // the background half of the per-texture cooldown in computeDesiredDiscard. + static F32 sBackgroundSeconds; - // 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 ; static U32 sMinLargeImageSize ; static U32 sMaxSmallImageSize ; @@ -335,27 +317,6 @@ public: } public: - - struct Compare - { - // lhs < rhs - bool operator()(const LLPointer<LLViewerFetchedTexture> &lhs, const LLPointer<LLViewerFetchedTexture> &rhs) const - { - const LLViewerFetchedTexture* lhsp = (const LLViewerFetchedTexture*)lhs; - const LLViewerFetchedTexture* rhsp = (const LLViewerFetchedTexture*)rhs; - - // greater priority is "less" - const F32 lpriority = lhsp->mMaxVirtualSize; - const F32 rpriority = rhsp->mMaxVirtualSize; - if (lpriority > rpriority) // higher priority - return true; - if (lpriority < rpriority) - return false; - return lhsp < rhsp; - } - }; - -public: /*virtual*/ S8 getType() const override; FTType getFTType() const; /*virtual*/ void forceImmediateUpdate() override; @@ -607,22 +568,15 @@ 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; + // The whole streaming pipeline: desired discard from the pixel:texel ratio. + // For each channel bucket the texture is used in, the most-demanding + // (largest coverage) face sets that bucket's requirement at + // floor(log4(texels / (R_global * channelRatio[b] * coverage))); the sharpest + // requirement across buckets wins (one GL image serves all its channels). + // A per-mip hysteresis dead-band against the current discard level prevents + // fetch/scaleDown thrash. avatar_bake textures use the configured max ratio + // instead of the pressure-driven sPixelToTexelRatio (anti cloud-bug). + S32 computeDesiredDiscard(S32 dim_max_i, bool avatar_bake) const; }; // diff --git a/indra/newview/llviewertexturelist.cpp b/indra/newview/llviewertexturelist.cpp index 780dda6ef7..16a3418bc7 100644 --- a/indra/newview/llviewertexturelist.cpp +++ b/indra/newview/llviewertexturelist.cpp @@ -71,7 +71,6 @@ void (*LLViewerTextureList::sUUIDCallback)(void **, const LLUUID&) = NULL; S32 LLViewerTextureList::sNumImages = 0; -F32 LLViewerTextureList::sCurrentBubbleMeters = 0.f; LLViewerTextureList gTextureList; @@ -917,100 +916,62 @@ void LLViewerTextureList::updateImageDecodePriority(LLViewerFetchedTexture* imag { llassert(!gCubeSnapshot); - constexpr F32 BIAS_TRS_ON_SCREEN = 1.f; // perf gate for face-loop early exit - if (imagep->getBoostLevel() < LLViewerFetchedTexture::BOOST_HIGH) // don't bother checking face list for boosted textures { static LLCachedControl<F32> texture_scale_min(gSavedSettings, "TextureScaleMinAreaFactor", 0.0095f); static LLCachedControl<F32> texture_scale_max(gSavedSettings, "TextureScaleMaxAreaFactor", 25.f); - F32 max_vsize = 0.f; - bool on_screen = false; - - // Accumulators for the per-texture signals published below. - // Defaults map to "deepest discard wanted" until evidence updates them. - F32 min_distance_factor = 1.f; - F32 max_on_screen_size = 0.f; - bool on_agent_avatar = false; - F32 draw_distance = llmax(gAgentCamera.mDrawDistance, 0.001f); - - // Close-camera bubble: faces inside `bubble` meters resolve to - // dist_factor = 0, so the distance ramp spans (bubble, draw_distance]. - static LLCachedControl<F32> close_bubble(gSavedSettings, "TextureCloseBubbleMeters", 5.f); - static LLCachedControl<F32> close_bubble_min(gSavedSettings, "TextureCloseBubbleMinMeters", 0.1f); - static LLCachedControl<F32> bubble_shrink_threshold(gSavedSettings, "TextureCloseBubbleShrinkThreshold", 0.8f); - static LLCachedControl<F32> bubble_track_rate(gSavedSettings, "TextureCloseBubbleTrackRate", 0.5f); - F32 bubble_full = llmax((F32)close_bubble, 0.f); - F32 bubble_min = llclamp((F32)close_bubble_min, 0.f, bubble_full); - // Advance the slow-track once per frame, not per texture: this - // function runs once per texture so a naive per-call lerp converges - // in a single frame. - static F32 s_tracked_bubble = -1.f; - static U32 s_tracked_bubble_frame = 0; - if (s_tracked_bubble < 0.f) s_tracked_bubble = bubble_full; - if (s_tracked_bubble_frame != LLFrameTimer::getFrameCount()) - { - s_tracked_bubble_frame = LLFrameTimer::getFrameCount(); - F32 progress = LLViewerTexture::getMemoryPressureProgress(); - F32 shrink_thresh = llclampf((F32)bubble_shrink_threshold); - F32 shrink_frac = (progress > shrink_thresh) - ? (progress - shrink_thresh) / llmax(1.f - shrink_thresh, 0.0001f) - : 0.f; - F32 target_bubble = bubble_full - (bubble_full - bubble_min) * shrink_frac; - F32 dt = (F32)gFrameIntervalSeconds; - F32 alpha = 1.f - expf(-llmax(dt, 0.f) * llmax((F32)bubble_track_rate, 0.f)); - s_tracked_bubble += (target_bubble - s_tracked_bubble) * alpha; - s_tracked_bubble = llclamp(s_tracked_bubble, bubble_min, bubble_full); - sCurrentBubbleMeters = s_tracked_bubble; - } - F32 bubble = llclamp(s_tracked_bubble, 0.f, draw_distance - 0.001f); - F32 ramp_range = llmax(draw_distance - bubble, 0.001f); + // Largest screen-space pixel coverage per priority bucket + // (0=Normal, 1=BaseColor, 2=Specular, 3=Emissive), plus the overall max. + // The per-bucket maxima drive desired discard with per-channel ratios; + // the overall max is the fetch priority (raw - no bias). A bucket with + // faces but zero coverage (all off-screen) publishes 0, which + // computeDesiredDiscard reads as "coarsest mip". + F32 channel_coverage[4] = { 0.f, 0.f, 0.f, 0.f }; + bool bucket_used[4] = { false, false, false, false }; + F32 max_coverage = 0.f; U32 face_count = 0; - U32 max_faces_to_check = 1024; + const U32 max_faces_to_check = 1024; - // Pick the least-aggressive channel across all uses, so a texture - // used as both diffuse and normal isn't penalized by its harshest - // role. -1 sentinel keeps emissive-only textures (W=3) from being - // clobbered by a smaller init value. - S32 priority_channel = -1; + // Cheap first pass: which buckets is this texture used in, and how many + // faces total. No per-face geometry work. for (U32 i = 0; i < LLRender::NUM_TEXTURE_CHANNELS; ++i) { - if (imagep->getNumFaces(i) > 0) + U32 n = imagep->getNumFaces(i); + face_count += n; + if (n > 0) { - S32 mapped = sChannelToPriority[i]; - priority_channel = (priority_channel < 0) ? mapped : llmin(priority_channel, mapped); + S32 b = sChannelToPriority[i]; + if (b >= 0 && b < 4) bucket_used[b] = true; } } - if (priority_channel < 0) + + if (face_count > max_faces_to_check) { - priority_channel = 1; // no faces - default to diffuse + // Used in so many places that scanning the face list isn't worth it + // (and isn't time-sliced) - treat as full-screen so it loads sharp. + for (S32 b = 0; b < 4; ++b) + if (bucket_used[b]) channel_coverage[b] = (F32)MAX_IMAGE_AREA; + max_coverage = (F32)MAX_IMAGE_AREA; } - imagep->mPriorityChannel = (S8)priority_channel; - - // get adjusted bias based on image resolution - LLImageGL* img = imagep->getGLTexture(); - F32 max_discard = F32(img ? img->getMaxDiscardLevel() : MAX_DISCARD_LEVEL); - F32 bias = llclamp(max_discard - 2.f, 1.f, LLViewerTexture::sDesiredDiscardBias); - - // convert bias into a vsize scaler - bias = (F32) llroundf(powf(4, bias - 1.f)); - - LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE; - for (U32 i = 0; i < LLRender::NUM_TEXTURE_CHANNELS; ++i) + else { - face_count += imagep->getNumFaces(i); - S32 faces_to_check = (face_count > max_faces_to_check) ? 0 : imagep->getNumFaces(i); - - for (S32 fi = 0; fi < faces_to_check; ++fi) + LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE; + for (U32 i = 0; i < LLRender::NUM_TEXTURE_CHANNELS; ++i) { - LLFace* face = (*(imagep->getFaceList(i)))[fi]; - - if (face && face->getViewerObject()) + const S32 bucket = sChannelToPriority[i]; + const U32 num_faces = imagep->getNumFaces(i); + for (U32 fi = 0; fi < num_faces; ++fi) { + LLFace* face = (*(imagep->getFaceList(i)))[fi]; + if (!face || !face->getViewerObject()) + { + continue; + } + F32 radius; F32 cos_angle_to_view_dir; - if ((gFrameCount - face->mLastTextureUpdate) > 10) { // only call calcPixelArea at most once every 10 frames for a given face // this helps eliminate redundant calls to calcPixelArea for faces that have multiple textures @@ -1021,159 +982,48 @@ void LLViewerTextureList::updateImageDecodePriority(LLViewerFetchedTexture* imag F32 vsize = face->getPixelArea(); - on_screen |= face->mInFrustum; - - F32 dist_above_bubble = llmax(face->mDistanceToCamera - bubble, 0.f); - F32 dist_factor = llclampf(dist_above_bubble / ramp_range); - min_distance_factor = llmin(min_distance_factor, dist_factor); - - if (face->mAvatar && face->mAvatar == gAgentAvatarp) - { - on_agent_avatar = true; - } - - // Scale desired texture resolution higher or lower depending on texture scale - // - // Minimum usage examples: a 1024x1024 texture with aplhabet (texture atlas), - // runing string shows one letter at a time. If texture has ten 100px symbols - // per side, minimal scale is (100/1024)^2 = 0.0095 - // - // Maximum usage examples: huge chunk of terrain repeats texture - // TODO: make this work with the GLTF texture transforms + // Scale coverage by texture repeat: a texture shown at a + // fraction of a face (atlas) needs only that fraction of + // texels; a tiled texture needs more. getMinScaleSq() is the + // cached min(|scaleS|,|scaleT|)^2, invalidated by setScale*. 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); - // 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 / - // camera-boost mutations below so the size signal is clean. - max_on_screen_size = llmax(max_on_screen_size, vsize); - - // apply bias to offscreen faces all the time, but only to onscreen faces when bias is large - // use mImportanceToCamera to make bias switch a bit more gradual - if (!face->mInFrustum || LLViewerTexture::sDesiredDiscardBias > 1.9f + face->mImportanceToCamera / 2.f) - { - vsize /= bias; - } - - max_vsize = llmax(max_vsize, vsize); - - // addTextureStats limits size to sMaxVirtualSize - if (max_vsize >= LLViewerFetchedTexture::sMaxVirtualSize - && (on_screen || LLViewerTexture::sDesiredDiscardBias <= BIAS_TRS_ON_SCREEN)) - { - break; - } + if (bucket >= 0 && bucket < 4) + channel_coverage[bucket] = llmax(channel_coverage[bucket], vsize); + max_coverage = llmax(max_coverage, vsize); } } - - if (max_vsize >= LLViewerFetchedTexture::sMaxVirtualSize - && (on_screen || LLViewerTexture::sDesiredDiscardBias <= BIAS_TRS_ON_SCREEN)) - { - break; - } - } - - bool used_face_fast_path = (face_count > max_faces_to_check); - if (used_face_fast_path) - { // this texture is used in so many places we should just boost it and not bother checking its vsize - // this is especially important because the above is not time sliced and can hit multiple ms for a single texture - max_vsize = MAX_IMAGE_AREA; } - imagep->addTextureStats(max_vsize); - - // Publish per-texture signals for processTextureStats. Closest face - // wins for distance (min); biggest face wins for size (max). Default - // distance=1, size=0 maps to "deepest discard wanted" - never- - // measured textures stay coarse until distance/size evidence arrives. - if (used_face_fast_path) - { - // Fast path saw only a prefix of faces - force best-quality - // sentinels to match the MAX_IMAGE_AREA vsize boost above. - imagep->mMinDistanceFactor = 0.f; - imagep->mMaxOnScreenSize = (F32)MAX_IMAGE_AREA; - } - else if (face_count == 0 && imagep->getBoostLevel() == LLGLTexture::BOOST_TERRAIN) + // Terrain detail textures register no faces (LLVOSurfacePatch + // addFace(NULL)); synthesize coverage from the nearest visible patch so + // they degrade with distance like everything else. + if (face_count == 0 && imagep->getBoostLevel() == LLGLTexture::BOOST_TERRAIN) { - // Terrain detail textures don't register faces with the texture - // (LLVOSurfacePatch addFace(NULL)). Drive distance from the LOD - // system; floor at a small nonzero value so pressure has - // something to bite into (pow(0, p) = 0). - static LLCachedControl<F32> terrain_distance_floor(gSavedSettings, "TextureTerrainDistanceFloor", 0.01f); - static LLCachedControl<F32> terrain_coverage(gSavedSettings, "TextureTerrainCoverageFraction", 0.99f); F32 nearest = LLSurface::sNearestVisiblePatchDistance; - F32 nearest_above_bubble = (nearest < FLT_MAX) ? llmax(nearest - bubble, 0.f) : ramp_range; - F32 dist = llclampf(nearest_above_bubble / ramp_range); - imagep->mMinDistanceFactor = llmax(dist, llclampf((F32)terrain_distance_floor)); - imagep->mMaxOnScreenSize = LLViewerTexture::sWindowPixelArea * llclampf((F32)terrain_coverage); + F32 draw_distance = llmax(gAgentCamera.mDrawDistance, 1.f); + F32 near_frac = (nearest < FLT_MAX) ? llclampf(1.f - nearest / draw_distance) : 0.f; + // Floor so terrain never collapses to nothing at draw distance. + F32 cov = LLViewerTexture::sWindowPixelArea * llmax(near_frac, 0.05f); + channel_coverage[1] = cov; // terrain detail maps are diffuse / base color + max_coverage = cov; } - else - { - imagep->mMinDistanceFactor = min_distance_factor; - imagep->mMaxOnScreenSize = max_on_screen_size; - } - imagep->mOnAgentAvatar = on_agent_avatar; - - // Bind-staleness. Avatar bakes exempt (cloud-bug protection). - // Per-interval increment is 1/max_discard so saturation time is - // interval * max_discard seconds regardless of texture size. - // Never-bound textures defer to distance/size or initial fetch - // could never start. - if (LLViewerFetchedTexture::isAgentAvatarBoost(imagep->getBoostLevel())) - { - imagep->mStalenessFactor = 0.f; - } - else if (LLImageGL* gli = imagep->getGLTexture()) - { - static LLCachedControl<F32> bind_decay_seconds(gSavedSettings, "TextureBindDecaySeconds", 5.f); - static LLCachedControl<F32> staleness_interval(gSavedSettings, "TextureStalenessIntervalSeconds", 5.f); - F32 grace = llmax((F32)bind_decay_seconds, 0.f); - F32 interval = llmax((F32)staleness_interval, 0.0001f); - // Clock starts at whichever is later: the last real bind or - // the GL-create time. The latter is the fallback for textures - // decoded into GL but never actually rendered - without it, - // mLastBindTime stays 0 forever and staleness can't evict. - F32 clock_time = llmax(gli->mLastBindTime, gli->mGLCreateTime); - bool has_clock = (clock_time > 0.f); - F32 time_since = has_clock ? (LLImageGL::sLastFrameTime - clock_time) : 0.f; + imagep->addTextureStats(max_coverage); - if (!has_clock || time_since <= grace) - { - imagep->mStalenessFactor = 0.f; - } - else - { - S32 full_w = imagep->getFullWidth(); - S32 full_h = imagep->getFullHeight(); - S32 max_discard = (full_w > 0 && full_h > 0) - ? LLImageGL::dimDerivedMaxDiscard(full_w, full_h) - : (S32)gli->getMaxDiscardLevel(); - if (max_discard > 0) - { - F32 steps = (time_since - grace) / interval; - F32 step_size = 1.f / (F32)max_discard; - imagep->mStalenessFactor = llclampf(steps * step_size); - } - else - { - imagep->mStalenessFactor = 0.f; - } - } + // Publish per-bucket coverage for LLViewerLODTexture::computeDesiredDiscard. + for (S32 b = 0; b < 4; ++b) + { + imagep->mChannelCoverage[b] = channel_coverage[b]; } - } #if 0 - imagep->setDebugText(llformat("%d/%d - %d/%d -- %d/%d", - (S32)sqrtf(max_vsize), - (S32)sqrtf(imagep->mMaxVirtualSize), + imagep->setDebugText(llformat("%d/%d -- %d/%d", imagep->getDiscardLevel(), imagep->getDesiredDiscardLevel(), imagep->getWidth(), @@ -1412,28 +1262,6 @@ 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. 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()) - { - update_count = (S32)(update_count * pressure_scale); - - // 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 the scaled rate permanently. - LLViewerTexture::sBiasTexturesUpdated += update_count; - } update_count = llmin(update_count, (U32) mUUIDMap.size()); { // copy entries out of UUID map to avoid iterator invalidation from deletion inside updateImageDecodeProiroty or updateFetch below diff --git a/indra/newview/llviewertexturelist.h b/indra/newview/llviewertexturelist.h index dbed8b5c2f..931f2ed50e 100644 --- a/indra/newview/llviewertexturelist.h +++ b/indra/newview/llviewertexturelist.h @@ -244,10 +244,6 @@ private: bool mInitialized ; LLFrameTimer mForceDecodeTimer; -public: - // Current close-camera bubble in meters (frame-coherent, slow-tracked). - static F32 sCurrentBubbleMeters; - private: static S32 sNumImages; static void (*sUUIDCallback)(void**, const LLUUID &); |
