aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.Graphics.Gpu/Engine/MME/MacroJit.cs
blob: 0f26490a8c2e0b3db57a06fb595b4d507be7a951 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using Ryujinx.Graphics.Device;
using System;
using System.Collections.Generic;

namespace Ryujinx.Graphics.Gpu.Engine.MME
{
    /// <summary>
    /// Represents a execution engine that uses a Just-in-Time compiler for fast execution.
    /// </summary>
    class MacroJit : IMacroEE
    {
        private readonly MacroJitContext _context = new();

        /// <summary>
        /// Arguments FIFO.
        /// </summary>
        public Queue<FifoWord> Fifo => _context.Fifo;

        private MacroJitCompiler.MacroExecute _execute;

        /// <summary>
        /// Executes a macro program until it exits.
        /// </summary>
        /// <param name="code">Code of the program to execute</param>
        /// <param name="state">Current GPU state</param>
        /// <param name="arg0">Optional argument passed to the program, 0 if not used</param>
        public void Execute(ReadOnlySpan<int> code, IDeviceState state, int arg0)
        {
            if (_execute == null)
            {
                MacroJitCompiler compiler = new();

                _execute = compiler.Compile(code);
            }

            _execute(_context, state, arg0);
        }
    }
}