From f7bcc884e46805f4dcda4fc7d7e7bccb2a3ac316 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Tue, 31 Dec 2019 17:08:20 -0300 Subject: Add XML documentation to Ryujinx.Graphics.Gpu --- Ryujinx.Graphics.Gpu/MacroInterpreter.cs | 92 ++++++++++++++++++++++++++++---- 1 file changed, 81 insertions(+), 11 deletions(-) (limited to 'Ryujinx.Graphics.Gpu/MacroInterpreter.cs') diff --git a/Ryujinx.Graphics.Gpu/MacroInterpreter.cs b/Ryujinx.Graphics.Gpu/MacroInterpreter.cs index e424b8ff..cfc3815b 100644 --- a/Ryujinx.Graphics.Gpu/MacroInterpreter.cs +++ b/Ryujinx.Graphics.Gpu/MacroInterpreter.cs @@ -5,6 +5,9 @@ using System.Collections.Generic; namespace Ryujinx.Graphics.Gpu { + /// + /// Macro code interpreter. + /// class MacroInterpreter { private enum AssignmentOperation @@ -42,10 +45,6 @@ namespace Ryujinx.Graphics.Gpu BitwiseNotAnd = 12 } - private GpuContext _context; - - private NvGpuFifo _pFifo; - public Queue Fifo { get; private set; } private int[] _gprs; @@ -61,16 +60,23 @@ namespace Ryujinx.Graphics.Gpu private int _pc; - public MacroInterpreter(GpuContext context, NvGpuFifo pFifo) + /// + /// Creates a new instance of the macro code interpreter. + /// + public MacroInterpreter() { - _context = context; - _pFifo = pFifo; - Fifo = new Queue(); _gprs = new int[8]; } + /// + /// Executes a macro program until it exits. + /// + /// Code of the program to execute + /// Start position to execute + /// Optional argument passed to the program, 0 if not used + /// Current GPU state public void Execute(int[] mme, int position, int param, GpuState state) { Reset(); @@ -88,6 +94,10 @@ namespace Ryujinx.Graphics.Gpu Step(mme, state); } + /// + /// Resets the internal interpreter state. + /// Call each time you run a new program. + /// private void Reset() { for (int index = 0; index < _gprs.Length; index++) @@ -101,6 +111,12 @@ namespace Ryujinx.Graphics.Gpu _carry = false; } + /// + /// Executes a single instruction of the program. + /// + /// Program code to execute + /// Current GPU state + /// True to continue execution, false if the program exited private bool Step(int[] mme, GpuState state) { int baseAddr = _pc - 1; @@ -226,12 +242,21 @@ namespace Ryujinx.Graphics.Gpu return !exit; } + /// + /// Fetches a single operation code from the program code. + /// + /// Program code private void FetchOpCode(int[] mme) { _opCode = _pipeOp; _pipeOp = mme[_pc++]; } + /// + /// Gets the result of the current Arithmetic and Logic unit operation. + /// + /// Current GPU state + /// Operation result private int GetAluResult(GpuState state) { AluOperation op = (AluOperation)(_opCode & 7); @@ -303,6 +328,13 @@ namespace Ryujinx.Graphics.Gpu throw new ArgumentException(nameof(_opCode)); } + /// + /// Gets the result of a Arithmetic and Logic operation using registers. + /// + /// Arithmetic and Logic unit operation with registers + /// First operand value + /// Second operand value + /// Operation result private int GetAluResult(AluRegOperation aluOp, int a, int b) { switch (aluOp) @@ -353,43 +385,70 @@ namespace Ryujinx.Graphics.Gpu throw new ArgumentOutOfRangeException(nameof(aluOp)); } + /// + /// Extracts a 32-bits signed integer constant from the current operation code. + /// + /// private int GetImm() { // Note: The immediate is signed, the sign-extension is intended here. return _opCode >> 14; } + /// + /// Sets the current method address, for method calls. + /// + /// Packed address and increment value private void SetMethAddr(int value) { _methAddr = (value >> 0) & 0xfff; _methIncr = (value >> 12) & 0x3f; } + /// + /// Sets the destination register value. + /// + /// Value to set (usually the operation result) private void SetDstGpr(int value) { _gprs[(_opCode >> 8) & 7] = value; } + /// + /// Gets first operand value from the respective register. + /// + /// Operand value private int GetGprA() { return GetGprValue((_opCode >> 11) & 7); } + /// + /// Gets second operand value from the respective register. + /// + /// Operand value private int GetGprB() { return GetGprValue((_opCode >> 14) & 7); } + /// + /// Gets the value from a register, or 0 if the R0 register is specified. + /// + /// Index of the register + /// Register value private int GetGprValue(int index) { return index != 0 ? _gprs[index] : 0; } + /// + /// Fetches a call argument from the call argument FIFO. + /// + /// The call argument, or 0 if the FIFO is empty private int FetchParam() { - int value; - - if (!Fifo.TryDequeue(out value)) + if (!Fifo.TryDequeue(out int value)) { Logger.PrintWarning(LogClass.Gpu, "Macro attempted to fetch an inexistent argument."); @@ -399,11 +458,22 @@ namespace Ryujinx.Graphics.Gpu return value; } + /// + /// Reads data from a GPU register. + /// + /// Current GPU state + /// Register offset to read + /// GPU register value private int Read(GpuState state, int reg) { return state.Read(reg); } + /// + /// Performs a GPU method call. + /// + /// Current GPU state + /// Call argument private void Send(GpuState state, int value) { MethodParams meth = new MethodParams(_methAddr, value); -- cgit v1.2.3