From 6479c3e48479259bca79bee6f1016e8108cc33a8 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Sun, 8 Jul 2018 13:14:35 -0300 Subject: [PATCH] Implement GPU primitive restart (#221) --- Ryujinx.Graphics/Gal/IGalRasterizer.cs | 6 +++++ Ryujinx.Graphics/Gal/OpenGL/OGLRasterizer.cs | 15 ++++++++++++ Ryujinx.HLE/Gpu/Engines/NvGpuEngine3d.cs | 24 ++++++++++++++++++++ Ryujinx.HLE/Gpu/Engines/NvGpuEngine3dReg.cs | 2 ++ 4 files changed, 47 insertions(+) diff --git a/Ryujinx.Graphics/Gal/IGalRasterizer.cs b/Ryujinx.Graphics/Gal/IGalRasterizer.cs index 586eae6ba7..2598efb610 100644 --- a/Ryujinx.Graphics/Gal/IGalRasterizer.cs +++ b/Ryujinx.Graphics/Gal/IGalRasterizer.cs @@ -36,6 +36,12 @@ namespace Ryujinx.Graphics.Gal void SetClearStencil(int Stencil); + void EnablePrimitiveRestart(); + + void DisablePrimitiveRestart(); + + void SetPrimitiveRestartIndex(uint Index); + void CreateVbo(long Key, byte[] Buffer); void CreateIbo(long Key, byte[] Buffer); diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLRasterizer.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLRasterizer.cs index b988571172..a4ec7f87cf 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/OGLRasterizer.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/OGLRasterizer.cs @@ -184,6 +184,21 @@ namespace Ryujinx.Graphics.Gal.OpenGL GL.ClearStencil(Stencil); } + public void EnablePrimitiveRestart() + { + GL.Enable(EnableCap.PrimitiveRestart); + } + + public void DisablePrimitiveRestart() + { + GL.Disable(EnableCap.PrimitiveRestart); + } + + public void SetPrimitiveRestartIndex(uint Index) + { + GL.PrimitiveRestartIndex(Index); + } + public void CreateVbo(long Key, byte[] Buffer) { int Handle = GL.GenBuffer(); diff --git a/Ryujinx.HLE/Gpu/Engines/NvGpuEngine3d.cs b/Ryujinx.HLE/Gpu/Engines/NvGpuEngine3d.cs index d46f5089a5..10c99494b2 100644 --- a/Ryujinx.HLE/Gpu/Engines/NvGpuEngine3d.cs +++ b/Ryujinx.HLE/Gpu/Engines/NvGpuEngine3d.cs @@ -85,6 +85,7 @@ namespace Ryujinx.HLE.Gpu.Engines SetDepth(); SetStencil(); SetAlphaBlending(); + SetPrimitiveRestart(); UploadTextures(Vmm, Keys); UploadUniforms(Vmm); @@ -389,6 +390,29 @@ namespace Ryujinx.HLE.Gpu.Engines } } + private void SetPrimitiveRestart() + { + bool Enable = (ReadRegister(NvGpuEngine3dReg.PrimRestartEnable) & 1) != 0; + + if (Enable) + { + Gpu.Renderer.Rasterizer.EnablePrimitiveRestart(); + } + else + { + Gpu.Renderer.Rasterizer.DisablePrimitiveRestart(); + } + + if (!Enable) + { + return; + } + + uint Index = (uint)ReadRegister(NvGpuEngine3dReg.PrimRestartIndex); + + Gpu.Renderer.Rasterizer.SetPrimitiveRestartIndex(Index); + } + private void UploadTextures(NvGpuVmm Vmm, long[] Keys) { long BaseShPosition = MakeInt64From2xInt32(NvGpuEngine3dReg.ShaderAddress); diff --git a/Ryujinx.HLE/Gpu/Engines/NvGpuEngine3dReg.cs b/Ryujinx.HLE/Gpu/Engines/NvGpuEngine3dReg.cs index 9eb2966d9e..3de2885ef2 100644 --- a/Ryujinx.HLE/Gpu/Engines/NvGpuEngine3dReg.cs +++ b/Ryujinx.HLE/Gpu/Engines/NvGpuEngine3dReg.cs @@ -50,6 +50,8 @@ namespace Ryujinx.HLE.Gpu.Engines StencilBackFuncFunc = 0x569, ShaderAddress = 0x582, VertexBeginGl = 0x586, + PrimRestartEnable = 0x591, + PrimRestartIndex = 0x592, IndexArrayAddress = 0x5f2, IndexArrayEndAddr = 0x5f4, IndexArrayFormat = 0x5f6,