From 9d866ff282777da99be3777d8a71b298774d5c8e Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Wed, 3 Jul 2024 23:58:27 +0100 Subject: [PATCH] Fix blend state optimisation breaking attachments Fixes SM3DW --- src/Ryujinx.Graphics.Metal/EncoderStateManager.cs | 6 +++--- src/Ryujinx.Graphics.Metal/State/PipelineUid.cs | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs b/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs index 32981b0a4..42d6d0ad9 100644 --- a/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs +++ b/src/Ryujinx.Graphics.Metal/EncoderStateManager.cs @@ -390,11 +390,11 @@ namespace Ryujinx.Graphics.Metal { _currentState.StoredBlend[i] = mtlBlend; - mtlBlend = new ColorBlendStateUid(); + mtlBlend.Swap(new ColorBlendStateUid()); } else if (mtlBlend.WriteMask == 0) { - mtlBlend = _currentState.StoredBlend[i]; + mtlBlend.Swap(_currentState.StoredBlend[i]); } } @@ -535,7 +535,7 @@ namespace Ryujinx.Graphics.Metal { _currentState.StoredBlend[index] = blendState; - blendState = new ColorBlendStateUid(); + blendState.Swap(new ColorBlendStateUid()); } _currentState.BlendColor = blend.BlendConstant; diff --git a/src/Ryujinx.Graphics.Metal/State/PipelineUid.cs b/src/Ryujinx.Graphics.Metal/State/PipelineUid.cs index 4e2784b42..c986a7e23 100644 --- a/src/Ryujinx.Graphics.Metal/State/PipelineUid.cs +++ b/src/Ryujinx.Graphics.Metal/State/PipelineUid.cs @@ -111,6 +111,14 @@ namespace Ryujinx.Graphics.Metal readonly get => ((Id0 >> 63) & 0x1) != 0UL; set => Id0 = (Id0 & 0x7FFFFFFFFFFFFFFF) | ((value ? 1UL : 0UL) << 63); } + + public void Swap(ColorBlendStateUid uid) + { + var format = PixelFormat; + + this = uid; + PixelFormat = format; + } } [SupportedOSPlatform("macos")]