Macro.cs 2.1 KB

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