diff --git a/Ryujinx.Graphics.Shader/Instructions/InstEmitTexture.cs b/Ryujinx.Graphics.Shader/Instructions/InstEmitTexture.cs index ea153b112b..77e3fae709 100644 --- a/Ryujinx.Graphics.Shader/Instructions/InstEmitTexture.cs +++ b/Ryujinx.Graphics.Shader/Instructions/InstEmitTexture.cs @@ -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; diff --git a/Ryujinx.Graphics.Shader/Translation/EmitterContext.cs b/Ryujinx.Graphics.Shader/Translation/EmitterContext.cs index 9b26fa4a67..8cd590161b 100644 --- a/Ryujinx.Graphics.Shader/Translation/EmitterContext.cs +++ b/Ryujinx.Graphics.Shader/Translation/EmitterContext.cs @@ -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 _operations; @@ -50,7 +48,7 @@ namespace Ryujinx.Graphics.Shader.Translation { case AttributeConsts.PositionX: case AttributeConsts.PositionY: - UsedFeatures |= FeatureFlags.FragCoordXY; + Config.SetUsedFeature(FeatureFlags.FragCoordXY); break; } } diff --git a/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs b/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs index aabd9ca66d..7b1587ae77 100644 --- a/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs +++ b/Ryujinx.Graphics.Shader/Translation/ShaderConfig.cs @@ -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; + } } } \ No newline at end of file diff --git a/Ryujinx.Graphics.Shader/Translation/Translator.cs b/Ryujinx.Graphics.Shader/Translation/Translator.cs index 1d7aacdd27..db0924b30b 100644 --- a/Ryujinx.Graphics.Shader/Translation/Translator.cs +++ b/Ryujinx.Graphics.Shader/Translation/Translator.cs @@ -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(); } @@ -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(); }