EventWait should not signal the event when it returns Success (#2739)
* Fix race when EventWait is called and a wait is done on the CPU * This is useless now * Fix EventSignal * Ensure the signal belongs to the current fence, to avoid stale signals
This commit is contained in:
parent
63f1663fa9
commit
0d174cbd45
7 changed files with 35 additions and 35 deletions
|
@ -314,24 +314,11 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
|||
return NvInternalResult.InvalidInput;
|
||||
}
|
||||
|
||||
lock (hostEvent.Lock)
|
||||
{
|
||||
hostEvent.Cancel(_device.Gpu);
|
||||
|
||||
NvHostEventState oldState = hostEvent.State;
|
||||
_device.System.HostSyncpoint.UpdateMin(hostEvent.Fence.Id);
|
||||
|
||||
if (oldState == NvHostEventState.Waiting)
|
||||
{
|
||||
hostEvent.State = NvHostEventState.Cancelling;
|
||||
|
||||
hostEvent.Cancel(_device.Gpu);
|
||||
}
|
||||
|
||||
hostEvent.State = NvHostEventState.Cancelled;
|
||||
|
||||
_device.System.HostSyncpoint.UpdateMin(hostEvent.Fence.Id);
|
||||
|
||||
return NvInternalResult.Success;
|
||||
}
|
||||
return NvInternalResult.Success;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -486,7 +473,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
|||
if (Event != null)
|
||||
{
|
||||
if (Event.State == NvHostEventState.Available ||
|
||||
Event.State == NvHostEventState.Signaled ||
|
||||
Event.State == NvHostEventState.Signaled ||
|
||||
Event.State == NvHostEventState.Cancelled)
|
||||
{
|
||||
eventIndex = index;
|
||||
|
|
|
@ -68,10 +68,17 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
|||
}
|
||||
}
|
||||
|
||||
private void GpuSignaled()
|
||||
private void GpuSignaled(SyncpointWaiterHandle waiterInformation)
|
||||
{
|
||||
lock (Lock)
|
||||
{
|
||||
// If the signal does not match our current waiter,
|
||||
// then it is from a past fence and we should just ignore it.
|
||||
if (waiterInformation != null && waiterInformation != _waiterInformation)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ResetFailingState();
|
||||
|
||||
Signal();
|
||||
|
@ -82,9 +89,14 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
|||
{
|
||||
lock (Lock)
|
||||
{
|
||||
if (_waiterInformation != null)
|
||||
NvHostEventState oldState = State;
|
||||
|
||||
State = NvHostEventState.Cancelling;
|
||||
|
||||
if (oldState == NvHostEventState.Waiting && _waiterInformation != null)
|
||||
{
|
||||
gpuContext.Synchronization.UnregisterCallback(Fence.Id, _waiterInformation);
|
||||
_waiterInformation = null;
|
||||
|
||||
if (_previousFailingFence.Id == Fence.Id && _previousFailingFence.Value == Fence.Value)
|
||||
{
|
||||
|
@ -96,10 +108,10 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
|||
|
||||
_previousFailingFence = Fence;
|
||||
}
|
||||
|
||||
Signal();
|
||||
}
|
||||
|
||||
State = NvHostEventState.Cancelled;
|
||||
|
||||
Event.WritableEvent.Clear();
|
||||
}
|
||||
}
|
||||
|
@ -108,9 +120,6 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
|||
{
|
||||
lock (Lock)
|
||||
{
|
||||
Fence = fence;
|
||||
State = NvHostEventState.Waiting;
|
||||
|
||||
// NOTE: nvservices code should always wait on the GPU side.
|
||||
// If we do this, we may get an abort or undefined behaviour when the GPU processing thread is blocked for a long period (for example, during shader compilation).
|
||||
// The reason for this is that the NVN code will try to wait until giving up.
|
||||
|
@ -123,12 +132,15 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
|||
|
||||
bool timedOut = Fence.Wait(gpuContext, Timeout.InfiniteTimeSpan);
|
||||
|
||||
GpuSignaled();
|
||||
ResetFailingState();
|
||||
|
||||
return timedOut;
|
||||
}
|
||||
else
|
||||
{
|
||||
Fence = fence;
|
||||
State = NvHostEventState.Waiting;
|
||||
|
||||
_waiterInformation = gpuContext.Synchronization.RegisterCallbackOnSyncpoint(Fence.Id, Fence.Value, GpuSignaled);
|
||||
|
||||
return true;
|
||||
|
|
|
@ -392,7 +392,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
|||
}
|
||||
else
|
||||
{
|
||||
item.Fence.RegisterCallback(_device.Gpu, () =>
|
||||
item.Fence.RegisterCallback(_device.Gpu, (x) =>
|
||||
{
|
||||
_device.Gpu.Window.SignalFrameReady();
|
||||
_device.Gpu.GPFifo.Interrupt();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Graphics.Gpu;
|
||||
using Ryujinx.Graphics.Gpu.Synchronization;
|
||||
using Ryujinx.HLE.HOS.Services.Nv.Types;
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
@ -66,7 +67,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
|||
return false;
|
||||
}
|
||||
|
||||
public void RegisterCallback(GpuContext gpuContext, Action callback)
|
||||
public void RegisterCallback(GpuContext gpuContext, Action<SyncpointWaiterHandle> callback)
|
||||
{
|
||||
ref NvFence fence = ref NvFences[FenceCount - 1];
|
||||
|
||||
|
@ -76,7 +77,7 @@ namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
|||
}
|
||||
else
|
||||
{
|
||||
callback();
|
||||
callback(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue