mirror of
https://github.com/yuzu-mirror/yuzu.git
synced 2024-11-18 13:17:33 +01:00
gl_shader_disk_cache: Remove per shader compression
This commit is contained in:
parent
8df9449bb8
commit
3fe542cf60
@ -247,20 +247,12 @@ ShaderDiskCacheOpenGL::LoadPrecompiledFile(FileUtil::IOFile& file) {
|
|||||||
return {};
|
return {};
|
||||||
|
|
||||||
u32 binary_length{};
|
u32 binary_length{};
|
||||||
u32 compressed_size{};
|
if (file.ReadBytes(&binary_length, sizeof(u32)) != sizeof(u32)) {
|
||||||
if (file.ReadBytes(&binary_length, sizeof(u32)) != sizeof(u32) ||
|
|
||||||
file.ReadBytes(&compressed_size, sizeof(u32)) != sizeof(u32)) {
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<u8> compressed_binary(compressed_size);
|
dump.binary.resize(binary_length);
|
||||||
if (file.ReadArray(compressed_binary.data(), compressed_binary.size()) !=
|
if (file.ReadArray(dump.binary.data(), binary_length) != binary_length) {
|
||||||
compressed_binary.size()) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
dump.binary = Common::Compression::DecompressDataZSTD(compressed_binary);
|
|
||||||
if (dump.binary.empty()) {
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,21 +269,15 @@ ShaderDiskCacheOpenGL::LoadPrecompiledFile(FileUtil::IOFile& file) {
|
|||||||
std::optional<ShaderDiskCacheDecompiled> ShaderDiskCacheOpenGL::LoadDecompiledEntry(
|
std::optional<ShaderDiskCacheDecompiled> ShaderDiskCacheOpenGL::LoadDecompiledEntry(
|
||||||
FileUtil::IOFile& file) {
|
FileUtil::IOFile& file) {
|
||||||
u32 code_size{};
|
u32 code_size{};
|
||||||
u32 compressed_code_size{};
|
if (file.ReadBytes(&code_size, sizeof(u32)) != sizeof(u32)) {
|
||||||
if (file.ReadBytes(&code_size, sizeof(u32)) != sizeof(u32) ||
|
|
||||||
file.ReadBytes(&compressed_code_size, sizeof(u32)) != sizeof(u32)) {
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<u8> compressed_code(compressed_code_size);
|
std::vector<u8> code(code_size);
|
||||||
if (file.ReadArray(compressed_code.data(), compressed_code.size()) != compressed_code.size()) {
|
if (file.ReadArray(code.data(), code.size()) != code_size) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<u8> code = Common::Compression::DecompressDataZSTD(compressed_code);
|
|
||||||
if (code.empty()) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
ShaderDiskCacheDecompiled entry;
|
ShaderDiskCacheDecompiled entry;
|
||||||
entry.code = std::string(reinterpret_cast<const char*>(code.data()), code_size);
|
entry.code = std::string(reinterpret_cast<const char*>(code.data()), code_size);
|
||||||
|
|
||||||
@ -369,13 +355,11 @@ std::optional<ShaderDiskCacheDecompiled> ShaderDiskCacheOpenGL::LoadDecompiledEn
|
|||||||
|
|
||||||
bool ShaderDiskCacheOpenGL::SaveDecompiledFile(FileUtil::IOFile& file, u64 unique_identifier,
|
bool ShaderDiskCacheOpenGL::SaveDecompiledFile(FileUtil::IOFile& file, u64 unique_identifier,
|
||||||
const std::string& code,
|
const std::string& code,
|
||||||
const std::vector<u8>& compressed_code,
|
|
||||||
const GLShader::ShaderEntries& entries) {
|
const GLShader::ShaderEntries& entries) {
|
||||||
if (file.WriteObject(static_cast<u32>(PrecompiledEntryKind::Decompiled)) != 1 ||
|
if (file.WriteObject(static_cast<u32>(PrecompiledEntryKind::Decompiled)) != 1 ||
|
||||||
file.WriteObject(unique_identifier) != 1 ||
|
file.WriteObject(unique_identifier) != 1 ||
|
||||||
file.WriteObject(static_cast<u32>(code.size())) != 1 ||
|
file.WriteObject(static_cast<u32>(code.size())) != 1 ||
|
||||||
file.WriteObject(static_cast<u32>(compressed_code.size())) != 1 ||
|
file.WriteArray(code.data(), code.size()) != code.size()) {
|
||||||
file.WriteArray(compressed_code.data(), compressed_code.size()) != compressed_code.size()) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -485,19 +469,12 @@ void ShaderDiskCacheOpenGL::SaveDecompiled(u64 unique_identifier, const std::str
|
|||||||
if (!IsUsable())
|
if (!IsUsable())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const std::vector<u8> compressed_code{Common::Compression::CompressDataZSTDDefault(
|
|
||||||
reinterpret_cast<const u8*>(code.data()), code.size())};
|
|
||||||
if (compressed_code.empty()) {
|
|
||||||
LOG_ERROR(Render_OpenGL, "Failed to compress GLSL code - skipping shader {:016x}",
|
|
||||||
unique_identifier);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
FileUtil::IOFile file = AppendPrecompiledFile();
|
FileUtil::IOFile file = AppendPrecompiledFile();
|
||||||
|
|
||||||
if (!file.IsOpen())
|
if (!file.IsOpen())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!SaveDecompiledFile(file, unique_identifier, code, compressed_code, entries)) {
|
if (!SaveDecompiledFile(file, unique_identifier, code, entries)) {
|
||||||
LOG_ERROR(Render_OpenGL,
|
LOG_ERROR(Render_OpenGL,
|
||||||
"Failed to save decompiled entry to the precompiled file - removing");
|
"Failed to save decompiled entry to the precompiled file - removing");
|
||||||
file.Close();
|
file.Close();
|
||||||
@ -516,25 +493,15 @@ void ShaderDiskCacheOpenGL::SaveDump(const ShaderDiskCacheUsage& usage, GLuint p
|
|||||||
std::vector<u8> binary(binary_length);
|
std::vector<u8> binary(binary_length);
|
||||||
glGetProgramBinary(program, binary_length, nullptr, &binary_format, binary.data());
|
glGetProgramBinary(program, binary_length, nullptr, &binary_format, binary.data());
|
||||||
|
|
||||||
const std::vector<u8> compressed_binary =
|
|
||||||
Common::Compression::CompressDataZSTDDefault(binary.data(), binary.size());
|
|
||||||
|
|
||||||
if (compressed_binary.empty()) {
|
|
||||||
LOG_ERROR(Render_OpenGL, "Failed to compress binary program in shader={:016x}",
|
|
||||||
usage.unique_identifier);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
FileUtil::IOFile file = AppendPrecompiledFile();
|
FileUtil::IOFile file = AppendPrecompiledFile();
|
||||||
|
|
||||||
if (!file.IsOpen())
|
if (!file.IsOpen())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (file.WriteObject(static_cast<u32>(PrecompiledEntryKind::Dump)) != 1 ||
|
if (file.WriteObject(static_cast<u32>(PrecompiledEntryKind::Dump)) != 1 ||
|
||||||
file.WriteObject(usage) != 1 || file.WriteObject(static_cast<u32>(binary_format)) != 1 ||
|
file.WriteObject(usage) != 1 || file.WriteObject(static_cast<u32>(binary_format)) != 1 ||
|
||||||
file.WriteObject(static_cast<u32>(binary_length)) != 1 ||
|
file.WriteObject(static_cast<u32>(binary_length)) != 1 ||
|
||||||
file.WriteObject(static_cast<u32>(compressed_binary.size())) != 1 ||
|
file.WriteArray(binary.data(), binary.size()) != binary_length) {
|
||||||
file.WriteArray(compressed_binary.data(), compressed_binary.size()) !=
|
|
||||||
compressed_binary.size()) {
|
|
||||||
LOG_ERROR(Render_OpenGL, "Failed to save binary program file in shader={:016x} - removing",
|
LOG_ERROR(Render_OpenGL, "Failed to save binary program file in shader={:016x} - removing",
|
||||||
usage.unique_identifier);
|
usage.unique_identifier);
|
||||||
file.Close();
|
file.Close();
|
||||||
|
@ -201,7 +201,6 @@ private:
|
|||||||
|
|
||||||
/// Saves a decompiled entry to the passed file. Returns true on success.
|
/// Saves a decompiled entry to the passed file. Returns true on success.
|
||||||
bool SaveDecompiledFile(FileUtil::IOFile& file, u64 unique_identifier, const std::string& code,
|
bool SaveDecompiledFile(FileUtil::IOFile& file, u64 unique_identifier, const std::string& code,
|
||||||
const std::vector<u8>& compressed_code,
|
|
||||||
const GLShader::ShaderEntries& entries);
|
const GLShader::ShaderEntries& entries);
|
||||||
|
|
||||||
/// Returns if the cache can be used
|
/// Returns if the cache can be used
|
||||||
|
Loading…
Reference in New Issue
Block a user