From 5264d55b39e15c7236d6114d74a9288fb0d62e3a Mon Sep 17 00:00:00 2001
From: gdkchan <gab.dark.100@gmail.com>
Date: Sat, 17 Oct 2020 05:16:40 -0300
Subject: [PATCH] Fix gl_in being used with built-in variables that are not
 per-vertex (#1624)

---
 Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs | 2 +-
 Ryujinx.Graphics.Shader/Translation/AttributeConsts.cs | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs b/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs
index d6f30b481b..465356e6ad 100644
--- a/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs
+++ b/Ryujinx.Graphics.Shader/CodeGen/Glsl/OperandManager.cs
@@ -206,7 +206,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
 
                     string name = builtInAttr.Name;
 
-                    if (config.Stage == ShaderStage.Geometry && !isOutAttr)
+                    if (config.Stage == ShaderStage.Geometry && (value & AttributeConsts.SpecialMask) == 0 && !isOutAttr)
                     {
                         name = $"gl_in[{indexExpr}].{name}";
                     }
diff --git a/Ryujinx.Graphics.Shader/Translation/AttributeConsts.cs b/Ryujinx.Graphics.Shader/Translation/AttributeConsts.cs
index c194b5c2e4..b618dbc30b 100644
--- a/Ryujinx.Graphics.Shader/Translation/AttributeConsts.cs
+++ b/Ryujinx.Graphics.Shader/Translation/AttributeConsts.cs
@@ -31,6 +31,7 @@ namespace Ryujinx.Graphics.Shader.Translation
 
         // Note: Those attributes are used internally by the translator
         // only, they don't exist on Maxwell.
+        public const int SpecialMask             = 0xff << 24;
         public const int FragmentOutputDepth     = 0x1000000;
         public const int FragmentOutputColorBase = 0x1000010;
         public const int FragmentOutputColorEnd  = FragmentOutputColorBase + 8 * 16;