From 1e167788d430c7df501953ce649a0cf2f8bd28d1 Mon Sep 17 00:00:00 2001 From: riperiperi Date: Sat, 22 Jan 2022 19:30:20 +0000 Subject: [PATCH] Fix counter queue leak when game decides to use host conditional rendering --- Ryujinx.Graphics.Vulkan/PipelineFull.cs | 43 +++++++++++++++---------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/Ryujinx.Graphics.Vulkan/PipelineFull.cs b/Ryujinx.Graphics.Vulkan/PipelineFull.cs index 0f092bc0c..15a68ea31 100644 --- a/Ryujinx.Graphics.Vulkan/PipelineFull.cs +++ b/Ryujinx.Graphics.Vulkan/PipelineFull.cs @@ -11,6 +11,7 @@ namespace Ryujinx.Graphics.Vulkan private bool _hasPendingQuery; private readonly List _activeQueries; + private CounterQueueEvent _activeConditionalRender; public PipelineFull(VulkanGraphicsDevice gd, Device device) : base(gd, device) { @@ -167,6 +168,9 @@ namespace Ryujinx.Graphics.Vulkan { // throw new NotSupportedException(); } + + _activeConditionalRender?.ReleaseHostAccess(); + _activeConditionalRender = null; } public bool TryHostConditionalRendering(ICounterEvent value, ulong compare, bool isEqual) @@ -180,26 +184,31 @@ namespace Ryujinx.Graphics.Vulkan // - Comparing against 0. // - Event has not already been flushed. - if (evt.Disposed) + if (compare == 0 && evt.Type == CounterType.SamplesPassed && evt.ClearCounter) { - // If the event has been flushed, then just use the values on the CPU. - // The query object may already be repurposed for another draw (eg. begin + end). - return false; - } - - if (Gd.Capabilities.SupportsConditionalRendering && compare == 0 && evt.Type == CounterType.SamplesPassed && evt.ClearCounter) - { - var buffer = evt.GetBuffer().Get(Cbs, 0, sizeof(long)).Value; - var flags = isEqual ? ConditionalRenderingFlagsEXT.ConditionalRenderingInvertedBitExt : 0; - - var conditionalRenderingBeginInfo = new ConditionalRenderingBeginInfoEXT() + if (!value.ReserveForHostAccess()) { - SType = StructureType.ConditionalRenderingBeginInfoExt, - Buffer = buffer, - Flags = flags - }; + // If the event has been flushed, then just use the values on the CPU. + // The query object may already be repurposed for another draw (eg. begin + end). + return false; + } - // Gd.ConditionalRenderingApi.CmdBeginConditionalRendering(CommandBuffer, conditionalRenderingBeginInfo); + if (Gd.Capabilities.SupportsConditionalRendering) + { + var buffer = evt.GetBuffer().Get(Cbs, 0, sizeof(long)).Value; + var flags = isEqual ? ConditionalRenderingFlagsEXT.ConditionalRenderingInvertedBitExt : 0; + + var conditionalRenderingBeginInfo = new ConditionalRenderingBeginInfoEXT() + { + SType = StructureType.ConditionalRenderingBeginInfoExt, + Buffer = buffer, + Flags = flags + }; + + // Gd.ConditionalRenderingApi.CmdBeginConditionalRendering(CommandBuffer, conditionalRenderingBeginInfo); + } + + _activeConditionalRender = evt; return true; } }