From 97764080b0eaf7b359b7e2332e6c1257ba86a71a Mon Sep 17 00:00:00 2001
From: Cosmic Linden <cosmic@lindenlab.com>
Date: Tue, 23 Jan 2024 15:17:15 -0800
Subject: Review feedback: Remove static RenderLocalLightCount, as cached
 settings refresh has surprising performance cost

---
 indra/newview/llgltfmaterialpreviewmgr.cpp | 5 ++++-
 indra/newview/pipeline.cpp                 | 9 +++------
 indra/newview/pipeline.h                   | 1 -
 3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/indra/newview/llgltfmaterialpreviewmgr.cpp b/indra/newview/llgltfmaterialpreviewmgr.cpp
index a8ea3429f4..1dba3f082f 100644
--- a/indra/newview/llgltfmaterialpreviewmgr.cpp
+++ b/indra/newview/llgltfmaterialpreviewmgr.cpp
@@ -34,6 +34,7 @@
 #include "llenvironment.h"
 #include "llselectmgr.h"
 #include "llviewercamera.h"
+#include "llviewercontrol.h"
 #include "llviewerobject.h"
 #include "llviewershadermgr.h"
 #include "llviewertexturelist.h"
@@ -419,7 +420,8 @@ BOOL LLGLTFPreviewTexture::render()
     LLVector3 light_dir3(1.0f, 1.0f, 1.0f);
     light_dir3.normalize();
     const LLVector4 light_dir = LLVector4(light_dir3, 0);
-    SetTemporarily<S32> sun_light_only(&LLPipeline::RenderLocalLightCount, 0);
+    const S32 old_local_light_count = gSavedSettings.get<S32>("RenderLocalLightCount");
+    gSavedSettings.set<S32>("RenderLocalLightCount", 0);
 
     gPipeline.mReflectionMapManager.forceDefaultProbeAndUpdateUniforms();
 
@@ -524,6 +526,7 @@ BOOL LLGLTFPreviewTexture::render()
     // Clean up
     gPipeline.setupHWLights();
     gPipeline.mReflectionMapManager.forceDefaultProbeAndUpdateUniforms(false);
+    gSavedSettings.set<S32>("RenderLocalLightCount", old_local_light_count);
 
     return TRUE;
 }
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index 94f2dc4a2a..d81bcef259 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -163,7 +163,6 @@ F32 LLPipeline::CameraFocusTransitionTime;
 F32 LLPipeline::CameraFNumber;
 F32 LLPipeline::CameraFocalLength;
 F32 LLPipeline::CameraFieldOfView;
-S32 LLPipeline::RenderLocalLightCount;
 F32 LLPipeline::RenderShadowNoise;
 F32 LLPipeline::RenderShadowBlurSize;
 F32 LLPipeline::RenderSSAOScale;
@@ -525,7 +524,6 @@ void LLPipeline::init()
 	connectRefreshCachedSettingsSafe("CameraFNumber");
 	connectRefreshCachedSettingsSafe("CameraFocalLength");
 	connectRefreshCachedSettingsSafe("CameraFieldOfView");
-	connectRefreshCachedSettingsSafe("RenderLocalLightCount");
 	connectRefreshCachedSettingsSafe("RenderShadowNoise");
 	connectRefreshCachedSettingsSafe("RenderShadowBlurSize");
 	connectRefreshCachedSettingsSafe("RenderSSAOScale");
@@ -1025,7 +1023,6 @@ void LLPipeline::refreshCachedSettings()
 	CameraFNumber = gSavedSettings.getF32("CameraFNumber");
 	CameraFocalLength = gSavedSettings.getF32("CameraFocalLength");
 	CameraFieldOfView = gSavedSettings.getF32("CameraFieldOfView");
-	RenderLocalLightCount = gSavedSettings.getS32("RenderLocalLightCount");
 	RenderShadowNoise = gSavedSettings.getF32("RenderShadowNoise");
 	RenderShadowBlurSize = gSavedSettings.getF32("RenderShadowBlurSize");
 	RenderSSAOScale = gSavedSettings.getF32("RenderSSAOScale");
@@ -5262,7 +5259,7 @@ void LLPipeline::calcNearbyLights(LLCamera& camera)
 		return;
 	}
 
-    const S32 local_light_count = LLPipeline::RenderLocalLightCount;
+    static LLCachedControl<S32> local_light_count(gSavedSettings, "RenderLocalLightCount", 256);
 
 	if (local_light_count >= 1)
 	{
@@ -5531,7 +5528,7 @@ void LLPipeline::setupHWLights()
 
 	mLightMovingMask = 0;
 	
-    const S32 local_light_count = LLPipeline::RenderLocalLightCount;
+    static LLCachedControl<S32> local_light_count(gSavedSettings, "RenderLocalLightCount", 256);
 
 	if (local_light_count >= 1)
 	{
@@ -7965,7 +7962,7 @@ void LLPipeline::renderDeferredLighting()
             unbindDeferredShader(gDeferredSoftenProgram);
         }
 
-        const S32 local_light_count = LLPipeline::RenderLocalLightCount;
+        static LLCachedControl<S32> local_light_count(gSavedSettings, "RenderLocalLightCount", 256);
 
         if (local_light_count > 0)
         {
diff --git a/indra/newview/pipeline.h b/indra/newview/pipeline.h
index 21c1d9a25d..5ace90b000 100644
--- a/indra/newview/pipeline.h
+++ b/indra/newview/pipeline.h
@@ -1015,7 +1015,6 @@ public:
 	static F32 CameraFNumber;
 	static F32 CameraFocalLength;
 	static F32 CameraFieldOfView;
-	static S32 RenderLocalLightCount;
 	static F32 RenderShadowNoise;
 	static F32 RenderShadowBlurSize;
 	static F32 RenderSSAOScale;
-- 
cgit v1.2.3