From ef755235551d68b2790ed7c5363038f46a226306 Mon Sep 17 00:00:00 2001
From: RunitaiLinden <davep@lindenlab.com>
Date: Wed, 13 Mar 2024 12:22:12 -0500
Subject: [PATCH] 983 add debug setting to control the maximum download
 resolution (#986)

* Create RenderMaxTextureResolution.md

* #983 Add RenderMaxTextureResolution setting.  Incidental crash fix.
---
 doc/testplans/RenderMaxTextureResolution.md | 16 ++++++++++++++++
 indra/newview/app_settings/settings.xml     | 11 +++++++++++
 indra/newview/llheroprobemanager.cpp        |  2 +-
 indra/newview/llheroprobemanager.h          |  4 ++--
 indra/newview/llviewertexture.cpp           | 10 +++++++++-
 5 files changed, 39 insertions(+), 4 deletions(-)
 create mode 100644 doc/testplans/RenderMaxTextureResolution.md

diff --git a/doc/testplans/RenderMaxTextureResolution.md b/doc/testplans/RenderMaxTextureResolution.md
new file mode 100644
index 00000000000..2b117050c75
--- /dev/null
+++ b/doc/testplans/RenderMaxTextureResolution.md
@@ -0,0 +1,16 @@
+The Setting RenderMaxTextureResolution controls the maximum resolution of non-boosted textures as displayed by the viewer.
+
+Valid values are 512-2048 (clamped in C++).
+
+![image](https://github.com/secondlife/viewer/assets/23218274/d0f889fc-8135-41d2-9d83-871ad4eebed5)
+
+![image](https://github.com/secondlife/viewer/assets/23218274/19950828-7eb1-4bb2-85d7-f35c63b34294)
+
+![image](https://github.com/secondlife/viewer/assets/23218274/249afc83-4de6-488d-a05e-4877d08573b1)
+
+Test Asset available on beta grid:
+Object: 'Damaged Helmet', AssetID 0623e759-11b5-746c-a75e-7ba1caa6eb0e
+
+
+
+
diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml
index aaab7f1d457..f248fac2ee2 100644
--- a/indra/newview/app_settings/settings.xml
+++ b/indra/newview/app_settings/settings.xml
@@ -9405,6 +9405,17 @@
     <string>U32</string>
     <key>Value</key>
     <integer>16</integer>
+  </map>
+  <key>RenderMaxTextureResolution</key>
+  <map>
+    <key>Comment</key>
+    <string>Maximum texture resolution to download for non-boosted textures.</string>
+    <key>Persist</key>
+    <integer>1</integer>
+    <key>Type</key>
+    <string>U32</string>
+    <key>Value</key>
+    <integer>2048</integer>
   </map>
     <key>RenderDebugTextureBind</key>
     <map>
diff --git a/indra/newview/llheroprobemanager.cpp b/indra/newview/llheroprobemanager.cpp
index 10b743ceefb..13c12b5e557 100644
--- a/indra/newview/llheroprobemanager.cpp
+++ b/indra/newview/llheroprobemanager.cpp
@@ -581,7 +581,7 @@ bool LLHeroProbeManager::registerViewerObject(LLVOVolume* drawablep)
 
 void LLHeroProbeManager::unregisterViewerObject(LLVOVolume* drawablep)
 {
-    std::vector<LLVOVolume*>::iterator found_itr = std::find(mHeroVOList.begin(), mHeroVOList.end(), drawablep);
+    std::vector<LLPointer<LLVOVolume>>::iterator found_itr = std::find(mHeroVOList.begin(), mHeroVOList.end(), drawablep);
     if (found_itr != mHeroVOList.end())
     {
         mHeroVOList.erase(found_itr);
diff --git a/indra/newview/llheroprobemanager.h b/indra/newview/llheroprobemanager.h
index 04027cd57e8..17e75a18d49 100644
--- a/indra/newview/llheroprobemanager.h
+++ b/indra/newview/llheroprobemanager.h
@@ -146,8 +146,8 @@ class alignas(16) LLHeroProbeManager
     
     U32 mCurrentProbeUpdateFrame = 0;
     
-    std::vector<LLVOVolume*>                       mHeroVOList;
-    LLVOVolume*                                 mNearestHero;
+    std::vector<LLPointer<LLVOVolume>>                       mHeroVOList;
+    LLPointer<LLVOVolume>                                 mNearestHero;
 
 };
 
diff --git a/indra/newview/llviewertexture.cpp b/indra/newview/llviewertexture.cpp
index 8436159e14e..9759b9a31ba 100644
--- a/indra/newview/llviewertexture.cpp
+++ b/indra/newview/llviewertexture.cpp
@@ -3079,7 +3079,15 @@ void LLViewerLODTexture::processTextureStats()
 	updateVirtualSize();
 	
 	static LLCachedControl<bool> textures_fullres(gSavedSettings,"TextureLoadFullRes", false);
-	
+
+    { // restrict texture resolution to download based on RenderMaxTextureResolution
+        static LLCachedControl<U32> max_texture_resolution(gSavedSettings, "RenderMaxTextureResolution", 2048);
+        // sanity clamp debug setting to avoid settings hack shenanigans
+        F32 tex_res = (F32)llclamp((S32)max_texture_resolution, 512, 2048);
+        tex_res *= tex_res;
+        mMaxVirtualSize = llmin(mMaxVirtualSize, tex_res);
+    }
+
 	if (textures_fullres)
 	{
 		mDesiredDiscardLevel = 0;
-- 
GitLab