From f1f1ecc9d116c8295b76d636774f5e922e8941ae Mon Sep 17 00:00:00 2001 From: iwubcode Date: Mon, 20 Mar 2023 01:23:51 -0500 Subject: Core / VideoCommon: update HiresTexture to use CustomAssetLoader --- Source/Core/VideoCommon/TextureCacheBase.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'Source/Core/VideoCommon/TextureCacheBase.cpp') diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index 5b0bde53ca..90d2c2048f 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -1582,7 +1582,7 @@ RcTcacheEntry TextureCacheBase::GetTexture(const int textureCacheSafetyColorSamp InvalidateTexture(oldest_entry); } - VideoCommon::CustomTextureData* data = nullptr; + std::shared_ptr data = nullptr; bool has_arbitrary_mipmaps = false; std::shared_ptr hires_texture; if (g_ActiveConfig.bHiresTextures) @@ -1590,19 +1590,27 @@ RcTcacheEntry TextureCacheBase::GetTexture(const int textureCacheSafetyColorSamp hires_texture = HiresTexture::Search(texture_info); if (hires_texture) { - data = &hires_texture->GetData(); + data = hires_texture->GetAsset()->GetData(); has_arbitrary_mipmaps = hires_texture->HasArbitraryMipmaps(); + if (data) + { + if (!hires_texture->GetAsset()->Validate(texture_info.GetRawWidth(), + texture_info.GetRawHeight())) + { + data = nullptr; + } + } } } return CreateTextureEntry( TextureCreationInfo{base_hash, full_hash, bytes_per_block, palette_size}, texture_info, - textureCacheSafetyColorSampleSize, data, has_arbitrary_mipmaps); + textureCacheSafetyColorSampleSize, data.get(), has_arbitrary_mipmaps); } RcTcacheEntry TextureCacheBase::CreateTextureEntry( const TextureCreationInfo& creation_info, const TextureInfo& texture_info, - const int safety_color_sample_size, VideoCommon::CustomTextureData* custom_texture_data, + const int safety_color_sample_size, const VideoCommon::CustomTextureData* custom_texture_data, const bool custom_arbitrary_mipmaps) { #ifdef __APPLE__ @@ -1741,7 +1749,7 @@ RcTcacheEntry TextureCacheBase::CreateTextureEntry( if (g_ActiveConfig.bDumpTextures) { - const std::string basename = HiresTexture::GenBaseName(texture_info, true); + const std::string basename = texture_info.CalculateTextureName().GetFullName(); for (u32 level = 0; level < texLevels; ++level) { DumpTexture(entry, basename, level, entry->has_arbitrary_mips); -- cgit v1.2.3 From ca8d6748d6409943d758b59bf255a161061a648e Mon Sep 17 00:00:00 2001 From: iwubcode Date: Tue, 21 Mar 2023 19:54:50 -0500 Subject: VideoCommon: introduce linked assets in TCacheEntry, allowing for assets to be reloaded --- Source/Core/VideoCommon/TextureCacheBase.cpp | 35 ++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'Source/Core/VideoCommon/TextureCacheBase.cpp') diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index 90d2c2048f..5bb8993897 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -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 data = nullptr; bool has_arbitrary_mipmaps = false; std::shared_ptr 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( -- cgit v1.2.3 From e831d7b6bb82da618db9f33e62c8f197dec079bf Mon Sep 17 00:00:00 2001 From: iwubcode Date: Wed, 22 Mar 2023 20:56:13 -0500 Subject: InputCommon / VideoCommon: remove dynamic input reloading the texture cache, this is no longer needed, assets reload automatically! --- Source/Core/VideoCommon/TextureCacheBase.cpp | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) (limited to 'Source/Core/VideoCommon/TextureCacheBase.cpp') diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index 5bb8993897..fc5c26b5a8 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -145,17 +145,6 @@ void TextureCacheBase::Invalidate() texture_pool.clear(); } -void TextureCacheBase::ForceReload() -{ - Invalidate(); - - // Clear all current hires textures, they are invalid - HiresTexture::Clear(); - - // Load fresh - HiresTexture::Update(); -} - void TextureCacheBase::OnConfigChanged(const VideoConfig& config) { if (config.bHiresTextures != backup_config.hires_textures || @@ -781,17 +770,10 @@ void TextureCacheBase::DoLoadState(PointerWrap& p) void TextureCacheBase::OnFrameEnd() { - if (m_force_reload_textures.TestAndClear()) - { - ForceReload(); - } - else - { - // Flush any outstanding EFB copies to RAM, in case the game is running at an uncapped frame - // rate and not waiting for vblank. Otherwise, we'd end up with a huge list of pending - // copies. - FlushEFBCopies(); - } + // Flush any outstanding EFB copies to RAM, in case the game is running at an uncapped frame + // rate and not waiting for vblank. Otherwise, we'd end up with a huge list of pending + // copies. + FlushEFBCopies(); Cleanup(g_presenter->FrameCount()); } -- cgit v1.2.3