From c0eeb158af74e7d6836297e0c27f4755f9e123f9 Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Fri, 12 May 2023 18:18:07 -0400
Subject: [PATCH] Hack to fix shaders not generating correct binary variants
 from various setting combinations

---
 indra/llrender/llglslshader.cpp     | 7 +++++++
 indra/llrender/llglslshader.h       | 1 +
 indra/newview/llviewershadermgr.cpp | 2 ++
 3 files changed, 10 insertions(+)

diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp
index 90c9d00bc1e..eb99b39802b 100644
--- a/indra/llrender/llglslshader.cpp
+++ b/indra/llrender/llglslshader.cpp
@@ -58,6 +58,7 @@ LLGLSLShader* LLGLSLShader::sCurBoundShaderPtr = NULL;
 S32 LLGLSLShader::sIndexedTextureChannels = 0;
 bool LLGLSLShader::sProfileEnabled = false;
 std::set<LLGLSLShader*> LLGLSLShader::sInstances;
+LLGLSLShader::defines_map_t LLGLSLShader::sGlobalDefines;
 U64 LLGLSLShader::sTotalTimeElapsed = 0;
 U32 LLGLSLShader::sTotalTrianglesDrawn = 0;
 U64 LLGLSLShader::sTotalSamplesDrawn = 0;
@@ -2001,6 +2002,12 @@ LLUUID LLGLSLShader::hash()
         hash_obj.update(define_pair.first);
         hash_obj.update(define_pair.second);
 
+    }
+    for (const auto& define_pair : LLGLSLShader::sGlobalDefines)
+    {
+        hash_obj.update(define_pair.first);
+        hash_obj.update(define_pair.second);
+
     }
     hash_obj.update(&mFeatures, sizeof(LLShaderFeatures));
     hash_obj.update(gGLManager.mGLVendor);
diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h
index 22664ac4d4c..5838aef8a92 100644
--- a/indra/llrender/llglslshader.h
+++ b/indra/llrender/llglslshader.h
@@ -313,6 +313,7 @@ class LLGLSLShader
     std::string mName;
     typedef std::map<std::string, std::string> defines_map_t;
     defines_map_t mDefines;
+    static defines_map_t sGlobalDefines;
     LLUUID mShaderHash;
     bool mUsingBinaryProgram = false;
 
diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp
index bc2b33e5ca1..df8227027b0 100644
--- a/indra/newview/llviewershadermgr.cpp
+++ b/indra/newview/llviewershadermgr.cpp
@@ -683,6 +683,8 @@ std::string LLViewerShaderMgr::loadBasicShaders()
 		attribs["REF_SAMPLE_COUNT"] = "32";
 	}
 
+	LLGLSLShader::sGlobalDefines = attribs;
+
 	// We no longer have to bind the shaders to global glhandles, they are automatically added to a map now.
 	for (U32 i = 0; i < shaders.size(); i++)
 	{
-- 
GitLab