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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
using Ryujinx.Graphics.Memory;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace Ryujinx.Graphics
{
public class NvGpuEngineP2mf : INvGpuEngine
{
public int[] Registers { get; private set; }
private NvGpu Gpu;
private Dictionary<int, NvGpuMethod> Methods;
private ReadOnlyCollection<int> DataBuffer;
public NvGpuEngineP2mf(NvGpu Gpu)
{
this.Gpu = Gpu;
Registers = new int[0x80];
Methods = new Dictionary<int, NvGpuMethod>();
void AddMethod(int Meth, int Count, int Stride, NvGpuMethod Method)
{
while (Count-- > 0)
{
Methods.Add(Meth, Method);
Meth += Stride;
}
}
AddMethod(0x6c, 1, 1, Execute);
AddMethod(0x6d, 1, 1, PushData);
}
public void CallMethod(NvGpuVmm Vmm, NvGpuPBEntry PBEntry)
{
if (Methods.TryGetValue(PBEntry.Method, out NvGpuMethod Method))
{
Method(Vmm, PBEntry);
}
else
{
WriteRegister(PBEntry);
}
}
private void Execute(NvGpuVmm Vmm, NvGpuPBEntry PBEntry)
{
//TODO: Some registers and copy modes are still not implemented.
int Control = PBEntry.Arguments[0];
long DstAddress = MakeInt64From2xInt32(NvGpuEngineP2mfReg.DstAddress);
int LineLengthIn = ReadRegister(NvGpuEngineP2mfReg.LineLengthIn);
DataBuffer = null;
Gpu.Fifo.Step();
for (int Offset = 0; Offset < LineLengthIn; Offset += 4)
{
Vmm.WriteInt32(DstAddress + Offset, DataBuffer[Offset >> 2]);
}
}
private void PushData(NvGpuVmm Vmm, NvGpuPBEntry PBEntry)
{
DataBuffer = PBEntry.Arguments;
}
private long MakeInt64From2xInt32(NvGpuEngineP2mfReg Reg)
{
return
(long)Registers[(int)Reg + 0] << 32 |
(uint)Registers[(int)Reg + 1];
}
private void WriteRegister(NvGpuPBEntry PBEntry)
{
int ArgsCount = PBEntry.Arguments.Count;
if (ArgsCount > 0)
{
Registers[PBEntry.Method] = PBEntry.Arguments[ArgsCount - 1];
}
}
private int ReadRegister(NvGpuEngineP2mfReg Reg)
{
return Registers[(int)Reg];
}
private void WriteRegister(NvGpuEngineP2mfReg Reg, int Value)
{
Registers[(int)Reg] = Value;
}
}
}
|