MacroJitContext.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using Ryujinx.Common.Logging;
  2. using Ryujinx.Graphics.Gpu.State;
  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<int> Fifo { get; } = new Queue<int>();
  15. /// <summary>
  16. /// Fetches a arguments from the arguments FIFO.
  17. /// </summary>
  18. /// <returns></returns>
  19. public int FetchParam()
  20. {
  21. if (!Fifo.TryDequeue(out int value))
  22. {
  23. Logger.Warning?.Print(LogClass.Gpu, "Macro attempted to fetch an inexistent argument.");
  24. return 0;
  25. }
  26. return value;
  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(GpuState state, int reg)
  35. {
  36. return state.Read(reg);
  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, GpuState state, int methAddr)
  45. {
  46. MethodParams meth = new MethodParams(methAddr, value);
  47. state.CallMethod(meth);
  48. }
  49. }
  50. }