2021-07-11 22:20:40 +02:00
|
|
|
|
using Ryujinx.Graphics.Device;
|
2021-08-26 23:50:28 +02:00
|
|
|
|
using Ryujinx.Graphics.Gpu.Engine.GPFifo;
|
2020-08-03 03:36:57 +02:00
|
|
|
|
using System;
|
2020-07-24 04:53:25 +02: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; }
|
|
|
|
|
|
2021-08-26 23:50:28 +02:00
|
|
|
|
private IMacroEE _executionEngine;
|
2020-07-24 04:53:25 +02:00
|
|
|
|
private bool _executionPending;
|
|
|
|
|
private int _argument;
|
2021-08-26 23:50:28 +02:00
|
|
|
|
private MacroHLEFunctionName _hleFunction;
|
2020-07-24 04:53:25 +02: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;
|
|
|
|
|
|
2021-08-26 23:50:28 +02:00
|
|
|
|
_executionEngine = null;
|
2020-07-24 04:53:25 +02:00
|
|
|
|
_executionPending = false;
|
|
|
|
|
_argument = 0;
|
2021-08-26 23:50:28 +02:00
|
|
|
|
_hleFunction = MacroHLEFunctionName.None;
|
2020-07-24 04:53:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the first argument for the macro call.
|
|
|
|
|
/// </summary>
|
2021-08-26 23:50:28 +02:00
|
|
|
|
/// <param name="context">GPU context where the macro code is being executed</param>
|
|
|
|
|
/// <param name="processor">GPU GP FIFO command processor</param>
|
|
|
|
|
/// <param name="code">Code to be executed</param>
|
2020-07-24 04:53:25 +02:00
|
|
|
|
/// <param name="argument">First argument</param>
|
2021-08-26 23:50:28 +02:00
|
|
|
|
public void StartExecution(GpuContext context, GPFifoProcessor processor, ReadOnlySpan<int> code, int argument)
|
2020-07-24 04:53:25 +02:00
|
|
|
|
{
|
|
|
|
|
_argument = argument;
|
|
|
|
|
|
|
|
|
|
_executionPending = true;
|
2021-08-26 23:50:28 +02:00
|
|
|
|
|
|
|
|
|
if (_executionEngine == null)
|
|
|
|
|
{
|
|
|
|
|
if (GraphicsConfig.EnableMacroHLE && MacroHLETable.TryGetMacroHLEFunction(code.Slice(Position), context.Capabilities, out _hleFunction))
|
|
|
|
|
{
|
|
|
|
|
_executionEngine = new MacroHLE(processor, _hleFunction);
|
|
|
|
|
}
|
|
|
|
|
else if (GraphicsConfig.EnableMacroJit)
|
|
|
|
|
{
|
|
|
|
|
_executionEngine = new MacroJit();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_executionEngine = new MacroInterpreter();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-16 18:53:04 +01:00
|
|
|
|
// We don't consume the parameter buffer value, so we don't need to flush it.
|
|
|
|
|
// Doing so improves performance if the value was written by a GPU shader.
|
|
|
|
|
if (_hleFunction == MacroHLEFunctionName.DrawElementsIndirect)
|
|
|
|
|
{
|
|
|
|
|
context.GPFifo.SetFlushSkips(1);
|
|
|
|
|
}
|
|
|
|
|
else if (_hleFunction == MacroHLEFunctionName.MultiDrawElementsIndirectCount)
|
2021-08-26 23:50:28 +02:00
|
|
|
|
{
|
|
|
|
|
context.GPFifo.SetFlushSkips(2);
|
|
|
|
|
}
|
2020-07-24 04:53:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Starts executing the macro program code.
|
|
|
|
|
/// </summary>
|
2020-08-03 03:36:57 +02:00
|
|
|
|
/// <param name="code">Program code</param>
|
2020-07-24 04:53:25 +02:00
|
|
|
|
/// <param name="state">Current GPU state</param>
|
2021-07-11 22:20:40 +02:00
|
|
|
|
public void Execute(ReadOnlySpan<int> code, IDeviceState state)
|
2020-07-24 04:53:25 +02:00
|
|
|
|
{
|
|
|
|
|
if (_executionPending)
|
|
|
|
|
{
|
|
|
|
|
_executionPending = false;
|
2020-08-03 03:36:57 +02:00
|
|
|
|
_executionEngine?.Execute(code.Slice(Position), state, _argument);
|
2020-07-24 04:53:25 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Pushes an argument to the macro call argument FIFO.
|
|
|
|
|
/// </summary>
|
2021-08-26 23:50:28 +02:00
|
|
|
|
/// <param name="gpuVa">GPU virtual address where the command word is located</param>
|
2020-07-24 04:53:25 +02:00
|
|
|
|
/// <param name="argument">Argument to be pushed</param>
|
2021-08-26 23:50:28 +02:00
|
|
|
|
public void PushArgument(ulong gpuVa, int argument)
|
2020-07-24 04:53:25 +02:00
|
|
|
|
{
|
2021-08-26 23:50:28 +02:00
|
|
|
|
_executionEngine?.Fifo.Enqueue(new FifoWord(gpuVa, argument));
|
2020-07-24 04:53:25 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|