Allow shader language and target API to be specified on the shader translator (#2402)
This commit is contained in:
parent
b0ac1ade7f
commit
d125fce3e8
11 changed files with 87 additions and 27 deletions
|
@ -29,7 +29,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||
|
||||
public IGpuAccessor GpuAccessor { get; }
|
||||
|
||||
public TranslationFlags Flags { get; }
|
||||
public TranslationOptions Options { get; }
|
||||
|
||||
public int Size { get; private set; }
|
||||
|
||||
|
@ -94,18 +94,18 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||
public int FirstConstantBufferBinding { get; private set; }
|
||||
public int FirstStorageBufferBinding { get; private set; }
|
||||
|
||||
public ShaderConfig(IGpuAccessor gpuAccessor, TranslationFlags flags, TranslationCounts counts)
|
||||
public ShaderConfig(IGpuAccessor gpuAccessor, TranslationOptions options, TranslationCounts counts)
|
||||
{
|
||||
Stage = ShaderStage.Compute;
|
||||
GpuAccessor = gpuAccessor;
|
||||
Flags = flags;
|
||||
Options = options;
|
||||
_counts = counts;
|
||||
TextureHandlesForCache = new HashSet<int>();
|
||||
_usedTextures = new Dictionary<TextureInfo, TextureMeta>();
|
||||
_usedImages = new Dictionary<TextureInfo, TextureMeta>();
|
||||
}
|
||||
|
||||
public ShaderConfig(ShaderHeader header, IGpuAccessor gpuAccessor, TranslationFlags flags, TranslationCounts counts) : this(gpuAccessor, flags, counts)
|
||||
public ShaderConfig(ShaderHeader header, IGpuAccessor gpuAccessor, TranslationOptions options, TranslationCounts counts) : this(gpuAccessor, options, counts)
|
||||
{
|
||||
Stage = header.Stage;
|
||||
GpPassthrough = header.Stage == ShaderStage.Geometry && header.GpPassthrough;
|
||||
|
|
8
Ryujinx.Graphics.Shader/Translation/TargetApi.cs
Normal file
8
Ryujinx.Graphics.Shader/Translation/TargetApi.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace Ryujinx.Graphics.Shader.Translation
|
||||
{
|
||||
public enum TargetApi
|
||||
{
|
||||
OpenGL,
|
||||
Vulkan
|
||||
}
|
||||
}
|
8
Ryujinx.Graphics.Shader/Translation/TargetLanguage.cs
Normal file
8
Ryujinx.Graphics.Shader/Translation/TargetLanguage.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace Ryujinx.Graphics.Shader.Translation
|
||||
{
|
||||
public enum TargetLanguage
|
||||
{
|
||||
Glsl,
|
||||
Spirv
|
||||
}
|
||||
}
|
16
Ryujinx.Graphics.Shader/Translation/TranslationOptions.cs
Normal file
16
Ryujinx.Graphics.Shader/Translation/TranslationOptions.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
namespace Ryujinx.Graphics.Shader.Translation
|
||||
{
|
||||
public struct TranslationOptions
|
||||
{
|
||||
public TargetLanguage TargetLanguage { get; }
|
||||
public TargetApi TargetApi { get; }
|
||||
public TranslationFlags Flags { get; }
|
||||
|
||||
public TranslationOptions(TargetLanguage targetLanguage, TargetApi targetApi, TranslationFlags flags)
|
||||
{
|
||||
TargetLanguage = targetLanguage;
|
||||
TargetApi = targetApi;
|
||||
Flags = flags;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,12 +26,12 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||
public static TranslatorContext CreateContext(
|
||||
ulong address,
|
||||
IGpuAccessor gpuAccessor,
|
||||
TranslationFlags flags,
|
||||
TranslationOptions options,
|
||||
TranslationCounts counts = null)
|
||||
{
|
||||
counts ??= new TranslationCounts();
|
||||
|
||||
Block[][] cfg = DecodeShader(address, gpuAccessor, flags, counts, out ShaderConfig config);
|
||||
Block[][] cfg = DecodeShader(address, gpuAccessor, options, counts, out ShaderConfig config);
|
||||
|
||||
return new TranslatorContext(address, cfg, config);
|
||||
}
|
||||
|
@ -103,7 +103,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||
private static Block[][] DecodeShader(
|
||||
ulong address,
|
||||
IGpuAccessor gpuAccessor,
|
||||
TranslationFlags flags,
|
||||
TranslationOptions options,
|
||||
TranslationCounts counts,
|
||||
out ShaderConfig config)
|
||||
{
|
||||
|
@ -112,15 +112,15 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||
|
||||
bool hasBindless;
|
||||
|
||||
if ((flags & TranslationFlags.Compute) != 0)
|
||||
if ((options.Flags & TranslationFlags.Compute) != 0)
|
||||
{
|
||||
config = new ShaderConfig(gpuAccessor, flags, counts);
|
||||
config = new ShaderConfig(gpuAccessor, options, counts);
|
||||
|
||||
cfg = Decoder.Decode(gpuAccessor, address, out hasBindless);
|
||||
}
|
||||
else
|
||||
{
|
||||
config = new ShaderConfig(new ShaderHeader(gpuAccessor, address), gpuAccessor, flags, counts);
|
||||
config = new ShaderConfig(new ShaderHeader(gpuAccessor, address), gpuAccessor, options, counts);
|
||||
|
||||
cfg = Decoder.Decode(gpuAccessor, address + HeaderSize, out hasBindless);
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||
}
|
||||
}
|
||||
|
||||
config.SizeAdd((int)maxEndAddress + (flags.HasFlag(TranslationFlags.Compute) ? 0 : HeaderSize));
|
||||
config.SizeAdd((int)maxEndAddress + (options.Flags.HasFlag(TranslationFlags.Compute) ? 0 : HeaderSize));
|
||||
|
||||
return cfg;
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
|||
{
|
||||
OpCode op = block.OpCodes[opIndex];
|
||||
|
||||
if ((context.Config.Flags & TranslationFlags.DebugMode) != 0)
|
||||
if ((context.Config.Options.Flags & TranslationFlags.DebugMode) != 0)
|
||||
{
|
||||
string instName;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue