From ce23bff285005206bd307c8a2f2533aa644a06fc Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 5 Sep 2024 13:18:48 +0200 Subject: [PATCH] Fix invalid depth stencil state when no depth stencil is present Partially fixes Sonic Frontiers and Castlevania Dominus Collection --- src/Ryujinx.Graphics.Metal/EncoderStateManager.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs b/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs index 6e5fa01d64..b618567773 100644 --- a/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs +++ b/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs @@ -21,6 +21,7 @@ namespace Ryujinx.Graphics.Metal private readonly BufferManager _bufferManager; private readonly DepthStencilCache _depthStencilCache; + private readonly MTLDepthStencilState _defaultState; private readonly EncoderState _mainState = new(); private EncoderState _currentState; @@ -44,6 +45,8 @@ namespace Ryujinx.Graphics.Metal _depthStencilCache = new(device); _currentState = _mainState; + _defaultState = _depthStencilCache.GetOrCreate(_currentState.DepthStencilUid); + // Zero buffer byte[] zeros = new byte[ZeroBufferSize]; fixed (byte* ptr = zeros) @@ -952,9 +955,16 @@ namespace Ryujinx.Graphics.Metal private readonly void SetDepthStencilState(MTLRenderCommandEncoder renderCommandEncoder) { - MTLDepthStencilState state = _depthStencilCache.GetOrCreate(_currentState.DepthStencilUid); + if (DepthStencil != null) + { + MTLDepthStencilState state = _depthStencilCache.GetOrCreate(_currentState.DepthStencilUid); - renderCommandEncoder.SetDepthStencilState(state); + renderCommandEncoder.SetDepthStencilState(state); + } + else + { + renderCommandEncoder.SetDepthStencilState(_defaultState); + } } private readonly void SetDepthClamp(MTLRenderCommandEncoder renderCommandEncoder)