Fix host reserved counter

This commit is contained in:
riperiperi 2024-02-14 23:23:37 +00:00
parent 14b2395290
commit 0aa6b31b39
7 changed files with 19 additions and 15 deletions

View file

@ -103,7 +103,7 @@ namespace Ryujinx.Graphics.GAL
void TextureBarrier();
void TextureBarrierTiled();
bool TryHostConditionalRendering(ICounterEvent value, ulong compare, bool isEqual);
bool TryHostConditionalRendering(ICounterEvent value, ulong compare, bool isEqual, bool forwarded = false);
bool TryHostConditionalRendering(ICounterEvent value, ICounterEvent compare, bool isEqual);
void EndHostConditionalRendering();
}

View file

@ -19,7 +19,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading.Commands
public static void Run(ref TryHostConditionalRenderingCommand command, ThreadedRenderer threaded, IRenderer renderer)
{
renderer.Pipeline.TryHostConditionalRendering(command._value.Get(threaded)?.Base, command._compare, command._isEqual);
renderer.Pipeline.TryHostConditionalRendering(command._value.Get(threaded)?.Base, command._compare, command._isEqual, true);
}
}
}

View file

@ -333,7 +333,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading
_renderer.QueueCommand();
}
public bool TryHostConditionalRendering(ICounterEvent value, ulong compare, bool isEqual)
public bool TryHostConditionalRendering(ICounterEvent value, ulong compare, bool isEqual, bool forwarded = false)
{
var evt = value as ThreadedCounterEvent;
if (evt != null)

View file

@ -1629,7 +1629,7 @@ namespace Ryujinx.Graphics.OpenGL
}
}
public bool TryHostConditionalRendering(ICounterEvent value, ulong compare, bool isEqual)
public bool TryHostConditionalRendering(ICounterEvent value, ulong compare, bool isEqual, bool forwarded = false)
{
// Compare an event and a constant value.
if (value is CounterQueueEvent evt)
@ -1642,7 +1642,8 @@ namespace Ryujinx.Graphics.OpenGL
if (compare == 0 && evt.Type == QueryTarget.SamplesPassed && evt.ClearCounter)
{
if (!value.ReserveForHostAccess())
// If the call is forwarded from backend threading, then we have already reserved host access.
if (!forwarded && !value.ReserveForHostAccess())
{
// 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).

View file

@ -21,7 +21,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries
private readonly CounterQueue _queue;
private readonly BufferedQuery _counter;
private bool _hostAccessReserved = false;
private int _hostAccessReserved = 0;
private int _refCount = 1; // Starts with a reference from the counter queue.
private readonly object _lock = new();
@ -115,8 +115,9 @@ namespace Ryujinx.Graphics.OpenGL.Queries
public bool ReserveForHostAccess()
{
if (_hostAccessReserved)
if (_hostAccessReserved > 0)
{
Interlocked.Increment(ref _hostAccessReserved);
return true;
}
@ -132,14 +133,14 @@ namespace Ryujinx.Graphics.OpenGL.Queries
return false;
}
_hostAccessReserved = true;
_hostAccessReserved = Interlocked.Increment(ref _hostAccessReserved);
return true;
}
public void ReleaseHostAccess()
{
_hostAccessReserved = false;
Interlocked.Decrement(ref _hostAccessReserved);
DecrementRefCount();
}

View file

@ -131,7 +131,7 @@ namespace Ryujinx.Graphics.Vulkan
_activeConditionalRender = null;
}
public bool TryHostConditionalRendering(ICounterEvent value, ulong compare, bool isEqual)
public bool TryHostConditionalRendering(ICounterEvent value, ulong compare, bool isEqual, bool forwarded = false)
{
// Compare an event and a constant value.
if (value is CounterQueueEvent evt)
@ -144,7 +144,8 @@ namespace Ryujinx.Graphics.Vulkan
if (compare == 0 && evt.Type == CounterType.SamplesPassed && evt.ClearCounter)
{
if (!value.ReserveForHostAccess())
// If the call is forwarded from backend threading, then we have already reserved host access.
if (!forwarded && !value.ReserveForHostAccess())
{
// 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).

View file

@ -19,7 +19,7 @@ namespace Ryujinx.Graphics.Vulkan.Queries
private readonly CounterQueue _queue;
private readonly BufferedQuery _counter;
private bool _hostAccessReserved;
private int _hostAccessReserved;
private int _refCount = 1; // Starts with a reference from the counter queue.
private readonly object _lock = new();
@ -121,8 +121,9 @@ namespace Ryujinx.Graphics.Vulkan.Queries
public bool ReserveForHostAccess()
{
if (_hostAccessReserved)
if (_hostAccessReserved > 0)
{
Interlocked.Increment(ref _hostAccessReserved);
return true;
}
@ -138,14 +139,14 @@ namespace Ryujinx.Graphics.Vulkan.Queries
return false;
}
_hostAccessReserved = true;
Interlocked.Increment(ref _hostAccessReserved);
return true;
}
public void ReleaseHostAccess()
{
_hostAccessReserved = false;
Interlocked.Decrement(ref _hostAccessReserved);
DecrementRefCount();
}