MacroJitContext.cs 1.7 KB

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