From 9a6759d1e512081be95e7f937502027a86fa1060 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Fri, 31 May 2024 11:43:26 +0100 Subject: [PATCH] Depth Bias --- src/Ryujinx.Graphics.Metal/EncoderState.cs | 4 ++++ .../EncoderStateManager.cs | 22 +++++++++++++++++++ src/Ryujinx.Graphics.Metal/Pipeline.cs | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Ryujinx.Graphics.Metal/EncoderState.cs b/src/Ryujinx.Graphics.Metal/EncoderState.cs index a75ea3dc9..deee78a60 100644 --- a/src/Ryujinx.Graphics.Metal/EncoderState.cs +++ b/src/Ryujinx.Graphics.Metal/EncoderState.cs @@ -51,6 +51,10 @@ namespace Ryujinx.Graphics.Metal public MTLCompareFunction DepthCompareFunction = MTLCompareFunction.Always; public bool DepthWriteEnabled = false; + public float DepthBias; + public float SlopeScale; + public float Clamp; + public MTLStencilDescriptor BackFaceStencil = new(); public MTLStencilDescriptor FrontFaceStencil = new(); public int BackRefValue = 0; diff --git a/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs b/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs index 0ca7dbd2d..74bdc4258 100644 --- a/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs +++ b/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs @@ -79,6 +79,7 @@ namespace Ryujinx.Graphics.Metal // Set all the inline state, since it might have changed var renderCommandEncoder = _pipeline.GetOrCreateRenderEncoder(); SetDepthClamp(renderCommandEncoder); + SetDepthBias(renderCommandEncoder); SetScissors(renderCommandEncoder); SetViewports(renderCommandEncoder); SetVertexBuffers(renderCommandEncoder, _currentState.VertexBuffers); @@ -165,6 +166,7 @@ namespace Ryujinx.Graphics.Metal // Rebind all the state SetDepthClamp(renderCommandEncoder); + SetDepthBias(renderCommandEncoder); SetCullMode(renderCommandEncoder); SetFrontFace(renderCommandEncoder); SetStencilRefValue(renderCommandEncoder); @@ -561,6 +563,21 @@ namespace Ryujinx.Graphics.Metal } } + // Inlineable + public void UpdateDepthBias(float depthBias, float slopeScale, float clamp) + { + _currentState.DepthBias = depthBias; + _currentState.SlopeScale = slopeScale; + _currentState.Clamp = clamp; + + // Inline update + if (_pipeline.CurrentEncoderType == EncoderType.Render && _pipeline.CurrentEncoder != null) + { + var renderCommandEncoder = new MTLRenderCommandEncoder(_pipeline.CurrentEncoder.Value); + SetDepthBias(renderCommandEncoder); + } + } + // Inlineable public void UpdateScissors(ReadOnlySpan> regions) { @@ -839,6 +856,11 @@ namespace Ryujinx.Graphics.Metal renderCommandEncoder.SetDepthClipMode(_currentState.DepthClipMode); } + private readonly void SetDepthBias(MTLRenderCommandEncoder renderCommandEncoder) + { + renderCommandEncoder.SetDepthBias(_currentState.DepthBias, _currentState.SlopeScale, _currentState.Clamp); + } + private unsafe void SetScissors(MTLRenderCommandEncoder renderCommandEncoder) { if (_currentState.Scissors.Length > 0) diff --git a/src/Ryujinx.Graphics.Metal/Pipeline.cs b/src/Ryujinx.Graphics.Metal/Pipeline.cs index 7cdc2c6d8..34c4d30cb 100644 --- a/src/Ryujinx.Graphics.Metal/Pipeline.cs +++ b/src/Ryujinx.Graphics.Metal/Pipeline.cs @@ -388,7 +388,7 @@ namespace Ryujinx.Graphics.Metal public void SetDepthBias(PolygonModeMask enables, float factor, float units, float clamp) { - Logger.Warning?.Print(LogClass.Gpu, "Not Implemented!"); + _encoderStateManager.UpdateDepthBias(units, factor, clamp); } public void SetDepthClamp(bool clamp)