From 43886472b636b62314423862814b7280d61880ed Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Thu, 16 Aug 2018 21:22:30 -0300 Subject: [PATCH] Address feedback --- Ryujinx.Graphics/Gal/GalFrameBufferFormat.cs | 2 +- Ryujinx.Graphics/Gal/ImageFormatConverter.cs | 3 +- .../Gal/OpenGL/{TCE.cs => ImageHandler.cs} | 17 +++++----- Ryujinx.Graphics/Gal/OpenGL/OGLFrameBuffer.cs | 24 +++++++------- Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs | 32 +++++++++---------- Ryujinx.Graphics/Gal/Shader/GlslDecompiler.cs | 2 +- Ryujinx.Graphics/Ryujinx.Graphics.csproj | 4 --- Ryujinx.HLE/Gpu/Engines/NvGpuEngine3d.cs | 10 +++--- 8 files changed, 46 insertions(+), 48 deletions(-) rename Ryujinx.Graphics/Gal/OpenGL/{TCE.cs => ImageHandler.cs} (90%) diff --git a/Ryujinx.Graphics/Gal/GalFrameBufferFormat.cs b/Ryujinx.Graphics/Gal/GalFrameBufferFormat.cs index 670c51b265..3180aeff9b 100644 --- a/Ryujinx.Graphics/Gal/GalFrameBufferFormat.cs +++ b/Ryujinx.Graphics/Gal/GalFrameBufferFormat.cs @@ -9,7 +9,7 @@ RGBA32Uint = 0xc2, RGBX32Float = 0xc3, RGBX32Sint = 0xc4, - RGBX32Uint = 0xc5, + RGBX32Uint = 0xc5, RGBA16Unorm = 0xc6, RGBA16Snorm = 0xc7, RGBA16Sint = 0xc8, diff --git a/Ryujinx.Graphics/Gal/ImageFormatConverter.cs b/Ryujinx.Graphics/Gal/ImageFormatConverter.cs index a713939425..a79c20f11b 100644 --- a/Ryujinx.Graphics/Gal/ImageFormatConverter.cs +++ b/Ryujinx.Graphics/Gal/ImageFormatConverter.cs @@ -242,7 +242,8 @@ namespace Ryujinx.Graphics.Gal return true; } - //Depth formats are easier to maintain so not false case, just return false + //Depth formats are fewer than colors, so it's harder to miss one + //Instead of checking for individual formats, return false return false; } diff --git a/Ryujinx.Graphics/Gal/OpenGL/TCE.cs b/Ryujinx.Graphics/Gal/OpenGL/ImageHandler.cs similarity index 90% rename from Ryujinx.Graphics/Gal/OpenGL/TCE.cs rename to Ryujinx.Graphics/Gal/OpenGL/ImageHandler.cs index 5f7cff8fc9..74f18dcd38 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/TCE.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/ImageHandler.cs @@ -3,7 +3,7 @@ using System; namespace Ryujinx.Graphics.Gal.OpenGL { - class TCE + class ImageHandler { //TODO: Use a variable value here public const int MaxBpp = 16; @@ -13,24 +13,25 @@ namespace Ryujinx.Graphics.Gal.OpenGL public GalImage Image { get; private set; } - public int Width { get => Image.Width; } - public int Height { get => Image.Height; } - public GalImageFormat Format { get => Image.Format; } + public int Width => Image.Width; + public int Height => Image.Height; + + public GalImageFormat Format => Image.Format; public PixelInternalFormat InternalFormat { get; private set; } - public PixelFormat PixelFormat { get; private set; } - public PixelType PixelType { get; private set; } + public PixelFormat PixelFormat { get; private set; } + public PixelType PixelType { get; private set; } public int Handle { get; private set; } private bool Initialized; - public TCE() + public ImageHandler() { Handle = GL.GenTexture(); } - public TCE(int Handle, GalImage Image) + public ImageHandler(int Handle, GalImage Image) { this.Handle = Handle; diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLFrameBuffer.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLFrameBuffer.cs index 76342c29f3..e0f12e4eca 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/OGLFrameBuffer.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/OGLFrameBuffer.cs @@ -40,8 +40,8 @@ namespace Ryujinx.Graphics.Gal.OpenGL private OGLTexture Texture; - private TCE RawTex; - private TCE ReadTex; + private ImageHandler RawTex; + private ImageHandler ReadTex; private Rect Viewport; private Rect Window; @@ -77,7 +77,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL public void BindColor(long Key, int Attachment) { - if (Texture.TryGetTCE(Key, out TCE Tex)) + if (Texture.TryGetImage(Key, out ImageHandler Tex)) { EnsureFrameBuffer(); @@ -98,7 +98,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL public void BindZeta(long Key) { - if (Texture.TryGetTCE(Key, out TCE Tex)) + if (Texture.TryGetImage(Key, out ImageHandler Tex)) { EnsureFrameBuffer(); @@ -162,7 +162,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL public void BindTexture(long Key, int Index) { - if (Texture.TryGetTCE(Key, out TCE Tex)) + if (Texture.TryGetImage(Key, out ImageHandler Tex)) { GL.ActiveTexture(TextureUnit.Texture0 + Index); @@ -172,7 +172,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL public void Set(long Key) { - if (Texture.TryGetTCE(Key, out TCE Tex)) + if (Texture.TryGetImage(Key, out ImageHandler Tex)) { ReadTex = Tex; } @@ -182,7 +182,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL { if (RawTex == null) { - RawTex = new TCE(); + RawTex = new ImageHandler(); } RawTex.EnsureSetup(new GalImage(Width, Height, RawFormat)); @@ -307,8 +307,8 @@ namespace Ryujinx.Graphics.Gal.OpenGL int DstX1, int DstY1) { - if (Texture.TryGetTCE(SrcKey, out TCE SrcTex) && - Texture.TryGetTCE(DstKey, out TCE DstTex)) + if (Texture.TryGetImage(SrcKey, out ImageHandler SrcTex) && + Texture.TryGetImage(DstKey, out ImageHandler DstTex)) { if (SrcTex.HasColor != DstTex.HasColor || SrcTex.HasDepth != DstTex.HasDepth || @@ -370,9 +370,9 @@ namespace Ryujinx.Graphics.Gal.OpenGL public void GetBufferData(long Key, Action Callback) { - if (Texture.TryGetTCE(Key, out TCE Tex)) + if (Texture.TryGetImage(Key, out ImageHandler Tex)) { - byte[] Data = new byte[Tex.Width * Tex.Height * TCE.MaxBpp]; + byte[] Data = new byte[Tex.Width * Tex.Height * ImageHandler.MaxBpp]; GL.BindTexture(TextureTarget.Texture2D, Tex.Handle); @@ -393,7 +393,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL int Height, byte[] Buffer) { - if (Texture.TryGetTCE(Key, out TCE Tex)) + if (Texture.TryGetImage(Key, out ImageHandler Tex)) { GL.BindTexture(TextureTarget.Texture2D, Tex.Handle); diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs index ba43951005..e4d4bd6480 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs @@ -6,11 +6,11 @@ namespace Ryujinx.Graphics.Gal.OpenGL { class OGLTexture : IGalTexture { - private OGLCachedResource TextureCache; + private OGLCachedResource TextureCache; public OGLTexture() { - TextureCache = new OGLCachedResource(DeleteTexture); + TextureCache = new OGLCachedResource(DeleteTexture); } public void LockCache() @@ -23,16 +23,16 @@ namespace Ryujinx.Graphics.Gal.OpenGL TextureCache.Unlock(); } - private static void DeleteTexture(TCE CachedTexture) + private static void DeleteTexture(ImageHandler CachedImage) { - GL.DeleteTexture(CachedTexture.Handle); + GL.DeleteTexture(CachedImage.Handle); } public void Create(long Key, byte[] Data, GalImage Image) { int Handle = GL.GenTexture(); - TextureCache.AddOrUpdate(Key, new TCE(Handle, Image), (uint)Data.Length); + TextureCache.AddOrUpdate(Key, new ImageHandler(Handle, Image), (uint)Data.Length); GL.BindTexture(TextureTarget.Texture2D, Handle); @@ -97,24 +97,24 @@ namespace Ryujinx.Graphics.Gal.OpenGL public void CreateFb(long Key, long Size, GalImage Image) { - if (!TryGetTCE(Key, out TCE Texture)) + if (!TryGetImage(Key, out ImageHandler CachedImage)) { - Texture = new TCE(); + CachedImage = new ImageHandler(); - TextureCache.AddOrUpdate(Key, Texture, Size); + TextureCache.AddOrUpdate(Key, CachedImage, Size); } - Texture.EnsureSetup(Image); + CachedImage.EnsureSetup(Image); } - public bool TryGetTCE(long Key, out TCE CachedTexture) + public bool TryGetImage(long Key, out ImageHandler CachedImage) { - if (TextureCache.TryGetValue(Key, out CachedTexture)) + if (TextureCache.TryGetValue(Key, out CachedImage)) { return true; } - CachedTexture = null; + CachedImage = null; return false; } @@ -169,9 +169,9 @@ namespace Ryujinx.Graphics.Gal.OpenGL { if (TextureCache.TryGetSize(Key, out long Size) && Size == DataSize) { - if (TextureCache.TryGetValue(Key, out TCE CachedTexture)) + if (TextureCache.TryGetValue(Key, out ImageHandler CachedImage)) { - Image = CachedTexture.Image; + Image = CachedImage.Image; return true; } @@ -184,11 +184,11 @@ namespace Ryujinx.Graphics.Gal.OpenGL public void Bind(long Key, int Index) { - if (TextureCache.TryGetValue(Key, out TCE CachedTexture)) + if (TextureCache.TryGetValue(Key, out ImageHandler CachedImage)) { GL.ActiveTexture(TextureUnit.Texture0 + Index); - GL.BindTexture(TextureTarget.Texture2D, CachedTexture.Handle); + GL.BindTexture(TextureTarget.Texture2D, CachedImage.Handle); } } diff --git a/Ryujinx.Graphics/Gal/Shader/GlslDecompiler.cs b/Ryujinx.Graphics/Gal/Shader/GlslDecompiler.cs index 981058e72b..726379846d 100644 --- a/Ryujinx.Graphics/Gal/Shader/GlslDecompiler.cs +++ b/Ryujinx.Graphics/Gal/Shader/GlslDecompiler.cs @@ -354,7 +354,7 @@ namespace Ryujinx.Graphics.Gal.Shader } else if (DeclInfo.Name.Contains(GlslDecl.FragmentOutputName)) { - Name = "layout (location = " + DeclInfo.Index / 4 + ") out vec4 " + DeclInfo.Name + Suffix + ";" + Environment.NewLine; + Name = "layout (location = " + DeclInfo.Index / 4 + ") out vec4 " + DeclInfo.Name + Suffix + ";"; } else { diff --git a/Ryujinx.Graphics/Ryujinx.Graphics.csproj b/Ryujinx.Graphics/Ryujinx.Graphics.csproj index cddb670782..7d86cbe134 100644 --- a/Ryujinx.Graphics/Ryujinx.Graphics.csproj +++ b/Ryujinx.Graphics/Ryujinx.Graphics.csproj @@ -13,10 +13,6 @@ true - - - - diff --git a/Ryujinx.HLE/Gpu/Engines/NvGpuEngine3d.cs b/Ryujinx.HLE/Gpu/Engines/NvGpuEngine3d.cs index f04eee5f62..1d0834ddb5 100644 --- a/Ryujinx.HLE/Gpu/Engines/NvGpuEngine3d.cs +++ b/Ryujinx.HLE/Gpu/Engines/NvGpuEngine3d.cs @@ -180,12 +180,12 @@ namespace Ryujinx.HLE.Gpu.Engines int Width = ReadRegister(NvGpuEngine3dReg.FrameBufferNWidth + FbIndex * 0x10); int Height = ReadRegister(NvGpuEngine3dReg.FrameBufferNHeight + FbIndex * 0x10); - - float TX = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNTranslateX + FbIndex * 4); - float TY = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNTranslateY + FbIndex * 4); - float SX = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNScaleX + FbIndex * 4); - float SY = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNScaleY + FbIndex * 4); + float TX = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNTranslateX + FbIndex * 8); + float TY = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNTranslateY + FbIndex * 8); + + float SX = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNScaleX + FbIndex * 8); + float SY = ReadRegisterFloat(NvGpuEngine3dReg.ViewportNScaleY + FbIndex * 8); int VpX = (int)MathF.Max(0, TX - MathF.Abs(SX)); int VpY = (int)MathF.Max(0, TY - MathF.Abs(SY));