0
0
Fork 0

Do not add more code after alpha test discard on fragment shader (#5529)

* Do not add more code after alpha test discard on fragment shader

* Shader cache version bump
This commit is contained in:
gdkchan 2023-08-07 12:20:37 -03:00 committed by GitHub
parent 3ab0a71c7b
commit 42750a74f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 9 deletions

View file

@ -22,7 +22,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
private const ushort FileFormatVersionMajor = 1; private const ushort FileFormatVersionMajor = 1;
private const ushort FileFormatVersionMinor = 2; private const ushort FileFormatVersionMinor = 2;
private const uint FileFormatVersionPacked = ((uint)FileFormatVersionMajor << 16) | FileFormatVersionMinor; private const uint FileFormatVersionPacked = ((uint)FileFormatVersionMajor << 16) | FileFormatVersionMinor;
private const uint CodeGenVersion = 4675; private const uint CodeGenVersion = 5529;
private const string SharedTocFileName = "shared.toc"; private const string SharedTocFileName = "shared.toc";
private const string SharedDataFileName = "shared.data"; private const string SharedDataFileName = "shared.data";

View file

@ -162,9 +162,11 @@ namespace Ryujinx.Graphics.Shader.Instructions
if (op.Ccc == Ccc.T) if (op.Ccc == Ccc.T)
{ {
context.PrepareForReturn(); if (context.PrepareForReturn())
{
context.Return(); context.Return();
} }
}
else else
{ {
Operand cond = GetCondition(context, op.Ccc, IrConsts.False); Operand cond = GetCondition(context, op.Ccc, IrConsts.False);
@ -174,8 +176,12 @@ namespace Ryujinx.Graphics.Shader.Instructions
{ {
Operand lblSkip = Label(); Operand lblSkip = Label();
context.BranchIfFalse(lblSkip, cond); context.BranchIfFalse(lblSkip, cond);
context.PrepareForReturn();
if (context.PrepareForReturn())
{
context.Return(); context.Return();
}
context.MarkLabel(lblSkip); context.MarkLabel(lblSkip);
} }
} }

View file

@ -304,11 +304,11 @@ namespace Ryujinx.Graphics.Shader.Translation
PrepareForVertexReturn(); PrepareForVertexReturn();
} }
public void PrepareForReturn() public bool PrepareForReturn()
{ {
if (IsNonMain) if (IsNonMain)
{ {
return; return true;
} }
if (Config.LastInVertexPipeline && if (Config.LastInVertexPipeline &&
@ -383,13 +383,13 @@ namespace Ryujinx.Graphics.Shader.Translation
AlphaTestOp alphaTestOp = Config.GpuAccessor.QueryAlphaTestCompare(); AlphaTestOp alphaTestOp = Config.GpuAccessor.QueryAlphaTestCompare();
if (alphaTestOp != AlphaTestOp.Always && (Config.OmapTargets & 8) != 0) if (alphaTestOp != AlphaTestOp.Always)
{ {
if (alphaTestOp == AlphaTestOp.Never) if (alphaTestOp == AlphaTestOp.Never)
{ {
this.Discard(); this.Discard();
} }
else else if ((Config.OmapTargets & 8) != 0)
{ {
Instruction comparator = alphaTestOp switch Instruction comparator = alphaTestOp switch
{ {
@ -415,6 +415,12 @@ namespace Ryujinx.Graphics.Shader.Translation
} }
} }
// We don't need to output anything if alpha test always fails.
if (alphaTestOp == AlphaTestOp.Never)
{
return false;
}
int regIndexBase = 0; int regIndexBase = 0;
for (int rtIndex = 0; rtIndex < 8; rtIndex++) for (int rtIndex = 0; rtIndex < 8; rtIndex++)
@ -462,6 +468,8 @@ namespace Ryujinx.Graphics.Shader.Translation
} }
} }
} }
return true;
} }
private void GenerateAlphaToCoverageDitherDiscard() private void GenerateAlphaToCoverageDitherDiscard()