From 0f52165e86fc45e14a098bb7c4d377dacd96096c Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Sat, 29 Jul 2023 00:30:08 -0400 Subject: [PATCH] SetStencilTest --- src/Ryujinx.Graphics.Metal/Pipeline.cs | 29 ++++++++++++++++++- .../RenderEncoderState.cs | 2 ++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Ryujinx.Graphics.Metal/Pipeline.cs b/src/Ryujinx.Graphics.Metal/Pipeline.cs index 8ea0d1bc7..04a9bc26f 100644 --- a/src/Ryujinx.Graphics.Metal/Pipeline.cs +++ b/src/Ryujinx.Graphics.Metal/Pipeline.cs @@ -387,7 +387,34 @@ namespace Ryujinx.Graphics.Metal public void SetStencilTest(StencilTestDescriptor stencilTest) { - // TODO + var depthStencilDescriptor = new MTLDepthStencilDescriptor + { + BackFaceStencil = new MTLStencilDescriptor + { + StencilFailureOperation = stencilTest.BackSFail.Convert(), + DepthFailureOperation = stencilTest.BackDpFail.Convert(), + DepthStencilPassOperation = stencilTest.BackDpPass.Convert(), + StencilCompareFunction = stencilTest.BackFunc.Convert(), + ReadMask = (uint)stencilTest.BackFuncMask, + WriteMask = (uint)stencilTest.BackMask + }, + FrontFaceStencil = new MTLStencilDescriptor + { + StencilFailureOperation = stencilTest.FrontSFail.Convert(), + DepthFailureOperation = stencilTest.FrontDpFail.Convert(), + DepthStencilPassOperation = stencilTest.FrontDpPass.Convert(), + StencilCompareFunction = stencilTest.FrontFunc.Convert(), + ReadMask = (uint)stencilTest.FrontFuncMask, + WriteMask = (uint)stencilTest.FrontMask + } + }; + + var depthStencilState = _device.NewDepthStencilState(depthStencilDescriptor); + + if (_currentEncoder is MTLRenderCommandEncoder renderCommandEncoder) + { + renderCommandEncoder.SetDepthStencilState(depthStencilState); + } } public void SetStorageBuffers(ReadOnlySpan buffers) diff --git a/src/Ryujinx.Graphics.Metal/RenderEncoderState.cs b/src/Ryujinx.Graphics.Metal/RenderEncoderState.cs index 5f078ded6..8e0d7b093 100644 --- a/src/Ryujinx.Graphics.Metal/RenderEncoderState.cs +++ b/src/Ryujinx.Graphics.Metal/RenderEncoderState.cs @@ -11,6 +11,7 @@ namespace Ryujinx.Graphics.Metal public PrimitiveTopology Topology = PrimitiveTopology.Triangles; public MTLCullMode CullMode = MTLCullMode.None; public MTLWinding Winding = MTLWinding.Clockwise; + public MTLDepthStencilState DepthStencilState = null; public RenderEncoderState(MTLRenderPipelineState renderPipelineState) { @@ -22,6 +23,7 @@ namespace Ryujinx.Graphics.Metal renderCommandEncoder.SetRenderPipelineState(RenderPipelineState); renderCommandEncoder.SetCullMode(CullMode); renderCommandEncoder.SetFrontFacingWinding(Winding); + renderCommandEncoder.SetDepthStencilState(DepthStencilState); } } }