mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-11-30 17:12:03 +00:00
Refactor shader translator ShaderConfig and reduce the number of out args (#1438)
This commit is contained in:
parent
b3c051bbec
commit
636542d817
4 changed files with 29 additions and 35 deletions
|
@ -283,14 +283,14 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
||||||
|
|
||||||
public static void Tld(EmitterContext context)
|
public static void Tld(EmitterContext context)
|
||||||
{
|
{
|
||||||
context.UsedFeatures |= FeatureFlags.IntegerSampling;
|
context.Config.SetUsedFeature(FeatureFlags.IntegerSampling);
|
||||||
|
|
||||||
EmitTextureSample(context, TextureFlags.IntCoords);
|
EmitTextureSample(context, TextureFlags.IntCoords);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void TldB(EmitterContext context)
|
public static void TldB(EmitterContext context)
|
||||||
{
|
{
|
||||||
context.UsedFeatures |= FeatureFlags.IntegerSampling;
|
context.Config.SetUsedFeature(FeatureFlags.IntegerSampling);
|
||||||
|
|
||||||
EmitTextureSample(context, TextureFlags.IntCoords | TextureFlags.Bindless);
|
EmitTextureSample(context, TextureFlags.IntCoords | TextureFlags.Bindless);
|
||||||
}
|
}
|
||||||
|
@ -432,7 +432,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
context.UsedFeatures |= FeatureFlags.IntegerSampling;
|
context.Config.SetUsedFeature(FeatureFlags.IntegerSampling);
|
||||||
|
|
||||||
flags = ConvertTextureFlags(tldsOp.Target) | TextureFlags.IntCoords;
|
flags = ConvertTextureFlags(tldsOp.Target) | TextureFlags.IntCoords;
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,6 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||||
public Block CurrBlock { get; set; }
|
public Block CurrBlock { get; set; }
|
||||||
public OpCode CurrOp { get; set; }
|
public OpCode CurrOp { get; set; }
|
||||||
|
|
||||||
public FeatureFlags UsedFeatures { get; set; }
|
|
||||||
|
|
||||||
public ShaderConfig Config { get; }
|
public ShaderConfig Config { get; }
|
||||||
|
|
||||||
private List<Operation> _operations;
|
private List<Operation> _operations;
|
||||||
|
@ -50,7 +48,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||||
{
|
{
|
||||||
case AttributeConsts.PositionX:
|
case AttributeConsts.PositionX:
|
||||||
case AttributeConsts.PositionY:
|
case AttributeConsts.PositionY:
|
||||||
UsedFeatures |= FeatureFlags.FragCoordXY;
|
Config.SetUsedFeature(FeatureFlags.FragCoordXY);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Ryujinx.Graphics.Shader.Translation
|
namespace Ryujinx.Graphics.Shader.Translation
|
||||||
{
|
{
|
||||||
struct ShaderConfig
|
class ShaderConfig
|
||||||
{
|
{
|
||||||
public ShaderStage Stage { get; }
|
public ShaderStage Stage { get; }
|
||||||
|
|
||||||
|
@ -22,7 +20,9 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||||
|
|
||||||
public TranslationFlags Flags { get; }
|
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)
|
public ShaderConfig(IGpuAccessor gpuAccessor, TranslationFlags flags)
|
||||||
{
|
{
|
||||||
|
@ -36,6 +36,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||||
OmapDepth = false;
|
OmapDepth = false;
|
||||||
GpuAccessor = gpuAccessor;
|
GpuAccessor = gpuAccessor;
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
|
Size = 0;
|
||||||
UsedFeatures = FeatureFlags.None;
|
UsedFeatures = FeatureFlags.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +52,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||||
OmapDepth = header.OmapDepth;
|
OmapDepth = header.OmapDepth;
|
||||||
GpuAccessor = gpuAccessor;
|
GpuAccessor = gpuAccessor;
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
|
Size = 0;
|
||||||
UsedFeatures = FeatureFlags.None;
|
UsedFeatures = FeatureFlags.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,5 +95,15 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||||
|
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SizeAdd(int size)
|
||||||
|
{
|
||||||
|
Size += size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetUsedFeature(FeatureFlags flags)
|
||||||
|
{
|
||||||
|
UsedFeatures |= flags;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -16,24 +16,20 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||||
|
|
||||||
public static ShaderProgram Translate(ulong address, IGpuAccessor gpuAccessor, TranslationFlags flags)
|
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);
|
return Translate(DecodeShader(address, gpuAccessor, flags, out ShaderConfig config), config);
|
||||||
|
|
||||||
config.UsedFeatures = featureFlags;
|
|
||||||
|
|
||||||
return Translate(ops, config, size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ShaderProgram Translate(ulong addressA, ulong addressB, IGpuAccessor gpuAccessor, TranslationFlags flags)
|
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[] opsA = DecodeShader(addressA, gpuAccessor, flags | TranslationFlags.VertexA, out ShaderConfig configA);
|
||||||
Operation[] opsB = DecodeShader(addressB, gpuAccessor, flags, out ShaderConfig config, out int sizeB, out FeatureFlags featureFlagsB);
|
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);
|
BasicBlock[] blocks = ControlFlowGraph.MakeCfg(ops);
|
||||||
|
|
||||||
|
@ -63,16 +59,10 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||||
|
|
||||||
string glslCode = program.Code;
|
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(
|
private static Operation[] DecodeShader(ulong address, IGpuAccessor gpuAccessor, TranslationFlags flags, out ShaderConfig config)
|
||||||
ulong address,
|
|
||||||
IGpuAccessor gpuAccessor,
|
|
||||||
TranslationFlags flags,
|
|
||||||
out ShaderConfig config,
|
|
||||||
out int size,
|
|
||||||
out FeatureFlags featureFlags)
|
|
||||||
{
|
{
|
||||||
Block[] cfg;
|
Block[] cfg;
|
||||||
|
|
||||||
|
@ -93,10 +83,6 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||||
{
|
{
|
||||||
gpuAccessor.Log("Invalid branch detected, failed to build CFG.");
|
gpuAccessor.Log("Invalid branch detected, failed to build CFG.");
|
||||||
|
|
||||||
size = 0;
|
|
||||||
|
|
||||||
featureFlags = FeatureFlags.None;
|
|
||||||
|
|
||||||
return Array.Empty<Operation>();
|
return Array.Empty<Operation>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,9 +183,7 @@ namespace Ryujinx.Graphics.Shader.Translation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size = (int)maxEndAddress + (((flags & TranslationFlags.Compute) != 0) ? 0 : HeaderSize);
|
config.SizeAdd((int)maxEndAddress + (flags.HasFlag(TranslationFlags.Compute) ? 0 : HeaderSize));
|
||||||
|
|
||||||
featureFlags = context.UsedFeatures;
|
|
||||||
|
|
||||||
return context.GetOperations();
|
return context.GetOperations();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue