diff --git a/Ryujinx.Graphics/Gal/GalImageFormat.cs b/Ryujinx.Graphics/Gal/GalImageFormat.cs index deb5e663bd..2712cbc253 100644 --- a/Ryujinx.Graphics/Gal/GalImageFormat.cs +++ b/Ryujinx.Graphics/Gal/GalImageFormat.cs @@ -47,9 +47,9 @@ namespace Ryujinx.Graphics.Gal BC3, BC4, BC5, - BC6H_SF16, - BC6H_UF16, - BC7, + BptcSfloat, + BptcUfloat, + BptcUnorm, Snorm = 1 << 26, Unorm = 1 << 27, diff --git a/Ryujinx.Graphics/Gal/GalTextureFormat.cs b/Ryujinx.Graphics/Gal/GalTextureFormat.cs index 7b8c0835c3..51ce577970 100644 --- a/Ryujinx.Graphics/Gal/GalTextureFormat.cs +++ b/Ryujinx.Graphics/Gal/GalTextureFormat.cs @@ -9,12 +9,12 @@ namespace Ryujinx.Graphics.Gal RGB10A2 = 0x9, RG16 = 0xc, R32 = 0xf, - BC6H_SF16 = 0x10, - BC6H_UF16 = 0x11, + BptcSfloat = 0x10, + BptcUfloat = 0x11, RGBA4 = 0x12, RGB5A1 = 0x14, RGB565 = 0x15, - BC7U = 0x17, + BptcUnorm = 0x17, RG8 = 0x18, R16 = 0x1b, R8 = 0x1d, diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLEnumConverter.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLEnumConverter.cs index 98b35627d5..6b3d4fd691 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/OGLEnumConverter.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/OGLEnumConverter.cs @@ -184,19 +184,20 @@ namespace Ryujinx.Graphics.Gal.OpenGL { switch (Format) { - case GalImageFormat.BC6H_SF16 | GalImageFormat.Float: return InternalFormat.CompressedRgbBptcSignedFloat; - case GalImageFormat.BC6H_UF16 | GalImageFormat.Float: return InternalFormat.CompressedRgbBptcUnsignedFloat; - case GalImageFormat.BC7 | GalImageFormat.Unorm: return InternalFormat.CompressedRgbaBptcUnorm; - case GalImageFormat.BC1 | GalImageFormat.Unorm: return InternalFormat.CompressedRgbaS3tcDxt1Ext; - case GalImageFormat.BC1 | GalImageFormat.Srgb: return InternalFormat.CompressedSrgbAlphaS3tcDxt1Ext; - case GalImageFormat.BC2 | GalImageFormat.Unorm: return InternalFormat.CompressedRgbaS3tcDxt3Ext; - case GalImageFormat.BC2 | GalImageFormat.Srgb: return InternalFormat.CompressedSrgbAlphaS3tcDxt3Ext; - case GalImageFormat.BC3 | GalImageFormat.Unorm: return InternalFormat.CompressedRgbaS3tcDxt5Ext; - case GalImageFormat.BC3 | GalImageFormat.Srgb: return InternalFormat.CompressedSrgbAlphaS3tcDxt5Ext; - case GalImageFormat.BC4 | GalImageFormat.Snorm: return InternalFormat.CompressedSignedRedRgtc1; - case GalImageFormat.BC4 | GalImageFormat.Unorm: return InternalFormat.CompressedRedRgtc1; - case GalImageFormat.BC5 | GalImageFormat.Snorm: return InternalFormat.CompressedSignedRgRgtc2; - case GalImageFormat.BC5 | GalImageFormat.Unorm: return InternalFormat.CompressedRgRgtc2; + case GalImageFormat.BptcSfloat | GalImageFormat.Float: return InternalFormat.CompressedRgbBptcSignedFloat; + case GalImageFormat.BptcUfloat | GalImageFormat.Float: return InternalFormat.CompressedRgbBptcUnsignedFloat; + case GalImageFormat.BptcUnorm | GalImageFormat.Unorm: return InternalFormat.CompressedRgbaBptcUnorm; + case GalImageFormat.BptcUnorm | GalImageFormat.Srgb: return InternalFormat.CompressedSrgbAlphaBptcUnorm; + case GalImageFormat.BC1 | GalImageFormat.Unorm: return InternalFormat.CompressedRgbaS3tcDxt1Ext; + case GalImageFormat.BC1 | GalImageFormat.Srgb: return InternalFormat.CompressedSrgbAlphaS3tcDxt1Ext; + case GalImageFormat.BC2 | GalImageFormat.Unorm: return InternalFormat.CompressedRgbaS3tcDxt3Ext; + case GalImageFormat.BC2 | GalImageFormat.Srgb: return InternalFormat.CompressedSrgbAlphaS3tcDxt3Ext; + case GalImageFormat.BC3 | GalImageFormat.Unorm: return InternalFormat.CompressedRgbaS3tcDxt5Ext; + case GalImageFormat.BC3 | GalImageFormat.Srgb: return InternalFormat.CompressedSrgbAlphaS3tcDxt5Ext; + case GalImageFormat.BC4 | GalImageFormat.Snorm: return InternalFormat.CompressedSignedRedRgtc1; + case GalImageFormat.BC4 | GalImageFormat.Unorm: return InternalFormat.CompressedRedRgtc1; + case GalImageFormat.BC5 | GalImageFormat.Snorm: return InternalFormat.CompressedSignedRgRgtc2; + case GalImageFormat.BC5 | GalImageFormat.Unorm: return InternalFormat.CompressedRgRgtc2; } throw new NotImplementedException($"{Format & GalImageFormat.FormatMask} {Format & GalImageFormat.TypeMask}"); diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLShader.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLShader.cs index efcb7e3471..b45a3a3a5a 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/OGLShader.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/OGLShader.cs @@ -55,16 +55,14 @@ namespace Ryujinx.Graphics.Gal.OpenGL GlslDecompiler Decompiler = new GlslDecompiler(); + int ShaderDumpIndex = ShaderDumper.DumpIndex; + if (IsDualVp) { ShaderDumper.Dump(Memory, Position, Type, "a"); ShaderDumper.Dump(Memory, PositionB, Type, "b"); - Program = Decompiler.Decompile( - Memory, - Position, - PositionB, - Type); + Program = Decompiler.Decompile(Memory, Position, PositionB, Type); } else { @@ -73,11 +71,14 @@ namespace Ryujinx.Graphics.Gal.OpenGL Program = Decompiler.Decompile(Memory, Position, Type); } - return new OGLShaderStage( - Type, - Program.Code, - Program.Uniforms, - Program.Textures); + string Code = Program.Code; + + if (ShaderDumper.IsDumpEnabled()) + { + Code = "//Shader " + ShaderDumpIndex + Environment.NewLine + Code; + } + + return new OGLShaderStage(Type, Code, Program.Uniforms, Program.Textures); } public IEnumerable GetConstBufferUsage(long Key) diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs index bedcb9f526..6c60852801 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs @@ -45,19 +45,19 @@ namespace Ryujinx.Graphics.Gal.OpenGL } (PixelInternalFormat InternalFmt, - PixelFormat Format, - PixelType Type) = OGLEnumConverter.GetImageFormat(Image.Format); + PixelFormat Format, + PixelType Type) = OGLEnumConverter.GetImageFormat(Image.Format); - GL.TexImage2D( - TextureTarget.Texture2D, - Level, - InternalFmt, - Image.Width, - Image.Height, - Border, - Format, - Type, - IntPtr.Zero); + GL.TexImage2D( + TextureTarget.Texture2D, + Level, + InternalFmt, + Image.Width, + Image.Height, + Border, + Format, + Type, + IntPtr.Zero); } public void Create(long Key, byte[] Data, GalImage Image) @@ -100,7 +100,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL Image.Width, Image.Height, 1); - Image.Format = GalImageFormat.RGBA8 | (Image.Format & GalImageFormat.TypeMask); + Image.Format = GalImageFormat.RGBA8 | GalImageFormat.Unorm; } (PixelInternalFormat InternalFmt, diff --git a/Ryujinx.Graphics/Gal/Shader/ShaderDecoder.cs b/Ryujinx.Graphics/Gal/Shader/ShaderDecoder.cs index eaa3b6efb6..f8c07f31ab 100644 --- a/Ryujinx.Graphics/Gal/Shader/ShaderDecoder.cs +++ b/Ryujinx.Graphics/Gal/Shader/ShaderDecoder.cs @@ -165,7 +165,7 @@ namespace Ryujinx.Graphics.Gal.Shader DbgOpCode += (Decode?.Method.Name ?? "???"); - if (Decode == ShaderDecode.Bra) + if (Decode == ShaderDecode.Bra || Decode == ShaderDecode.Ssy) { int Offset = ((int)(OpCode >> 20) << 8) >> 8; diff --git a/Ryujinx.Graphics/Gal/ShaderDumper.cs b/Ryujinx.Graphics/Gal/ShaderDumper.cs index 541368e89b..d3bcbf0d87 100644 --- a/Ryujinx.Graphics/Gal/ShaderDumper.cs +++ b/Ryujinx.Graphics/Gal/ShaderDumper.cs @@ -7,11 +7,11 @@ namespace Ryujinx.Graphics.Gal { private static string RuntimeDir; - private static int DumpIndex = 1; + public static int DumpIndex { get; private set; } = 1; public static void Dump(IGalMemory Memory, long Position, GalShaderType Type, string ExtSuffix = "") { - if (string.IsNullOrWhiteSpace(GraphicsConfig.ShadersDumpPath)) + if (!IsDumpEnabled()) { return; } @@ -25,9 +25,10 @@ namespace Ryujinx.Graphics.Gal using (FileStream FullFile = File.Create(FullPath)) using (FileStream CodeFile = File.Create(CodePath)) - using (BinaryWriter FullWriter = new BinaryWriter(FullFile)) - using (BinaryWriter CodeWriter = new BinaryWriter(CodeFile)) { + BinaryWriter FullWriter = new BinaryWriter(FullFile); + BinaryWriter CodeWriter = new BinaryWriter(CodeFile); + for (long i = 0; i < 0x50; i += 4) { FullWriter.Write(Memory.ReadInt32(Position + i)); @@ -69,6 +70,11 @@ namespace Ryujinx.Graphics.Gal } } + public static bool IsDumpEnabled() + { + return !string.IsNullOrWhiteSpace(GraphicsConfig.ShadersDumpPath); + } + private static string FullDir() { return CreateAndReturn(Path.Combine(DumpDir(), "Full")); diff --git a/Ryujinx.Graphics/Texture/ImageUtils.cs b/Ryujinx.Graphics/Texture/ImageUtils.cs index 19bc756d52..d2172c2ef8 100644 --- a/Ryujinx.Graphics/Texture/ImageUtils.cs +++ b/Ryujinx.Graphics/Texture/ImageUtils.cs @@ -65,9 +65,9 @@ namespace Ryujinx.Graphics.Texture { GalTextureFormat.D16, GalImageFormat.D16 | Unorm }, //Compressed formats - { GalTextureFormat.BC6H_SF16, GalImageFormat.BC6H_SF16 | Unorm }, - { GalTextureFormat.BC6H_UF16, GalImageFormat.BC6H_UF16 | Float }, - { GalTextureFormat.BC7U, GalImageFormat.BC7 | Unorm }, + { GalTextureFormat.BptcSfloat, GalImageFormat.BptcSfloat | Float }, + { GalTextureFormat.BptcUfloat, GalImageFormat.BptcUfloat | Float }, + { GalTextureFormat.BptcUnorm, GalImageFormat.BptcUnorm | Unorm | Srgb }, { GalTextureFormat.BC1, GalImageFormat.BC1 | Unorm | Srgb }, { GalTextureFormat.BC2, GalImageFormat.BC2 | Unorm | Srgb }, { GalTextureFormat.BC3, GalImageFormat.BC3 | Unorm | Srgb }, @@ -100,11 +100,11 @@ namespace Ryujinx.Graphics.Texture { GalImageFormat.RGB10A2, new ImageDescriptor(4, 1, 1, TargetBuffer.Color) }, { GalImageFormat.R32, new ImageDescriptor(4, 1, 1, TargetBuffer.Color) }, { GalImageFormat.RGBA4, new ImageDescriptor(2, 1, 1, TargetBuffer.Color) }, - { GalImageFormat.BC6H_SF16, new ImageDescriptor(16, 4, 4, TargetBuffer.Color) }, - { GalImageFormat.BC6H_UF16, new ImageDescriptor(16, 4, 4, TargetBuffer.Color) }, + { GalImageFormat.BptcSfloat, new ImageDescriptor(16, 4, 4, TargetBuffer.Color) }, + { GalImageFormat.BptcUfloat, new ImageDescriptor(16, 4, 4, TargetBuffer.Color) }, { GalImageFormat.RGB5A1, new ImageDescriptor(2, 1, 1, TargetBuffer.Color) }, { GalImageFormat.RGB565, new ImageDescriptor(2, 1, 1, TargetBuffer.Color) }, - { GalImageFormat.BC7, new ImageDescriptor(16, 4, 4, TargetBuffer.Color) }, + { GalImageFormat.BptcUnorm, new ImageDescriptor(16, 4, 4, TargetBuffer.Color) }, { GalImageFormat.RG16, new ImageDescriptor(4, 1, 1, TargetBuffer.Color) }, { GalImageFormat.RG8, new ImageDescriptor(2, 1, 1, TargetBuffer.Color) }, { GalImageFormat.R16, new ImageDescriptor(2, 1, 1, TargetBuffer.Color) }, @@ -151,7 +151,7 @@ namespace Ryujinx.Graphics.Texture if (!s_TextureTable.TryGetValue(Format, out GalImageFormat ImageFormat)) { - throw new NotImplementedException("Format " + ((int)Format).ToString("x2") + " not implemented!"); + throw new NotImplementedException($"Format 0x{((int)Format):x} not implemented!"); } GalImageFormat FormatType = ConvSrgb ? Srgb : GetFormatType(RType); @@ -160,7 +160,7 @@ namespace Ryujinx.Graphics.Texture if (!ImageFormat.HasFlag(FormatType)) { - throw new NotImplementedException("Format " + CombinedFormat + " not implemented!"); + throw new NotImplementedException($"Format \"{CombinedFormat}\" not implemented!"); } return CombinedFormat; @@ -380,7 +380,7 @@ namespace Ryujinx.Graphics.Texture return Descriptor; } - throw new NotImplementedException("Image with format " + PixelFormat.ToString() + " not implemented"); + throw new NotImplementedException($"Format \"{PixelFormat}\" not implemented!"); } private static GalImageFormat GetFormatType(GalTextureType Type)