gl_shader_disk_cache: Pass return values returning instead of by parameters

This commit is contained in:
ReinUsesLisp 2019-01-15 02:17:38 -03:00
parent ed956569a4
commit 8ee3666a3c
3 changed files with 36 additions and 38 deletions

View File

@ -344,17 +344,15 @@ ShaderDiskCacheUsage CachedShader::GetUsage(GLenum primitive_mode,
ShaderCacheOpenGL::ShaderCacheOpenGL(RasterizerOpenGL& rasterizer) : RasterizerCache{rasterizer} {}
void ShaderCacheOpenGL::LoadDiskCache() {
std::vector<ShaderDiskCacheRaw> raws;
std::vector<ShaderDiskCacheUsage> usages;
if (!disk_cache.LoadTransferable(raws, usages)) {
const auto transferable = disk_cache.LoadTransferable();
if (!transferable) {
return;
}
const auto [raws, usages] = *transferable;
std::map<u64, ShaderDiskCacheDecompiled> decompiled;
std::map<ShaderDiskCacheUsage, ShaderDiskCacheDump> dumps;
disk_cache.LoadPrecompiled(decompiled, dumps);
auto [decompiled, dumps] = disk_cache.LoadPrecompiled();
const std::set<GLenum> supported_formats{GetSupportedFormats()};
const auto supported_formats{GetSupportedFormats()};
const auto unspecialized{GenerateUnspecializedShaders(raws, decompiled)};
// Build shaders

View File

@ -111,17 +111,17 @@ void ShaderDiskCacheRaw::Save(FileUtil::IOFile& file) const {
}
}
bool ShaderDiskCacheOpenGL::LoadTransferable(std::vector<ShaderDiskCacheRaw>& raws,
std::vector<ShaderDiskCacheUsage>& usages) {
std::optional<std::pair<std::vector<ShaderDiskCacheRaw>, std::vector<ShaderDiskCacheUsage>>>
ShaderDiskCacheOpenGL::LoadTransferable() {
if (!Settings::values.use_disk_shader_cache) {
return false;
return {};
}
FileUtil::IOFile file(GetTransferablePath(), "rb");
if (!file.IsOpen()) {
LOG_INFO(Render_OpenGL, "No transferable shader cache found for game with title id={}",
GetTitleID());
return false;
return {};
}
const u64 file_size = file.GetSize();
@ -132,15 +132,17 @@ bool ShaderDiskCacheOpenGL::LoadTransferable(std::vector<ShaderDiskCacheRaw>& ra
LOG_INFO(Render_OpenGL, "Transferable shader cache is old - removing");
file.Close();
FileUtil::Delete(GetTransferablePath());
return false;
return {};
}
if (version > NativeVersion) {
LOG_WARNING(Render_OpenGL, "Transferable shader cache was generated with a newer version "
"of the emulator - skipping");
return false;
return {};
}
// Version is valid, load the shaders
std::vector<ShaderDiskCacheRaw> raws;
std::vector<ShaderDiskCacheUsage> usages;
while (file.Tell() < file_size) {
TransferableEntryKind kind{};
file.ReadBytes(&kind, sizeof(u32));
@ -161,25 +163,24 @@ bool ShaderDiskCacheOpenGL::LoadTransferable(std::vector<ShaderDiskCacheRaw>& ra
default:
LOG_ERROR(Render_OpenGL, "Unknown transferable shader cache entry kind={} - aborting",
static_cast<u32>(kind));
return false;
return {};
}
}
return true;
return {{raws, usages}};
}
bool ShaderDiskCacheOpenGL::LoadPrecompiled(
std::map<u64, ShaderDiskCacheDecompiled>& decompiled,
std::map<ShaderDiskCacheUsage, ShaderDiskCacheDump>& dumps) {
std::pair<std::map<u64, ShaderDiskCacheDecompiled>,
std::map<ShaderDiskCacheUsage, ShaderDiskCacheDump>>
ShaderDiskCacheOpenGL::LoadPrecompiled() {
if (!Settings::values.use_disk_shader_cache) {
return false;
return {};
}
FileUtil::IOFile file(GetPrecompiledPath(), "rb");
if (!file.IsOpen()) {
LOG_INFO(Render_OpenGL, "No precompiled shader cache found for game with title id={}",
GetTitleID());
return false;
return {};
}
const u64 file_size = file.GetSize();
@ -189,9 +190,11 @@ bool ShaderDiskCacheOpenGL::LoadPrecompiled(
LOG_INFO(Render_OpenGL, "Precompiled cache is from another version of yuzu - removing");
file.Close();
InvalidatePrecompiled();
return false;
return {};
}
std::map<u64, ShaderDiskCacheDecompiled> decompiled;
std::map<ShaderDiskCacheUsage, ShaderDiskCacheDump> dumps;
while (file.Tell() < file_size) {
PrecompiledEntryKind kind{};
file.ReadBytes(&kind, sizeof(u32));
@ -217,9 +220,7 @@ bool ShaderDiskCacheOpenGL::LoadPrecompiled(
"Failed to decompress GLSL code in precompiled shader={:016x} - removing",
unique_identifier);
InvalidatePrecompiled();
dumps.clear();
decompiled.clear();
return false;
return {};
}
entry.code = std::string(reinterpret_cast<const char*>(code.data()), code_size);
@ -294,9 +295,7 @@ bool ShaderDiskCacheOpenGL::LoadPrecompiled(
LOG_ERROR(Render_OpenGL,
"Failed to decompress precompiled binary program - removing");
InvalidatePrecompiled();
dumps.clear();
decompiled.clear();
return false;
return {};
}
dumps.insert({usage, dump});
@ -306,12 +305,10 @@ bool ShaderDiskCacheOpenGL::LoadPrecompiled(
LOG_ERROR(Render_OpenGL, "Unknown precompiled shader cache entry kind={} - removing",
static_cast<u32>(kind));
InvalidatePrecompiled();
dumps.clear();
decompiled.clear();
return false;
return {};
}
}
return true;
return {decompiled, dumps};
}
void ShaderDiskCacheOpenGL::InvalidateTransferable() const {

View File

@ -4,9 +4,11 @@
#pragma once
#include <optional>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <glad/glad.h>
@ -142,13 +144,14 @@ struct ShaderDiskCacheDump {
class ShaderDiskCacheOpenGL {
public:
/// Loads transferable cache. If file has a old version, it deletes it. Returns true on success.
bool LoadTransferable(std::vector<ShaderDiskCacheRaw>& raws,
std::vector<ShaderDiskCacheUsage>& usages);
/// Loads transferable cache. If file has a old version or on failure, it deletes the file.
std::optional<std::pair<std::vector<ShaderDiskCacheRaw>, std::vector<ShaderDiskCacheUsage>>>
LoadTransferable();
/// Loads current game's precompiled cache. Invalidates if emulator's version has changed.
bool LoadPrecompiled(std::map<u64, ShaderDiskCacheDecompiled>& decompiled,
std::map<ShaderDiskCacheUsage, ShaderDiskCacheDump>& dumps);
/// Loads current game's precompiled cache. Invalidates on failure.
std::pair<std::map<u64, ShaderDiskCacheDecompiled>,
std::map<ShaderDiskCacheUsage, ShaderDiskCacheDump>>
LoadPrecompiled();
/// Removes the transferable (and precompiled) cache file.
void InvalidateTransferable() const;