From 3a3062605c8c87fdc087478b38d54ba9d1b8a97c Mon Sep 17 00:00:00 2001 From: Thog Date: Thu, 21 Feb 2019 18:29:39 +0100 Subject: [PATCH] Start looking into cube map again Also add some way to log write in register in engines --- Ryujinx.Graphics/Gal/GalImage.cs | 11 +++++++++-- Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs | 19 +++++++++++++++++++ Ryujinx.Graphics/Graphics3d/NvGpuEngine2d.cs | 1 + Ryujinx.Graphics/Graphics3d/NvGpuEngine3d.cs | 6 ++++++ .../Graphics3d/NvGpuEngine3dReg.cs | 3 +++ .../Graphics3d/NvGpuEngineM2mf.cs | 2 ++ .../Graphics3d/NvGpuEngineP2mf.cs | 2 ++ .../Graphics3d/Texture/ImageUtils.cs | 9 ++++++--- .../Graphics3d/Texture/TextureFactory.cs | 11 +++++++++-- 9 files changed, 57 insertions(+), 7 deletions(-) diff --git a/Ryujinx.Graphics/Gal/GalImage.cs b/Ryujinx.Graphics/Gal/GalImage.cs index bb71f662d6..fb904b0925 100644 --- a/Ryujinx.Graphics/Gal/GalImage.cs +++ b/Ryujinx.Graphics/Gal/GalImage.cs @@ -60,7 +60,7 @@ namespace Ryujinx.Graphics.Gal Pitch = ImageUtils.GetPitch(Format, Width); } - public bool SizeMatches(GalImage Image) + public bool SizeMatches(GalImage Image, bool IgnoreLayer = false) { if (ImageUtils.GetBytesPerPixel(Format) != ImageUtils.GetBytesPerPixel(Image.Format)) @@ -74,7 +74,14 @@ namespace Ryujinx.Graphics.Gal return false; } - return Height == Image.Height && Depth == Image.Depth && LayerCount == Image.LayerCount; + bool Result = Height == Image.Height && Depth == Image.Depth; + + if (!IgnoreLayer) + { + Result = Result && LayerCount == Image.LayerCount; + } + + return Result; } } } \ No newline at end of file diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs index 57660f7ddd..4fef11d296 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs @@ -258,6 +258,25 @@ namespace Ryujinx.Graphics.Gal.OpenGL Type, Data); break; + case TextureTarget.TextureCubeMap: + Span Array = new Span(Data); + + int FaceSize = ImageUtils.GetSize(Image) / 6; + + for (int Face = 0; Face < 6; Face++) + { + GL.TexImage2D( + TextureTarget.TextureCubeMapPositiveX + Face, + Level, + InternalFmt, + Image.Width, + Image.Height, + Border, + Format, + Type, + Array.Slice(Face * FaceSize, FaceSize).ToArray()); + } + break; default: throw new NotImplementedException($"Unsupported texture target type: {Target}"); } diff --git a/Ryujinx.Graphics/Graphics3d/NvGpuEngine2d.cs b/Ryujinx.Graphics/Graphics3d/NvGpuEngine2d.cs index 3295f6da05..45eee0449f 100644 --- a/Ryujinx.Graphics/Graphics3d/NvGpuEngine2d.cs +++ b/Ryujinx.Graphics/Graphics3d/NvGpuEngine2d.cs @@ -241,6 +241,7 @@ namespace Ryujinx.Graphics.Graphics3d private void WriteRegister(GpuMethodCall MethCall) { Registers[MethCall.Method] = MethCall.Argument; + Logger.PrintDebug(LogClass.Gpu, $"[2D] Writing to register {(NvGpuEngine2dReg)MethCall.Method} value {MethCall.Argument:x}"); } private long ReadRegisterFixed1_31_32(NvGpuEngine2dReg Reg) diff --git a/Ryujinx.Graphics/Graphics3d/NvGpuEngine3d.cs b/Ryujinx.Graphics/Graphics3d/NvGpuEngine3d.cs index 782ac03d6e..989c8ac662 100644 --- a/Ryujinx.Graphics/Graphics3d/NvGpuEngine3d.cs +++ b/Ryujinx.Graphics/Graphics3d/NvGpuEngine3d.cs @@ -1,4 +1,5 @@ using Ryujinx.Common; +using Ryujinx.Common.Logging; using Ryujinx.Graphics.Gal; using Ryujinx.Graphics.Memory; using Ryujinx.Graphics.Texture; @@ -188,6 +189,10 @@ namespace Ryujinx.Graphics.Graphics3d int Width = ReadRegister(NvGpuEngine3dReg.FrameBufferNWidth + FbIndex * 0x10); int Height = ReadRegister(NvGpuEngine3dReg.FrameBufferNHeight + FbIndex * 0x10); + int ArrayMode = ReadRegister(NvGpuEngine3dReg.FrameBufferNArrayMode + FbIndex * 0x10); + int LayerCount = ArrayMode & 0xFFFF; + int LayerStride = ReadRegister(NvGpuEngine3dReg.FrameBufferNLayerStride + FbIndex * 0x10); + int BaseLayer = ReadRegister(NvGpuEngine3dReg.FrameBufferNBaseLayer + FbIndex * 0x10); int BlockDim = ReadRegister(NvGpuEngine3dReg.FrameBufferNBlockDim + FbIndex * 0x10); int GobBlockHeight = 1 << ((BlockDim >> 4) & 7); @@ -1091,6 +1096,7 @@ namespace Ryujinx.Graphics.Graphics3d private void WriteRegister(GpuMethodCall MethCall) { Registers[MethCall.Method] = MethCall.Argument; + Logger.PrintDebug(LogClass.Gpu, $"[3D] Writing to register {(NvGpuEngine3dReg)MethCall.Method} value {MethCall.Argument:x}"); } private int ReadRegister(NvGpuEngine3dReg Reg) diff --git a/Ryujinx.Graphics/Graphics3d/NvGpuEngine3dReg.cs b/Ryujinx.Graphics/Graphics3d/NvGpuEngine3dReg.cs index 026b0cd198..c28111a4a9 100644 --- a/Ryujinx.Graphics/Graphics3d/NvGpuEngine3dReg.cs +++ b/Ryujinx.Graphics/Graphics3d/NvGpuEngine3dReg.cs @@ -7,6 +7,9 @@ namespace Ryujinx.Graphics.Graphics3d FrameBufferNHeight = 0x203, FrameBufferNFormat = 0x204, FrameBufferNBlockDim = 0x205, + FrameBufferNArrayMode = 0x206, + FrameBufferNLayerStride = 0x207, + FrameBufferNBaseLayer = 0x208, ViewportNScaleX = 0x280, ViewportNScaleY = 0x281, ViewportNScaleZ = 0x282, diff --git a/Ryujinx.Graphics/Graphics3d/NvGpuEngineM2mf.cs b/Ryujinx.Graphics/Graphics3d/NvGpuEngineM2mf.cs index 5ce4fca0d2..33be1591d7 100644 --- a/Ryujinx.Graphics/Graphics3d/NvGpuEngineM2mf.cs +++ b/Ryujinx.Graphics/Graphics3d/NvGpuEngineM2mf.cs @@ -1,3 +1,4 @@ +using Ryujinx.Common.Logging; using Ryujinx.Graphics.Memory; using Ryujinx.Graphics.Texture; using System.Collections.Generic; @@ -180,6 +181,7 @@ namespace Ryujinx.Graphics.Graphics3d private void WriteRegister(GpuMethodCall MethCall) { Registers[MethCall.Method] = MethCall.Argument; + Logger.PrintWarning(LogClass.Gpu, $"[2D] Writing to register {(NvGpuEngine2dReg)MethCall.Method} value {MethCall.Argument:x}"); } private int ReadRegister(NvGpuEngineM2mfReg Reg) diff --git a/Ryujinx.Graphics/Graphics3d/NvGpuEngineP2mf.cs b/Ryujinx.Graphics/Graphics3d/NvGpuEngineP2mf.cs index 82b98b42de..9ae5470142 100644 --- a/Ryujinx.Graphics/Graphics3d/NvGpuEngineP2mf.cs +++ b/Ryujinx.Graphics/Graphics3d/NvGpuEngineP2mf.cs @@ -1,3 +1,4 @@ +using Ryujinx.Common.Logging; using Ryujinx.Graphics.Memory; using Ryujinx.Graphics.Texture; using System.Collections.Generic; @@ -149,6 +150,7 @@ namespace Ryujinx.Graphics.Graphics3d private void WriteRegister(GpuMethodCall MethCall) { Registers[MethCall.Method] = MethCall.Argument; + Logger.PrintDebug(LogClass.Gpu, $"[M2MF] Writing to register {(NvGpuEngineM2mfReg)MethCall.Method} value {MethCall.Argument:x}"); } private int ReadRegister(NvGpuEngineP2mfReg Reg) diff --git a/Ryujinx.Graphics/Graphics3d/Texture/ImageUtils.cs b/Ryujinx.Graphics/Graphics3d/Texture/ImageUtils.cs index 2a72996b05..c4208935c3 100644 --- a/Ryujinx.Graphics/Graphics3d/Texture/ImageUtils.cs +++ b/Ryujinx.Graphics/Graphics3d/Texture/ImageUtils.cs @@ -362,11 +362,11 @@ namespace Ryujinx.Graphics.Texture switch (ComponentCount) { case 1: - return Desc.BytesPerPixel * Width; + return Desc.BytesPerPixel * Width * Image.LayerCount; case 2: - return Desc.BytesPerPixel * Width * Height; + return Desc.BytesPerPixel * Width * Height * Image.LayerCount; case 3: - return Desc.BytesPerPixel * Width * Height * Depth; + return Desc.BytesPerPixel * Width * Height * Depth * Image.LayerCount; default: throw new InvalidOperationException($"Invalid component count: {ComponentCount}"); } @@ -511,6 +511,8 @@ namespace Ryujinx.Graphics.Texture return TextureTarget.Texture3D; case GalTextureTarget.OneDArray: return TextureTarget.Texture1DArray; + case GalTextureTarget.OneDBuffer: + return TextureTarget.TextureBuffer; case GalTextureTarget.TwoDArray: return TextureTarget.Texture2DArray; case GalTextureTarget.CubeMap: @@ -542,6 +544,7 @@ namespace Ryujinx.Graphics.Texture case GalTextureTarget.OneD: return 1; case GalTextureTarget.OneDArray: + case GalTextureTarget.OneDBuffer: case GalTextureTarget.TwoD: case GalTextureTarget.TwoDNoMipMap: return 2; diff --git a/Ryujinx.Graphics/Graphics3d/Texture/TextureFactory.cs b/Ryujinx.Graphics/Graphics3d/Texture/TextureFactory.cs index feafcedb44..a2ce86f56d 100644 --- a/Ryujinx.Graphics/Graphics3d/Texture/TextureFactory.cs +++ b/Ryujinx.Graphics/Graphics3d/Texture/TextureFactory.cs @@ -67,8 +67,15 @@ namespace Ryujinx.Graphics.Texture } else if (TextureTarget == GalTextureTarget.CubeMap) { - // TODO: WRONG - Depth = 6; + // FIXME: This is a bit hacky but I guess it's fine for now + LayoutCount = 6; + Depth = 1; + } + else if (TextureTarget == GalTextureTarget.CubeArray) + { + // FIXME: This is a really really hacky but I guess it's fine for now + LayoutCount *= 6; + Depth = 1; } GalImage Image = new GalImage(