From 3dee712164e635fd3a0d2e9d359a7d11a80bf675 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Mon, 8 Nov 2021 12:57:28 -0300 Subject: [PATCH] Fix bindless/global memory elimination with inverted predicates (#2826) * Fix bindless/global memory elimination with inverted predicates * Shader cache version bump --- Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs | 2 +- .../Translation/Optimizations/Utils.cs | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs b/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs index 67a397b3c..4e1e130cb 100644 --- a/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs +++ b/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs @@ -40,7 +40,7 @@ namespace Ryujinx.Graphics.Gpu.Shader /// /// Version of the codegen (to be changed when codegen or guest format change). /// - private const ulong ShaderCodeGenVersion = 2822; + private const ulong ShaderCodeGenVersion = 2826; // Progress reporting helpers private volatile int _shaderCount; diff --git a/Ryujinx.Graphics.Shader/Translation/Optimizations/Utils.cs b/Ryujinx.Graphics.Shader/Translation/Optimizations/Utils.cs index 83ff8c404..4ca6d6877 100644 --- a/Ryujinx.Graphics.Shader/Translation/Optimizations/Utils.cs +++ b/Ryujinx.Graphics.Shader/Translation/Optimizations/Utils.cs @@ -10,11 +10,7 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations { if (sourceBlock.Operations.Count > 0) { - Operation lastOp = sourceBlock.Operations.Last.Value as Operation; - - if (lastOp != null && - ((sourceBlock.Next == block && lastOp.Inst == Instruction.BranchIfFalse) || - (sourceBlock.Branch == block && lastOp.Inst == Instruction.BranchIfTrue))) + if (sourceBlock.GetLastOp() is Operation lastOp && IsConditionalBranch(lastOp.Inst) && sourceBlock.Next == block) { return lastOp; } @@ -24,6 +20,11 @@ namespace Ryujinx.Graphics.Shader.Translation.Optimizations return null; } + private static bool IsConditionalBranch(Instruction inst) + { + return inst == Instruction.BranchIfFalse || inst == Instruction.BranchIfTrue; + } + private static bool BlockConditionsMatch(BasicBlock currentBlock, BasicBlock queryBlock) { // Check if all the conditions for the query block are satisfied by the current block.