update solution to new SDK

This commit is contained in:
Nayla Hanegan 2023-06-23 13:23:34 -04:00
commit d9fab5b727
No known key found for this signature in database
GPG key ID: 3075216CED0DB01D
45 changed files with 53 additions and 156 deletions

View file

@ -151,111 +151,9 @@ void HiresTexture::Update()
void HiresTexture::Clear()
{
if (s_prefetcher.joinable())
{
s_textureCacheAbortLoading.Set();
s_prefetcher.join();
}
s_textureMap.clear();
s_textureCache.clear();
}
void HiresTexture::Prefetch()
{
Common::SetCurrentThreadName("Prefetcher");
size_t size_sum = 0;
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
const size_t max_mem =
(sys_mem / 2 < recommended_min_mem) ? (sys_mem / 2) : (sys_mem - recommended_min_mem);
Common::Timer timer;
timer.Start();
for (const auto& entry : s_textureMap)
{
const std::string& base_filename = entry.first;
if (base_filename.find("_mip") == std::string::npos)
{
std::unique_lock<std::mutex> lk(s_textureCacheMutex);
auto iter = s_textureCache.find(base_filename);
if (iter == s_textureCache.end())
{
// unlock while loading a texture. This may result in a race condition where
// we'll load a texture twice, but it reduces the stuttering a lot.
lk.unlock();
std::unique_ptr<HiresTexture> texture = Load(base_filename, 0, 0);
lk.lock();
if (texture)
{
std::shared_ptr<HiresTexture> ptr(std::move(texture));
iter = s_textureCache.insert(iter, std::make_pair(base_filename, ptr));
}
}
if (iter != s_textureCache.end())
{
for (const VideoCommon::CustomTextureData::Level& l : iter->second->m_data.m_levels)
size_sum += l.data.size();
}
}
if (s_textureCacheAbortLoading.IsSet())
{
return;
}
if (size_sum > max_mem)
{
Config::SetCurrent(Config::GFX_HIRES_TEXTURES, true);
OSD::AddMessage(
fmt::format(
"Custom Textures prefetching after {:.1f} MB aborted, not enough RAM available",
size_sum / (1024.0 * 1024.0)),
10000);
return;
}
}
OSD::AddMessage(fmt::format("Custom Textures loaded, {:.1f} MB in {:.1f}s",
size_sum / (1024.0 * 1024.0), timer.ElapsedMs() / 1000.0),
10000);
}
std::string HiresTexture::GenBaseName(const TextureInfo& texture_info, bool dump)
{
if (!dump && s_textureMap.empty())
return "";
const auto texture_name_details = texture_info.CalculateTextureName();
// look for an exact match first
const std::string full_name = texture_name_details.GetFullName();
if (dump || s_textureMap.find(full_name) != s_textureMap.end())
return full_name;
// else try and find a wildcard
if (!dump)
{
// Single wildcard ignoring the tlut hash
const std::string texture_name_single_wildcard_tlut =
fmt::format("{}_{}_$_{}", texture_name_details.base_name, texture_name_details.texture_name,
texture_name_details.format_name);
if (s_textureMap.find(texture_name_single_wildcard_tlut) != s_textureMap.end())
return texture_name_single_wildcard_tlut;
// Single wildcard ignoring the texture hash
const std::string texture_name_single_wildcard_tex =
fmt::format("{}_${}_{}", texture_name_details.base_name, texture_name_details.tlut_name,
texture_name_details.format_name);
if (s_textureMap.find(texture_name_single_wildcard_tex) != s_textureMap.end())
return texture_name_single_wildcard_tex;
}
return "";
s_hires_texture_cache.clear();
s_hires_texture_id_to_arbmipmap.clear();
s_file_library = std::make_shared<VideoCommon::DirectFilesystemAssetLibrary>();
}
std::shared_ptr<HiresTexture> HiresTexture::Search(const TextureInfo& texture_info)