Program.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Ryujinx.Graphics.Shader;
  2. using Ryujinx.Graphics.Shader.Translation;
  3. using System;
  4. using System.IO;
  5. using System.Runtime.InteropServices;
  6. namespace Ryujinx.ShaderTools
  7. {
  8. class Program
  9. {
  10. private class GpuAccessor : IGpuAccessor
  11. {
  12. private readonly byte[] _data;
  13. public GpuAccessor(byte[] data)
  14. {
  15. _data = data;
  16. }
  17. public T MemoryRead<T>(ulong address) where T : unmanaged
  18. {
  19. return MemoryMarshal.Cast<byte, T>(new ReadOnlySpan<byte>(_data).Slice((int)address))[0];
  20. }
  21. }
  22. static void Main(string[] args)
  23. {
  24. if (args.Length == 1 || args.Length == 2)
  25. {
  26. TranslationFlags flags = TranslationFlags.DebugMode;
  27. if (args.Length == 2 && args[0] == "--compute")
  28. {
  29. flags |= TranslationFlags.Compute;
  30. }
  31. byte[] data = File.ReadAllBytes(args[^1]);
  32. string code = Translator.CreateContext(0, new GpuAccessor(data), flags).Translate(out _).Code;
  33. Console.WriteLine(code);
  34. }
  35. else
  36. {
  37. Console.WriteLine("Usage: Ryujinx.ShaderTools [--compute] shader.bin");
  38. }
  39. }
  40. }
  41. }