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 78efb46d5d..0cd6dbc15a 100644 --- a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp @@ -203,22 +203,22 @@ ShaderDiskCache::LoadPrecompiledFile(FileUtil::IOFile& file) { 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; + decompressed_precompiled_cache_offset = 0; ShaderCacheVersionHash file_hash{}; if (!LoadArrayFromPrecompiled(file_hash.data(), file_hash.size())) { - precompiled_cache_virtual_file_offset = 0; + decompressed_precompiled_cache_offset = 0; return {}; } if (GetShaderCacheVersionHash() != file_hash) { LOG_INFO(Render_OpenGL, "Precompiled cache is from another version of the emulator"); - precompiled_cache_virtual_file_offset = 0; + decompressed_precompiled_cache_offset = 0; return {}; } std::unordered_map decompiled; ShaderDumpsMap dumps; - while (precompiled_cache_virtual_file_offset < precompiled_cache_virtual_file.GetSize()) { + while (decompressed_precompiled_cache_offset < decompressed_precompiled_cache.size()) { PrecompiledEntryKind kind{}; if (!LoadObjectFromPrecompiled(kind)) { return {}; @@ -308,7 +308,7 @@ void ShaderDiskCache::InvalidateTransferable() { void ShaderDiskCache::InvalidatePrecompiled() { // Clear virtaul precompiled cache file - precompiled_cache_virtual_file.Resize(0); + decompressed_precompiled_cache.resize(0); if (!FileUtil::Delete(GetPrecompiledPath())) { LOG_ERROR(Render_OpenGL, "Failed to invalidate precompiled file={}", GetPrecompiledPath()); @@ -342,7 +342,7 @@ void ShaderDiskCache::SaveDecompiled(u64 unique_identifier, if (!IsUsable()) return; - if (precompiled_cache_virtual_file.GetSize() == 0) { + if (decompressed_precompiled_cache.size() == 0) { SavePrecompiledHeaderToVirtualPrecompiledCache(); } @@ -413,10 +413,9 @@ void ShaderDiskCache::SavePrecompiledHeaderToVirtualPrecompiledCache() { } void ShaderDiskCache::SaveVirtualPrecompiledFile() { - precompiled_cache_virtual_file_offset = 0; - const std::vector& uncompressed = precompiled_cache_virtual_file.ReadAllBytes(); - const std::vector& compressed = - Common::Compression::CompressDataZSTDDefault(uncompressed.data(), uncompressed.size()); + decompressed_precompiled_cache_offset = 0; + const std::vector& compressed = Common::Compression::CompressDataZSTDDefault( + decompressed_precompiled_cache.data(), decompressed_precompiled_cache.size()); const auto precompiled_path{GetPrecompiledPath()}; FileUtil::IOFile file(precompiled_path, "wb"); @@ -486,4 +485,4 @@ std::string ShaderDiskCache::GetTitleID() { return title_id; } -} // namespace OpenGL \ No newline at end of file +} // namespace OpenGL diff --git a/src/video_core/renderer_opengl/gl_shader_disk_cache.h b/src/video_core/renderer_opengl/gl_shader_disk_cache.h index c74eb60cc5..5e2779ef6e 100644 --- a/src/video_core/renderer_opengl/gl_shader_disk_cache.h +++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.h @@ -4,6 +4,7 @@ #pragma once +#include #include #include #include @@ -18,7 +19,6 @@ #include "common/assert.h" #include "common/common_types.h" -#include "common/vfs/vfs_vector.h" #include "video_core/regs.h" #include "video_core/renderer_opengl/gl_shader_decompiler.h" #include "video_core/renderer_opengl/gl_shader_gen.h" @@ -163,18 +163,20 @@ private: template bool SaveArrayToPrecompiled(const T* data, std::size_t length) { - const std::size_t write_length = precompiled_cache_virtual_file.WriteArray( - data, length, precompiled_cache_virtual_file_offset); - precompiled_cache_virtual_file_offset += write_length; - return write_length == sizeof(T) * length; + const u8* data_view = reinterpret_cast(data); + decompressed_precompiled_cache.insert(decompressed_precompiled_cache.end(), &data_view[0], + &data_view[length * sizeof(T)]); + decompressed_precompiled_cache_offset += length * sizeof(T); + return true; } template bool LoadArrayFromPrecompiled(T* data, std::size_t length) { - const std::size_t read_length = precompiled_cache_virtual_file.ReadArray( - data, length, precompiled_cache_virtual_file_offset); - precompiled_cache_virtual_file_offset += read_length; - return read_length == sizeof(T) * length; + u8* data_view = reinterpret_cast(data); + std::copy_n(decompressed_precompiled_cache.data() + decompressed_precompiled_cache_offset, + length * sizeof(T), data_view); + decompressed_precompiled_cache_offset += length * sizeof(T); + return true; } template @@ -194,9 +196,9 @@ private: // Stores whole precompiled cache which will be read from or saved to the precompiled chache // file - Common::VectorVfsFile precompiled_cache_virtual_file; + std::vector decompressed_precompiled_cache; // Stores the current offset of the precompiled cache file for IO purposes - std::size_t precompiled_cache_virtual_file_offset = 0; + std::size_t decompressed_precompiled_cache_offset = 0; // Stored transferable shaders std::unordered_map transferable; @@ -210,4 +212,4 @@ private: std::string title_id; }; -} // namespace OpenGL \ No newline at end of file +} // namespace OpenGL