From cc60ba9d22ecc582206b61074a0fd6ee2c987ed1 Mon Sep 17 00:00:00 2001 From: Mary Date: Tue, 17 Nov 2020 22:31:05 +0100 Subject: [PATCH] shader cache: Fix possible race causing crashes on manifest at startup (#1718) * shader cache: Fix possible race causing crashes on manifest at startup This fix a misplace function call ending up causing possibly two write on the cache.info at the same time. * shader cache: Make RemoveManifestEntries async too to be sure all operations are perform before starting the game --- .../Shader/Cache/CacheCollection.cs | 23 ++++++++++++++++++- .../Shader/Cache/CacheManager.cs | 4 ++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Ryujinx.Graphics.Gpu/Shader/Cache/CacheCollection.cs b/Ryujinx.Graphics.Gpu/Shader/Cache/CacheCollection.cs index effd893a23..924d720b1b 100644 --- a/Ryujinx.Graphics.Gpu/Shader/Cache/CacheCollection.cs +++ b/Ryujinx.Graphics.Gpu/Shader/Cache/CacheCollection.cs @@ -33,6 +33,11 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache /// SaveManifest, + /// + /// Remove entries from the hash manifest and save it. + /// + RemoveManifestEntries, + /// /// Flush temporary cache to archive. /// @@ -227,11 +232,24 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache FlushToArchive(); } + /// + /// Queue a task to remove entries from the hash manifest. + /// + /// Entries to remove from the manifest + public void RemoveManifestEntriesAsync(HashSet entries) + { + _fileWriterWorkerQueue.Add(new CacheFileOperationTask + { + Type = CacheFileOperation.RemoveManifestEntries, + Data = entries + }); + } + /// /// Remove given entries from the manifest. /// /// Entries to remove from the manifest - public void RemoveManifestEntries(HashSet entries) + private void RemoveManifestEntries(HashSet entries) { lock (_hashTable) { @@ -488,6 +506,9 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache case CacheFileOperation.SaveManifest: SaveManifest(); break; + case CacheFileOperation.RemoveManifestEntries: + RemoveManifestEntries((HashSet)task.Data); + break; case CacheFileOperation.FlushToArchive: FlushToArchive(); break; diff --git a/Ryujinx.Graphics.Gpu/Shader/Cache/CacheManager.cs b/Ryujinx.Graphics.Gpu/Shader/Cache/CacheManager.cs index 0c4eba2a8c..f977e96bc9 100644 --- a/Ryujinx.Graphics.Gpu/Shader/Cache/CacheManager.cs +++ b/Ryujinx.Graphics.Gpu/Shader/Cache/CacheManager.cs @@ -58,8 +58,8 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache /// Entries to remove from the manifest of all caches public void RemoveManifestEntries(HashSet entries) { - _guestProgramCache.RemoveManifestEntries(entries); - _hostProgramCache.RemoveManifestEntries(entries); + _guestProgramCache.RemoveManifestEntriesAsync(entries); + _hostProgramCache.RemoveManifestEntriesAsync(entries); } ///