mirror of
https://github.com/ryujinx-mirror/ryujinx.git
synced 2024-11-26 12:03:01 +00:00
1f554c1093
* Renaming part 1 * Renaming part 2 * Renaming part 3 * Renaming part 4 * Renaming part 5 * Renaming part 6 * Renaming part 7 * Renaming part 8 * Renaming part 9 * Renaming part 10 * General cleanup * Thought I got all of these * Apply #595 * Additional renaming * Tweaks from feedback * Rename files
79 lines
No EOL
2.2 KiB
C#
79 lines
No EOL
2.2 KiB
C#
using ChocolArm64.Memory;
|
|
using System.Collections.Concurrent;
|
|
|
|
namespace Ryujinx.Graphics.Memory
|
|
{
|
|
class NvGpuVmmCache
|
|
{
|
|
private const int PageBits = MemoryManager.PageBits;
|
|
|
|
private const long PageSize = MemoryManager.PageSize;
|
|
private const long PageMask = MemoryManager.PageMask;
|
|
|
|
private ConcurrentDictionary<long, int>[] _cachedPages;
|
|
|
|
private MemoryManager _memory;
|
|
|
|
public NvGpuVmmCache(MemoryManager memory)
|
|
{
|
|
_memory = memory;
|
|
|
|
_cachedPages = new ConcurrentDictionary<long, int>[1 << 20];
|
|
}
|
|
|
|
public bool IsRegionModified(long position, long size, NvGpuBufferType bufferType)
|
|
{
|
|
long va = position;
|
|
|
|
long pa = _memory.GetPhysicalAddress(va);
|
|
|
|
long endAddr = (va + size + PageMask) & ~PageMask;
|
|
|
|
long addrTruncated = va & ~PageMask;
|
|
|
|
bool modified = _memory.IsRegionModified(addrTruncated, endAddr - addrTruncated);
|
|
|
|
int newBuffMask = 1 << (int)bufferType;
|
|
|
|
long cachedPagesCount = 0;
|
|
|
|
while (va < endAddr)
|
|
{
|
|
long page = _memory.GetPhysicalAddress(va) >> PageBits;
|
|
|
|
ConcurrentDictionary<long, int> dictionary = _cachedPages[page];
|
|
|
|
if (dictionary == null)
|
|
{
|
|
dictionary = new ConcurrentDictionary<long, int>();
|
|
|
|
_cachedPages[page] = dictionary;
|
|
}
|
|
else if (modified)
|
|
{
|
|
_cachedPages[page].Clear();
|
|
}
|
|
|
|
if (dictionary.TryGetValue(pa, out int currBuffMask))
|
|
{
|
|
if ((currBuffMask & newBuffMask) != 0)
|
|
{
|
|
cachedPagesCount++;
|
|
}
|
|
else
|
|
{
|
|
dictionary[pa] |= newBuffMask;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dictionary[pa] = newBuffMask;
|
|
}
|
|
|
|
va += PageSize;
|
|
}
|
|
|
|
return cachedPagesCount != (endAddr - addrTruncated) >> PageBits;
|
|
}
|
|
}
|
|
} |