summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/TextureCacheBase.cpp
diff options
context:
space:
mode:
authorJMC47 <JMC4789@gmail.com>2025-06-07 15:51:34 -0400
committerGitHub <noreply@github.com>2025-06-07 15:51:34 -0400
commit52fcdde4852ccab197092da37b00548e33844d85 (patch)
tree02b438f5d1fa1c127f73bdb0a0f12c2678965435 /Source/Core/VideoCommon/TextureCacheBase.cpp
parent5eb61024c6e94b949ce21eac81003b43587fc155 (diff)
parentc3d3b8153388866117334cdc719889d1f676a16e (diff)
Merge pull request #13386 from iwubcode/resource_manager_system
VideoCommon: add resource manager, tracks resources to load assets in optimal way and manage memory
Diffstat (limited to 'Source/Core/VideoCommon/TextureCacheBase.cpp')
-rw-r--r--Source/Core/VideoCommon/TextureCacheBase.cpp124
1 files changed, 35 insertions, 89 deletions
diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp
index b370481c04..f58460e9ad 100644
--- a/Source/Core/VideoCommon/TextureCacheBase.cpp
+++ b/Source/Core/VideoCommon/TextureCacheBase.cpp
@@ -37,13 +37,14 @@
#include "VideoCommon/AbstractFramebuffer.h"
#include "VideoCommon/AbstractGfx.h"
#include "VideoCommon/AbstractStagingTexture.h"
+#include "VideoCommon/Assets/CustomResourceManager.h"
#include "VideoCommon/Assets/CustomTextureData.h"
+#include "VideoCommon/Assets/TextureAssetUtils.h"
#include "VideoCommon/BPMemory.h"
#include "VideoCommon/FramebufferManager.h"
#include "VideoCommon/GraphicsModSystem/Runtime/FBInfo.h"
#include "VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionData.h"
#include "VideoCommon/GraphicsModSystem/Runtime/GraphicsModManager.h"
-#include "VideoCommon/HiresTextures.h"
#include "VideoCommon/OpcodeDecoding.h"
#include "VideoCommon/PixelShaderManager.h"
#include "VideoCommon/Present.h"
@@ -262,25 +263,12 @@ void TextureCacheBase::SetBackupConfig(const VideoConfig& config)
bool TextureCacheBase::DidLinkedAssetsChange(const TCacheEntry& entry)
{
- for (const auto& cached_asset : entry.linked_game_texture_assets)
- {
- if (cached_asset.m_asset)
- {
- if (cached_asset.m_asset->GetLastLoadedTime() > cached_asset.m_cached_write_time)
- return true;
- }
- }
+ if (!entry.hires_texture)
+ return false;
- for (const auto& cached_asset : entry.linked_asset_dependencies)
- {
- if (cached_asset.m_asset)
- {
- if (cached_asset.m_asset->GetLastLoadedTime() > cached_asset.m_cached_write_time)
- return true;
- }
- }
+ const auto [texture_data, load_time] = entry.hires_texture->LoadTexture();
- return false;
+ return load_time > entry.last_load_time;
}
RcTcacheEntry TextureCacheBase::ApplyPaletteToEntry(RcTcacheEntry& entry, const u8* palette,
@@ -1566,80 +1554,50 @@ RcTcacheEntry TextureCacheBase::GetTexture(const int textureCacheSafetyColorSamp
InvalidateTexture(oldest_entry);
}
- std::vector<VideoCommon::CachedAsset<VideoCommon::GameTextureAsset>> cached_game_assets;
- std::vector<std::shared_ptr<VideoCommon::TextureData>> data_for_assets;
+ std::shared_ptr<HiresTexture> hires_texture;
bool has_arbitrary_mipmaps = false;
bool skip_texture_dump = false;
- std::shared_ptr<HiresTexture> hires_texture;
+ std::shared_ptr<VideoCommon::CustomTextureData> custom_texture_data = nullptr;
+ VideoCommon::CustomAsset::TimeType load_time = {};
if (g_ActiveConfig.bHiresTextures)
{
hires_texture = HiresTexture::Search(texture_info);
if (hires_texture)
{
- auto asset = hires_texture->GetAsset();
- const auto loaded_time = asset->GetLastLoadedTime();
- cached_game_assets.push_back(
- VideoCommon::CachedAsset<VideoCommon::GameTextureAsset>{std::move(asset), loaded_time});
has_arbitrary_mipmaps = hires_texture->HasArbitraryMipmaps();
+ std::tie(custom_texture_data, load_time) = hires_texture->LoadTexture();
+ if (custom_texture_data && !VideoCommon::ValidateTextureData(
+ hires_texture->GetId(), *custom_texture_data,
+ texture_info.GetRawWidth(), texture_info.GetRawHeight()))
+ {
+ custom_texture_data = nullptr;
+ load_time = {};
+ }
skip_texture_dump = true;
}
}
- std::vector<VideoCommon::CachedAsset<VideoCommon::CustomAsset>> additional_dependencies;
-
std::string texture_name = "";
if (g_ActiveConfig.bGraphicMods)
{
u32 height = texture_info.GetRawHeight();
u32 width = texture_info.GetRawWidth();
- if (hires_texture)
- {
- auto asset = hires_texture->GetAsset();
- if (asset)
- {
- auto data = asset->GetData();
- if (data)
- {
- if (!data->m_texture.m_slices.empty())
- {
- if (!data->m_texture.m_slices[0].m_levels.empty())
- {
- height = data->m_texture.m_slices[0].m_levels[0].height;
- width = data->m_texture.m_slices[0].m_levels[0].width;
- }
- }
- }
- }
- }
texture_name = texture_info.CalculateTextureName().GetFullName();
- GraphicsModActionData::TextureCreate texture_create{
- texture_name, width, height, &cached_game_assets, &additional_dependencies};
+ GraphicsModActionData::TextureCreate texture_create{texture_name, width, height, nullptr,
+ nullptr};
for (const auto& action : g_graphics_mod_manager->GetTextureCreateActions(texture_name))
{
action->OnTextureCreate(&texture_create);
}
}
- data_for_assets.reserve(cached_game_assets.size());
- for (auto& cached_asset : cached_game_assets)
- {
- auto data = cached_asset.m_asset->GetData();
- if (data)
- {
- if (cached_asset.m_asset->Validate(texture_info.GetRawWidth(), texture_info.GetRawHeight()))
- {
- data_for_assets.push_back(data);
- }
- }
- }
-
auto entry =
CreateTextureEntry(TextureCreationInfo{base_hash, full_hash, bytes_per_block, palette_size},
- texture_info, textureCacheSafetyColorSampleSize,
- std::move(data_for_assets), has_arbitrary_mipmaps, skip_texture_dump);
- entry->linked_game_texture_assets = std::move(cached_game_assets);
- entry->linked_asset_dependencies = std::move(additional_dependencies);
+ texture_info, textureCacheSafetyColorSampleSize, custom_texture_data.get(),
+ has_arbitrary_mipmaps, skip_texture_dump);
+ entry->hires_texture = std::move(hires_texture);
+ entry->last_load_time = load_time;
entry->texture_info_name = std::move(texture_name);
return entry;
}
@@ -1649,8 +1607,7 @@ RcTcacheEntry TextureCacheBase::GetTexture(const int textureCacheSafetyColorSamp
// expected because each texture is loaded into a texture array
RcTcacheEntry TextureCacheBase::CreateTextureEntry(
const TextureCreationInfo& creation_info, const TextureInfo& texture_info,
- const int safety_color_sample_size,
- std::vector<std::shared_ptr<VideoCommon::TextureData>> assets_data,
+ const int safety_color_sample_size, VideoCommon::CustomTextureData* custom_texture_data,
const bool custom_arbitrary_mipmaps, bool skip_texture_dump)
{
#ifdef __APPLE__
@@ -1660,33 +1617,22 @@ RcTcacheEntry TextureCacheBase::CreateTextureEntry(
#endif
RcTcacheEntry entry;
- if (!assets_data.empty())
+ if (custom_texture_data)
{
- const auto calculate_max_levels = [&]() {
- const auto max_element = std::ranges::max_element(
- assets_data, {}, [](const auto& v) { return v->m_texture.m_slices[0].m_levels.size(); });
- return (*max_element)->m_texture.m_slices[0].m_levels.size();
- };
- const u32 texLevels = no_mips ? 1 : (u32)calculate_max_levels();
- const auto& first_level = assets_data[0]->m_texture.m_slices[0].m_levels[0];
- const TextureConfig config(first_level.width, first_level.height, texLevels,
- static_cast<u32>(assets_data.size()), 1, first_level.format, 0,
- AbstractTextureType::Texture_2DArray);
+ const u32 texLevels = no_mips ? 1 : (u32)custom_texture_data->m_slices[0].m_levels.size();
+ const auto& first_level = custom_texture_data->m_slices[0].m_levels[0];
+ const TextureConfig config(first_level.width, first_level.height, texLevels, 1, 1,
+ first_level.format, 0, AbstractTextureType::Texture_2DArray);
entry = AllocateCacheEntry(config);
if (!entry) [[unlikely]]
return entry;
- for (u32 data_index = 0; data_index < static_cast<u32>(assets_data.size()); data_index++)
+ const auto& slice = custom_texture_data->m_slices[0];
+ for (u32 level_index = 0;
+ level_index < std::min(texLevels, static_cast<u32>(slice.m_levels.size())); ++level_index)
{
- const auto& asset = assets_data[data_index];
- const auto& slice = asset->m_texture.m_slices[0];
- for (u32 level_index = 0;
- level_index < std::min(texLevels, static_cast<u32>(slice.m_levels.size()));
- ++level_index)
- {
- const auto& level = slice.m_levels[level_index];
- entry->texture->Load(level_index, level.width, level.height, level.row_length,
- level.data.data(), level.data.size(), data_index);
- }
+ const auto& level = slice.m_levels[level_index];
+ entry->texture->Load(level_index, level.width, level.height, level.row_length,
+ level.data.data(), level.data.size());
}
entry->has_arbitrary_mips = custom_arbitrary_mipmaps;