aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.ShaderTools/Program.cs
blob: 39b9425cf70b6612c10d9543560ab9b5f3c1eeff (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
40
41
42
43
44
45
46
47
48
49
using Ryujinx.Graphics.Shader;
using Ryujinx.Graphics.Shader.Translation;
using System;
using System.IO;
using System.Runtime.InteropServices;

namespace Ryujinx.ShaderTools
{
    class Program
    {
        private class GpuAccessor : IGpuAccessor
        {
            private readonly byte[] _data;

            public GpuAccessor(byte[] data)
            {
                _data = data;
            }

            public T MemoryRead<T>(ulong address) where T : unmanaged
            {
                return MemoryMarshal.Cast<byte, T>(new ReadOnlySpan<byte>(_data).Slice((int)address))[0];
            }
        }

        static void Main(string[] args)
        {
            if (args.Length == 1 || args.Length == 2)
            {
                TranslationFlags flags = TranslationFlags.DebugMode;

                if (args.Length == 2 && args[0] == "--compute")
                {
                    flags |= TranslationFlags.Compute;
                }

                byte[] data = File.ReadAllBytes(args[^1]);

                string code = Translator.CreateContext(0, new GpuAccessor(data), flags).Translate(out _).Code;

                Console.WriteLine(code);
            }
            else
            {
                Console.WriteLine("Usage: Ryujinx.ShaderTools [--compute] shader.bin");
            }
        }
    }
}