blob: ab5ea288c60ad35ecc3523086ad325b2024425c6 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
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;
}
}
}
|