From ec8803b6f3db45e0a6629afc08e815516f52491a Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Thu, 8 Jul 2021 22:44:59 -0400
Subject: [PATCH] Use fast path in OSX fxaa

---
 indra/llrender/llgl.cpp                                  | 4 ++++
 indra/llrender/llgl.h                                    | 1 +
 indra/llrender/llshadermgr.cpp                           | 9 ++++++++-
 .../app_settings/shaders/class1/deferred/fxaaF.glsl      | 1 +
 4 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/indra/llrender/llgl.cpp b/indra/llrender/llgl.cpp
index 2c8ce92872f..631cfff2b0d 100644
--- a/indra/llrender/llgl.cpp
+++ b/indra/llrender/llgl.cpp
@@ -181,6 +181,7 @@ LLGLManager::LLGLManager() :
 	mHasDebugOutput(FALSE),
 
 	mHasTextureSwizzle(false),
+    mHasGPUShader4(false),
 	mIsATI(FALSE),
 	mIsNVIDIA(FALSE),
 	mIsIntel(FALSE),
@@ -744,6 +745,7 @@ void LLGLManager::asLLSD(LLSD& info)
 	info["has_srgb_texture"] = mHassRGBTexture;
 	info["has_srgb_framebuffer"] = mHassRGBFramebuffer;
     info["has_texture_srgb_decode"] = mHasTexturesRGBDecode;
+    info["has_gpu_shader_4"] = mHasGPUShader4;
 
 	// Vendor-specific extensions
 	info["is_ati"] = mIsATI;
@@ -891,6 +893,7 @@ void LLGLManager::initExtensions()
 	mHasFragmentShader = mGLVersion >= 2.0f || (epoxy_has_gl_extension("GL_ARB_fragment_shader") && (LLRender::sGLCoreProfile || epoxy_has_gl_extension("GL_ARB_shading_language_100")));
 
 	mHasTextureSwizzle = mGLVersion >= 3.3f || epoxy_has_gl_extension("GL_ARB_texture_swizzle");
+    mHasGPUShader4 = mGLVersion >= 3.0f || epoxy_has_gl_extension("GL_EXT_gpu_shader4");
 #endif
 
 #if LL_LINUX
@@ -917,6 +920,7 @@ void LLGLManager::initExtensions()
 		mHasVertexShader = FALSE;
 		mHasFragmentShader = FALSE;
 		mHasTextureSwizzle = FALSE;
+        mHasGPUShader4 = FALSE;
 		LL_WARNS("RenderInit") << "GL extension support DISABLED via LL_GL_NOEXT" << LL_ENDL;
 	}
 	else if (getenv("LL_GL_BASICEXT"))	/* Flawfinder: ignore */
diff --git a/indra/llrender/llgl.h b/indra/llrender/llgl.h
index f1f48d5a775..5043627e2a8 100644
--- a/indra/llrender/llgl.h
+++ b/indra/llrender/llgl.h
@@ -130,6 +130,7 @@ class LLGLManager
 	BOOL mHassRGBFramebuffer;
     BOOL mHasTexturesRGBDecode;
 	bool mHasTextureSwizzle;
+    bool mHasGPUShader4;
 
 	// Vendor-specific extensions
 	BOOL mIsATI;
diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp
index 74d88576bfa..e765e45e80d 100644
--- a/indra/llrender/llshadermgr.cpp
+++ b/indra/llrender/llshadermgr.cpp
@@ -715,7 +715,14 @@ GLuint LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_lev
 			//set version to 1.20
 			shader_code_text[shader_code_count++] = strdup("#version 120\n");
        		extra_code_text[extra_code_count++] = strdup("#define FXAA_GLSL_120 1\n");
-			extra_code_text[extra_code_count++] = strdup("#define FXAA_FAST_PIXEL_OFFSET 0\n");
+            if (gGLManager.mHasGPUShader4) 
+			{
+                extra_code_text[extra_code_count++] = strdup("#define FXAA_FAST_PIXEL_OFFSET 1\n");
+			}
+            else
+            {
+                extra_code_text[extra_code_count++] = strdup("#define FXAA_FAST_PIXEL_OFFSET 0\n");
+            }
 			extra_code_text[extra_code_count++] = strdup("#define ATTRIBUTE attribute\n");
 			extra_code_text[extra_code_count++] = strdup("#define VARYING varying\n");
 			extra_code_text[extra_code_count++] = strdup("#define VARYING_FLAT varying\n");
diff --git a/indra/newview/app_settings/shaders/class1/deferred/fxaaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fxaaF.glsl
index 9358f490977..304bf34fec2 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/fxaaF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/fxaaF.glsl
@@ -25,6 +25,7 @@
  
 #extension GL_ARB_texture_rectangle : enable
 #extension GL_ARB_shader_texture_lod : enable
+#extension GL_EXT_gpu_shader4 : enable
 
 /*[EXTRA_CODE_HERE]*/
 
-- 
GitLab