mirror of
https://github.com/ryujinx-mirror/ryujinx.git
synced 2024-12-15 17:51:16 +01:00
f1d1670b0b
* Implement HLE macro for DrawElementsIndirect * Shader cache version bump * Use GL_ARB_shader_draw_parameters extension on OpenGL * Fix DrawIndexedIndirectCount on Vulkan when extension is not supported * Implement DrawIndex * Alignment * Fix some validation errors * Rename BaseIds to DrawParameters * Fix incorrect index buffer and vertex buffer size in some cases * Add HLE macros for DrawArraysInstanced and DrawElementsInstanced * Perform a regular draw when indirect data is not modified * Use non-indirect draw methods if indirect buffer was not GPU modified * Only check if draw parameters match if the shader actually uses them * Expose Macro HLE setting on GUI * Reset FirstVertex and FirstInstance after draw * Update shader cache version again since some people already tested this * PR feedback Co-authored-by: riperiperi <rhy3756547@hotmail.com>
102 lines
3.5 KiB
C#
102 lines
3.5 KiB
C#
using Ryujinx.Graphics.Device;
|
|
using Ryujinx.Graphics.Gpu.Engine.GPFifo;
|
|
using System;
|
|
|
|
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 IMacroEE _executionEngine;
|
|
private bool _executionPending;
|
|
private int _argument;
|
|
private MacroHLEFunctionName _hleFunction;
|
|
|
|
/// <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;
|
|
|
|
_executionEngine = null;
|
|
_executionPending = false;
|
|
_argument = 0;
|
|
_hleFunction = MacroHLEFunctionName.None;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the first argument for the macro call.
|
|
/// </summary>
|
|
/// <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>
|
|
/// <param name="argument">First argument</param>
|
|
public void StartExecution(GpuContext context, GPFifoProcessor processor, ReadOnlySpan<int> code, int argument)
|
|
{
|
|
_argument = argument;
|
|
|
|
_executionPending = true;
|
|
|
|
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();
|
|
}
|
|
}
|
|
|
|
// 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)
|
|
{
|
|
context.GPFifo.SetFlushSkips(2);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Starts executing the macro program code.
|
|
/// </summary>
|
|
/// <param name="code">Program code</param>
|
|
/// <param name="state">Current GPU state</param>
|
|
public void Execute(ReadOnlySpan<int> code, IDeviceState state)
|
|
{
|
|
if (_executionPending)
|
|
{
|
|
_executionPending = false;
|
|
_executionEngine?.Execute(code.Slice(Position), state, _argument);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Pushes an argument to the macro call argument FIFO.
|
|
/// </summary>
|
|
/// <param name="gpuVa">GPU virtual address where the command word is located</param>
|
|
/// <param name="argument">Argument to be pushed</param>
|
|
public void PushArgument(ulong gpuVa, int argument)
|
|
{
|
|
_executionEngine?.Fifo.Enqueue(new FifoWord(gpuVa, argument));
|
|
}
|
|
}
|
|
}
|