From 20e1d1cd33a042f51422c108ff9ed23976b8491c Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Sat, 18 May 2024 21:29:46 -0400 Subject: [PATCH] Implement SetDepthClamp --- src/Ryujinx.Graphics.Metal/EncoderState.cs | 1 + .../EncoderStateManager.cs | 19 +++++++++++++++++++ src/Ryujinx.Graphics.Metal/Pipeline.cs | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Ryujinx.Graphics.Metal/EncoderState.cs b/src/Ryujinx.Graphics.Metal/EncoderState.cs index 248acd364..b5d6bcade 100644 --- a/src/Ryujinx.Graphics.Metal/EncoderState.cs +++ b/src/Ryujinx.Graphics.Metal/EncoderState.cs @@ -29,6 +29,7 @@ namespace Ryujinx.Graphics.Metal public MTLDepthStencilState? DepthStencilState = null; + public MTLDepthClipMode DepthClipMode = MTLDepthClipMode.Clip; public MTLCompareFunction DepthCompareFunction = MTLCompareFunction.Always; public bool DepthWriteEnabled = false; diff --git a/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs b/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs index 88e6330ed..7acb99973 100644 --- a/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs +++ b/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs @@ -153,6 +153,7 @@ namespace Ryujinx.Graphics.Metal _currentState.BlendColor.Alpha); SetDepthStencilState(renderCommandEncoder, _currentState.DepthStencilState); + SetDepthClamp(renderCommandEncoder, _currentState.DepthClipMode); SetScissors(renderCommandEncoder, _currentState.Scissors); SetViewports(renderCommandEncoder, _currentState.Viewports); SetBuffers(renderCommandEncoder, _currentState.VertexBuffers); @@ -341,6 +342,19 @@ namespace Ryujinx.Graphics.Metal } } + // Inlineable + public void UpdateDepthClamp(bool clamp) + { + _currentState.DepthClipMode = clamp ? MTLDepthClipMode.Clamp : MTLDepthClipMode.Clip; + + // Inline Update + + if (_pipeline.CurrentEncoderType == EncoderType.Render && _pipeline.CurrentEncoder != null) + { + var renderCommandEncoder = new MTLRenderCommandEncoder(_pipeline.CurrentEncoder.Value); + } + } + // Inlineable public void UpdateScissors(ReadOnlySpan> regions) { @@ -552,6 +566,11 @@ namespace Ryujinx.Graphics.Metal } } + private static void SetDepthClamp(MTLRenderCommandEncoder renderCommandEncoder, MTLDepthClipMode depthClipMode) + { + renderCommandEncoder.SetDepthClipMode(depthClipMode); + } + private unsafe static void SetScissors(MTLRenderCommandEncoder renderCommandEncoder, MTLScissorRect[] scissors) { if (scissors.Length > 0) diff --git a/src/Ryujinx.Graphics.Metal/Pipeline.cs b/src/Ryujinx.Graphics.Metal/Pipeline.cs index c7b926611..f48efaed8 100644 --- a/src/Ryujinx.Graphics.Metal/Pipeline.cs +++ b/src/Ryujinx.Graphics.Metal/Pipeline.cs @@ -321,7 +321,7 @@ namespace Ryujinx.Graphics.Metal public void SetDepthClamp(bool clamp) { - Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!"); + _encoderStateManager.UpdateDepthClamp(clamp); } public void SetDepthMode(DepthMode mode)