shadertools: Prepare for new target Languages and APIs (#2465)

* shadertools: Prepare for new target Langugaes and APIs

This improves shader tools command line by adding support for target
language and api.

* Address gdkchan's comments
This commit is contained in:
Mary
2021-07-18 12:49:39 +02:00
committed by GitHub
parent ca5ac37cd6
commit 97a2133207
5 changed files with 87 additions and 19 deletions

View File

@ -7,11 +7,21 @@ namespace Ryujinx.Graphics.Shader
public ShaderStage Stage { get; }
public string Code { get; private set; }
public byte[] BinaryCode { get; }
public ShaderProgram(ShaderStage stage, string code)
private ShaderProgram(ShaderStage stage)
{
Stage = stage;
Code = code;
}
public ShaderProgram(ShaderStage stage, string code) : this(stage)
{
Code = code;
}
public ShaderProgram(ShaderStage stage, byte[] binaryCode) : this(stage)
{
BinaryCode = binaryCode;
}
public void Prepend(string line)

View File

@ -3,6 +3,7 @@ namespace Ryujinx.Graphics.Shader.Translation
public enum TargetLanguage
{
Glsl,
Spirv
Spirv,
Arb
}
}

View File

@ -3,6 +3,7 @@ using Ryujinx.Graphics.Shader.Decoders;
using Ryujinx.Graphics.Shader.IntermediateRepresentation;
using Ryujinx.Graphics.Shader.StructuredIr;
using Ryujinx.Graphics.Shader.Translation.Optimizations;
using System;
using System.Collections.Generic;
using static Ryujinx.Graphics.Shader.IntermediateRepresentation.OperandHelper;
@ -87,7 +88,16 @@ namespace Ryujinx.Graphics.Shader.Translation
StructuredProgramInfo sInfo = StructuredProgram.MakeStructuredProgram(funcs, config);
string glslCode = GlslGenerator.Generate(sInfo, config);
ShaderProgram program;
switch (config.Options.TargetLanguage)
{
case TargetLanguage.Glsl:
program = new ShaderProgram(config.Stage, GlslGenerator.Generate(sInfo, config));
break;
default:
throw new NotImplementedException(config.Options.TargetLanguage.ToString());
}
shaderProgramInfo = new ShaderProgramInfo(
config.GetConstantBufferDescriptors(),
@ -97,7 +107,7 @@ namespace Ryujinx.Graphics.Shader.Translation
config.UsedFeatures.HasFlag(FeatureFlags.InstanceId),
config.ClipDistancesWritten);
return new ShaderProgram(config.Stage, glslCode);
return program;
}
private static Block[][] DecodeShader(