2018-09-18 06:30:35 +02:00
|
|
|
using Ryujinx.Graphics.Memory;
|
2018-11-17 05:01:31 +01:00
|
|
|
using Ryujinx.Graphics.Texture;
|
2018-09-18 06:30:35 +02:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics
|
|
|
|
{
|
2018-11-17 05:01:31 +01:00
|
|
|
class NvGpuEngineP2mf : INvGpuEngine
|
2018-09-18 06:30:35 +02:00
|
|
|
{
|
|
|
|
public int[] Registers { get; private set; }
|
|
|
|
|
|
|
|
private NvGpu Gpu;
|
|
|
|
|
|
|
|
private Dictionary<int, NvGpuMethod> Methods;
|
|
|
|
|
2018-11-17 05:01:31 +01:00
|
|
|
private int CopyStartX;
|
|
|
|
private int CopyStartY;
|
|
|
|
|
|
|
|
private int CopyWidth;
|
|
|
|
private int CopyHeight;
|
|
|
|
private int CopyGobBlockHeight;
|
|
|
|
|
|
|
|
private long CopyAddress;
|
|
|
|
|
|
|
|
private int CopyOffset;
|
|
|
|
private int CopySize;
|
|
|
|
|
|
|
|
private bool CopyLinear;
|
|
|
|
|
|
|
|
private byte[] Buffer;
|
2018-09-18 06:30:35 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-11-17 05:01:31 +01:00
|
|
|
public void CallMethod(NvGpuVmm Vmm, GpuMethodCall MethCall)
|
2018-09-18 06:30:35 +02:00
|
|
|
{
|
2018-11-17 05:01:31 +01:00
|
|
|
if (Methods.TryGetValue(MethCall.Method, out NvGpuMethod Method))
|
2018-09-18 06:30:35 +02:00
|
|
|
{
|
2018-11-17 05:01:31 +01:00
|
|
|
Method(Vmm, MethCall);
|
2018-09-18 06:30:35 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-11-17 05:01:31 +01:00
|
|
|
WriteRegister(MethCall);
|
2018-09-18 06:30:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-17 05:01:31 +01:00
|
|
|
private void Execute(NvGpuVmm Vmm, GpuMethodCall MethCall)
|
2018-09-18 06:30:35 +02:00
|
|
|
{
|
|
|
|
//TODO: Some registers and copy modes are still not implemented.
|
2018-11-17 05:01:31 +01:00
|
|
|
int Control = MethCall.Argument;
|
2018-09-18 06:30:35 +02:00
|
|
|
|
|
|
|
long DstAddress = MakeInt64From2xInt32(NvGpuEngineP2mfReg.DstAddress);
|
|
|
|
|
2018-11-17 05:01:31 +01:00
|
|
|
int DstPitch = ReadRegister(NvGpuEngineP2mfReg.DstPitch);
|
|
|
|
int DstBlkDim = ReadRegister(NvGpuEngineP2mfReg.DstBlockDim);
|
|
|
|
|
|
|
|
int DstX = ReadRegister(NvGpuEngineP2mfReg.DstX);
|
|
|
|
int DstY = ReadRegister(NvGpuEngineP2mfReg.DstY);
|
|
|
|
|
|
|
|
int DstWidth = ReadRegister(NvGpuEngineP2mfReg.DstWidth);
|
|
|
|
int DstHeight = ReadRegister(NvGpuEngineP2mfReg.DstHeight);
|
|
|
|
|
2018-09-18 06:30:35 +02:00
|
|
|
int LineLengthIn = ReadRegister(NvGpuEngineP2mfReg.LineLengthIn);
|
2018-11-17 05:01:31 +01:00
|
|
|
int LineCount = ReadRegister(NvGpuEngineP2mfReg.LineCount);
|
2018-09-18 06:30:35 +02:00
|
|
|
|
2018-11-17 05:01:31 +01:00
|
|
|
CopyLinear = (Control & 1) != 0;
|
2018-09-18 06:30:35 +02:00
|
|
|
|
2018-11-17 05:01:31 +01:00
|
|
|
CopyGobBlockHeight = 1 << ((DstBlkDim >> 4) & 0xf);
|
2018-09-18 06:30:35 +02:00
|
|
|
|
2018-11-17 05:01:31 +01:00
|
|
|
CopyStartX = DstX;
|
|
|
|
CopyStartY = DstY;
|
|
|
|
|
|
|
|
CopyWidth = DstWidth;
|
|
|
|
CopyHeight = DstHeight;
|
|
|
|
|
|
|
|
CopyAddress = DstAddress;
|
|
|
|
|
|
|
|
CopyOffset = 0;
|
|
|
|
CopySize = LineLengthIn * LineCount;
|
|
|
|
|
|
|
|
Buffer = new byte[CopySize];
|
2018-09-18 06:30:35 +02:00
|
|
|
}
|
|
|
|
|
2018-11-17 05:01:31 +01:00
|
|
|
private void PushData(NvGpuVmm Vmm, GpuMethodCall MethCall)
|
2018-09-18 06:30:35 +02:00
|
|
|
{
|
2018-11-17 05:01:31 +01:00
|
|
|
if (Buffer == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int Shift = 0; Shift < 32 && CopyOffset < CopySize; Shift += 8, CopyOffset++)
|
|
|
|
{
|
|
|
|
Buffer[CopyOffset] = (byte)(MethCall.Argument >> Shift);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MethCall.IsLastCall)
|
|
|
|
{
|
|
|
|
if (CopyLinear)
|
|
|
|
{
|
|
|
|
Vmm.WriteBytes(CopyAddress, Buffer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BlockLinearSwizzle Swizzle = new BlockLinearSwizzle(CopyWidth, 1, CopyGobBlockHeight);
|
|
|
|
|
|
|
|
int SrcOffset = 0;
|
|
|
|
|
|
|
|
for (int Y = CopyStartY; Y < CopyHeight && SrcOffset < CopySize; Y++)
|
|
|
|
for (int X = CopyStartX; X < CopyWidth && SrcOffset < CopySize; X++)
|
|
|
|
{
|
|
|
|
int DstOffset = Swizzle.GetSwizzleOffset(X, Y);
|
|
|
|
|
|
|
|
Vmm.WriteByte(CopyAddress + DstOffset, Buffer[SrcOffset++]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Buffer = null;
|
|
|
|
}
|
2018-09-18 06:30:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private long MakeInt64From2xInt32(NvGpuEngineP2mfReg Reg)
|
|
|
|
{
|
|
|
|
return
|
|
|
|
(long)Registers[(int)Reg + 0] << 32 |
|
|
|
|
(uint)Registers[(int)Reg + 1];
|
|
|
|
}
|
|
|
|
|
2018-11-17 05:01:31 +01:00
|
|
|
private void WriteRegister(GpuMethodCall MethCall)
|
2018-09-18 06:30:35 +02:00
|
|
|
{
|
2018-11-17 05:01:31 +01:00
|
|
|
Registers[MethCall.Method] = MethCall.Argument;
|
2018-09-18 06:30:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private int ReadRegister(NvGpuEngineP2mfReg Reg)
|
|
|
|
{
|
|
|
|
return Registers[(int)Reg];
|
|
|
|
}
|
|
|
|
|
|
|
|
private void WriteRegister(NvGpuEngineP2mfReg Reg, int Value)
|
|
|
|
{
|
|
|
|
Registers[(int)Reg] = Value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|