Skip to content

Commit

Permalink
Shader: Assume the only remaining source is the right one when all ot…
Browse files Browse the repository at this point in the history
…hers are undefined (#7331)

* Shader: Assume the only remaining source is the right one when all other are undefined

* Shader cache version bump

* Improve comment
  • Loading branch information
gdkchan authored Sep 20, 2024
1 parent 24ee8c3 commit d717aef
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DiskCacheHostStorage
private const ushort FileFormatVersionMajor = 1;
private const ushort FileFormatVersionMinor = 2;
private const uint FileFormatVersionPacked = ((uint)FileFormatVersionMajor << 16) | FileFormatVersionMinor;
private const uint CodeGenVersion = 7320;
private const uint CodeGenVersion = 7331;

private const string SharedTocFileName = "shared.toc";
private const string SharedDataFileName = "shared.data";
Expand Down
22 changes: 22 additions & 0 deletions src/Ryujinx.Graphics.Shader/Translation/Optimizations/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ public static Operand FindLastOperation(Operand source, BasicBlock block, bool r
// Ensure that conditions met for that branch are also met for the current one.
// Prefer the latest sources for the phi node.

int undefCount = 0;

for (int i = phiNode.SourcesCount - 1; i >= 0; i--)
{
BasicBlock phiBlock = phiNode.GetBlock(i);
Expand All @@ -159,6 +161,26 @@ public static Operand FindLastOperation(Operand source, BasicBlock block, bool r
return match;
}
}
else if (phiSource.Type == OperandType.Undefined)
{
undefCount++;
}
}

// If all sources but one are undefined, we can assume that the one
// that is not undefined is the right one.

if (undefCount == phiNode.SourcesCount - 1)
{
for (int i = phiNode.SourcesCount - 1; i >= 0; i--)
{
Operand phiSource = phiNode.GetSource(i);

if (phiSource.Type != OperandType.Undefined)
{
return phiSource;
}
}
}
}

Expand Down

0 comments on commit d717aef

Please sign in to comment.