Fix host reserved counter
This commit is contained in:
parent
14b2395290
commit
0aa6b31b39
7 changed files with 19 additions and 15 deletions
|
@ -103,7 +103,7 @@ namespace Ryujinx.Graphics.GAL
|
||||||
void TextureBarrier();
|
void TextureBarrier();
|
||||||
void TextureBarrierTiled();
|
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);
|
bool TryHostConditionalRendering(ICounterEvent value, ICounterEvent compare, bool isEqual);
|
||||||
void EndHostConditionalRendering();
|
void EndHostConditionalRendering();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading.Commands
|
||||||
|
|
||||||
public static void Run(ref TryHostConditionalRenderingCommand command, ThreadedRenderer threaded, IRenderer renderer)
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -333,7 +333,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading
|
||||||
_renderer.QueueCommand();
|
_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;
|
var evt = value as ThreadedCounterEvent;
|
||||||
if (evt != null)
|
if (evt != null)
|
||||||
|
|
|
@ -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.
|
// Compare an event and a constant value.
|
||||||
if (value is CounterQueueEvent evt)
|
if (value is CounterQueueEvent evt)
|
||||||
|
@ -1642,7 +1642,8 @@ namespace Ryujinx.Graphics.OpenGL
|
||||||
|
|
||||||
if (compare == 0 && evt.Type == QueryTarget.SamplesPassed && evt.ClearCounter)
|
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.
|
// 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).
|
// The query object may already be repurposed for another draw (eg. begin + end).
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries
|
||||||
private readonly CounterQueue _queue;
|
private readonly CounterQueue _queue;
|
||||||
private readonly BufferedQuery _counter;
|
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 int _refCount = 1; // Starts with a reference from the counter queue.
|
||||||
|
|
||||||
private readonly object _lock = new();
|
private readonly object _lock = new();
|
||||||
|
@ -115,8 +115,9 @@ namespace Ryujinx.Graphics.OpenGL.Queries
|
||||||
|
|
||||||
public bool ReserveForHostAccess()
|
public bool ReserveForHostAccess()
|
||||||
{
|
{
|
||||||
if (_hostAccessReserved)
|
if (_hostAccessReserved > 0)
|
||||||
{
|
{
|
||||||
|
Interlocked.Increment(ref _hostAccessReserved);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,14 +133,14 @@ namespace Ryujinx.Graphics.OpenGL.Queries
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_hostAccessReserved = true;
|
_hostAccessReserved = Interlocked.Increment(ref _hostAccessReserved);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReleaseHostAccess()
|
public void ReleaseHostAccess()
|
||||||
{
|
{
|
||||||
_hostAccessReserved = false;
|
Interlocked.Decrement(ref _hostAccessReserved);
|
||||||
|
|
||||||
DecrementRefCount();
|
DecrementRefCount();
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,7 +131,7 @@ namespace Ryujinx.Graphics.Vulkan
|
||||||
_activeConditionalRender = null;
|
_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.
|
// Compare an event and a constant value.
|
||||||
if (value is CounterQueueEvent evt)
|
if (value is CounterQueueEvent evt)
|
||||||
|
@ -144,7 +144,8 @@ namespace Ryujinx.Graphics.Vulkan
|
||||||
|
|
||||||
if (compare == 0 && evt.Type == CounterType.SamplesPassed && evt.ClearCounter)
|
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.
|
// 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).
|
// The query object may already be repurposed for another draw (eg. begin + end).
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace Ryujinx.Graphics.Vulkan.Queries
|
||||||
private readonly CounterQueue _queue;
|
private readonly CounterQueue _queue;
|
||||||
private readonly BufferedQuery _counter;
|
private readonly BufferedQuery _counter;
|
||||||
|
|
||||||
private bool _hostAccessReserved;
|
private int _hostAccessReserved;
|
||||||
private int _refCount = 1; // Starts with a reference from the counter queue.
|
private int _refCount = 1; // Starts with a reference from the counter queue.
|
||||||
|
|
||||||
private readonly object _lock = new();
|
private readonly object _lock = new();
|
||||||
|
@ -121,8 +121,9 @@ namespace Ryujinx.Graphics.Vulkan.Queries
|
||||||
|
|
||||||
public bool ReserveForHostAccess()
|
public bool ReserveForHostAccess()
|
||||||
{
|
{
|
||||||
if (_hostAccessReserved)
|
if (_hostAccessReserved > 0)
|
||||||
{
|
{
|
||||||
|
Interlocked.Increment(ref _hostAccessReserved);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,14 +139,14 @@ namespace Ryujinx.Graphics.Vulkan.Queries
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_hostAccessReserved = true;
|
Interlocked.Increment(ref _hostAccessReserved);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReleaseHostAccess()
|
public void ReleaseHostAccess()
|
||||||
{
|
{
|
||||||
_hostAccessReserved = false;
|
Interlocked.Decrement(ref _hostAccessReserved);
|
||||||
|
|
||||||
DecrementRefCount();
|
DecrementRefCount();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue