mirror of
https://github.com/yuzu-mirror/yuzu
synced 2024-12-21 01:23:12 +00:00
gl_shader_disk_cache: Compress precompiled shader cache file with Zstandard
This commit is contained in:
parent
9db2c734c9
commit
3091b40691
1 changed files with 10 additions and 6 deletions
|
@ -11,6 +11,7 @@
|
||||||
#include "common/file_util.h"
|
#include "common/file_util.h"
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "common/scm_rev.h"
|
#include "common/scm_rev.h"
|
||||||
|
#include "common/zstd_compression.h"
|
||||||
|
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/hle/kernel/process.h"
|
#include "core/hle/kernel/process.h"
|
||||||
|
@ -209,9 +210,11 @@ ShaderDiskCacheOpenGL::LoadPrecompiled() {
|
||||||
std::optional<std::pair<std::unordered_map<u64, ShaderDiskCacheDecompiled>,
|
std::optional<std::pair<std::unordered_map<u64, ShaderDiskCacheDecompiled>,
|
||||||
std::unordered_map<ShaderDiskCacheUsage, ShaderDiskCacheDump>>>
|
std::unordered_map<ShaderDiskCacheUsage, ShaderDiskCacheDump>>>
|
||||||
ShaderDiskCacheOpenGL::LoadPrecompiledFile(FileUtil::IOFile& file) {
|
ShaderDiskCacheOpenGL::LoadPrecompiledFile(FileUtil::IOFile& file) {
|
||||||
std::vector<u8> precompiled_cache(file.GetSize());
|
// Read compressed file from disk and decompress to virtual precompiled cache file
|
||||||
file.ReadBytes(precompiled_cache.data(), precompiled_cache.size());
|
std::vector<u8> compressed(file.GetSize());
|
||||||
SaveArrayToPrecompiled(precompiled_cache.data(), precompiled_cache.size());
|
file.ReadBytes(compressed.data(), compressed.size());
|
||||||
|
const std::vector<u8> decompressed = Common::Compression::DecompressDataZSTD(compressed);
|
||||||
|
SaveArrayToPrecompiled(decompressed.data(), decompressed.size());
|
||||||
precompiled_cache_virtual_file_offset = 0;
|
precompiled_cache_virtual_file_offset = 0;
|
||||||
|
|
||||||
ShaderCacheVersionHash file_hash{};
|
ShaderCacheVersionHash file_hash{};
|
||||||
|
@ -564,7 +567,9 @@ void ShaderDiskCacheOpenGL::SavePrecompiledHeaderToVirtualPrecompiledCache() {
|
||||||
|
|
||||||
void ShaderDiskCacheOpenGL::SaveVirtualPrecompiledFile() {
|
void ShaderDiskCacheOpenGL::SaveVirtualPrecompiledFile() {
|
||||||
precompiled_cache_virtual_file_offset = 0;
|
precompiled_cache_virtual_file_offset = 0;
|
||||||
const std::vector<u8>& precompiled_cache = precompiled_cache_virtual_file.ReadAllBytes();
|
const std::vector<u8>& uncompressed = precompiled_cache_virtual_file.ReadAllBytes();
|
||||||
|
const std::vector<u8>& compressed =
|
||||||
|
Common::Compression::CompressDataZSTDDefault(uncompressed.data(), uncompressed.size());
|
||||||
|
|
||||||
const auto precompiled_path{GetPrecompiledPath()};
|
const auto precompiled_path{GetPrecompiledPath()};
|
||||||
FileUtil::IOFile file(precompiled_path, "wb");
|
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);
|
LOG_ERROR(Render_OpenGL, "Failed to open precompiled cache in path={}", precompiled_path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (file.WriteBytes(precompiled_cache.data(), precompiled_cache.size()) !=
|
if (file.WriteBytes(compressed.data(), compressed.size()) != compressed.size()) {
|
||||||
precompiled_cache.size()) {
|
|
||||||
LOG_ERROR(Render_OpenGL, "Failed to write precompiled cache version in path={}",
|
LOG_ERROR(Render_OpenGL, "Failed to write precompiled cache version in path={}",
|
||||||
precompiled_path);
|
precompiled_path);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue