Prefer Brotli compression for disk shader cache.

This commit is contained in:
MutantAura 2024-05-21 23:58:54 +01:00
commit 99d6a3beb1
3 changed files with 39 additions and 5 deletions

View file

@ -125,9 +125,16 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
CompressionAlgorithm algorithm = CompressionAlgorithm.None; CompressionAlgorithm algorithm = CompressionAlgorithm.None;
Read(ref algorithm); Read(ref algorithm);
if (algorithm == CompressionAlgorithm.Deflate) switch (algorithm)
{ {
case CompressionAlgorithm.None:
break;
case CompressionAlgorithm.Deflate:
_activeStream = new DeflateStream(_stream, CompressionMode.Decompress, true); _activeStream = new DeflateStream(_stream, CompressionMode.Decompress, true);
break;
case CompressionAlgorithm.Brotli:
_activeStream = new BrotliStream(_stream, CompressionMode.Decompress, true);
break;
} }
} }
@ -139,9 +146,18 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
{ {
Write(ref algorithm); Write(ref algorithm);
if (algorithm == CompressionAlgorithm.Deflate) switch (algorithm)
{ {
case CompressionAlgorithm.None:
break;
case CompressionAlgorithm.Deflate:
_activeStream = new DeflateStream(_stream, CompressionLevel.Fastest, true); _activeStream = new DeflateStream(_stream, CompressionLevel.Fastest, true);
break;
case CompressionAlgorithm.Brotli:
_activeStream = new BrotliStream(_stream, CompressionLevel.Fastest, true);
break;
default:
throw new ArgumentException($"Invalid compression algorithm \"{algorithm}\"");
} }
} }
@ -187,6 +203,14 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
} }
stream.Dispose(); stream.Dispose();
break; break;
case CompressionAlgorithm.Brotli:
stream = new BrotliStream(stream, CompressionMode.Decompress, true);
for (int offset = 0; offset < data.Length;)
{
offset += stream.Read(data[offset..]);
}
stream.Dispose();
break;
} }
} }
@ -210,6 +234,11 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
stream.Write(data); stream.Write(data);
stream.Dispose(); stream.Dispose();
break; break;
case CompressionAlgorithm.Brotli:
stream = new BrotliStream(stream, CompressionLevel.Optimal, true);
stream.Write(data);
stream.Dispose();
break;
} }
} }
} }

View file

@ -14,5 +14,10 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
/// Deflate compression (RFC 1951). /// Deflate compression (RFC 1951).
/// </summary> /// </summary>
Deflate, Deflate,
/// <summary>
/// Brotli compression (RFC 7932).
/// </summary>
Brotli,
} }
} }

View file

@ -51,7 +51,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
/// <returns>Compression algorithm</returns> /// <returns>Compression algorithm</returns>
public static CompressionAlgorithm GetCompressionAlgorithm() public static CompressionAlgorithm GetCompressionAlgorithm()
{ {
return CompressionAlgorithm.Deflate; return CompressionAlgorithm.Brotli;
} }
} }
} }