diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLExtension.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLExtension.cs index 11daeb593c..52b3d0ce31 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/OGLExtension.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/OGLExtension.cs @@ -9,9 +9,12 @@ namespace Ryujinx.Graphics.Gal.OpenGL private static Lazy s_TextureMirrorClamp = new Lazy(() => HasExtension("GL_EXT_texture_mirror_clamp")); private static Lazy s_ViewportArray = new Lazy(() => HasExtension("GL_ARB_viewport_array")); + private static Lazy s_NvidiaDriver = new Lazy(() => IsNvidiaDriver()); + public static bool EnhancedLayouts => s_EnhancedLayouts.Value; public static bool TextureMirrorClamp => s_TextureMirrorClamp.Value; public static bool ViewportArray => s_ViewportArray.Value; + public static bool NvidiaDrvier => s_NvidiaDriver.Value; private static bool HasExtension(string Name) { @@ -27,5 +30,9 @@ namespace Ryujinx.Graphics.Gal.OpenGL return false; } + + private static bool IsNvidiaDriver() { + return GL.GetString(StringName.Vendor).Equals("NVIDIA Corporation"); + } } } \ No newline at end of file diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLShader.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLShader.cs index 10a9120df2..dc168ff919 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/OGLShader.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/OGLShader.cs @@ -53,7 +53,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL { GlslProgram Program; - GlslDecompiler Decompiler = new GlslDecompiler(OGLLimit.MaxUboSize); + GlslDecompiler Decompiler = new GlslDecompiler(OGLLimit.MaxUboSize, OGLExtension.NvidiaDrvier); int ShaderDumpIndex = ShaderDumper.DumpIndex; diff --git a/Ryujinx.Graphics/Gal/Shader/GlslDecompiler.cs b/Ryujinx.Graphics/Gal/Shader/GlslDecompiler.cs index 43ce5ff940..5f809525f9 100644 --- a/Ryujinx.Graphics/Gal/Shader/GlslDecompiler.cs +++ b/Ryujinx.Graphics/Gal/Shader/GlslDecompiler.cs @@ -35,7 +35,9 @@ namespace Ryujinx.Graphics.Gal.Shader public int MaxUboSize { get; } - public GlslDecompiler(int MaxUboSize) + private bool IsNvidiaDriver; + + public GlslDecompiler(int MaxUboSize, bool IsNvidiaDriver) { InstsExpr = new Dictionary() { @@ -113,6 +115,7 @@ namespace Ryujinx.Graphics.Gal.Shader }; this.MaxUboSize = MaxUboSize / 16; + this.IsNvidiaDriver = IsNvidiaDriver; } public GlslProgram Decompile( @@ -1233,6 +1236,7 @@ namespace Ryujinx.Graphics.Gal.Shader return GetTextureGatherOperation(Op, Sampler, Coords, Ch); } + // TODO: support AOFFI on non nvidia drivers private string GetTxlfExpr(ShaderIrOp Op) { // TODO: Support all suffixes @@ -1253,7 +1257,7 @@ namespace Ryujinx.Graphics.Gal.Shader Lod = GetOperExpr(Op, Meta.LevelOfDetail); } - if ((Suffix & TextureInstructionSuffix.AOffI) != 0) + if ((Suffix & TextureInstructionSuffix.AOffI) != 0 && IsNvidiaDriver) { string Offset = GetTextureOffset(Meta, GetOperExpr(Op, Meta.Offset)); return "texelFetchOffset(" + Sampler + ", " + Coords + ", " + Lod + ", " + Offset + ")." + Ch; @@ -1421,6 +1425,7 @@ namespace Ryujinx.Graphics.Gal.Shader } } + // TODO: support AOFFI on non nvidia drivers private string GetTextureGatherOperation(ShaderIrOp Op, string Sampler, string Coords, string Ch) { ShaderIrMetaTex Meta = (ShaderIrMetaTex)Op.MetaData; @@ -1436,7 +1441,7 @@ namespace Ryujinx.Graphics.Gal.Shader Comp = GetOperExpr(Op, Meta.DepthCompare); } - if ((Suffix & TextureInstructionSuffix.AOffI) != 0) + if ((Suffix & TextureInstructionSuffix.AOffI) != 0 && IsNvidiaDriver) { string Offset = GetTextureOffset(Meta, "floatBitsToInt((" + GetOperExpr(Op, Meta.Offset) + "))", 8, 0x3F); @@ -1456,6 +1461,7 @@ namespace Ryujinx.Graphics.Gal.Shader return "textureGather(" + Sampler + ", " + Coords + ", " + Comp + ")" + ChString; } + // TODO: support AOFFI on non nvidia drivers private string GetTextureOperation(ShaderIrOp Op, string Sampler, string Coords, string Ch) { ShaderIrMetaTex Meta = (ShaderIrMetaTex)Op.MetaData; @@ -1472,7 +1478,7 @@ namespace Ryujinx.Graphics.Gal.Shader // TODO: Support LBA and LLA if ((Suffix & TextureInstructionSuffix.LZ) != 0) { - if ((Suffix & TextureInstructionSuffix.AOffI) != 0) + if ((Suffix & TextureInstructionSuffix.AOffI) != 0 && IsNvidiaDriver) { string Offset = GetTextureOffset(Meta, "floatBitsToInt((" + GetOperExpr(Op, Meta.Offset) + "))"); @@ -1483,7 +1489,7 @@ namespace Ryujinx.Graphics.Gal.Shader } else if ((Suffix & TextureInstructionSuffix.LB) != 0) { - if ((Suffix & TextureInstructionSuffix.AOffI) != 0) + if ((Suffix & TextureInstructionSuffix.AOffI) != 0 && IsNvidiaDriver) { string Offset = GetTextureOffset(Meta, "floatBitsToInt((" + GetOperExpr(Op, Meta.Offset) + "))"); @@ -1494,7 +1500,7 @@ namespace Ryujinx.Graphics.Gal.Shader } else if ((Suffix & TextureInstructionSuffix.LL) != 0) { - if ((Suffix & TextureInstructionSuffix.AOffI) != 0) + if ((Suffix & TextureInstructionSuffix.AOffI) != 0 && IsNvidiaDriver) { string Offset = GetTextureOffset(Meta, "floatBitsToInt((" + GetOperExpr(Op, Meta.Offset) + "))"); @@ -1503,7 +1509,7 @@ namespace Ryujinx.Graphics.Gal.Shader return "textureLod(" + Sampler + ", " + Coords + ", " + GetOperExpr(Op, Meta.LevelOfDetail) + ")" + ChString; } - else if ((Suffix & TextureInstructionSuffix.AOffI) != 0) + else if ((Suffix & TextureInstructionSuffix.AOffI) != 0 && IsNvidiaDriver) { string Offset = GetTextureOffset(Meta, "floatBitsToInt((" + GetOperExpr(Op, Meta.Offset) + "))"); diff --git a/Ryujinx.ShaderTools/Program.cs b/Ryujinx.ShaderTools/Program.cs index 30fa71aea2..77aba0abe6 100644 --- a/Ryujinx.ShaderTools/Program.cs +++ b/Ryujinx.ShaderTools/Program.cs @@ -13,7 +13,7 @@ namespace Ryujinx.ShaderTools { if (args.Length == 2) { - GlslDecompiler Decompiler = new GlslDecompiler(MaxUboSize); + GlslDecompiler Decompiler = new GlslDecompiler(MaxUboSize, true); GalShaderType ShaderType = GalShaderType.Vertex;