From 6bc2733c1796788590c9f0114013d2e4b555e31e Mon Sep 17 00:00:00 2001 From: Mary Date: Sun, 13 Dec 2020 08:46:07 +0100 Subject: salieri: Support read-only mode if archive is already opened (#1807) This improves shader cache resilience when people opens another program that touch the cache.zip. --- .../Shader/Cache/CacheCollection.cs | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'Ryujinx.Graphics.Gpu/Shader/Cache/CacheCollection.cs') diff --git a/Ryujinx.Graphics.Gpu/Shader/Cache/CacheCollection.cs b/Ryujinx.Graphics.Gpu/Shader/Cache/CacheCollection.cs index 9b61ef4a..2660e528 100644 --- a/Ryujinx.Graphics.Gpu/Shader/Cache/CacheCollection.cs +++ b/Ryujinx.Graphics.Gpu/Shader/Cache/CacheCollection.cs @@ -116,6 +116,8 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache /// private ZipArchive _cacheArchive; + public bool IsReadOnly { get; } + /// /// Immutable copy of the hash table. /// @@ -167,6 +169,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache _hashType = hashType; _version = version; _hashTable = new HashSet(); + IsReadOnly = CacheHelper.IsArchiveReadOnly(GetArchivePath()); Load(); @@ -230,6 +233,13 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache /// Entries to remove from the manifest public void RemoveManifestEntriesAsync(HashSet entries) { + if (IsReadOnly) + { + Logger.Warning?.Print(LogClass.Gpu, "Trying to remove manifest entries on a read-only cache, ignoring."); + + return; + } + _fileWriterWorkerQueue.Add(new CacheFileOperationTask { Type = CacheFileOperation.RemoveManifestEntries, @@ -308,6 +318,20 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache string archivePath = GetArchivePath(); + if (IsReadOnly) + { + Logger.Warning?.Print(LogClass.Gpu, $"Cache collection archive in read-only, archiving task skipped."); + + return; + } + + if (CacheHelper.IsArchiveReadOnly(archivePath)) + { + Logger.Warning?.Print(LogClass.Gpu, $"Cache collection archive in use, archiving task skipped."); + + return; + } + // Open the zip in read/write. _cacheArchive = ZipFile.Open(archivePath, ZipArchiveMode.Update); @@ -446,6 +470,13 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache /// The value to cache public void AddValue(ref Hash128 keyHash, byte[] value) { + if (IsReadOnly) + { + Logger.Warning?.Print(LogClass.Gpu, "Trying to add {keyHash} on a read-only cache, ignoring."); + + return; + } + Debug.Assert(value != null); bool isAlreadyPresent; @@ -488,6 +519,13 @@ namespace Ryujinx.Graphics.Gpu.Shader.Cache /// The value to cache public void ReplaceValue(ref Hash128 keyHash, byte[] value) { + if (IsReadOnly) + { + Logger.Warning?.Print(LogClass.Gpu, "Trying to replace {keyHash} on a read-only cache, ignoring."); + + return; + } + Debug.Assert(value != null); // Only queue file change operations -- cgit v1.2.3