From 2dc24a9148e1dc98ada6629fe6eebb673ceb336b Mon Sep 17 00:00:00 2001 From: iwubcode Date: Tue, 20 Jun 2023 18:59:55 -0500 Subject: [PATCH] VideoCommon: move cached texture asset to 'CustomAsset' common code --- Source/Core/VideoCommon/Assets/CustomAsset.h | 14 ++++++++++++++ Source/Core/VideoCommon/TextureCacheBase.cpp | 4 ++-- Source/Core/VideoCommon/TextureCacheBase.h | 9 ++------- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Source/Core/VideoCommon/Assets/CustomAsset.h b/Source/Core/VideoCommon/Assets/CustomAsset.h index 563955188c..9a11a49365 100644 --- a/Source/Core/VideoCommon/Assets/CustomAsset.h +++ b/Source/Core/VideoCommon/Assets/CustomAsset.h @@ -85,4 +85,18 @@ protected: std::shared_ptr m_data; }; +// A helper struct that contains +// an asset with a last cached write time +// This can be used to determine if the asset +// has diverged from the last known state +// To know if it is time to update other dependencies +// based on the asset data +// TODO C++20: use a 'derived_from' concept against 'CustomAsset' when available +template +struct CachedAsset +{ + std::shared_ptr m_asset; + VideoCommon::CustomAssetLibrary::TimeType m_cached_write_time; +}; + } // namespace VideoCommon diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index fc5c26b5a8..c26cbb5f4c 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -267,7 +267,7 @@ bool TextureCacheBase::DidLinkedAssetsChange(const TCacheEntry& entry) 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; + return last_asset_write_time > entry.linked_asset.m_cached_write_time; } RcTcacheEntry TextureCacheBase::ApplyPaletteToEntry(RcTcacheEntry& entry, const u8* palette, @@ -1590,7 +1590,7 @@ RcTcacheEntry TextureCacheBase::GetTexture(const int textureCacheSafetyColorSamp InvalidateTexture(oldest_entry); } - CachedTextureAsset cached_texture_asset; + VideoCommon::CachedAsset cached_texture_asset; std::shared_ptr data = nullptr; bool has_arbitrary_mipmaps = false; std::shared_ptr hires_texture; diff --git a/Source/Core/VideoCommon/TextureCacheBase.h b/Source/Core/VideoCommon/TextureCacheBase.h index 766b21bc80..f248d2b49f 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.h +++ b/Source/Core/VideoCommon/TextureCacheBase.h @@ -22,6 +22,7 @@ #include "Common/MathUtil.h" #include "VideoCommon/AbstractTexture.h" +#include "VideoCommon/Assets/CustomAsset.h" #include "VideoCommon/BPMemory.h" #include "VideoCommon/TextureConfig.h" #include "VideoCommon/TextureDecoder.h" @@ -115,12 +116,6 @@ struct fmt::formatter } }; -struct CachedTextureAsset -{ - std::shared_ptr m_asset; - std::optional m_last_write_time; -}; - struct TCacheEntry { // common members @@ -172,7 +167,7 @@ struct TCacheEntry std::string texture_info_name = ""; - CachedTextureAsset linked_asset; + VideoCommon::CachedAsset linked_asset; explicit TCacheEntry(std::unique_ptr tex, std::unique_ptr fb);