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

View File

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

View File

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