From 0954e76a261235107b2255c33de595d188570274 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Sat, 3 Oct 2020 02:43:33 -0300 Subject: Improve BRX target detection heuristics (#1591) --- Ryujinx.Graphics.Shader/Decoders/Decoder.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'Ryujinx.Graphics.Shader/Decoders') diff --git a/Ryujinx.Graphics.Shader/Decoders/Decoder.cs b/Ryujinx.Graphics.Shader/Decoders/Decoder.cs index e2c9212b..a15d7f9e 100644 --- a/Ryujinx.Graphics.Shader/Decoders/Decoder.cs +++ b/Ryujinx.Graphics.Shader/Decoders/Decoder.cs @@ -128,7 +128,7 @@ namespace Ryujinx.Graphics.Shader.Decoders } // Do we have a block after the current one? - if (!IsExit(currBlock.GetLastOp()) && currBlock.BrIndir != null) + if (currBlock.BrIndir != null && HasBlockAfter(gpuAccessor, currBlock, startAddress)) { bool targetVisited = visited.ContainsKey(currBlock.EndAddress); @@ -154,6 +154,19 @@ namespace Ryujinx.Graphics.Shader.Decoders return blocks.ToArray(); } + private static bool HasBlockAfter(IGpuAccessor gpuAccessor, Block currBlock, ulong startAdddress) + { + if (!gpuAccessor.MemoryMapped(startAdddress + currBlock.EndAddress) || + !gpuAccessor.MemoryMapped(startAdddress + currBlock.EndAddress + 7)) + { + return false; + } + + ulong inst = gpuAccessor.MemoryRead(startAdddress + currBlock.EndAddress); + + return inst != 0UL; + } + private static bool BinarySearch(List blocks, ulong address, out int index) { index = 0; -- cgit v1.2.3