Separate GPU engines (part 2/2) (#2440)

* 3D engine now uses DeviceState too, plus new state modification tracking

* Remove old methods code

* Remove GpuState and friends

* Optimize DeviceState, force inline some functions

* This change was not supposed to go in

* Proper channel initialization

* Optimize state read/write methods even more

* Fix debug build

* Do not dirty state if the write is redundant

* The YControl register should dirty either the viewport or front face state too, to update the host origin

* Avoid redundant vertex buffer updates

* Move state and get rid of the Ryujinx.Graphics.Gpu.State namespace

* Comments and nits

* Fix rebase

* PR feedback

* Move changed = false to improve codegen

* PR feedback

* Carry RyuJIT a bit more
This commit is contained in:
gdkchan 2021-07-11 17:20:40 -03:00 committed by GitHub
parent b5190f1681
commit 40b21cc3c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
111 changed files with 5262 additions and 4020 deletions

View file

@ -1,4 +1,4 @@
using Ryujinx.Graphics.Gpu.State;
using Ryujinx.Graphics.Device;
using System;
using System.Collections.Generic;
@ -12,7 +12,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
/// <summary>
/// Arguments FIFO.
/// </summary>
public Queue<int> Fifo { get; }
Queue<int> Fifo { get; }
/// <summary>
/// Should execute the GPU Macro code being passed.
@ -20,6 +20,6 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
/// <param name="code">Code to be executed</param>
/// <param name="state">GPU state at the time of the call</param>
/// <param name="arg0">First argument to be passed to the GPU Macro</param>
void Execute(ReadOnlySpan<int> code, GpuState state, int arg0);
void Execute(ReadOnlySpan<int> code, IDeviceState state, int arg0);
}
}

View file

@ -1,4 +1,4 @@
using Ryujinx.Graphics.Gpu.State;
using Ryujinx.Graphics.Device;
using System;
namespace Ryujinx.Graphics.Gpu.Engine.MME
@ -55,7 +55,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
/// </summary>
/// <param name="code">Program code</param>
/// <param name="state">Current GPU state</param>
public void Execute(ReadOnlySpan<int> code, GpuState state)
public void Execute(ReadOnlySpan<int> code, IDeviceState state)
{
if (_executionPending)
{

View file

@ -1,5 +1,5 @@
using Ryujinx.Common.Logging;
using Ryujinx.Graphics.Gpu.State;
using Ryujinx.Graphics.Device;
using System;
using System.Collections.Generic;
@ -45,7 +45,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
/// <param name="code">Code of the program to execute</param>
/// <param name="state">Current GPU state</param>
/// <param name="arg0">Optional argument passed to the program, 0 if not used</param>
public void Execute(ReadOnlySpan<int> code, GpuState state, int arg0)
public void Execute(ReadOnlySpan<int> code, IDeviceState state, int arg0)
{
Reset();
@ -55,7 +55,9 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
FetchOpCode(code);
while (Step(code, state)) ;
while (Step(code, state))
{
}
// Due to the delay slot, we still need to execute
// one more instruction before we actually exit.
@ -85,7 +87,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
/// <param name="code">Program code to execute</param>
/// <param name="state">Current GPU state</param>
/// <returns>True to continue execution, false if the program exited</returns>
private bool Step(ReadOnlySpan<int> code, GpuState state)
private bool Step(ReadOnlySpan<int> code, IDeviceState state)
{
int baseAddr = _pc - 1;
@ -193,7 +195,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
/// </summary>
/// <param name="state">Current GPU state</param>
/// <returns>Operation result</returns>
private int GetAluResult(GpuState state)
private int GetAluResult(IDeviceState state)
{
AluOperation op = (AluOperation)(_opCode & 7);
@ -378,9 +380,9 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
/// <param name="state">Current GPU state</param>
/// <param name="reg">Register offset to read</param>
/// <returns>GPU register value</returns>
private int Read(GpuState state, int reg)
private int Read(IDeviceState state, int reg)
{
return state.Read(reg);
return state.Read(reg * 4);
}
/// <summary>
@ -388,11 +390,9 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
/// </summary>
/// <param name="state">Current GPU state</param>
/// <param name="value">Call argument</param>
private void Send(GpuState state, int value)
private void Send(IDeviceState state, int value)
{
MethodParams meth = new MethodParams(_methAddr, value);
state.CallMethod(meth);
state.Write(_methAddr * 4, value);
_methAddr += _methIncr;
}

View file

@ -1,4 +1,4 @@
using Ryujinx.Graphics.Gpu.State;
using Ryujinx.Graphics.Device;
using System;
using System.Collections.Generic;
@ -24,7 +24,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
/// <param name="code">Code of the program to execute</param>
/// <param name="state">Current GPU state</param>
/// <param name="arg0">Optional argument passed to the program, 0 if not used</param>
public void Execute(ReadOnlySpan<int> code, GpuState state, int arg0)
public void Execute(ReadOnlySpan<int> code, IDeviceState state, int arg0)
{
if (_execute == null)
{

View file

@ -1,4 +1,4 @@
using Ryujinx.Graphics.Gpu.State;
using Ryujinx.Graphics.Device;
using System;
using System.Collections.Generic;
using System.Reflection.Emit;
@ -22,7 +22,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
/// </summary>
public MacroJitCompiler()
{
_meth = new DynamicMethod("Macro", typeof(void), new Type[] { typeof(MacroJitContext), typeof(GpuState), typeof(int) });
_meth = new DynamicMethod("Macro", typeof(void), new Type[] { typeof(MacroJitContext), typeof(IDeviceState), typeof(int) });
_ilGen = _meth.GetILGenerator();
_gprs = new LocalBuilder[8];
@ -39,7 +39,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
_ilGen.Emit(OpCodes.Stloc, _gprs[1]);
}
public delegate void MacroExecute(MacroJitContext context, GpuState state, int arg0);
public delegate void MacroExecute(MacroJitContext context, IDeviceState state, int arg0);
/// <summary>
/// Translates a new piece of GPU Macro code into host executable code.

View file

@ -1,5 +1,5 @@
using Ryujinx.Common.Logging;
using Ryujinx.Graphics.Gpu.State;
using Ryujinx.Graphics.Device;
using System.Collections.Generic;
namespace Ryujinx.Graphics.Gpu.Engine.MME
@ -36,9 +36,9 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
/// <param name="state">Current GPU state</param>
/// <param name="reg">Register offset to read</param>
/// <returns>GPU register value</returns>
public static int Read(GpuState state, int reg)
public static int Read(IDeviceState state, int reg)
{
return state.Read(reg);
return state.Read(reg * 4);
}
/// <summary>
@ -47,11 +47,9 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME
/// <param name="value">Call argument</param>
/// <param name="state">Current GPU state</param>
/// <param name="methAddr">Address, in words, of the method</param>
public static void Send(int value, GpuState state, int methAddr)
public static void Send(int value, IDeviceState state, int methAddr)
{
MethodParams meth = new MethodParams(methAddr, value);
state.CallMethod(meth);
state.Write(methAddr * 4, value);
}
}
}