mirror of
https://github.com/ryujinx-mirror/ryujinx.git
synced 2025-09-08 20:06:27 -05:00
Ensure syncpoints are released and event handles closed on channel close (#2812)
This commit is contained in:
@@ -93,7 +93,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||
return result;
|
||||
}
|
||||
|
||||
private KEvent QueryEvent(uint eventId)
|
||||
private int QueryEvent(uint eventId)
|
||||
{
|
||||
lock (_events)
|
||||
{
|
||||
@@ -113,32 +113,18 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||
|
||||
if (eventSlot >= EventsCount || _events[eventSlot] == null || _events[eventSlot].Fence.Id != syncpointId)
|
||||
{
|
||||
return null;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return _events[eventSlot].Event;
|
||||
return _events[eventSlot].EventHandle;
|
||||
}
|
||||
}
|
||||
|
||||
public override NvInternalResult QueryEvent(out int eventHandle, uint eventId)
|
||||
{
|
||||
KEvent targetEvent = QueryEvent(eventId);
|
||||
eventHandle = QueryEvent(eventId);
|
||||
|
||||
if (targetEvent != null)
|
||||
{
|
||||
if (Context.Process.HandleTable.GenerateHandle(targetEvent.ReadableEvent, out eventHandle) != KernelResult.Success)
|
||||
{
|
||||
throw new InvalidOperationException("Out of handles!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
eventHandle = 0;
|
||||
|
||||
return NvInternalResult.InvalidInput;
|
||||
}
|
||||
|
||||
return NvInternalResult.Success;
|
||||
return eventHandle != 0 ? NvInternalResult.Success : NvInternalResult.InvalidInput;
|
||||
}
|
||||
|
||||
private NvInternalResult SyncptRead(ref NvFence arguments)
|
||||
@@ -263,7 +249,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||
hostEvent.State == NvHostEventState.Cancelled ||
|
||||
hostEvent.State == NvHostEventState.Signaled)
|
||||
{
|
||||
_events[userEventId].Dispose();
|
||||
_events[userEventId].CloseEvent(Context);
|
||||
_events[userEventId] = null;
|
||||
|
||||
return NvInternalResult.Success;
|
||||
@@ -544,7 +530,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||
} while (evnt.State != NvHostEventState.Signaled);
|
||||
}
|
||||
|
||||
evnt.Dispose();
|
||||
evnt.CloseEvent(Context);
|
||||
|
||||
_events[i] = null;
|
||||
}
|
||||
|
@@ -1,6 +1,8 @@
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Graphics.Gpu;
|
||||
using Ryujinx.Graphics.Gpu.Synchronization;
|
||||
using Ryujinx.HLE.HOS.Kernel;
|
||||
using Ryujinx.HLE.HOS.Kernel.Common;
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using Ryujinx.HLE.HOS.Services.Nv.Types;
|
||||
using System;
|
||||
@@ -8,11 +10,12 @@ using System.Threading;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||
{
|
||||
class NvHostEvent : IDisposable
|
||||
class NvHostEvent
|
||||
{
|
||||
public NvFence Fence;
|
||||
public NvHostEventState State;
|
||||
public KEvent Event;
|
||||
public int EventHandle;
|
||||
|
||||
private uint _eventId;
|
||||
private NvHostSyncpt _syncpointManager;
|
||||
@@ -21,7 +24,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||
private NvFence _previousFailingFence;
|
||||
private uint _failingCount;
|
||||
|
||||
public object Lock = new object();
|
||||
public readonly object Lock = new object();
|
||||
|
||||
/// <summary>
|
||||
/// Max failing count until waiting on CPU.
|
||||
@@ -37,6 +40,11 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||
|
||||
Event = new KEvent(system.KernelContext);
|
||||
|
||||
if (KernelStatic.GetCurrentProcess().HandleTable.GenerateHandle(Event.ReadableEvent, out EventHandle) != KernelResult.Success)
|
||||
{
|
||||
throw new InvalidOperationException("Out of handles!");
|
||||
}
|
||||
|
||||
_eventId = eventId;
|
||||
|
||||
_syncpointManager = syncpointManager;
|
||||
@@ -165,10 +173,13 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||
return res;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
public void CloseEvent(ServiceCtx context)
|
||||
{
|
||||
Event.ReadableEvent.DecrementReferenceCount();
|
||||
Event.WritableEvent.DecrementReferenceCount();
|
||||
if (EventHandle != 0)
|
||||
{
|
||||
context.Process.HandleTable.CloseHandle(EventHandle);
|
||||
EventHandle = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user