2018-05-17 18:25:42 +00:00
|
|
|
|
using Ryujinx.Graphics.Gal;
|
|
|
|
|
using Ryujinx.Graphics.Gal.Shader;
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2018-06-20 16:30:18 +00:00
|
|
|
|
using System.Text;
|
2018-05-17 18:25:42 +00:00
|
|
|
|
|
2018-06-11 00:46:42 +00:00
|
|
|
|
namespace Ryujinx.ShaderTools
|
2018-05-17 18:25:42 +00:00
|
|
|
|
{
|
|
|
|
|
class Program
|
|
|
|
|
{
|
|
|
|
|
static void Main(string[] args)
|
|
|
|
|
{
|
2018-06-20 16:30:18 +00:00
|
|
|
|
if (args.Length == 4)
|
2018-05-17 18:25:42 +00:00
|
|
|
|
{
|
|
|
|
|
GalShaderType ShaderType = GalShaderType.Vertex;
|
|
|
|
|
|
2018-06-20 16:30:18 +00:00
|
|
|
|
switch (args[1].ToLower())
|
2018-05-17 18:25:42 +00: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 16:30:18 +00:00
|
|
|
|
using (FileStream Output = new FileStream(args[3], FileMode.Create))
|
|
|
|
|
using (FileStream FS = new FileStream(args[2], FileMode.Open, FileAccess.Read))
|
2018-05-17 18:25:42 +00:00
|
|
|
|
{
|
2018-05-23 01:43:31 +00:00
|
|
|
|
Memory Mem = new Memory(FS);
|
2018-05-17 18:25:42 +00:00
|
|
|
|
|
2018-06-20 16:30:18 +00: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 18:25:42 +00:00
|
|
|
|
|
2018-06-20 16:30:18 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-23 01:43:31 +00:00
|
|
|
|
}
|
2018-05-17 18:25:42 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-06-20 16:30:18 +00:00
|
|
|
|
Console.WriteLine("Usage: Ryujinx.ShaderTools [spirv|glsl] [v|tc|te|g|f] shader.bin output.bin");
|
2018-05-17 18:25:42 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|