mirror of
https://git.743378673.xyz/MeloNX/MeloNX.git
synced 2025-08-02 07:27:10 +02:00
NvServices refactoring (#120)
* Initial implementation of NvMap/NvHostCtrl * More work on NvHostCtrl * Refactoring of nvservices, move GPU Vmm, make Vmm per-process, refactor most gpu devices, move Gpu to Core, fix CbBind * Implement GetGpuTime, support CancelSynchronization, fix issue on InsertWaitingMutex, proper double buffering support (again, not working properly for commercial games, only hb) * Try to fix perf regression reading/writing textures, moved syncpts and events to a UserCtx class, delete global state when the process exits, other minor tweaks * Remove now unused code, add comment about probably wrong result codes
This commit is contained in:
parent
4419e8d6b4
commit
34037701c7
75 changed files with 2472 additions and 1440 deletions
107
Ryujinx.Core/OsHle/Services/Nv/NvHostCtrl/NvHostSyncPt.cs
Normal file
107
Ryujinx.Core/OsHle/Services/Nv/NvHostCtrl/NvHostSyncPt.cs
Normal file
|
@ -0,0 +1,107 @@
|
|||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
||||
namespace Ryujinx.Core.OsHle.Services.Nv.NvHostCtrl
|
||||
{
|
||||
class NvHostSyncpt
|
||||
{
|
||||
public const int SyncptsCount = 192;
|
||||
|
||||
private int[] CounterMin;
|
||||
private int[] CounterMax;
|
||||
|
||||
private long EventMask;
|
||||
|
||||
private ConcurrentDictionary<EventWaitHandle, int> Waiters;
|
||||
|
||||
public NvHostSyncpt()
|
||||
{
|
||||
CounterMin = new int[SyncptsCount];
|
||||
CounterMax = new int[SyncptsCount];
|
||||
|
||||
Waiters = new ConcurrentDictionary<EventWaitHandle, int>();
|
||||
}
|
||||
|
||||
public int GetMin(int Id)
|
||||
{
|
||||
return CounterMin[Id];
|
||||
}
|
||||
|
||||
public int GetMax(int Id)
|
||||
{
|
||||
return CounterMax[Id];
|
||||
}
|
||||
|
||||
public int Increment(int Id)
|
||||
{
|
||||
if (((EventMask >> Id) & 1) != 0)
|
||||
{
|
||||
Interlocked.Increment(ref CounterMax[Id]);
|
||||
}
|
||||
|
||||
return IncrementMin(Id);
|
||||
}
|
||||
|
||||
public int IncrementMin(int Id)
|
||||
{
|
||||
int Value = Interlocked.Increment(ref CounterMin[Id]);
|
||||
|
||||
WakeUpWaiters(Id, Value);
|
||||
|
||||
return Value;
|
||||
}
|
||||
|
||||
public int IncrementMax(int Id)
|
||||
{
|
||||
return Interlocked.Increment(ref CounterMax[Id]);
|
||||
}
|
||||
|
||||
public void AddWaiter(int Threshold, EventWaitHandle WaitEvent)
|
||||
{
|
||||
if (!Waiters.TryAdd(WaitEvent, Threshold))
|
||||
{
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
public bool RemoveWaiter(EventWaitHandle WaitEvent)
|
||||
{
|
||||
return Waiters.TryRemove(WaitEvent, out _);
|
||||
}
|
||||
|
||||
private void WakeUpWaiters(int Id, int NewValue)
|
||||
{
|
||||
foreach (KeyValuePair<EventWaitHandle, int> KV in Waiters)
|
||||
{
|
||||
if (MinCompare(Id, NewValue, CounterMax[Id], KV.Value))
|
||||
{
|
||||
KV.Key.Set();
|
||||
|
||||
Waiters.TryRemove(KV.Key, out _);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool MinCompare(int Id, int Threshold)
|
||||
{
|
||||
return MinCompare(Id, CounterMin[Id], CounterMax[Id], Threshold);
|
||||
}
|
||||
|
||||
private bool MinCompare(int Id, int Min, int Max, int Threshold)
|
||||
{
|
||||
int MinDiff = Min - Threshold;
|
||||
int MaxDiff = Max - Threshold;
|
||||
|
||||
if (((EventMask >> Id) & 1) != 0)
|
||||
{
|
||||
return MinDiff >= 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (uint)MaxDiff >= (uint)MinDiff;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue