diff options
author | gdkchan <gab.dark.100@gmail.com> | 2022-07-11 19:36:58 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-12 00:36:58 +0200 |
commit | 4523a73f75528d57bc7bc6d78024a6737a012a86 (patch) | |
tree | 78c29041246f674098271851a39a4323f3d3a710 | |
parent | f4c47f3c9af542438b2af141932dad058f38d36e (diff) |
Propagate Shader phi nodes with the same source value from all blocks (#3457)1.1.175
* Propagate Shader phi nodes with the same source value from all incoming blocks
* Shader cache version bump
-rw-r--r-- | Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheHostStorage.cs | 2 | ||||
-rw-r--r-- | Ryujinx.Graphics.Shader/Translation/Optimizations/Optimizer.cs | 53 |
2 files changed, 54 insertions, 1 deletions
diff --git a/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheHostStorage.cs b/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheHostStorage.cs index 37b25793..c332e2df 100644 --- a/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheHostStorage.cs +++ b/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheHostStorage.cs @@ -21,7 +21,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache private const ushort FileFormatVersionMajor = 1; private const ushort FileFormatVersionMinor = 1; private const uint FileFormatVersionPacked = ((uint)FileFormatVersionMajor << 16) | FileFormatVersionMinor; - private const uint CodeGenVersion = 3069; + private const uint CodeGenVersion = 3457; private const string SharedTocFileName = "shared.toc"; private const string SharedDataFileName = "shared.data"; diff --git a/Ryujinx.Graphics.Shader/Translation/Optimizations/Optimizer.cs b/Ryujinx.Graphics.Shader/Translation/Optimizations/Optimizer.cs index 078f3bb9..47963eac 100644 --- a/Ryujinx.Graphics.Shader/Translation/Optimizations/Optimizer.cs +++ b/Ryujinx.Graphics.Shader/Translation/Optimizations/Optimizer.cs @@ -45,6 +45,11 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations if (!(node.Value is Operation operation) || isUnused) { + if (node.Value is PhiNode phi && !isUnused) + { + isUnused = PropagatePhi(phi); + } + if (isUnused) { RemoveNode(block, node); @@ -101,6 +106,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations { // Propagate copy source operand to all uses of // the destination operand. + Operand dest = copyOp.Dest; Operand src = copyOp.GetSource(0); @@ -118,6 +124,53 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations } } + private static bool PropagatePhi(PhiNode phi) + { + // If all phi sources are the same, we can propagate it and remove the phi. + + Operand firstSrc = phi.GetSource(0); + + for (int index = 1; index < phi.SourcesCount; index++) + { + if (!IsSameOperand(firstSrc, phi.GetSource(index))) + { + return false; + } + } + + // All sources are equal, we can propagate the value. + + Operand dest = phi.Dest; + + INode[] uses = dest.UseOps.ToArray(); + + foreach (INode useNode in uses) + { + for (int index = 0; index < useNode.SourcesCount; index++) + { + if (useNode.GetSource(index) == dest) + { + useNode.SetSource(index, firstSrc); + } + } + } + + return true; + } + + private static bool IsSameOperand(Operand x, Operand y) + { + if (x.Type != y.Type || x.Value != y.Value) + { + return false; + } + + return x.Type == OperandType.Attribute || + x.Type == OperandType.AttributePerPatch || + x.Type == OperandType.Constant || + x.Type == OperandType.ConstantBuffer; + } + private static bool PropagatePack(Operation packOp) { // Propagate pack source operands to uses by unpack |