From 3bc53382c8392bd99b8bac35bd34959d49f07b39 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Mon, 27 Aug 2018 02:51:03 -0300 Subject: [PATCH] Add TEX texture types and 1D and 3D textures support. Stub depth --- Ryujinx.Graphics/Gal/OpenGL/ImageHandler.cs | 43 +++++-------------- .../Gal/OpenGL/OGLEnumConverter.cs | 2 + Ryujinx.Graphics/Gal/OpenGL/OGLHelper.cs | 18 ++++++++ Ryujinx.Graphics/Gal/Shader/GlslDecompiler.cs | 26 +++++++---- .../Gal/Shader/ShaderDecodeMem.cs | 34 +++++++++++---- Ryujinx/Ryujinx.conf | 2 +- 6 files changed, 75 insertions(+), 50 deletions(-) diff --git a/Ryujinx.Graphics/Gal/OpenGL/ImageHandler.cs b/Ryujinx.Graphics/Gal/OpenGL/ImageHandler.cs index 3ab874d53..1e18fe930 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/ImageHandler.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/ImageHandler.cs @@ -91,38 +91,17 @@ namespace Ryujinx.Graphics.Gal.OpenGL const int Level = 0; const int Border = 0; - switch (Target) - { - case TextureTarget.Texture2D: - GL.TexImage2D( - Target, - Level, - InternalFormat, - Image.Width, - Image.Height, - Border, - PixelFormat, - PixelType, - IntPtr.Zero); - break; - - case TextureTarget.Texture2DArray: - GL.TexImage3D( - Target, - Level, - InternalFormat, - Image.Width, - Image.Height, - Image.Depth, - Border, - PixelFormat, - PixelType, - IntPtr.Zero); - break; - - default: - throw new NotImplementedException(Target.ToString()); - } + OGLHelper.TexImage( + Target, + Level, + InternalFormat, + Image.Width, + Image.Height, + Image.Depth, + Border, + PixelFormat, + PixelType, + null); if (Initialized) { diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLEnumConverter.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLEnumConverter.cs index 9fb3c4392..6e983a7b9 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/OGLEnumConverter.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/OGLEnumConverter.cs @@ -304,8 +304,10 @@ namespace Ryujinx.Graphics.Gal.OpenGL { switch (Target) { + case GalImageTarget._1d: return TextureTarget.Texture1D; case GalImageTarget._2d: return TextureTarget.Texture2D; case GalImageTarget._2dArray: return TextureTarget.Texture2DArray; + case GalImageTarget._3d: return TextureTarget.Texture3D; case GalImageTarget.CubeMap: return TextureTarget.TextureCubeMap; } diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLHelper.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLHelper.cs index f137dc273..0106673e5 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/OGLHelper.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/OGLHelper.cs @@ -19,6 +19,18 @@ namespace Ryujinx.Graphics.Gal.OpenGL { switch (Target) { + case TextureTarget.Texture1D: + GL.TexImage1D( + Target, + Level, + InternalFormat, + Width, + Border, + PixelFormat, + PixelType, + Data); + break; + case TextureTarget.Texture2D: GL.TexImage2D( Target, @@ -33,6 +45,9 @@ namespace Ryujinx.Graphics.Gal.OpenGL break; case TextureTarget.Texture2DArray: + case TextureTarget.Texture3D: + //FIXME: Unstub depth when swizzle is fixed + Depth = 1; GL.TexImage3D( Target, Level, @@ -110,6 +125,9 @@ namespace Ryujinx.Graphics.Gal.OpenGL break; case TextureTarget.Texture2DArray: + case TextureTarget.Texture3D: + //FIXME: Unstub depth when swizzle is fixed + Depth = 1; GL.CompressedTexImage3D( Target, Level, diff --git a/Ryujinx.Graphics/Gal/Shader/GlslDecompiler.cs b/Ryujinx.Graphics/Gal/Shader/GlslDecompiler.cs index 0a1be5e41..75ece0f2e 100644 --- a/Ryujinx.Graphics/Gal/Shader/GlslDecompiler.cs +++ b/Ryujinx.Graphics/Gal/Shader/GlslDecompiler.cs @@ -145,8 +145,6 @@ namespace Ryujinx.Graphics.Gal.Shader { SB = new StringBuilder(); - SB.AppendLine("#version 410 core"); - PrintDeclHeader(); PrintDeclTextures(); PrintDeclUniforms(); @@ -185,6 +183,8 @@ namespace Ryujinx.Graphics.Gal.Shader private void PrintDeclHeader() { + SB.AppendLine("#version 410 core"); + if (Decl.ShaderType == GalShaderType.Geometry) { int MaxVertices = Header.MaxOutputVertexCount; @@ -209,9 +209,9 @@ namespace Ryujinx.Graphics.Gal.Shader SB.AppendLine("layout(triangles) in;" + Environment.NewLine); SB.AppendLine($"layout({OutputTopology}, max_vertices = {MaxVertices}) out;"); - - SB.AppendLine(); } + + SB.AppendLine(); } private void PrintDeclTextures() @@ -259,11 +259,9 @@ namespace Ryujinx.Graphics.Gal.Shader SB.AppendLine(IdentationStr + "int " + GlslDecl.InstanceUniformName + ";"); - SB.AppendLine("};"); + SB.AppendLine("};" + Environment.NewLine); } - SB.AppendLine(); - foreach (ShaderDeclInfo DeclInfo in Decl.Uniforms.Values.OrderBy(DeclKeySelector)) { SB.AppendLine($"layout (std140) uniform {DeclInfo.Name} {{"); @@ -1217,11 +1215,15 @@ namespace Ryujinx.Graphics.Gal.Shader GetOperExpr(Op, Op.OperandB) + ", " + GetOperExpr(Op, Op.OperandC) + ")"; } - else + else if (Op.OperandB != null) { return "vec2(" + GetOperExpr(Op, Op.OperandA) + ", " + GetOperExpr(Op, Op.OperandB) + ")"; } + else + { + return GetOperExpr(Op, Op.OperandA); + } } private string GetITexSamplerCoords(ShaderIrOp Op) @@ -1232,11 +1234,15 @@ namespace Ryujinx.Graphics.Gal.Shader GetOperExpr(Op, Op.OperandB) + ", " + GetOperExpr(Op, Op.OperandC) + ")"; } - else + else if (Op.OperandB != null) { return "ivec2(" + GetOperExpr(Op, Op.OperandA) + ", " + GetOperExpr(Op, Op.OperandB) + ")"; } + else + { + return GetOperExpr(Op, Op.OperandA); + } } private string GetOperExpr(ShaderIrOp Op, ShaderIrNode Oper) @@ -1383,8 +1389,10 @@ namespace Ryujinx.Graphics.Gal.Shader { switch (Type) { + case ShaderTextureType._1d: return "sampler1D"; case ShaderTextureType._2d: return "sampler2D"; case ShaderTextureType._2dArray: return "sampler2DArray"; + case ShaderTextureType._3d: return "sampler3D"; case ShaderTextureType.Cube: return "samplerCube"; } diff --git a/Ryujinx.Graphics/Gal/Shader/ShaderDecodeMem.cs b/Ryujinx.Graphics/Gal/Shader/ShaderDecodeMem.cs index 3707784fc..1ae572725 100644 --- a/Ryujinx.Graphics/Gal/Shader/ShaderDecodeMem.cs +++ b/Ryujinx.Graphics/Gal/Shader/ShaderDecodeMem.cs @@ -31,6 +31,16 @@ namespace Ryujinx.Graphics.Gal.Shader { RGB_, RG_A, R_BA, _GBA, RGBA, ____, ____, ____ } }; + private static ShaderTextureType[] TexTypes = new ShaderTextureType[] + { + ShaderTextureType._1d, + ShaderTextureType._2d, + ShaderTextureType._3d, + ShaderTextureType.Cube, + }; + + private static int[] TexTypeCoords = new int[] { 1, 2, 3, 3 }; + private static ShaderTextureType[] TexsTypes = new ShaderTextureType[] { ShaderTextureType._1d, @@ -159,14 +169,15 @@ namespace Ryujinx.Graphics.Gal.Shader private static void EmitTex(ShaderIrBlock Block, long OpCode, bool GprHandle) { - //TODO: Support other formats. - ShaderIrOperGpr[] Coords = new ShaderIrOperGpr[2]; + int TypeId = (int)((OpCode >> 29) & 3); - for (int Index = 0; Index < Coords.Length; Index++) + ShaderIrOperGpr[] Coords = new ShaderIrOperGpr[3]; + + ShaderTextureType Type = TexTypes[TypeId]; + + for (int Index = 0; Index < TexTypeCoords[TypeId]; Index++) { - Coords[Index] = GetOperGpr8(OpCode); - - Coords[Index].Index += Index; + Coords[Index] = GetOperGpr8(OpCode) + Index; if (Coords[Index].Index > ShaderIrOperGpr.ZRIndex) { @@ -186,9 +197,9 @@ namespace Ryujinx.Graphics.Gal.Shader { ShaderIrOperGpr Dst = new ShaderIrOperGpr(TempRegStart + Ch); - ShaderIrMetaTex Meta = new ShaderIrMetaTex(ShaderTextureType._2d, TextureIndex, Ch); + ShaderIrMetaTex Meta = new ShaderIrMetaTex(Type, TextureIndex, Ch); - ShaderIrOp Op = new ShaderIrOp(Inst, Coords[0], Coords[1], null, Meta); + ShaderIrOp Op = new ShaderIrOp(Inst, Coords[0], Coords[1], Coords[2], Meta); Block.AddNode(GetPredNode(new ShaderIrAsg(Dst, Op), OpCode)); } @@ -266,6 +277,13 @@ namespace Ryujinx.Graphics.Gal.Shader OperC = GetOperGpr8 (OpCode); break; + //This layout is copy-pasted, complitely untested + case ShaderTextureType._3d: + OperA = GetOperGpr8(OpCode) + 1; + OperB = GetOperGpr20(OpCode); + OperC = GetOperGpr8(OpCode); + break; + //Unsure about this layout case ShaderTextureType.Cube: OperA = GetOperGpr8 (OpCode); diff --git a/Ryujinx/Ryujinx.conf b/Ryujinx/Ryujinx.conf index 6e15a6ac2..8e736d38c 100644 --- a/Ryujinx/Ryujinx.conf +++ b/Ryujinx/Ryujinx.conf @@ -2,7 +2,7 @@ Enable_Memory_Checks = false #Dump shaders in local directory (e.g. `C:\ShaderDumps`) -Graphics_Shaders_Dump_Path = +Graphics_Shaders_Dump_Path = D:\Shaders #Enable print debug logs Logging_Enable_Debug = false