From 95bad6995c110a662c8059e4f8035426303c0840 Mon Sep 17 00:00:00 2001 From: riperiperi Date: Thu, 11 May 2023 17:41:34 +0100 Subject: [PATCH] GPU: Fix shader cache assuming past shader data was mapped (#4885) This fixes a potential issue where a shader lookup could match the address of a previous _different_ shader, but that shader is now partially unmapped. This would just crash with an invalid region exception. To compare a shader in the address cache with one in memory, we get the memory at the location with the previous shader's size. However, it's possible it has been unmapped and then remapped with a smaller size. In this case, we should just get back the mapped portion of the shader, which will then fail the comparison immediately and get to compile/lookup for the new one. This might fix a random crash in TOTK that was reported by Piplup. I don't know if it does, because I don't have the game yet. --- src/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs b/src/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs index e1ab93278c..d543f42ad8 100644 --- a/src/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs +++ b/src/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs @@ -591,7 +591,7 @@ namespace Ryujinx.Graphics.Gpu.Shader return true; } - ReadOnlySpan memoryCode = memoryManager.GetSpan(gpuVa, shader.Code.Length); + ReadOnlySpan memoryCode = memoryManager.GetSpanMapped(gpuVa, shader.Code.Length); return memoryCode.SequenceEqual(shader.Code); }