summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/HiresTextures.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Core/VideoCommon/HiresTextures.cpp')
-rw-r--r--Source/Core/VideoCommon/HiresTextures.cpp58
1 files changed, 32 insertions, 26 deletions
diff --git a/Source/Core/VideoCommon/HiresTextures.cpp b/Source/Core/VideoCommon/HiresTextures.cpp
index 70b9df00be..d70a6ab44e 100644
--- a/Source/Core/VideoCommon/HiresTextures.cpp
+++ b/Source/Core/VideoCommon/HiresTextures.cpp
@@ -5,22 +5,22 @@
#include "VideoCommon/HiresTextures.h"
#include <algorithm>
-#include <cinttypes>
-#include <cstring>
#include <memory>
#include <mutex>
#include <string>
+#include <string_view>
#include <thread>
#include <unordered_map>
#include <utility>
#include <vector>
#include <xxhash.h>
+#include <fmt/format.h>
+
#include "Common/File.h"
#include "Common/FileSearch.h"
#include "Common/FileUtil.h"
#include "Common/Flag.h"
-#include "Common/Hash.h"
#include "Common/Image.h"
#include "Common/Logging/Log.h"
#include "Common/MemoryUtil.h"
@@ -39,6 +39,8 @@ struct DiskTexture
bool has_arbitrary_mipmaps;
};
+constexpr std::string_view s_format_prefix{"tex1_"};
+
static std::unordered_map<std::string, DiskTexture> s_textureMap;
static std::unordered_map<std::string, std::shared_ptr<HiresTexture>> s_textureCache;
static std::mutex s_textureCacheMutex;
@@ -46,8 +48,6 @@ static Common::Flag s_textureCacheAbortLoading;
static std::thread s_prefetcher;
-static const std::string s_format_prefix = "tex1_";
-
void HiresTexture::Init()
{
Update();
@@ -135,12 +135,13 @@ void HiresTexture::Prefetch()
Common::SetCurrentThreadName("Prefetcher");
size_t size_sum = 0;
- size_t sys_mem = Common::MemPhysical();
- size_t recommended_min_mem = 2 * size_t(1024 * 1024 * 1024);
+ const size_t sys_mem = Common::MemPhysical();
+ const size_t recommended_min_mem = 2 * size_t(1024 * 1024 * 1024);
// keep 2GB memory for system stability if system RAM is 4GB+ - use half of memory in other cases
- size_t max_mem =
+ const size_t max_mem =
(sys_mem / 2 < recommended_min_mem) ? (sys_mem / 2) : (sys_mem - recommended_min_mem);
- u32 starttime = Common::Timer::GetTimeMs();
+
+ const u32 start_time = Common::Timer::GetTimeMs();
for (const auto& entry : s_textureMap)
{
const std::string& base_filename = entry.first;
@@ -180,16 +181,17 @@ void HiresTexture::Prefetch()
Config::SetCurrent(Config::GFX_HIRES_TEXTURES, false);
OSD::AddMessage(
- StringFromFormat(
- "Custom Textures prefetching after %.1f MB aborted, not enough RAM available",
+ fmt::format(
+ "Custom Textures prefetching after {:.1f} MB aborted, not enough RAM available",
size_sum / (1024.0 * 1024.0)),
10000);
return;
}
}
- u32 stoptime = Common::Timer::GetTimeMs();
- OSD::AddMessage(StringFromFormat("Custom Textures loaded, %.1f MB in %.1f s",
- size_sum / (1024.0 * 1024.0), (stoptime - starttime) / 1000.0),
+
+ const u32 stop_time = Common::Timer::GetTimeMs();
+ OSD::AddMessage(fmt::format("Custom Textures loaded, {:.1f} MB in {:.1f}s",
+ size_sum / (1024.0 * 1024.0), (stop_time - start_time) / 1000.0),
10000);
}
@@ -244,22 +246,26 @@ std::string HiresTexture::GenBaseName(const u8* texture, size_t texture_size, co
tlut += 2 * min;
}
- u64 tex_hash = XXH64(texture, texture_size, 0);
- u64 tlut_hash = tlut_size ? XXH64(tlut, tlut_size, 0) : 0;
+ const u64 tex_hash = XXH64(texture, texture_size, 0);
+ const u64 tlut_hash = tlut_size ? XXH64(tlut, tlut_size, 0) : 0;
- std::string basename = s_format_prefix + StringFromFormat("%dx%d%s_%016" PRIx64, width, height,
- has_mipmaps ? "_m" : "", tex_hash);
- std::string tlutname = tlut_size ? StringFromFormat("_%016" PRIx64, tlut_hash) : "";
- std::string formatname = StringFromFormat("_%d", static_cast<int>(format));
- std::string fullname = basename + tlutname + formatname;
+ const std::string base_name = fmt::format("{}{}x{}{}_{:016x}", s_format_prefix, width, height,
+ has_mipmaps ? "_m" : "", tex_hash);
+ const std::string tlut_name = tlut_size ? fmt::format("_{:016x}", tlut_hash) : "";
+ const std::string format_name = fmt::format("_{}", static_cast<int>(format));
+ const std::string full_name = base_name + tlut_name + format_name;
// try to match a wildcard template
- if (!dump && s_textureMap.find(basename + "_$" + formatname) != s_textureMap.end())
- return basename + "_$" + formatname;
+ if (!dump)
+ {
+ const std::string texture_name = fmt::format("{}_${}", base_name, format_name);
+ if (s_textureMap.find(texture_name) != s_textureMap.end())
+ return texture_name;
+ }
// else generate the complete texture
- if (dump || s_textureMap.find(fullname) != s_textureMap.end())
- return fullname;
+ if (dump || s_textureMap.find(full_name) != s_textureMap.end())
+ return full_name;
return "";
}
@@ -326,7 +332,7 @@ std::unique_ptr<HiresTexture> HiresTexture::Load(const std::string& base_filenam
{
std::string filename = base_filename;
if (mip_level != 0)
- filename += StringFromFormat("_mip%u", mip_level);
+ filename += fmt::format("_mip{}", mip_level);
filename_iter = s_textureMap.find(filename);
if (filename_iter == s_textureMap.end())