Texture_Cache: Update resolution scaler profile

This commit is contained in:
Fernando Sahmkow
2019-07-06 18:15:39 -04:00
committed by FernandoS27
parent e1a86c2abc
commit 1cfd3ff034
5 changed files with 96 additions and 10 deletions

View File

@@ -36,6 +36,7 @@
#define LOAD_DIR "load"
#define DUMP_DIR "dump"
#define SHADER_DIR "shader"
#define RESCALING_DIR "rescaling"
#define LOG_DIR "log"
// Filenames

View File

@@ -695,6 +695,7 @@ const std::string& GetUserPath(UserPath path, const std::string& new_path) {
paths.emplace(UserPath::LoadDir, user_path + LOAD_DIR DIR_SEP);
paths.emplace(UserPath::DumpDir, user_path + DUMP_DIR DIR_SEP);
paths.emplace(UserPath::ShaderDir, user_path + SHADER_DIR DIR_SEP);
paths.emplace(UserPath::RescalingDir, user_path + RESCALING_DIR DIR_SEP);
paths.emplace(UserPath::SysDataDir, user_path + SYSDATA_DIR DIR_SEP);
paths.emplace(UserPath::KeysDir, user_path + KEYS_DIR DIR_SEP);
// TODO: Put the logs in a better location for each OS

View File

@@ -33,6 +33,7 @@ enum class UserPath {
LoadDir,
DumpDir,
ShaderDir,
RescalingDir,
SysDataDir,
UserDir,
};

View File

@@ -0,0 +1,74 @@
// Copyright 2019 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <fstream>
#include <json.hpp>
#include "core/core.h"
#include "core/hle/kernel/process.h"
#include "video_core/texture_cache/resolution_scaling/database.h"
namespace VideoCommon::Resolution {
explicit ScalingDatabase::ScalingDatabase(Core::System& system) : database{}, blacklist{}, system{system} {
title_id = system.CurrentProcess()->GetTitleID();
}
ScalingDatabase::~ScalingDatabase() {
SaveDatabase();
}
void ScalingDatabase::SaveDatabase() {
json out;
out["version"] = DBVersion;
auto entries = json::array();
for (const auto& pair : database) {
const auto [key, value] = pair;
if (value) {
entries.push_back({
{"format", static_cast<u32>(key.format)},
{"width", key.width},
{"height", key.height},
});
}
}
out["entries"] = std::move(entries);
std::ofstream file(GetProfilePath());
file << std::setw(4) << out << std::endl;
}
void ScalingDatabase::Register(const PixelFormat format, const u32 width, const u32 height) {
if (blacklist.count(key) == 0) {
ResolutionKey key{format, width, height};
database.emplace(key, false);
}
}
void MarkRendered(const PixelFormat format, const u32 width, const u32 height) {
ResolutionKey key{format, width, height};
auto search = database.find(key);
if (search != database.end()) {
search->second = true;
}
}
void ScalingDatabase::Unregister(const PixelFormat format, const u32 width, const u32 height) {
ResolutionKey key{format, width, height};
database.erase(key);
blacklist.insert(key);
}
std::string GetBaseDir() const {
return FileUtil::GetUserPath(FileUtil::UserPath::RescalingDir);
}
std::string ScalingDatabase::GetTitleID() const {
return fmt::format("{:016X}", title_id);
}
std::string ScalingDatabase::GetProfilePath() const {
return FileUtil::SanitizePath(GetBaseDir() + DIR_SEP_CHR + GetTitleID() + ".json");
}
} // namespace VideoCommon::Resolution

View File

@@ -7,6 +7,10 @@
#include <unordered_set>
#include "video_core/surface.h"
namespace Core {
class System;
}
namespace VideoCommon::Resolution {
using VideoCore::Surface::PixelFormat;
@@ -44,25 +48,30 @@ namespace VideoCommon::Resolution {
class ScalingDatabase {
public:
explicit ScalingDatabase() : database{} {}
explicit ScalingDatabase(Core::System& system);
~ScalingDatabase();
void SaveDatabase();
bool IsInDatabase(const PixelFormat format, const u32 width, const u32 height) {
ResolutionKey key{format, width, height};
return database.count(key) > 0;
}
void Register(const PixelFormat format, const u32 width, const u32 height) {
ResolutionKey key{format, width, height};
database.insert(key);
}
void MarkRendered(const PixelFormat format, const u32 width, const u32 height);
void Register(const PixelFormat format, const u32 width, const u32 height);
void Unregister(const PixelFormat format, const u32 width, const u32 height);
void Unregister(const PixelFormat format, const u32 width, const u32 height) {
ResolutionKey key{format, width, height};
database.erase(key);
}
std::string GetTitleID() const;
std::string GetProfilePath() const;
private:
std::unordered_set<ResolutionKey> database;
std::unordered_map<ResolutionKey, bool> database;
std::unordered_set<ResolutionKey> blacklist;
u64 title_id;
Core::System& system;
static constexpr u32 DBVersion = 1;
};
} // namespace VideoCommon::Resolution