From ab4867505ec0d3f5a9ec4f042ccd6f7890e3632e Mon Sep 17 00:00:00 2001 From: gdkchan Date: Sun, 29 Mar 2020 00:02:58 -0300 Subject: Implement GPU scissors (#1058) * Implement GPU scissors * Remove unused using * Add missing changes for Clear --- Ryujinx.Graphics.Gpu/Engine/MethodClear.cs | 6 ++++++ Ryujinx.Graphics.Gpu/Engine/Methods.cs | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) (limited to 'Ryujinx.Graphics.Gpu/Engine') diff --git a/Ryujinx.Graphics.Gpu/Engine/MethodClear.cs b/Ryujinx.Graphics.Gpu/Engine/MethodClear.cs index dfa7b12e..ff538df3 100644 --- a/Ryujinx.Graphics.Gpu/Engine/MethodClear.cs +++ b/Ryujinx.Graphics.Gpu/Engine/MethodClear.cs @@ -13,6 +13,12 @@ namespace Ryujinx.Graphics.Gpu.Engine /// Method call argument private void Clear(GpuState state, int argument) { + // Scissor affects clears aswell. + if (state.QueryModified(MethodOffset.ScissorState)) + { + UpdateScissorState(state); + } + UpdateRenderTargetState(state, useControl: false); TextureManager.CommitGraphicsBindings(); diff --git a/Ryujinx.Graphics.Gpu/Engine/Methods.cs b/Ryujinx.Graphics.Gpu/Engine/Methods.cs index a2c9876e..0b30e61d 100644 --- a/Ryujinx.Graphics.Gpu/Engine/Methods.cs +++ b/Ryujinx.Graphics.Gpu/Engine/Methods.cs @@ -117,6 +117,11 @@ namespace Ryujinx.Graphics.Gpu.Engine UpdateRenderTargetState(state, useControl: true); } + if (state.QueryModified(MethodOffset.ScissorState)) + { + UpdateScissorState(state); + } + if (state.QueryModified(MethodOffset.DepthTestEnable, MethodOffset.DepthWriteEnable, MethodOffset.DepthTestFunc)) @@ -321,6 +326,27 @@ namespace Ryujinx.Graphics.Gpu.Engine return colorState.Format != 0 && colorState.WidthOrStride != 0; } + /// + /// Updates host scissor test state based on current GPU state. + /// + /// Current GPU state + private void UpdateScissorState(GpuState state) + { + for (int index = 0; index < Constants.TotalViewports; index++) + { + ScissorState scissor = state.Get(MethodOffset.ScissorState, index); + + bool enable = scissor.Enable && (scissor.X1 != 0 || scissor.Y1 != 0 || scissor.X2 != 0xffff || scissor.Y2 != 0xffff); + + _context.Renderer.Pipeline.SetScissorEnable(index, enable); + + if (enable) + { + _context.Renderer.Pipeline.SetScissor(index, scissor.X1, scissor.Y1, scissor.X2 - scissor.X1, scissor.Y2 - scissor.Y1); + } + } + } + /// /// Updates host depth test state based on current GPU state. /// -- cgit v1.2.3