diff --git a/src/Ryujinx.Graphics.GAL/IRenderer.cs b/src/Ryujinx.Graphics.GAL/IRenderer.cs index 3bf56465e..16394bab4 100644 --- a/src/Ryujinx.Graphics.GAL/IRenderer.cs +++ b/src/Ryujinx.Graphics.GAL/IRenderer.cs @@ -45,7 +45,7 @@ namespace Ryujinx.Graphics.GAL void PreFrame(); - ICounterEvent ReportCounter(CounterType type, EventHandler resultHandler, float divisor, bool hostReserved); + ICounterEvent ReportCounter(CounterType type, EventHandler resultHandler, float divisor, int hostReserved); void ResetCounter(CounterType type); diff --git a/src/Ryujinx.Graphics.GAL/Multithreading/Commands/Renderer/ReportCounterCommand.cs b/src/Ryujinx.Graphics.GAL/Multithreading/Commands/Renderer/ReportCounterCommand.cs index 18b96f74b..d9539900a 100644 --- a/src/Ryujinx.Graphics.GAL/Multithreading/Commands/Renderer/ReportCounterCommand.cs +++ b/src/Ryujinx.Graphics.GAL/Multithreading/Commands/Renderer/ReportCounterCommand.cs @@ -11,9 +11,9 @@ namespace Ryujinx.Graphics.GAL.Multithreading.Commands.Renderer private CounterType _type; private TableRef> _resultHandler; private float _divisor; - private bool _hostReserved; + private int _hostReserved; - public void Set(TableRef evt, CounterType type, TableRef> resultHandler, float divisor, bool hostReserved) + public void Set(TableRef evt, CounterType type, TableRef> resultHandler, float divisor, int hostReserved) { _event = evt; _type = type; diff --git a/src/Ryujinx.Graphics.GAL/Multithreading/Resources/ThreadedCounterEvent.cs b/src/Ryujinx.Graphics.GAL/Multithreading/Resources/ThreadedCounterEvent.cs index 15db2b9fa..26daaf61c 100644 --- a/src/Ryujinx.Graphics.GAL/Multithreading/Resources/ThreadedCounterEvent.cs +++ b/src/Ryujinx.Graphics.GAL/Multithreading/Resources/ThreadedCounterEvent.cs @@ -14,7 +14,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading.Resources public CounterType Type { get; } public bool ClearCounter { get; } - private bool _reserved; + private int _reserved; private int _createLock; public ThreadedCounterEvent(ThreadedRenderer renderer, CounterType type, bool clearCounter) @@ -61,7 +61,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading.Resources } else { - _reserved = true; + Interlocked.Increment(ref _reserved); } Volatile.Write(ref _createLock, 0); @@ -70,10 +70,10 @@ namespace Ryujinx.Graphics.GAL.Multithreading.Resources } } - public void Create(IRenderer renderer, CounterType type, System.EventHandler eventHandler, float divisor, bool hostReserved) + public void Create(IRenderer renderer, CounterType type, System.EventHandler eventHandler, float divisor, int hostReserved) { ThreadedHelpers.SpinUntilExchange(ref _createLock, 1, 0); - Base = renderer.ReportCounter(type, eventHandler, divisor, hostReserved || _reserved); + Base = renderer.ReportCounter(type, eventHandler, divisor, hostReserved + _reserved); Volatile.Write(ref _createLock, 0); } } diff --git a/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs b/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs index 830fbf2d9..ed2580ba2 100644 --- a/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs +++ b/src/Ryujinx.Graphics.GAL/Multithreading/ThreadedRenderer.cs @@ -419,7 +419,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading QueueCommand(); } - public ICounterEvent ReportCounter(CounterType type, EventHandler resultHandler, float divisor, bool hostReserved) + public ICounterEvent ReportCounter(CounterType type, EventHandler resultHandler, float divisor, int hostReserved) { ThreadedCounterEvent evt = new(this, type, _lastSampleCounterClear); New().Set(Ref(evt), type, Ref(resultHandler), divisor, hostReserved); diff --git a/src/Ryujinx.Graphics.Gpu/Engine/Threed/SemaphoreUpdater.cs b/src/Ryujinx.Graphics.Gpu/Engine/Threed/SemaphoreUpdater.cs index a9a96d54a..96cc346fc 100644 --- a/src/Ryujinx.Graphics.Gpu/Engine/Threed/SemaphoreUpdater.cs +++ b/src/Ryujinx.Graphics.Gpu/Engine/Threed/SemaphoreUpdater.cs @@ -179,13 +179,13 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed case ReportCounterType.SamplesPassed: float scale = _channel.TextureManager.RenderTargetScale; float divisor = scale * scale; - counter = _context.Renderer.ReportCounter(CounterType.SamplesPassed, resultHandler, divisor, false); + counter = _context.Renderer.ReportCounter(CounterType.SamplesPassed, resultHandler, divisor, 0); break; case ReportCounterType.PrimitivesGenerated: - counter = _context.Renderer.ReportCounter(CounterType.PrimitivesGenerated, resultHandler, 1f, false); + counter = _context.Renderer.ReportCounter(CounterType.PrimitivesGenerated, resultHandler, 1f, 0); break; case ReportCounterType.TransformFeedbackPrimitivesWritten: - counter = _context.Renderer.ReportCounter(CounterType.TransformFeedbackPrimitivesWritten, resultHandler, 1f, false); + counter = _context.Renderer.ReportCounter(CounterType.TransformFeedbackPrimitivesWritten, resultHandler, 1f, 0); break; } diff --git a/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs b/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs index 1dd08ff6a..b14f1b059 100644 --- a/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs +++ b/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs @@ -205,7 +205,7 @@ namespace Ryujinx.Graphics.OpenGL ResourcePool.Tick(); } - public ICounterEvent ReportCounter(CounterType type, EventHandler resultHandler, float divisor, bool hostReserved) + public ICounterEvent ReportCounter(CounterType type, EventHandler resultHandler, float divisor, int hostReserved) { return _counters.QueueReport(type, resultHandler, divisor, _pipeline.DrawCount, hostReserved); } diff --git a/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs b/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs index 2f36840f0..3b30ce13b 100644 --- a/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs +++ b/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs @@ -106,7 +106,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries } } - public CounterQueueEvent QueueReport(EventHandler resultHandler, float divisor, ulong lastDrawIndex, bool hostReserved) + public CounterQueueEvent QueueReport(EventHandler resultHandler, float divisor, ulong lastDrawIndex, int hostReserved) { CounterQueueEvent result; ulong draws = lastDrawIndex - _current.DrawIndex; @@ -116,9 +116,9 @@ namespace Ryujinx.Graphics.OpenGL.Queries // A query's result only matters if more than one draw was performed during it. // Otherwise, dummy it out and return 0 immediately. - if (hostReserved) + while (hostReserved-- > 0) { - // This counter event is guaranteed to be available for host conditional rendering. + // This counter event is guaranteed to be available for host conditional rendering for the given number of uses. _current.ReserveForHostAccess(); } diff --git a/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs b/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs index 25e0588ae..7aee9e1f2 100644 --- a/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs +++ b/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs @@ -127,7 +127,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries return false; } - _hostAccessReserved = Interlocked.Increment(ref _hostAccessReserved); + Interlocked.Increment(ref _hostAccessReserved); return true; } diff --git a/src/Ryujinx.Graphics.OpenGL/Queries/Counters.cs b/src/Ryujinx.Graphics.OpenGL/Queries/Counters.cs index de8fb1142..85446878e 100644 --- a/src/Ryujinx.Graphics.OpenGL/Queries/Counters.cs +++ b/src/Ryujinx.Graphics.OpenGL/Queries/Counters.cs @@ -29,7 +29,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries } } - public CounterQueueEvent QueueReport(CounterType type, EventHandler resultHandler, float divisor, ulong lastDrawIndex, bool hostReserved) + public CounterQueueEvent QueueReport(CounterType type, EventHandler resultHandler, float divisor, ulong lastDrawIndex, int hostReserved) { return _counterQueues[(int)type].QueueReport(resultHandler, divisor, lastDrawIndex, hostReserved); } diff --git a/src/Ryujinx.Graphics.Vulkan/Queries/CounterQueue.cs b/src/Ryujinx.Graphics.Vulkan/Queries/CounterQueue.cs index 0d133e50e..e873fd248 100644 --- a/src/Ryujinx.Graphics.Vulkan/Queries/CounterQueue.cs +++ b/src/Ryujinx.Graphics.Vulkan/Queries/CounterQueue.cs @@ -139,7 +139,7 @@ namespace Ryujinx.Graphics.Vulkan.Queries } } - public CounterQueueEvent QueueReport(EventHandler resultHandler, float divisor, ulong lastDrawIndex, bool hostReserved) + public CounterQueueEvent QueueReport(EventHandler resultHandler, float divisor, ulong lastDrawIndex, int hostReserved) { CounterQueueEvent result; ulong draws = lastDrawIndex - _current.DrawIndex; @@ -149,9 +149,9 @@ namespace Ryujinx.Graphics.Vulkan.Queries // A query's result only matters if more than one draw was performed during it. // Otherwise, dummy it out and return 0 immediately. - if (hostReserved) + while (hostReserved-- > 0) { - // This counter event is guaranteed to be available for host conditional rendering. + // This counter event is guaranteed to be available for host conditional rendering for the given number of uses. _current.ReserveForHostAccess(); } diff --git a/src/Ryujinx.Graphics.Vulkan/Queries/Counters.cs b/src/Ryujinx.Graphics.Vulkan/Queries/Counters.cs index 518ede5f3..15ab11ed1 100644 --- a/src/Ryujinx.Graphics.Vulkan/Queries/Counters.cs +++ b/src/Ryujinx.Graphics.Vulkan/Queries/Counters.cs @@ -37,7 +37,7 @@ namespace Ryujinx.Graphics.Vulkan.Queries _counterQueues[(int)CounterType.SamplesPassed].ResetFutureCounters(cmd, count); } - public CounterQueueEvent QueueReport(CounterType type, EventHandler resultHandler, float divisor, bool hostReserved) + public CounterQueueEvent QueueReport(CounterType type, EventHandler resultHandler, float divisor, int hostReserved) { return _counterQueues[(int)type].QueueReport(resultHandler, divisor, _pipeline.DrawCount, hostReserved); } diff --git a/src/Ryujinx.Graphics.Vulkan/VulkanRenderer.cs b/src/Ryujinx.Graphics.Vulkan/VulkanRenderer.cs index 434545fe0..814982933 100644 --- a/src/Ryujinx.Graphics.Vulkan/VulkanRenderer.cs +++ b/src/Ryujinx.Graphics.Vulkan/VulkanRenderer.cs @@ -832,7 +832,7 @@ namespace Ryujinx.Graphics.Vulkan SyncManager.Cleanup(); } - public ICounterEvent ReportCounter(CounterType type, EventHandler resultHandler, float divisor, bool hostReserved) + public ICounterEvent ReportCounter(CounterType type, EventHandler resultHandler, float divisor, int hostReserved) { return _counters.QueueReport(type, resultHandler, divisor, hostReserved); }