forked from Mirror/Ryujinx
Ensure syncpoints are released and event handles closed on channel close (#2812)
This commit is contained in:
parent
f78bcb8048
commit
81e9b86cdb
4 changed files with 84 additions and 49 deletions
|
@ -542,6 +542,18 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel
|
||||||
{
|
{
|
||||||
_host1xContext.Host1x.DestroyContext(_contextId);
|
_host1xContext.Host1x.DestroyContext(_contextId);
|
||||||
Channel.Dispose();
|
Channel.Dispose();
|
||||||
|
|
||||||
|
for (int i = 0; i < MaxModuleSyncpoint; i++)
|
||||||
|
{
|
||||||
|
if (ChannelSyncpoints[i] != 0)
|
||||||
|
{
|
||||||
|
_device.System.HostSyncpoint.ReleaseSyncpoint(ChannelSyncpoints[i]);
|
||||||
|
ChannelSyncpoints[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_device.System.HostSyncpoint.ReleaseSyncpoint(_channelSyncpoint.Id);
|
||||||
|
_channelSyncpoint.Id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Host1xContext GetHost1XContext(GpuContext gpu, long pid)
|
private static Host1xContext GetHost1XContext(GpuContext gpu, long pid)
|
||||||
|
|
|
@ -12,11 +12,27 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel
|
||||||
private KEvent _smExceptionBptPauseReportEvent;
|
private KEvent _smExceptionBptPauseReportEvent;
|
||||||
private KEvent _errorNotifierEvent;
|
private KEvent _errorNotifierEvent;
|
||||||
|
|
||||||
|
private int _smExceptionBptIntReportEventHandle;
|
||||||
|
private int _smExceptionBptPauseReportEventHandle;
|
||||||
|
private int _errorNotifierEventHandle;
|
||||||
|
|
||||||
public NvHostGpuDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, long owner) : base(context, memory, owner)
|
public NvHostGpuDeviceFile(ServiceCtx context, IVirtualMemoryManager memory, long owner) : base(context, memory, owner)
|
||||||
{
|
{
|
||||||
_smExceptionBptIntReportEvent = new KEvent(context.Device.System.KernelContext);
|
_smExceptionBptIntReportEvent = CreateEvent(context, out _smExceptionBptIntReportEventHandle);
|
||||||
_smExceptionBptPauseReportEvent = new KEvent(context.Device.System.KernelContext);
|
_smExceptionBptPauseReportEvent = CreateEvent(context, out _smExceptionBptPauseReportEventHandle);
|
||||||
_errorNotifierEvent = new KEvent(context.Device.System.KernelContext);
|
_errorNotifierEvent = CreateEvent(context, out _errorNotifierEventHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static KEvent CreateEvent(ServiceCtx context, out int handle)
|
||||||
|
{
|
||||||
|
KEvent evnt = new KEvent(context.Device.System.KernelContext);
|
||||||
|
|
||||||
|
if (context.Process.HandleTable.GenerateHandle(evnt.ReadableEvent, out handle) != KernelResult.Success)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Out of handles!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return evnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override NvInternalResult Ioctl2(NvIoctl command, Span<byte> arguments, Span<byte> inlineInBuffer)
|
public override NvInternalResult Ioctl2(NvIoctl command, Span<byte> arguments, Span<byte> inlineInBuffer)
|
||||||
|
@ -39,41 +55,51 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel
|
||||||
public override NvInternalResult QueryEvent(out int eventHandle, uint eventId)
|
public override NvInternalResult QueryEvent(out int eventHandle, uint eventId)
|
||||||
{
|
{
|
||||||
// TODO: accurately represent and implement those events.
|
// TODO: accurately represent and implement those events.
|
||||||
KEvent targetEvent = null;
|
|
||||||
|
|
||||||
switch (eventId)
|
switch (eventId)
|
||||||
{
|
{
|
||||||
case 0x1:
|
case 0x1:
|
||||||
targetEvent = _smExceptionBptIntReportEvent;
|
eventHandle = _smExceptionBptIntReportEventHandle;
|
||||||
break;
|
break;
|
||||||
case 0x2:
|
case 0x2:
|
||||||
targetEvent = _smExceptionBptPauseReportEvent;
|
eventHandle = _smExceptionBptPauseReportEventHandle;
|
||||||
break;
|
break;
|
||||||
case 0x3:
|
case 0x3:
|
||||||
targetEvent = _errorNotifierEvent;
|
eventHandle = _errorNotifierEventHandle;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
eventHandle = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetEvent != null)
|
return eventHandle != 0 ? NvInternalResult.Success : NvInternalResult.InvalidInput;
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private NvInternalResult SubmitGpfifoEx(ref SubmitGpfifoArguments arguments, Span<ulong> inlineData)
|
private NvInternalResult SubmitGpfifoEx(ref SubmitGpfifoArguments arguments, Span<ulong> inlineData)
|
||||||
{
|
{
|
||||||
return SubmitGpfifo(ref arguments, inlineData);
|
return SubmitGpfifo(ref arguments, inlineData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Close()
|
||||||
|
{
|
||||||
|
if (_smExceptionBptIntReportEventHandle != 0)
|
||||||
|
{
|
||||||
|
Context.Process.HandleTable.CloseHandle(_smExceptionBptIntReportEventHandle);
|
||||||
|
_smExceptionBptIntReportEventHandle = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_smExceptionBptPauseReportEventHandle != 0)
|
||||||
|
{
|
||||||
|
Context.Process.HandleTable.CloseHandle(_smExceptionBptPauseReportEventHandle);
|
||||||
|
_smExceptionBptPauseReportEventHandle = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_errorNotifierEventHandle != 0)
|
||||||
|
{
|
||||||
|
Context.Process.HandleTable.CloseHandle(_errorNotifierEventHandle);
|
||||||
|
_errorNotifierEventHandle = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
base.Close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private KEvent QueryEvent(uint eventId)
|
private int QueryEvent(uint eventId)
|
||||||
{
|
{
|
||||||
lock (_events)
|
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)
|
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)
|
public override NvInternalResult QueryEvent(out int eventHandle, uint eventId)
|
||||||
{
|
{
|
||||||
KEvent targetEvent = QueryEvent(eventId);
|
eventHandle = QueryEvent(eventId);
|
||||||
|
|
||||||
if (targetEvent != null)
|
return eventHandle != 0 ? NvInternalResult.Success : NvInternalResult.InvalidInput;
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private NvInternalResult SyncptRead(ref NvFence arguments)
|
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.Cancelled ||
|
||||||
hostEvent.State == NvHostEventState.Signaled)
|
hostEvent.State == NvHostEventState.Signaled)
|
||||||
{
|
{
|
||||||
_events[userEventId].Dispose();
|
_events[userEventId].CloseEvent(Context);
|
||||||
_events[userEventId] = null;
|
_events[userEventId] = null;
|
||||||
|
|
||||||
return NvInternalResult.Success;
|
return NvInternalResult.Success;
|
||||||
|
@ -544,7 +530,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||||
} while (evnt.State != NvHostEventState.Signaled);
|
} while (evnt.State != NvHostEventState.Signaled);
|
||||||
}
|
}
|
||||||
|
|
||||||
evnt.Dispose();
|
evnt.CloseEvent(Context);
|
||||||
|
|
||||||
_events[i] = null;
|
_events[i] = null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
using Ryujinx.Common.Logging;
|
using Ryujinx.Common.Logging;
|
||||||
using Ryujinx.Graphics.Gpu;
|
using Ryujinx.Graphics.Gpu;
|
||||||
using Ryujinx.Graphics.Gpu.Synchronization;
|
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.Kernel.Threading;
|
||||||
using Ryujinx.HLE.HOS.Services.Nv.Types;
|
using Ryujinx.HLE.HOS.Services.Nv.Types;
|
||||||
using System;
|
using System;
|
||||||
|
@ -8,11 +10,12 @@ using System.Threading;
|
||||||
|
|
||||||
namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||||
{
|
{
|
||||||
class NvHostEvent : IDisposable
|
class NvHostEvent
|
||||||
{
|
{
|
||||||
public NvFence Fence;
|
public NvFence Fence;
|
||||||
public NvHostEventState State;
|
public NvHostEventState State;
|
||||||
public KEvent Event;
|
public KEvent Event;
|
||||||
|
public int EventHandle;
|
||||||
|
|
||||||
private uint _eventId;
|
private uint _eventId;
|
||||||
private NvHostSyncpt _syncpointManager;
|
private NvHostSyncpt _syncpointManager;
|
||||||
|
@ -21,7 +24,7 @@ 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();
|
public readonly object Lock = new object();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Max failing count until waiting on CPU.
|
/// Max failing count until waiting on CPU.
|
||||||
|
@ -37,6 +40,11 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||||
|
|
||||||
Event = new KEvent(system.KernelContext);
|
Event = new KEvent(system.KernelContext);
|
||||||
|
|
||||||
|
if (KernelStatic.GetCurrentProcess().HandleTable.GenerateHandle(Event.ReadableEvent, out EventHandle) != KernelResult.Success)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Out of handles!");
|
||||||
|
}
|
||||||
|
|
||||||
_eventId = eventId;
|
_eventId = eventId;
|
||||||
|
|
||||||
_syncpointManager = syncpointManager;
|
_syncpointManager = syncpointManager;
|
||||||
|
@ -165,10 +173,13 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostCtrl
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void CloseEvent(ServiceCtx context)
|
||||||
{
|
{
|
||||||
Event.ReadableEvent.DecrementReferenceCount();
|
if (EventHandle != 0)
|
||||||
Event.WritableEvent.DecrementReferenceCount();
|
{
|
||||||
|
context.Process.HandleTable.CloseHandle(EventHandle);
|
||||||
|
EventHandle = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue