mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 22:29:39 -06:00
VideoCommon: introduce linked assets in TCacheEntry, allowing for assets to be reloaded
This commit is contained in:
@ -272,6 +272,15 @@ void TextureCacheBase::SetBackupConfig(const VideoConfig& config)
|
||||
config.graphics_mod_config ? config.graphics_mod_config->GetChangeCount() : 0;
|
||||
}
|
||||
|
||||
bool TextureCacheBase::DidLinkedAssetsChange(const TCacheEntry& entry)
|
||||
{
|
||||
if (!entry.linked_asset.m_asset)
|
||||
return false;
|
||||
|
||||
const auto last_asset_write_time = entry.linked_asset.m_asset->GetLastLoadedTime();
|
||||
return last_asset_write_time > entry.linked_asset.m_last_write_time;
|
||||
}
|
||||
|
||||
RcTcacheEntry TextureCacheBase::ApplyPaletteToEntry(RcTcacheEntry& entry, const u8* palette,
|
||||
TLUTFormat tlutfmt)
|
||||
{
|
||||
@ -1271,9 +1280,26 @@ private:
|
||||
};
|
||||
|
||||
TCacheEntry* TextureCacheBase::Load(const TextureInfo& texture_info)
|
||||
{
|
||||
if (auto entry = LoadImpl(texture_info, false))
|
||||
{
|
||||
if (!DidLinkedAssetsChange(*entry))
|
||||
{
|
||||
return entry;
|
||||
}
|
||||
|
||||
InvalidateTexture(GetTexCacheIter(entry));
|
||||
return LoadImpl(texture_info, true);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TCacheEntry* TextureCacheBase::LoadImpl(const TextureInfo& texture_info, bool force_reload)
|
||||
{
|
||||
// if this stage was not invalidated by changes to texture registers, keep the current texture
|
||||
if (TMEM::IsValid(texture_info.GetStage()) && bound_textures[texture_info.GetStage()])
|
||||
if (!force_reload && TMEM::IsValid(texture_info.GetStage()) &&
|
||||
bound_textures[texture_info.GetStage()])
|
||||
{
|
||||
TCacheEntry* entry = bound_textures[texture_info.GetStage()].get();
|
||||
// If the TMEM configuration is such that this texture is more or less guaranteed to still
|
||||
@ -1582,6 +1608,7 @@ RcTcacheEntry TextureCacheBase::GetTexture(const int textureCacheSafetyColorSamp
|
||||
InvalidateTexture(oldest_entry);
|
||||
}
|
||||
|
||||
CachedTextureAsset cached_texture_asset;
|
||||
std::shared_ptr<VideoCommon::CustomTextureData> data = nullptr;
|
||||
bool has_arbitrary_mipmaps = false;
|
||||
std::shared_ptr<HiresTexture> hires_texture;
|
||||
@ -1591,6 +1618,8 @@ RcTcacheEntry TextureCacheBase::GetTexture(const int textureCacheSafetyColorSamp
|
||||
if (hires_texture)
|
||||
{
|
||||
data = hires_texture->GetAsset()->GetData();
|
||||
cached_texture_asset = {hires_texture->GetAsset(),
|
||||
hires_texture->GetAsset()->GetLastLoadedTime()};
|
||||
has_arbitrary_mipmaps = hires_texture->HasArbitraryMipmaps();
|
||||
if (data)
|
||||
{
|
||||
@ -1603,9 +1632,11 @@ RcTcacheEntry TextureCacheBase::GetTexture(const int textureCacheSafetyColorSamp
|
||||
}
|
||||
}
|
||||
|
||||
return CreateTextureEntry(
|
||||
auto entry = CreateTextureEntry(
|
||||
TextureCreationInfo{base_hash, full_hash, bytes_per_block, palette_size}, texture_info,
|
||||
textureCacheSafetyColorSampleSize, data.get(), has_arbitrary_mipmaps);
|
||||
entry->linked_asset = std::move(cached_texture_asset);
|
||||
return entry;
|
||||
}
|
||||
|
||||
RcTcacheEntry TextureCacheBase::CreateTextureEntry(
|
||||
|
Reference in New Issue
Block a user