1
0
Fork 0

Change VFS vector to regular vector

This commit is contained in:
James Rowe 2019-09-09 18:27:01 -06:00
parent 6f2756089d
commit a20c81d593
2 changed files with 24 additions and 23 deletions

View File

@ -203,22 +203,22 @@ ShaderDiskCache::LoadPrecompiledFile(FileUtil::IOFile& file) {
file.ReadBytes(compressed.data(), compressed.size()); file.ReadBytes(compressed.data(), compressed.size());
const std::vector<u8> decompressed = Common::Compression::DecompressDataZSTD(compressed); const std::vector<u8> decompressed = Common::Compression::DecompressDataZSTD(compressed);
SaveArrayToPrecompiled(decompressed.data(), decompressed.size()); SaveArrayToPrecompiled(decompressed.data(), decompressed.size());
precompiled_cache_virtual_file_offset = 0; decompressed_precompiled_cache_offset = 0;
ShaderCacheVersionHash file_hash{}; ShaderCacheVersionHash file_hash{};
if (!LoadArrayFromPrecompiled(file_hash.data(), file_hash.size())) { if (!LoadArrayFromPrecompiled(file_hash.data(), file_hash.size())) {
precompiled_cache_virtual_file_offset = 0; decompressed_precompiled_cache_offset = 0;
return {}; return {};
} }
if (GetShaderCacheVersionHash() != file_hash) { if (GetShaderCacheVersionHash() != file_hash) {
LOG_INFO(Render_OpenGL, "Precompiled cache is from another version of the emulator"); 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 {}; return {};
} }
std::unordered_map<u64, ShaderDiskCacheDecompiled> decompiled; std::unordered_map<u64, ShaderDiskCacheDecompiled> decompiled;
ShaderDumpsMap dumps; ShaderDumpsMap dumps;
while (precompiled_cache_virtual_file_offset < precompiled_cache_virtual_file.GetSize()) { while (decompressed_precompiled_cache_offset < decompressed_precompiled_cache.size()) {
PrecompiledEntryKind kind{}; PrecompiledEntryKind kind{};
if (!LoadObjectFromPrecompiled(kind)) { if (!LoadObjectFromPrecompiled(kind)) {
return {}; return {};
@ -308,7 +308,7 @@ void ShaderDiskCache::InvalidateTransferable() {
void ShaderDiskCache::InvalidatePrecompiled() { void ShaderDiskCache::InvalidatePrecompiled() {
// Clear virtaul precompiled cache file // Clear virtaul precompiled cache file
precompiled_cache_virtual_file.Resize(0); decompressed_precompiled_cache.resize(0);
if (!FileUtil::Delete(GetPrecompiledPath())) { if (!FileUtil::Delete(GetPrecompiledPath())) {
LOG_ERROR(Render_OpenGL, "Failed to invalidate precompiled file={}", GetPrecompiledPath()); LOG_ERROR(Render_OpenGL, "Failed to invalidate precompiled file={}", GetPrecompiledPath());
@ -342,7 +342,7 @@ void ShaderDiskCache::SaveDecompiled(u64 unique_identifier,
if (!IsUsable()) if (!IsUsable())
return; return;
if (precompiled_cache_virtual_file.GetSize() == 0) { if (decompressed_precompiled_cache.size() == 0) {
SavePrecompiledHeaderToVirtualPrecompiledCache(); SavePrecompiledHeaderToVirtualPrecompiledCache();
} }
@ -413,10 +413,9 @@ void ShaderDiskCache::SavePrecompiledHeaderToVirtualPrecompiledCache() {
} }
void ShaderDiskCache::SaveVirtualPrecompiledFile() { void ShaderDiskCache::SaveVirtualPrecompiledFile() {
precompiled_cache_virtual_file_offset = 0; decompressed_precompiled_cache_offset = 0;
const std::vector<u8>& uncompressed = precompiled_cache_virtual_file.ReadAllBytes(); const std::vector<u8>& compressed = Common::Compression::CompressDataZSTDDefault(
const std::vector<u8>& compressed = decompressed_precompiled_cache.data(), decompressed_precompiled_cache.size());
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");
@ -486,4 +485,4 @@ std::string ShaderDiskCache::GetTitleID() {
return title_id; return title_id;
} }
} // namespace OpenGL } // namespace OpenGL

View File

@ -4,6 +4,7 @@
#pragma once #pragma once
#include <algorithm>
#include <array> #include <array>
#include <bitset> #include <bitset>
#include <optional> #include <optional>
@ -18,7 +19,6 @@
#include "common/assert.h" #include "common/assert.h"
#include "common/common_types.h" #include "common/common_types.h"
#include "common/vfs/vfs_vector.h"
#include "video_core/regs.h" #include "video_core/regs.h"
#include "video_core/renderer_opengl/gl_shader_decompiler.h" #include "video_core/renderer_opengl/gl_shader_decompiler.h"
#include "video_core/renderer_opengl/gl_shader_gen.h" #include "video_core/renderer_opengl/gl_shader_gen.h"
@ -163,18 +163,20 @@ private:
template <typename T> template <typename T>
bool SaveArrayToPrecompiled(const T* data, std::size_t length) { bool SaveArrayToPrecompiled(const T* data, std::size_t length) {
const std::size_t write_length = precompiled_cache_virtual_file.WriteArray( const u8* data_view = reinterpret_cast<const u8*>(data);
data, length, precompiled_cache_virtual_file_offset); decompressed_precompiled_cache.insert(decompressed_precompiled_cache.end(), &data_view[0],
precompiled_cache_virtual_file_offset += write_length; &data_view[length * sizeof(T)]);
return write_length == sizeof(T) * length; decompressed_precompiled_cache_offset += length * sizeof(T);
return true;
} }
template <typename T> template <typename T>
bool LoadArrayFromPrecompiled(T* data, std::size_t length) { bool LoadArrayFromPrecompiled(T* data, std::size_t length) {
const std::size_t read_length = precompiled_cache_virtual_file.ReadArray( u8* data_view = reinterpret_cast<u8*>(data);
data, length, precompiled_cache_virtual_file_offset); std::copy_n(decompressed_precompiled_cache.data() + decompressed_precompiled_cache_offset,
precompiled_cache_virtual_file_offset += read_length; length * sizeof(T), data_view);
return read_length == sizeof(T) * length; decompressed_precompiled_cache_offset += length * sizeof(T);
return true;
} }
template <typename T> template <typename T>
@ -194,9 +196,9 @@ private:
// Stores whole precompiled cache which will be read from or saved to the precompiled chache // Stores whole precompiled cache which will be read from or saved to the precompiled chache
// file // file
Common::VectorVfsFile precompiled_cache_virtual_file; std::vector<u8> decompressed_precompiled_cache;
// Stores the current offset of the precompiled cache file for IO purposes // 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 // Stored transferable shaders
std::unordered_map<u64, ShaderDiskCacheRaw> transferable; std::unordered_map<u64, ShaderDiskCacheRaw> transferable;
@ -210,4 +212,4 @@ private:
std::string title_id; std::string title_id;
}; };
} // namespace OpenGL } // namespace OpenGL