Refactor shader translator ShaderConfig and reduce the number of out args (#1438)

This commit is contained in:
gdkchan 2020-07-30 02:53:23 -03:00 committed by GitHub
parent b3c051bbec
commit 636542d817
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 35 deletions

View file

@ -283,14 +283,14 @@ namespace Ryujinx.Graphics.Shader.Instructions
public static void Tld(EmitterContext context)
{
context.UsedFeatures |= FeatureFlags.IntegerSampling;
context.Config.SetUsedFeature(FeatureFlags.IntegerSampling);
EmitTextureSample(context, TextureFlags.IntCoords);
}
public static void TldB(EmitterContext context)
{
context.UsedFeatures |= FeatureFlags.IntegerSampling;
context.Config.SetUsedFeature(FeatureFlags.IntegerSampling);
EmitTextureSample(context, TextureFlags.IntCoords | TextureFlags.Bindless);
}
@ -432,7 +432,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
return;
}
context.UsedFeatures |= FeatureFlags.IntegerSampling;
context.Config.SetUsedFeature(FeatureFlags.IntegerSampling);
flags = ConvertTextureFlags(tldsOp.Target) | TextureFlags.IntCoords;

View file

@ -11,8 +11,6 @@ namespace Ryujinx.Graphics.Shader.Translation
public Block CurrBlock { get; set; }
public OpCode CurrOp { get; set; }
public FeatureFlags UsedFeatures { get; set; }
public ShaderConfig Config { get; }
private List<Operation> _operations;
@ -50,7 +48,7 @@ namespace Ryujinx.Graphics.Shader.Translation
{
case AttributeConsts.PositionX:
case AttributeConsts.PositionY:
UsedFeatures |= FeatureFlags.FragCoordXY;
Config.SetUsedFeature(FeatureFlags.FragCoordXY);
break;
}
}

View file

@ -1,8 +1,6 @@
using System;
namespace Ryujinx.Graphics.Shader.Translation
{
struct ShaderConfig
class ShaderConfig
{
public ShaderStage Stage { get; }
@ -22,7 +20,9 @@ namespace Ryujinx.Graphics.Shader.Translation
public TranslationFlags Flags { get; }
public FeatureFlags UsedFeatures { get; set; }
public int Size { get; private set; }
public FeatureFlags UsedFeatures { get; private set; }
public ShaderConfig(IGpuAccessor gpuAccessor, TranslationFlags flags)
{
@ -36,6 +36,7 @@ namespace Ryujinx.Graphics.Shader.Translation
OmapDepth = false;
GpuAccessor = gpuAccessor;
Flags = flags;
Size = 0;
UsedFeatures = FeatureFlags.None;
}
@ -51,6 +52,7 @@ namespace Ryujinx.Graphics.Shader.Translation
OmapDepth = header.OmapDepth;
GpuAccessor = gpuAccessor;
Flags = flags;
Size = 0;
UsedFeatures = FeatureFlags.None;
}
@ -93,5 +95,15 @@ namespace Ryujinx.Graphics.Shader.Translation
return format;
}
public void SizeAdd(int size)
{
Size += size;
}
public void SetUsedFeature(FeatureFlags flags)
{
UsedFeatures |= flags;
}
}
}

View file

@ -16,24 +16,20 @@ namespace Ryujinx.Graphics.Shader.Translation
public static ShaderProgram Translate(ulong address, IGpuAccessor gpuAccessor, TranslationFlags flags)
{
Operation[] ops = DecodeShader(address, gpuAccessor, flags, out ShaderConfig config, out int size, out FeatureFlags featureFlags);
config.UsedFeatures = featureFlags;
return Translate(ops, config, size);
return Translate(DecodeShader(address, gpuAccessor, flags, out ShaderConfig config), config);
}
public static ShaderProgram Translate(ulong addressA, ulong addressB, IGpuAccessor gpuAccessor, TranslationFlags flags)
{
Operation[] opsA = DecodeShader(addressA, gpuAccessor, flags | TranslationFlags.VertexA, out _, out int sizeA, out FeatureFlags featureFlagsA);
Operation[] opsB = DecodeShader(addressB, gpuAccessor, flags, out ShaderConfig config, out int sizeB, out FeatureFlags featureFlagsB);
Operation[] opsA = DecodeShader(addressA, gpuAccessor, flags | TranslationFlags.VertexA, out ShaderConfig configA);
Operation[] opsB = DecodeShader(addressB, gpuAccessor, flags, out ShaderConfig config);
config.UsedFeatures = featureFlagsA | featureFlagsB;
config.SetUsedFeature(configA.UsedFeatures);
return Translate(Combine(opsA, opsB), config, sizeB, sizeA);
return Translate(Combine(opsA, opsB), config, configA.Size);
}
private static ShaderProgram Translate(Operation[] ops, ShaderConfig config, int size, int sizeA = 0)
private static ShaderProgram Translate(Operation[] ops, ShaderConfig config, int sizeA = 0)
{
BasicBlock[] blocks = ControlFlowGraph.MakeCfg(ops);
@ -63,16 +59,10 @@ namespace Ryujinx.Graphics.Shader.Translation
string glslCode = program.Code;
return new ShaderProgram(spInfo, config.Stage, glslCode, size, sizeA);
return new ShaderProgram(spInfo, config.Stage, glslCode, config.Size, sizeA);
}
private static Operation[] DecodeShader(
ulong address,
IGpuAccessor gpuAccessor,
TranslationFlags flags,
out ShaderConfig config,
out int size,
out FeatureFlags featureFlags)
private static Operation[] DecodeShader(ulong address, IGpuAccessor gpuAccessor, TranslationFlags flags, out ShaderConfig config)
{
Block[] cfg;
@ -93,10 +83,6 @@ namespace Ryujinx.Graphics.Shader.Translation
{
gpuAccessor.Log("Invalid branch detected, failed to build CFG.");
size = 0;
featureFlags = FeatureFlags.None;
return Array.Empty<Operation>();
}
@ -197,9 +183,7 @@ namespace Ryujinx.Graphics.Shader.Translation
}
}
size = (int)maxEndAddress + (((flags & TranslationFlags.Compute) != 0) ? 0 : HeaderSize);
featureFlags = context.UsedFeatures;
config.SizeAdd((int)maxEndAddress + (flags.HasFlag(TranslationFlags.Compute) ? 0 : HeaderSize));
return context.GetOperations();
}