nvservice: add a lock around NvHostEvent and remove release fence on SFv2 (#1197)
* nvservice: add a lock to NvHostEvent * Disable surface flinger release fence and readd infinite timeout * FenceAction: Add a timeout of 1 seconds as this shouldn't wait forever anyuway * surfaceflinger: remove leftovers from the release fence * Don't allow infinite timeout on syncpoint while printing all timeout for better debugging
This commit is contained in:
parent
0a3b75ae2b
commit
764891e670
4 changed files with 237 additions and 211 deletions
|
@ -112,14 +112,10 @@ namespace Ryujinx.Graphics.Gpu.Synchronization
|
||||||
throw new ArgumentOutOfRangeException(nameof(id));
|
throw new ArgumentOutOfRangeException(nameof(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool warnAboutTimeout = false;
|
|
||||||
|
|
||||||
// TODO: Remove this when GPU channel scheduling will be implemented.
|
// TODO: Remove this when GPU channel scheduling will be implemented.
|
||||||
if (timeout == Timeout.InfiniteTimeSpan)
|
if (timeout == Timeout.InfiniteTimeSpan)
|
||||||
{
|
{
|
||||||
timeout = TimeSpan.FromSeconds(1);
|
timeout = TimeSpan.FromSeconds(1);
|
||||||
|
|
||||||
warnAboutTimeout = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
using (ManualResetEvent waitEvent = new ManualResetEvent(false))
|
using (ManualResetEvent waitEvent = new ManualResetEvent(false))
|
||||||
|
@ -134,11 +130,8 @@ namespace Ryujinx.Graphics.Gpu.Synchronization
|
||||||
bool signaled = waitEvent.WaitOne(timeout);
|
bool signaled = waitEvent.WaitOne(timeout);
|
||||||
|
|
||||||
if (!signaled && info != null)
|
if (!signaled && info != null)
|
||||||
{
|
|
||||||
if (warnAboutTimeout)
|
|
||||||
{
|
{
|
||||||
Logger.PrintError(LogClass.Gpu, $"Wait on syncpoint {id} for threshold {threshold} took more than {timeout.TotalMilliseconds}ms, resuming execution...");
|
Logger.PrintError(LogClass.Gpu, $"Wait on syncpoint {id} for threshold {threshold} took more than {timeout.TotalMilliseconds}ms, resuming execution...");
|
||||||
}
|
|
||||||
|
|
||||||
_syncpoints[id].UnregisterCallback(info);
|
_syncpoints[id].UnregisterCallback(info);
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,8 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||||
}
|
}
|
||||||
|
|
||||||
private KEvent QueryEvent(uint eventId)
|
private KEvent QueryEvent(uint eventId)
|
||||||
|
{
|
||||||
|
lock (_events)
|
||||||
{
|
{
|
||||||
uint eventSlot;
|
uint eventSlot;
|
||||||
uint syncpointId;
|
uint syncpointId;
|
||||||
|
@ -116,6 +118,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||||
|
|
||||||
return _events[eventSlot].Event;
|
return _events[eventSlot].Event;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override NvInternalResult QueryEvent(out int eventHandle, uint eventId)
|
public override NvInternalResult QueryEvent(out int eventHandle, uint eventId)
|
||||||
{
|
{
|
||||||
|
@ -225,6 +228,8 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||||
}
|
}
|
||||||
|
|
||||||
private NvInternalResult EventRegister(ref uint userEventId)
|
private NvInternalResult EventRegister(ref uint userEventId)
|
||||||
|
{
|
||||||
|
lock (_events)
|
||||||
{
|
{
|
||||||
NvInternalResult result = EventUnregister(ref userEventId);
|
NvInternalResult result = EventUnregister(ref userEventId);
|
||||||
|
|
||||||
|
@ -236,7 +241,11 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private NvInternalResult EventUnregister(ref uint userEventId)
|
private NvInternalResult EventUnregister(ref uint userEventId)
|
||||||
|
{
|
||||||
|
lock (_events)
|
||||||
{
|
{
|
||||||
if (userEventId >= EventsCount)
|
if (userEventId >= EventsCount)
|
||||||
{
|
{
|
||||||
|
@ -262,8 +271,11 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||||
|
|
||||||
return NvInternalResult.Busy;
|
return NvInternalResult.Busy;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private NvInternalResult EventKill(ref ulong eventMask)
|
private NvInternalResult EventKill(ref ulong eventMask)
|
||||||
|
{
|
||||||
|
lock (_events)
|
||||||
{
|
{
|
||||||
NvInternalResult result = NvInternalResult.Success;
|
NvInternalResult result = NvInternalResult.Success;
|
||||||
|
|
||||||
|
@ -282,6 +294,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private NvInternalResult EventSignal(ref uint userEventId)
|
private NvInternalResult EventSignal(ref uint userEventId)
|
||||||
{
|
{
|
||||||
|
@ -292,6 +305,8 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||||
return NvInternalResult.InvalidInput;
|
return NvInternalResult.InvalidInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lock (_events)
|
||||||
|
{
|
||||||
NvHostEvent hostEvent = _events[eventId];
|
NvHostEvent hostEvent = _events[eventId];
|
||||||
|
|
||||||
if (hostEvent == null)
|
if (hostEvent == null)
|
||||||
|
@ -299,6 +314,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||||
return NvInternalResult.InvalidInput;
|
return NvInternalResult.InvalidInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lock (hostEvent.Lock)
|
||||||
|
{
|
||||||
|
|
||||||
NvHostEventState oldState = hostEvent.State;
|
NvHostEventState oldState = hostEvent.State;
|
||||||
|
|
||||||
if (oldState == NvHostEventState.Waiting)
|
if (oldState == NvHostEventState.Waiting)
|
||||||
|
@ -314,6 +332,8 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||||
|
|
||||||
return NvInternalResult.Success;
|
return NvInternalResult.Success;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private NvInternalResult SyncptReadMinOrMax(ref NvFence arguments, bool max)
|
private NvInternalResult SyncptReadMinOrMax(ref NvFence arguments, bool max)
|
||||||
{
|
{
|
||||||
|
@ -379,6 +399,8 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||||
|
|
||||||
uint eventIndex;
|
uint eventIndex;
|
||||||
|
|
||||||
|
lock (_events)
|
||||||
|
{
|
||||||
if (isWaitEventAsyncCmd)
|
if (isWaitEventAsyncCmd)
|
||||||
{
|
{
|
||||||
eventIndex = value;
|
eventIndex = value;
|
||||||
|
@ -392,13 +414,16 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
hostEvent = GetFreeEvent(fence.Id, out eventIndex);
|
hostEvent = GetFreeEventLocked(fence.Id, out eventIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hostEvent != null &&
|
if (hostEvent != null)
|
||||||
(hostEvent.State == NvHostEventState.Available ||
|
{
|
||||||
|
lock (hostEvent.Lock)
|
||||||
|
{
|
||||||
|
if (hostEvent.State == NvHostEventState.Available ||
|
||||||
hostEvent.State == NvHostEventState.Signaled ||
|
hostEvent.State == NvHostEventState.Signaled ||
|
||||||
hostEvent.State == NvHostEventState.Cancelled))
|
hostEvent.State == NvHostEventState.Cancelled)
|
||||||
{
|
{
|
||||||
bool timedOut = hostEvent.Wait(_device.Gpu, fence);
|
bool timedOut = hostEvent.Wait(_device.Gpu, fence);
|
||||||
|
|
||||||
|
@ -435,11 +460,20 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||||
|
|
||||||
result = NvInternalResult.InvalidInput;
|
result = NvInternalResult.InvalidInput;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logger.PrintError(LogClass.ServiceNv, $"Invalid Event at index {eventIndex} (isWaitEventAsyncCmd: {isWaitEventAsyncCmd}, isWaitEventCmd: {isWaitEventCmd})");
|
||||||
|
|
||||||
|
result = NvInternalResult.InvalidInput;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NvHostEvent GetFreeEvent(uint id, out uint eventIndex)
|
private NvHostEvent GetFreeEventLocked(uint id, out uint eventIndex)
|
||||||
{
|
{
|
||||||
eventIndex = EventsCount;
|
eventIndex = EventsCount;
|
||||||
|
|
||||||
|
@ -490,12 +524,16 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||||
{
|
{
|
||||||
Logger.PrintWarning(LogClass.ServiceNv, "Closing channel");
|
Logger.PrintWarning(LogClass.ServiceNv, "Closing channel");
|
||||||
|
|
||||||
|
lock (_events)
|
||||||
|
{
|
||||||
// If the device file need to be closed, cancel all user events and dispose events.
|
// If the device file need to be closed, cancel all user events and dispose events.
|
||||||
for (int i = 0; i < _events.Length; i++)
|
for (int i = 0; i < _events.Length; i++)
|
||||||
{
|
{
|
||||||
NvHostEvent evnt = _events[i];
|
NvHostEvent evnt = _events[i];
|
||||||
|
|
||||||
if (evnt != null)
|
if (evnt != null)
|
||||||
|
{
|
||||||
|
lock (evnt.Lock)
|
||||||
{
|
{
|
||||||
if (evnt.State == NvHostEventState.Waiting)
|
if (evnt.State == NvHostEventState.Waiting)
|
||||||
{
|
{
|
||||||
|
@ -526,4 +564,6 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,8 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||||
private NvFence _previousFailingFence;
|
private NvFence _previousFailingFence;
|
||||||
private uint _failingCount;
|
private uint _failingCount;
|
||||||
|
|
||||||
|
public object Lock = new object();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Max failing count until waiting on CPU.
|
/// Max failing count until waiting on CPU.
|
||||||
/// FIXME: This seems enough for most of the cases, reduce if needed.
|
/// FIXME: This seems enough for most of the cases, reduce if needed.
|
||||||
|
@ -49,14 +51,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||||
_failingCount = 0;
|
_failingCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset()
|
|
||||||
{
|
|
||||||
Fence.Id = 0;
|
|
||||||
Fence.Value = 0;
|
|
||||||
State = NvHostEventState.Available;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Signal()
|
private void Signal()
|
||||||
|
{
|
||||||
|
lock (Lock)
|
||||||
{
|
{
|
||||||
NvHostEventState oldState = State;
|
NvHostEventState oldState = State;
|
||||||
|
|
||||||
|
@ -69,15 +66,21 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||||
|
|
||||||
State = NvHostEventState.Signaled;
|
State = NvHostEventState.Signaled;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void GpuSignaled()
|
private void GpuSignaled()
|
||||||
|
{
|
||||||
|
lock (Lock)
|
||||||
{
|
{
|
||||||
ResetFailingState();
|
ResetFailingState();
|
||||||
|
|
||||||
Signal();
|
Signal();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Cancel(GpuContext gpuContext)
|
public void Cancel(GpuContext gpuContext)
|
||||||
|
{
|
||||||
|
lock (Lock)
|
||||||
{
|
{
|
||||||
if (_waiterInformation != null)
|
if (_waiterInformation != null)
|
||||||
{
|
{
|
||||||
|
@ -99,8 +102,11 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||||
|
|
||||||
Event.WritableEvent.Clear();
|
Event.WritableEvent.Clear();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool Wait(GpuContext gpuContext, NvFence fence)
|
public bool Wait(GpuContext gpuContext, NvFence fence)
|
||||||
|
{
|
||||||
|
lock (Lock)
|
||||||
{
|
{
|
||||||
Fence = fence;
|
Fence = fence;
|
||||||
State = NvHostEventState.Waiting;
|
State = NvHostEventState.Waiting;
|
||||||
|
@ -128,6 +134,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string DumpState(GpuContext gpuContext)
|
public string DumpState(GpuContext gpuContext)
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,8 +26,6 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
||||||
|
|
||||||
private Stopwatch _chrono;
|
private Stopwatch _chrono;
|
||||||
|
|
||||||
private AndroidFence _vblankFence;
|
|
||||||
|
|
||||||
private long _ticks;
|
private long _ticks;
|
||||||
private long _ticksPerFrame;
|
private long _ticksPerFrame;
|
||||||
|
|
||||||
|
@ -49,7 +47,6 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
||||||
{
|
{
|
||||||
public Layer Layer;
|
public Layer Layer;
|
||||||
public BufferItem Item;
|
public BufferItem Item;
|
||||||
public AndroidFence Fence;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SurfaceFlinger(Switch device)
|
public SurfaceFlinger(Switch device)
|
||||||
|
@ -69,13 +66,6 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
||||||
|
|
||||||
UpdateSwapInterval(1);
|
UpdateSwapInterval(1);
|
||||||
|
|
||||||
_vblankFence = AndroidFence.NoFence;
|
|
||||||
_vblankFence.AddFence(new NvFence
|
|
||||||
{
|
|
||||||
Id = NvHostSyncpt.VBlank0SyncpointId,
|
|
||||||
Value = 0
|
|
||||||
});
|
|
||||||
|
|
||||||
_composerThread.Start();
|
_composerThread.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,8 +212,6 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
||||||
{
|
{
|
||||||
lock (Lock)
|
lock (Lock)
|
||||||
{
|
{
|
||||||
_vblankFence.NvFences[0].Increment(_device.Gpu);
|
|
||||||
|
|
||||||
// TODO: support multilayers (& multidisplay ?)
|
// TODO: support multilayers (& multidisplay ?)
|
||||||
if (_layers.Count == 0)
|
if (_layers.Count == 0)
|
||||||
{
|
{
|
||||||
|
@ -298,14 +286,10 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
||||||
flipX,
|
flipX,
|
||||||
flipY);
|
flipY);
|
||||||
|
|
||||||
// Enforce that dequeueBuffer wait for the next vblank
|
|
||||||
_vblankFence.NvFences[0].Value++;
|
|
||||||
|
|
||||||
TextureCallbackInformation textureCallbackInformation = new TextureCallbackInformation
|
TextureCallbackInformation textureCallbackInformation = new TextureCallbackInformation
|
||||||
{
|
{
|
||||||
Layer = layer,
|
Layer = layer,
|
||||||
Item = item,
|
Item = item,
|
||||||
Fence = _vblankFence
|
|
||||||
};
|
};
|
||||||
|
|
||||||
_device.Gpu.Window.EnqueueFrameThreadSafe(
|
_device.Gpu.Window.EnqueueFrameThreadSafe(
|
||||||
|
@ -330,7 +314,9 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
||||||
|
|
||||||
private void ReleaseBuffer(TextureCallbackInformation information)
|
private void ReleaseBuffer(TextureCallbackInformation information)
|
||||||
{
|
{
|
||||||
information.Layer.Consumer.ReleaseBuffer(information.Item, ref information.Fence);
|
AndroidFence fence = AndroidFence.NoFence;
|
||||||
|
|
||||||
|
information.Layer.Consumer.ReleaseBuffer(information.Item, ref fence);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AcquireBuffer(GpuContext ignored, object obj)
|
private void AcquireBuffer(GpuContext ignored, object obj)
|
||||||
|
|
Loading…
Reference in a new issue