From f502cfaf62d52decb5c74d42f33ce6643f62fc26 Mon Sep 17 00:00:00 2001 From: riperiperi Date: Thu, 29 Sep 2022 16:32:49 +0100 Subject: Vulkan: Zero blend state when disabled or write mask is 0 (#3719) * Zero blend state when disabled or write mask is 0 Any difference in the blend state when blend is disabled is meaningless, but Ryujinx would compare different disabled blends and compile them as separate pipelines. This change ensures that all pipelines where blend state is meaningless record it as such, which avoids compiling a bunch of pipelines that are essentially identical. The NVIDIA driver is pretty forgiving when it comes to silly pipeline misses like this, but other drivers don't offer the same level of kindness. This should reduce stuttering on those drivers, and might improve overall performance very slightly due to less pipeline variants being in the hash table. * Fix blend possibly being wrong when an attachment is unmasked --- Ryujinx.Graphics.Vulkan/PipelineConverter.cs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'Ryujinx.Graphics.Vulkan/PipelineConverter.cs') diff --git a/Ryujinx.Graphics.Vulkan/PipelineConverter.cs b/Ryujinx.Graphics.Vulkan/PipelineConverter.cs index 3ff111e8..477d0cec 100644 --- a/Ryujinx.Graphics.Vulkan/PipelineConverter.cs +++ b/Ryujinx.Graphics.Vulkan/PipelineConverter.cs @@ -257,15 +257,23 @@ namespace Ryujinx.Graphics.Vulkan { var blend = state.BlendDescriptors[i]; - pipeline.Internal.ColorBlendAttachmentState[i] = new PipelineColorBlendAttachmentState( - blend.Enable, - blend.ColorSrcFactor.Convert(), - blend.ColorDstFactor.Convert(), - blend.ColorOp.Convert(), - blend.AlphaSrcFactor.Convert(), - blend.AlphaDstFactor.Convert(), - blend.AlphaOp.Convert(), - (ColorComponentFlags)state.ColorWriteMask[i]); + if (blend.Enable && state.ColorWriteMask[i] != 0) + { + pipeline.Internal.ColorBlendAttachmentState[i] = new PipelineColorBlendAttachmentState( + blend.Enable, + blend.ColorSrcFactor.Convert(), + blend.ColorDstFactor.Convert(), + blend.ColorOp.Convert(), + blend.AlphaSrcFactor.Convert(), + blend.AlphaDstFactor.Convert(), + blend.AlphaOp.Convert(), + (ColorComponentFlags)state.ColorWriteMask[i]); + } + else + { + pipeline.Internal.ColorBlendAttachmentState[i] = new PipelineColorBlendAttachmentState( + colorWriteMask: (ColorComponentFlags)state.ColorWriteMask[i]); + } } int maxAttachmentIndex = 0; -- cgit v1.2.3