Skip some checks for regions where just one resource is resident
This commit is contained in:
parent
9303a7e9ae
commit
f7b8c5dc57
2 changed files with 76 additions and 8 deletions
|
@ -160,23 +160,23 @@ namespace ChocolArm64.Memory
|
||||||
return HostPageSize;
|
return HostPageSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool[] IsRegionModified(long Position, long Size)
|
public (bool[], long) IsRegionModified(long Position, long Size)
|
||||||
{
|
{
|
||||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
{
|
{
|
||||||
return null;
|
return (null, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
long EndPos = Position + Size;
|
long EndPos = Position + Size;
|
||||||
|
|
||||||
if ((ulong)EndPos < (ulong)Position)
|
if ((ulong)EndPos < (ulong)Position)
|
||||||
{
|
{
|
||||||
return null;
|
return (null, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ulong)EndPos > AMemoryMgr.RamSize)
|
if ((ulong)EndPos > AMemoryMgr.RamSize)
|
||||||
{
|
{
|
||||||
return null;
|
return (null, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
IntPtr MemAddress = new IntPtr(RamPtr + Position);
|
IntPtr MemAddress = new IntPtr(RamPtr + Position);
|
||||||
|
@ -201,7 +201,7 @@ namespace ChocolArm64.Memory
|
||||||
Modified[(VA - Position) / HostPageSize] = true;
|
Modified[(VA - Position) / HostPageSize] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Modified;
|
return (Modified, Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IntPtr GetHostAddress(long Position, long Size)
|
public IntPtr GetHostAddress(long Position, long Size)
|
||||||
|
|
|
@ -25,6 +25,8 @@ namespace Ryujinx.HLE.Gpu.Memory
|
||||||
|
|
||||||
private List<Range>[] Regions;
|
private List<Range>[] Regions;
|
||||||
|
|
||||||
|
private HashSet<long> ResidencyKeys;
|
||||||
|
|
||||||
public LinkedListNode<long> Node { get; set; }
|
public LinkedListNode<long> Node { get; set; }
|
||||||
|
|
||||||
public int Timestamp { get; private set; }
|
public int Timestamp { get; private set; }
|
||||||
|
@ -37,6 +39,27 @@ namespace Ryujinx.HLE.Gpu.Memory
|
||||||
{
|
{
|
||||||
Regions[Index] = new List<Range>();
|
Regions[Index] = new List<Range>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ResidencyKeys = new HashSet<long>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddResidency(long Key)
|
||||||
|
{
|
||||||
|
ResidencyKeys.Add(Key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveResidency(HashSet<long>[] Residency, long PageSize)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < (int)NvGpuBufferType.Count; i++)
|
||||||
|
{
|
||||||
|
foreach (Range Region in Regions[i])
|
||||||
|
{
|
||||||
|
foreach (long Key in ResidencyKeys)
|
||||||
|
{
|
||||||
|
Residency[Region.Start / PageSize].Remove(Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AddRange(long Start, long End, NvGpuBufferType BufferType)
|
public bool AddRange(long Start, long End, NvGpuBufferType BufferType)
|
||||||
|
@ -89,6 +112,10 @@ namespace Ryujinx.HLE.Gpu.Memory
|
||||||
|
|
||||||
private LinkedList<long> SortedCache;
|
private LinkedList<long> SortedCache;
|
||||||
|
|
||||||
|
private HashSet<long>[] Residency;
|
||||||
|
|
||||||
|
private const int PageSize = AMemoryMgr.PageSize;
|
||||||
|
|
||||||
private int CpCount;
|
private int CpCount;
|
||||||
|
|
||||||
public NvGpuVmmCache()
|
public NvGpuVmmCache()
|
||||||
|
@ -96,11 +123,18 @@ namespace Ryujinx.HLE.Gpu.Memory
|
||||||
Cache = new Dictionary<long, CachedPage>();
|
Cache = new Dictionary<long, CachedPage>();
|
||||||
|
|
||||||
SortedCache = new LinkedList<long>();
|
SortedCache = new LinkedList<long>();
|
||||||
|
|
||||||
|
Residency = new HashSet<long>[AMemoryMgr.RamSize / PageSize];
|
||||||
|
|
||||||
|
for (int i = 0; i < Residency.Length; i++)
|
||||||
|
{
|
||||||
|
Residency[i] = new HashSet<long>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsRegionModified(AMemory Memory, NvGpuBufferType BufferType, long PA, long Size)
|
public bool IsRegionModified(AMemory Memory, NvGpuBufferType BufferType, long PA, long Size)
|
||||||
{
|
{
|
||||||
bool[] Modified = Memory.IsRegionModified(PA, Size);
|
(bool[] Modified, long ModifiedCount) = Memory.IsRegionModified(PA, Size);
|
||||||
|
|
||||||
if (Modified == null)
|
if (Modified == null)
|
||||||
{
|
{
|
||||||
|
@ -109,10 +143,17 @@ namespace Ryujinx.HLE.Gpu.Memory
|
||||||
|
|
||||||
ClearCachedPagesIfNeeded();
|
ClearCachedPagesIfNeeded();
|
||||||
|
|
||||||
long PageSize = Memory.GetHostPageSize();
|
bool HasResidents = AddResidency(PA, Size);
|
||||||
|
|
||||||
|
if (!HasResidents && ModifiedCount == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
long Mask = PageSize - 1;
|
long Mask = PageSize - 1;
|
||||||
|
|
||||||
|
long ResidencyKey = PA;
|
||||||
|
|
||||||
long PAEnd = PA + Size;
|
long PAEnd = PA + Size;
|
||||||
|
|
||||||
bool RegMod = false;
|
bool RegMod = false;
|
||||||
|
@ -147,6 +188,8 @@ namespace Ryujinx.HLE.Gpu.Memory
|
||||||
Cache[Key] = Cp;
|
Cache[Key] = Cp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Cp.AddResidency(ResidencyKey);
|
||||||
|
|
||||||
Cp.Node = SortedCache.AddLast(Key);
|
Cp.Node = SortedCache.AddLast(Key);
|
||||||
|
|
||||||
RegMod |= Cp.AddRange(PA, PAPgEnd, BufferType);
|
RegMod |= Cp.AddRange(PA, PAPgEnd, BufferType);
|
||||||
|
@ -159,6 +202,29 @@ namespace Ryujinx.HLE.Gpu.Memory
|
||||||
return RegMod;
|
return RegMod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool AddResidency(long PA, long Size)
|
||||||
|
{
|
||||||
|
long Mask = PageSize - 1;
|
||||||
|
|
||||||
|
long Key = PA;
|
||||||
|
|
||||||
|
bool ResidentFound = false;
|
||||||
|
|
||||||
|
for (long Cursor = PA & ~Mask; Cursor < ((PA + Size + PageSize - 1) & ~Mask); Cursor += PageSize)
|
||||||
|
{
|
||||||
|
long PageIndex = Cursor / PageSize;
|
||||||
|
|
||||||
|
Residency[PageIndex].Add(Key);
|
||||||
|
|
||||||
|
if (Residency[PageIndex].Count > 1)
|
||||||
|
{
|
||||||
|
ResidentFound = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResidentFound;
|
||||||
|
}
|
||||||
|
|
||||||
private void ClearCachedPagesIfNeeded()
|
private void ClearCachedPagesIfNeeded()
|
||||||
{
|
{
|
||||||
if (CpCount <= MaxCpCount)
|
if (CpCount <= MaxCpCount)
|
||||||
|
@ -179,6 +245,8 @@ namespace Ryujinx.HLE.Gpu.Memory
|
||||||
|
|
||||||
CachedPage Cp = Cache[Key];
|
CachedPage Cp = Cache[Key];
|
||||||
|
|
||||||
|
Cp.RemoveResidency(Residency, PageSize);
|
||||||
|
|
||||||
Cache.Remove(Key);
|
Cache.Remove(Key);
|
||||||
|
|
||||||
CpCount -= Cp.GetTotalCount();
|
CpCount -= Cp.GetTotalCount();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue