/ src / Ryujinx.Graphics.Gpu / Engine / MME / MacroJitContext.cs
MacroJitContext.cs
 1  using Ryujinx.Common.Logging;
 2  using Ryujinx.Graphics.Device;
 3  using System.Collections.Generic;
 4  
 5  namespace Ryujinx.Graphics.Gpu.Engine.MME
 6  {
 7      /// <summary>
 8      /// Represents a Macro Just-in-Time compiler execution context.
 9      /// </summary>
10      class MacroJitContext
11      {
12          /// <summary>
13          /// Arguments FIFO.
14          /// </summary>
15          public Queue<FifoWord> Fifo { get; } = new();
16  
17          /// <summary>
18          /// Fetches a arguments from the arguments FIFO.
19          /// </summary>
20          /// <returns>The call argument, or 0 if the FIFO is empty</returns>
21          public int FetchParam()
22          {
23              if (!Fifo.TryDequeue(out var value))
24              {
25                  Logger.Warning?.Print(LogClass.Gpu, "Macro attempted to fetch an inexistent argument.");
26  
27                  return 0;
28              }
29  
30              return value.Word;
31          }
32  
33          /// <summary>
34          /// Reads data from a GPU register.
35          /// </summary>
36          /// <param name="state">Current GPU state</param>
37          /// <param name="reg">Register offset to read</param>
38          /// <returns>GPU register value</returns>
39          public static int Read(IDeviceState state, int reg)
40          {
41              return state.Read(reg * 4);
42          }
43  
44          /// <summary>
45          /// Performs a GPU method call.
46          /// </summary>
47          /// <param name="value">Call argument</param>
48          /// <param name="state">Current GPU state</param>
49          /// <param name="methAddr">Address, in words, of the method</param>
50          public static void Send(int value, IDeviceState state, int methAddr)
51          {
52              state.Write(methAddr * 4, value);
53          }
54      }
55  }