mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-12-23 06:31:21 -08:00
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
@ -112,14 +112,10 @@ namespace Ryujinx.Graphics.Gpu.Synchronization
|
||||
throw new ArgumentOutOfRangeException(nameof(id));
|
||||
}
|
||||
|
||||
bool warnAboutTimeout = false;
|
||||
|
||||
// TODO: Remove this when GPU channel scheduling will be implemented.
|
||||
if (timeout == Timeout.InfiniteTimeSpan)
|
||||
{
|
||||
timeout = TimeSpan.FromSeconds(1);
|
||||
|
||||
warnAboutTimeout = true;
|
||||
}
|
||||
|
||||
using (ManualResetEvent waitEvent = new ManualResetEvent(false))
|
||||
@ -134,11 +130,8 @@ namespace Ryujinx.Graphics.Gpu.Synchronization
|
||||
bool signaled = waitEvent.WaitOne(timeout);
|
||||
|
||||
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...");
|
||||
}
|
||||
|
||||
_syncpoints[id].UnregisterCallback(info);
|
||||
}
|
||||
|
@ -94,6 +94,8 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||
}
|
||||
|
||||
private KEvent QueryEvent(uint eventId)
|
||||
{
|
||||
lock (_events)
|
||||
{
|
||||
uint eventSlot;
|
||||
uint syncpointId;
|
||||
@ -116,6 +118,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||
|
||||
return _events[eventSlot].Event;
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
lock (_events)
|
||||
{
|
||||
NvInternalResult result = EventUnregister(ref userEventId);
|
||||
|
||||
@ -236,7 +241,11 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private NvInternalResult EventUnregister(ref uint userEventId)
|
||||
{
|
||||
lock (_events)
|
||||
{
|
||||
if (userEventId >= EventsCount)
|
||||
{
|
||||
@ -262,8 +271,11 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||
|
||||
return NvInternalResult.Busy;
|
||||
}
|
||||
}
|
||||
|
||||
private NvInternalResult EventKill(ref ulong eventMask)
|
||||
{
|
||||
lock (_events)
|
||||
{
|
||||
NvInternalResult result = NvInternalResult.Success;
|
||||
|
||||
@ -282,6 +294,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private NvInternalResult EventSignal(ref uint userEventId)
|
||||
{
|
||||
@ -292,6 +305,8 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||
return NvInternalResult.InvalidInput;
|
||||
}
|
||||
|
||||
lock (_events)
|
||||
{
|
||||
NvHostEvent hostEvent = _events[eventId];
|
||||
|
||||
if (hostEvent == null)
|
||||
@ -299,6 +314,9 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||
return NvInternalResult.InvalidInput;
|
||||
}
|
||||
|
||||
lock (hostEvent.Lock)
|
||||
{
|
||||
|
||||
NvHostEventState oldState = hostEvent.State;
|
||||
|
||||
if (oldState == NvHostEventState.Waiting)
|
||||
@ -314,6 +332,8 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||
|
||||
return NvInternalResult.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private NvInternalResult SyncptReadMinOrMax(ref NvFence arguments, bool max)
|
||||
{
|
||||
@ -379,6 +399,8 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||
|
||||
uint eventIndex;
|
||||
|
||||
lock (_events)
|
||||
{
|
||||
if (isWaitEventAsyncCmd)
|
||||
{
|
||||
eventIndex = value;
|
||||
@ -392,13 +414,16 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||
}
|
||||
else
|
||||
{
|
||||
hostEvent = GetFreeEvent(fence.Id, out eventIndex);
|
||||
hostEvent = GetFreeEventLocked(fence.Id, out eventIndex);
|
||||
}
|
||||
|
||||
if (hostEvent != null &&
|
||||
(hostEvent.State == NvHostEventState.Available ||
|
||||
if (hostEvent != null)
|
||||
{
|
||||
lock (hostEvent.Lock)
|
||||
{
|
||||
if (hostEvent.State == NvHostEventState.Available ||
|
||||
hostEvent.State == NvHostEventState.Signaled ||
|
||||
hostEvent.State == NvHostEventState.Cancelled))
|
||||
hostEvent.State == NvHostEventState.Cancelled)
|
||||
{
|
||||
bool timedOut = hostEvent.Wait(_device.Gpu, fence);
|
||||
|
||||
@ -435,11 +460,20 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||
|
||||
result = NvInternalResult.InvalidInput;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.PrintError(LogClass.ServiceNv, $"Invalid Event at index {eventIndex} (isWaitEventAsyncCmd: {isWaitEventAsyncCmd}, isWaitEventCmd: {isWaitEventCmd})");
|
||||
|
||||
result = NvInternalResult.InvalidInput;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public NvHostEvent GetFreeEvent(uint id, out uint eventIndex)
|
||||
private NvHostEvent GetFreeEventLocked(uint id, out uint eventIndex)
|
||||
{
|
||||
eventIndex = EventsCount;
|
||||
|
||||
@ -490,12 +524,16 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||
{
|
||||
Logger.PrintWarning(LogClass.ServiceNv, "Closing channel");
|
||||
|
||||
lock (_events)
|
||||
{
|
||||
// If the device file need to be closed, cancel all user events and dispose events.
|
||||
for (int i = 0; i < _events.Length; i++)
|
||||
{
|
||||
NvHostEvent evnt = _events[i];
|
||||
|
||||
if (evnt != null)
|
||||
{
|
||||
lock (evnt.Lock)
|
||||
{
|
||||
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 uint _failingCount;
|
||||
|
||||
public object Lock = new object();
|
||||
|
||||
/// <summary>
|
||||
/// Max failing count until waiting on CPU.
|
||||
/// 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;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Fence.Id = 0;
|
||||
Fence.Value = 0;
|
||||
State = NvHostEventState.Available;
|
||||
}
|
||||
|
||||
private void Signal()
|
||||
{
|
||||
lock (Lock)
|
||||
{
|
||||
NvHostEventState oldState = State;
|
||||
|
||||
@ -69,15 +66,21 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||
|
||||
State = NvHostEventState.Signaled;
|
||||
}
|
||||
}
|
||||
|
||||
private void GpuSignaled()
|
||||
{
|
||||
lock (Lock)
|
||||
{
|
||||
ResetFailingState();
|
||||
|
||||
Signal();
|
||||
}
|
||||
}
|
||||
|
||||
public void Cancel(GpuContext gpuContext)
|
||||
{
|
||||
lock (Lock)
|
||||
{
|
||||
if (_waiterInformation != null)
|
||||
{
|
||||
@ -99,8 +102,11 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||
|
||||
Event.WritableEvent.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public bool Wait(GpuContext gpuContext, NvFence fence)
|
||||
{
|
||||
lock (Lock)
|
||||
{
|
||||
Fence = fence;
|
||||
State = NvHostEventState.Waiting;
|
||||
@ -128,6 +134,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string DumpState(GpuContext gpuContext)
|
||||
{
|
||||
|
@ -26,8 +26,6 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
||||
|
||||
private Stopwatch _chrono;
|
||||
|
||||
private AndroidFence _vblankFence;
|
||||
|
||||
private long _ticks;
|
||||
private long _ticksPerFrame;
|
||||
|
||||
@ -49,7 +47,6 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
||||
{
|
||||
public Layer Layer;
|
||||
public BufferItem Item;
|
||||
public AndroidFence Fence;
|
||||
}
|
||||
|
||||
public SurfaceFlinger(Switch device)
|
||||
@ -69,13 +66,6 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
||||
|
||||
UpdateSwapInterval(1);
|
||||
|
||||
_vblankFence = AndroidFence.NoFence;
|
||||
_vblankFence.AddFence(new NvFence
|
||||
{
|
||||
Id = NvHostSyncpt.VBlank0SyncpointId,
|
||||
Value = 0
|
||||
});
|
||||
|
||||
_composerThread.Start();
|
||||
}
|
||||
|
||||
@ -222,8 +212,6 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
||||
{
|
||||
lock (Lock)
|
||||
{
|
||||
_vblankFence.NvFences[0].Increment(_device.Gpu);
|
||||
|
||||
// TODO: support multilayers (& multidisplay ?)
|
||||
if (_layers.Count == 0)
|
||||
{
|
||||
@ -298,14 +286,10 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
||||
flipX,
|
||||
flipY);
|
||||
|
||||
// Enforce that dequeueBuffer wait for the next vblank
|
||||
_vblankFence.NvFences[0].Value++;
|
||||
|
||||
TextureCallbackInformation textureCallbackInformation = new TextureCallbackInformation
|
||||
{
|
||||
Layer = layer,
|
||||
Item = item,
|
||||
Fence = _vblankFence
|
||||
};
|
||||
|
||||
_device.Gpu.Window.EnqueueFrameThreadSafe(
|
||||
@ -330,7 +314,9 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
||||
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user