From 40b21cc3c4d2622bbd4f88d43073341854d9a671 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Sun, 11 Jul 2021 17:20:40 -0300 Subject: 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 --- Ryujinx.Graphics.Gpu/Engine/MME/IMacroEE.cs | 6 +++--- Ryujinx.Graphics.Gpu/Engine/MME/Macro.cs | 4 ++-- .../Engine/MME/MacroInterpreter.cs | 22 +++++++++++----------- Ryujinx.Graphics.Gpu/Engine/MME/MacroJit.cs | 4 ++-- .../Engine/MME/MacroJitCompiler.cs | 6 +++--- Ryujinx.Graphics.Gpu/Engine/MME/MacroJitContext.cs | 12 +++++------- 6 files changed, 26 insertions(+), 28 deletions(-) (limited to 'Ryujinx.Graphics.Gpu/Engine/MME') diff --git a/Ryujinx.Graphics.Gpu/Engine/MME/IMacroEE.cs b/Ryujinx.Graphics.Gpu/Engine/MME/IMacroEE.cs index b056ecc8..b957de08 100644 --- a/Ryujinx.Graphics.Gpu/Engine/MME/IMacroEE.cs +++ b/Ryujinx.Graphics.Gpu/Engine/MME/IMacroEE.cs @@ -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 /// /// Arguments FIFO. /// - public Queue Fifo { get; } + Queue Fifo { get; } /// /// Should execute the GPU Macro code being passed. @@ -20,6 +20,6 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME /// Code to be executed /// GPU state at the time of the call /// First argument to be passed to the GPU Macro - void Execute(ReadOnlySpan code, GpuState state, int arg0); + void Execute(ReadOnlySpan code, IDeviceState state, int arg0); } } diff --git a/Ryujinx.Graphics.Gpu/Engine/MME/Macro.cs b/Ryujinx.Graphics.Gpu/Engine/MME/Macro.cs index 9847f4c0..1a79afb9 100644 --- a/Ryujinx.Graphics.Gpu/Engine/MME/Macro.cs +++ b/Ryujinx.Graphics.Gpu/Engine/MME/Macro.cs @@ -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 /// /// Program code /// Current GPU state - public void Execute(ReadOnlySpan code, GpuState state) + public void Execute(ReadOnlySpan code, IDeviceState state) { if (_executionPending) { diff --git a/Ryujinx.Graphics.Gpu/Engine/MME/MacroInterpreter.cs b/Ryujinx.Graphics.Gpu/Engine/MME/MacroInterpreter.cs index 9a834ca6..0173a7fb 100644 --- a/Ryujinx.Graphics.Gpu/Engine/MME/MacroInterpreter.cs +++ b/Ryujinx.Graphics.Gpu/Engine/MME/MacroInterpreter.cs @@ -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 /// Code of the program to execute /// Current GPU state /// Optional argument passed to the program, 0 if not used - public void Execute(ReadOnlySpan code, GpuState state, int arg0) + public void Execute(ReadOnlySpan 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 /// Program code to execute /// Current GPU state /// True to continue execution, false if the program exited - private bool Step(ReadOnlySpan code, GpuState state) + private bool Step(ReadOnlySpan code, IDeviceState state) { int baseAddr = _pc - 1; @@ -193,7 +195,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME /// /// Current GPU state /// Operation result - 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 /// Current GPU state /// Register offset to read /// GPU register value - private int Read(GpuState state, int reg) + private int Read(IDeviceState state, int reg) { - return state.Read(reg); + return state.Read(reg * 4); } /// @@ -388,11 +390,9 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME /// /// Current GPU state /// Call argument - 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; } diff --git a/Ryujinx.Graphics.Gpu/Engine/MME/MacroJit.cs b/Ryujinx.Graphics.Gpu/Engine/MME/MacroJit.cs index 346ae6cf..f0393dd1 100644 --- a/Ryujinx.Graphics.Gpu/Engine/MME/MacroJit.cs +++ b/Ryujinx.Graphics.Gpu/Engine/MME/MacroJit.cs @@ -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 /// Code of the program to execute /// Current GPU state /// Optional argument passed to the program, 0 if not used - public void Execute(ReadOnlySpan code, GpuState state, int arg0) + public void Execute(ReadOnlySpan code, IDeviceState state, int arg0) { if (_execute == null) { diff --git a/Ryujinx.Graphics.Gpu/Engine/MME/MacroJitCompiler.cs b/Ryujinx.Graphics.Gpu/Engine/MME/MacroJitCompiler.cs index e752b9dc..d281a75a 100644 --- a/Ryujinx.Graphics.Gpu/Engine/MME/MacroJitCompiler.cs +++ b/Ryujinx.Graphics.Gpu/Engine/MME/MacroJitCompiler.cs @@ -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 /// 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); /// /// Translates a new piece of GPU Macro code into host executable code. diff --git a/Ryujinx.Graphics.Gpu/Engine/MME/MacroJitContext.cs b/Ryujinx.Graphics.Gpu/Engine/MME/MacroJitContext.cs index ba426dc0..aa31c9ee 100644 --- a/Ryujinx.Graphics.Gpu/Engine/MME/MacroJitContext.cs +++ b/Ryujinx.Graphics.Gpu/Engine/MME/MacroJitContext.cs @@ -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 /// Current GPU state /// Register offset to read /// GPU register value - 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); } /// @@ -47,11 +47,9 @@ namespace Ryujinx.Graphics.Gpu.Engine.MME /// Call argument /// Current GPU state /// Address, in words, of the method - 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); } } } -- cgit v1.2.3