From 3091b40691d767161c0265bab4bddb6687e3698d Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 10 Feb 2019 16:38:34 +0100 Subject: [PATCH] gl_shader_disk_cache: Compress precompiled shader cache file with Zstandard --- .../renderer_opengl/gl_shader_disk_cache.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp index 4c76f943f..3c39e5c8c 100644 --- a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp @@ -11,6 +11,7 @@ #include "common/file_util.h" #include "common/logging/log.h" #include "common/scm_rev.h" +#include "common/zstd_compression.h" #include "core/core.h" #include "core/hle/kernel/process.h" @@ -209,9 +210,11 @@ ShaderDiskCacheOpenGL::LoadPrecompiled() { std::optional, std::unordered_map>> ShaderDiskCacheOpenGL::LoadPrecompiledFile(FileUtil::IOFile& file) { - std::vector precompiled_cache(file.GetSize()); - file.ReadBytes(precompiled_cache.data(), precompiled_cache.size()); - SaveArrayToPrecompiled(precompiled_cache.data(), precompiled_cache.size()); + // Read compressed file from disk and decompress to virtual precompiled cache file + std::vector compressed(file.GetSize()); + file.ReadBytes(compressed.data(), compressed.size()); + const std::vector decompressed = Common::Compression::DecompressDataZSTD(compressed); + SaveArrayToPrecompiled(decompressed.data(), decompressed.size()); precompiled_cache_virtual_file_offset = 0; ShaderCacheVersionHash file_hash{}; @@ -564,7 +567,9 @@ void ShaderDiskCacheOpenGL::SavePrecompiledHeaderToVirtualPrecompiledCache() { void ShaderDiskCacheOpenGL::SaveVirtualPrecompiledFile() { precompiled_cache_virtual_file_offset = 0; - const std::vector& precompiled_cache = precompiled_cache_virtual_file.ReadAllBytes(); + const std::vector& uncompressed = precompiled_cache_virtual_file.ReadAllBytes(); + const std::vector& compressed = + Common::Compression::CompressDataZSTDDefault(uncompressed.data(), uncompressed.size()); const auto precompiled_path{GetPrecompiledPath()}; FileUtil::IOFile file(precompiled_path, "wb"); @@ -573,8 +578,7 @@ void ShaderDiskCacheOpenGL::SaveVirtualPrecompiledFile() { LOG_ERROR(Render_OpenGL, "Failed to open precompiled cache in path={}", precompiled_path); return; } - if (file.WriteBytes(precompiled_cache.data(), precompiled_cache.size()) != - precompiled_cache.size()) { + if (file.WriteBytes(compressed.data(), compressed.size()) != compressed.size()) { LOG_ERROR(Render_OpenGL, "Failed to write precompiled cache version in path={}", precompiled_path); return;