2018-05-17 14:25:42 -04:00
|
|
|
|
using Ryujinx.Graphics.Gal;
|
|
|
|
|
using Ryujinx.Graphics.Gal.Shader;
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2018-06-20 12:30:18 -04:00
|
|
|
|
using System.Text;
|
2018-05-17 14:25:42 -04:00
|
|
|
|
|
2018-06-10 20:46:42 -04:00
|
|
|
|
namespace Ryujinx.ShaderTools
|
2018-05-17 14:25:42 -04:00
|
|
|
|
{
|
|
|
|
|
class Program
|
|
|
|
|
{
|
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
{
|
2018-06-20 12:30:18 -04:00
|
|
|
|
if (args.Length == 4)
|
2018-05-17 14:25:42 -04:00
|
|
|
|
{
|
|
|
|
|
GalShaderType ShaderType = GalShaderType.Vertex;
|
|
|
|
|
|
2018-06-20 12:30:18 -04:00
|
|
|
|
switch (args[1].ToLower())
|
2018-05-17 14:25:42 -04:00
|
|
|
|
{
|
|
|
|
|
case "v": ShaderType = GalShaderType.Vertex; break;
|
|
|
|
|
case "tc": ShaderType = GalShaderType.TessControl; break;
|
|
|
|
|
case "te": ShaderType = GalShaderType.TessEvaluation; break;
|
|
|
|
|
case "g": ShaderType = GalShaderType.Geometry; break;
|
|
|
|
|
case "f": ShaderType = GalShaderType.Fragment; break;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-20 12:30:18 -04:00
|
|
|
|
using (FileStream Output = new FileStream(args[3], FileMode.Create))
|
|
|
|
|
using (FileStream FS = new FileStream(args[2], FileMode.Open, FileAccess.Read))
|
2018-05-17 14:25:42 -04:00
|
|
|
|
{
|
2018-05-22 21:43:31 -04:00
|
|
|
|
Memory Mem = new Memory(FS);
|
2018-05-17 14:25:42 -04:00
|
|
|
|
|
2018-06-20 12:30:18 -04:00
|
|
|
|
switch (args[0].ToLower())
|
|
|
|
|
{
|
|
|
|
|
case "glsl":
|
|
|
|
|
{
|
|
|
|
|
GlslDecompiler GlslDecompiler = new GlslDecompiler();
|
|
|
|
|
|
|
|
|
|
GlslProgram Program = GlslDecompiler.Decompile(Mem, 0, ShaderType);
|
|
|
|
|
|
|
|
|
|
Output.Write(System.Text.Encoding.UTF8.GetBytes(Program.Code));
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case "spirv":
|
|
|
|
|
{
|
|
|
|
|
SpirvDecompiler SpirvDecompiler = new SpirvDecompiler();
|
|
|
|
|
|
|
|
|
|
SpirvProgram Program = SpirvDecompiler.Decompile(Mem, 0, ShaderType);
|
|
|
|
|
|
|
|
|
|
Output.Write(Program.Bytecode);
|
2018-05-17 14:25:42 -04:00
|
|
|
|
|
2018-06-20 12:30:18 -04:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-22 21:43:31 -04:00
|
|
|
|
}
|
2018-05-17 14:25:42 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-06-20 12:30:18 -04:00
|
|
|
|
Console.WriteLine("Usage: Ryujinx.ShaderTools [spirv|glsl] [v|tc|te|g|f] shader.bin output.bin");
|
2018-05-17 14:25:42 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|