Macro.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using Ryujinx.Graphics.Gpu.State;
  2. namespace Ryujinx.Graphics.Gpu.Engine.MME
  3. {
  4. /// <summary>
  5. /// GPU macro program.
  6. /// </summary>
  7. struct Macro
  8. {
  9. /// <summary>
  10. /// Word offset of the code on the code memory.
  11. /// </summary>
  12. public int Position { get; }
  13. private bool _executionPending;
  14. private int _argument;
  15. private readonly MacroInterpreter _interpreter;
  16. /// <summary>
  17. /// Creates a new instance of the GPU cached macro program.
  18. /// </summary>
  19. /// <param name="position">Macro code start position</param>
  20. public Macro(int position)
  21. {
  22. Position = position;
  23. _executionPending = false;
  24. _argument = 0;
  25. _interpreter = new MacroInterpreter();
  26. }
  27. /// <summary>
  28. /// Sets the first argument for the macro call.
  29. /// </summary>
  30. /// <param name="argument">First argument</param>
  31. public void StartExecution(int argument)
  32. {
  33. _argument = argument;
  34. _executionPending = true;
  35. }
  36. /// <summary>
  37. /// Starts executing the macro program code.
  38. /// </summary>
  39. /// <param name="mme">Program code</param>
  40. /// <param name="state">Current GPU state</param>
  41. public void Execute(int[] mme, ShadowRamControl shadowCtrl, GpuState state)
  42. {
  43. if (_executionPending)
  44. {
  45. _executionPending = false;
  46. _interpreter?.Execute(mme, Position, _argument, shadowCtrl, state);
  47. }
  48. }
  49. /// <summary>
  50. /// Pushes an argument to the macro call argument FIFO.
  51. /// </summary>
  52. /// <param name="argument">Argument to be pushed</param>
  53. public void PushArgument(int argument)
  54. {
  55. _interpreter?.Fifo.Enqueue(argument);
  56. }
  57. }
  58. }