2018-09-08 17:51:50 +00:00
|
|
|
using Ryujinx.Graphics.Memory;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2018-12-03 02:38:47 +00:00
|
|
|
namespace Ryujinx.Graphics.Graphics3d
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2018-11-17 04:01:31 +00:00
|
|
|
class NvGpuFifo
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
|
|
|
private const int MacrosCount = 0x80;
|
|
|
|
private const int MacroIndexMask = MacrosCount - 1;
|
|
|
|
|
2019-07-02 02:39:22 +00:00
|
|
|
// Note: The size of the macro memory is unknown, we just make
|
|
|
|
// a guess here and use 256kb as the size. Increase if needed.
|
2018-06-18 04:32:11 +00:00
|
|
|
private const int MmeWords = 256 * 256;
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
private NvGpu _gpu;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
private NvGpuEngine[] _subChannels;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
|
|
|
private struct CachedMacro
|
|
|
|
{
|
2018-06-18 04:32:11 +00:00
|
|
|
public int Position { get; private set; }
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
private bool _executionPending;
|
|
|
|
private int _argument;
|
2018-11-17 04:01:31 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
private MacroInterpreter _interpreter;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
public CachedMacro(NvGpuFifo pFifo, INvGpuEngine engine, int position)
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
Position = position;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
_executionPending = false;
|
|
|
|
_argument = 0;
|
2018-11-17 04:01:31 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
_interpreter = new MacroInterpreter(pFifo, engine);
|
2018-04-08 19:17:35 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
public void StartExecution(int argument)
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
_argument = argument;
|
2018-11-17 04:01:31 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
_executionPending = true;
|
2018-11-17 04:01:31 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
public void Execute(NvGpuVmm vmm, int[] mme)
|
2018-11-17 04:01:31 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
if (_executionPending)
|
2018-11-17 04:01:31 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
_executionPending = false;
|
2018-11-17 04:01:31 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
_interpreter?.Execute(vmm, mme, Position, _argument);
|
2018-11-17 04:01:31 +00:00
|
|
|
}
|
2018-04-08 19:17:35 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
public void PushArgument(int argument)
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
_interpreter?.Fifo.Enqueue(argument);
|
2018-04-08 19:17:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
private int _currMacroPosition;
|
|
|
|
private int _currMacroBindIndex;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
private CachedMacro[] _macros;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
private int[] _mme;
|
2018-06-18 04:32:11 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
public NvGpuFifo(NvGpu gpu)
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
_gpu = gpu;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
_subChannels = new NvGpuEngine[8];
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
_macros = new CachedMacro[MacrosCount];
|
2018-06-18 04:32:11 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
_mme = new int[MmeWords];
|
2018-04-08 19:17:35 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
public void CallMethod(NvGpuVmm vmm, GpuMethodCall methCall)
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
if ((NvGpuFifoMeth)methCall.Method == NvGpuFifoMeth.BindChannel)
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
NvGpuEngine engine = (NvGpuEngine)methCall.Argument;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
_subChannels[methCall.SubChannel] = engine;
|
2018-09-18 04:30:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
switch (_subChannels[methCall.SubChannel])
|
2018-09-18 04:30:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
case NvGpuEngine._2d: Call2dMethod (vmm, methCall); break;
|
|
|
|
case NvGpuEngine._3d: Call3dMethod (vmm, methCall); break;
|
|
|
|
case NvGpuEngine.P2mf: CallP2mfMethod(vmm, methCall); break;
|
|
|
|
case NvGpuEngine.M2mf: CallM2mfMethod(vmm, methCall); break;
|
2018-09-18 04:30:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
private void Call2dMethod(NvGpuVmm vmm, GpuMethodCall methCall)
|
2018-09-18 04:30:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
_gpu.Engine2d.CallMethod(vmm, methCall);
|
2018-09-18 04:30:35 +00:00
|
|
|
}
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
private void Call3dMethod(NvGpuVmm vmm, GpuMethodCall methCall)
|
2018-09-18 04:30:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
if (methCall.Method < 0x80)
|
2018-09-18 04:30:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
switch ((NvGpuFifoMeth)methCall.Method)
|
2018-09-18 04:30:35 +00:00
|
|
|
{
|
2018-04-08 19:17:35 +00:00
|
|
|
case NvGpuFifoMeth.SetMacroUploadAddress:
|
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
_currMacroPosition = methCall.Argument;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NvGpuFifoMeth.SendMacroCodeData:
|
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
_mme[_currMacroPosition++] = methCall.Argument;
|
2018-11-17 04:01:31 +00:00
|
|
|
|
2018-04-08 19:17:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NvGpuFifoMeth.SetMacroBindingIndex:
|
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
_currMacroBindIndex = methCall.Argument;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NvGpuFifoMeth.BindMacro:
|
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
int position = methCall.Argument;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-05-30 00:40:00 +00:00
|
|
|
_macros[_currMacroBindIndex++] = new CachedMacro(this, _gpu.Engine3d, position);
|
2018-04-08 19:17:35 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2018-11-17 04:01:31 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
default: CallP2mfMethod(vmm, methCall); break;
|
2018-04-08 19:17:35 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-04 01:45:25 +00:00
|
|
|
else if (methCall.Method < 0xe00)
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
_gpu.Engine3d.CallMethod(vmm, methCall);
|
2018-04-08 19:17:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
int macroIndex = (methCall.Method >> 1) & MacroIndexMask;
|
2018-04-08 19:17:35 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if ((methCall.Method & 1) != 0)
|
2018-04-08 19:17:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
_macros[macroIndex].PushArgument(methCall.Argument);
|
2018-04-08 19:17:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
_macros[macroIndex].StartExecution(methCall.Argument);
|
2018-11-17 04:01:31 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
if (methCall.IsLastCall)
|
2018-11-17 04:01:31 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
_macros[macroIndex].Execute(vmm, _mme);
|
2018-04-08 19:17:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-06-13 13:55:01 +00:00
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
private void CallP2mfMethod(NvGpuVmm vmm, GpuMethodCall methCall)
|
2018-09-18 04:30:35 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
_gpu.EngineP2mf.CallMethod(vmm, methCall);
|
2018-09-18 04:30:35 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 01:45:25 +00:00
|
|
|
private void CallM2mfMethod(NvGpuVmm vmm, GpuMethodCall methCall)
|
2018-06-13 13:55:01 +00:00
|
|
|
{
|
2019-03-04 01:45:25 +00:00
|
|
|
_gpu.EngineM2mf.CallMethod(vmm, methCall);
|
2018-06-13 13:55:01 +00:00
|
|
|
}
|
2018-04-08 19:17:35 +00:00
|
|
|
}
|
|
|
|
}
|