From 7d14bc4be64c5d2e09e8a7fc7fd583901ca9909e Mon Sep 17 00:00:00 2001 From: riperiperi Date: Thu, 26 May 2022 20:49:06 +0100 Subject: [PATCH] Flush queries on attachment change rather than program change Occlusion queries are usually used in a depth only pass so the attachments changing is a better indication of the query block ending. Write mask changes are also considered since some games do depth only pass by setting 0 write mask on all the colour targets. --- Ryujinx.Graphics.Vulkan/PipelineBase.cs | 17 +++++++++++++++-- Ryujinx.Graphics.Vulkan/PipelineFull.cs | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Ryujinx.Graphics.Vulkan/PipelineBase.cs b/Ryujinx.Graphics.Vulkan/PipelineBase.cs index 08d7b0aa5b0d..6bcbd67172a0 100644 --- a/Ryujinx.Graphics.Vulkan/PipelineBase.cs +++ b/Ryujinx.Graphics.Vulkan/PipelineBase.cs @@ -45,6 +45,7 @@ class PipelineBase : IDisposable protected FramebufferParams FramebufferParams; private Auto _framebuffer; private Auto _renderPass; + private int _writtenAttachmentCount; private bool _renderPassActive; private readonly DescriptorSetUpdater _descriptorSetUpdater; @@ -605,10 +606,9 @@ public void SetProgram(IProgram program) stages.CopyTo(_newState.Stages.ToSpan().Slice(0, stages.Length)); SignalStateChange(); - SignalProgramChange(); } - protected virtual void SignalProgramChange() + protected virtual void SignalAttachmentChange() { } @@ -621,15 +621,27 @@ public void SetRasterizerDiscard(bool discard) public void SetRenderTargetColorMasks(ReadOnlySpan componentMask) { int count = Math.Min(Constants.MaxRenderTargets, componentMask.Length); + int writtenAttachments = 0; for (int i = 0; i < count; i++) { ref var vkBlend = ref _newState.Internal.ColorBlendAttachmentState[i]; vkBlend.ColorWriteMask = (ColorComponentFlags)componentMask[i]; + + if (componentMask[i] != 0) + { + writtenAttachments++; + } } SignalStateChange(); + + if (writtenAttachments != _writtenAttachmentCount) + { + SignalAttachmentChange(); + _writtenAttachmentCount = writtenAttachments; + } } public void SetRenderTargets(ITexture[] colors, ITexture depthStencil) @@ -638,6 +650,7 @@ public void SetRenderTargets(ITexture[] colors, ITexture depthStencil) CreateFramebuffer(colors, depthStencil); CreateRenderPass(); SignalStateChange(); + SignalAttachmentChange(); } public void SetRenderTargetScale(float scale) diff --git a/Ryujinx.Graphics.Vulkan/PipelineFull.cs b/Ryujinx.Graphics.Vulkan/PipelineFull.cs index 4dac49dd7a3e..f674e436bad3 100644 --- a/Ryujinx.Graphics.Vulkan/PipelineFull.cs +++ b/Ryujinx.Graphics.Vulkan/PipelineFull.cs @@ -384,7 +384,7 @@ public void CopyQueryResults(BufferedQuery query) _hasPendingQuery = true; } - protected override void SignalProgramChange() + protected override void SignalAttachmentChange() { FlushPendingQuery(); }