2021-07-11 16:20:40 -04:00
|
|
|
|
using Ryujinx.Graphics.Device;
|
2020-08-02 21:36:57 -04:00
|
|
|
|
using System;
|
2020-07-23 22:53:25 -04:00
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Graphics.Gpu.Engine.MME
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// GPU macro program.
|
|
|
|
|
/// </summary>
|
|
|
|
|
struct Macro
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Word offset of the code on the code memory.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int Position { get; }
|
|
|
|
|
|
|
|
|
|
private bool _executionPending;
|
|
|
|
|
private int _argument;
|
|
|
|
|
|
2020-08-02 21:36:57 -04:00
|
|
|
|
private readonly IMacroEE _executionEngine;
|
2020-07-23 22:53:25 -04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a new instance of the GPU cached macro program.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="position">Macro code start position</param>
|
|
|
|
|
public Macro(int position)
|
|
|
|
|
{
|
|
|
|
|
Position = position;
|
|
|
|
|
|
|
|
|
|
_executionPending = false;
|
|
|
|
|
_argument = 0;
|
|
|
|
|
|
2020-08-02 21:36:57 -04:00
|
|
|
|
if (GraphicsConfig.EnableMacroJit)
|
|
|
|
|
{
|
|
|
|
|
_executionEngine = new MacroJit();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_executionEngine = new MacroInterpreter();
|
|
|
|
|
}
|
2020-07-23 22:53:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the first argument for the macro call.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="argument">First argument</param>
|
|
|
|
|
public void StartExecution(int argument)
|
|
|
|
|
{
|
|
|
|
|
_argument = argument;
|
|
|
|
|
|
|
|
|
|
_executionPending = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Starts executing the macro program code.
|
|
|
|
|
/// </summary>
|
2020-08-02 21:36:57 -04:00
|
|
|
|
/// <param name="code">Program code</param>
|
2020-07-23 22:53:25 -04:00
|
|
|
|
/// <param name="state">Current GPU state</param>
|
2021-07-11 16:20:40 -04:00
|
|
|
|
public void Execute(ReadOnlySpan<int> code, IDeviceState state)
|
2020-07-23 22:53:25 -04:00
|
|
|
|
{
|
|
|
|
|
if (_executionPending)
|
|
|
|
|
{
|
|
|
|
|
_executionPending = false;
|
|
|
|
|
|
2020-08-02 21:36:57 -04:00
|
|
|
|
_executionEngine?.Execute(code.Slice(Position), state, _argument);
|
2020-07-23 22:53:25 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Pushes an argument to the macro call argument FIFO.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="argument">Argument to be pushed</param>
|
|
|
|
|
public void PushArgument(int argument)
|
|
|
|
|
{
|
2020-08-02 21:36:57 -04:00
|
|
|
|
_executionEngine?.Fifo.Enqueue(argument);
|
2020-07-23 22:53:25 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|