Merge pull request #11981 from iwubcode/move_cached_asset_to_common

VideoCommon: move cached texture asset to 'CustomAsset' common code
This commit is contained in:
Admiral H. Curtiss 2023-06-23 17:59:24 +02:00 committed by GitHub
commit 5bf3d55d38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 9 deletions

View File

@ -85,4 +85,18 @@ protected:
std::shared_ptr<UnderlyingType> m_data; std::shared_ptr<UnderlyingType> 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 <typename AssetType>
struct CachedAsset
{
std::shared_ptr<AssetType> m_asset;
VideoCommon::CustomAssetLibrary::TimeType m_cached_write_time;
};
} // namespace VideoCommon } // namespace VideoCommon

View File

@ -267,7 +267,7 @@ bool TextureCacheBase::DidLinkedAssetsChange(const TCacheEntry& entry)
return false; return false;
const auto last_asset_write_time = entry.linked_asset.m_asset->GetLastLoadedTime(); 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, RcTcacheEntry TextureCacheBase::ApplyPaletteToEntry(RcTcacheEntry& entry, const u8* palette,
@ -1590,7 +1590,7 @@ RcTcacheEntry TextureCacheBase::GetTexture(const int textureCacheSafetyColorSamp
InvalidateTexture(oldest_entry); InvalidateTexture(oldest_entry);
} }
CachedTextureAsset cached_texture_asset; VideoCommon::CachedAsset<VideoCommon::GameTextureAsset> cached_texture_asset;
std::shared_ptr<VideoCommon::CustomTextureData> data = nullptr; std::shared_ptr<VideoCommon::CustomTextureData> data = nullptr;
bool has_arbitrary_mipmaps = false; bool has_arbitrary_mipmaps = false;
std::shared_ptr<HiresTexture> hires_texture; std::shared_ptr<HiresTexture> hires_texture;

View File

@ -22,6 +22,7 @@
#include "Common/MathUtil.h" #include "Common/MathUtil.h"
#include "VideoCommon/AbstractTexture.h" #include "VideoCommon/AbstractTexture.h"
#include "VideoCommon/Assets/CustomAsset.h"
#include "VideoCommon/BPMemory.h" #include "VideoCommon/BPMemory.h"
#include "VideoCommon/TextureConfig.h" #include "VideoCommon/TextureConfig.h"
#include "VideoCommon/TextureDecoder.h" #include "VideoCommon/TextureDecoder.h"
@ -115,12 +116,6 @@ struct fmt::formatter<EFBCopyParams>
} }
}; };
struct CachedTextureAsset
{
std::shared_ptr<VideoCommon::GameTextureAsset> m_asset;
std::optional<std::filesystem::file_time_type> m_last_write_time;
};
struct TCacheEntry struct TCacheEntry
{ {
// common members // common members
@ -172,7 +167,7 @@ struct TCacheEntry
std::string texture_info_name = ""; std::string texture_info_name = "";
CachedTextureAsset linked_asset; VideoCommon::CachedAsset<VideoCommon::GameTextureAsset> linked_asset;
explicit TCacheEntry(std::unique_ptr<AbstractTexture> tex, explicit TCacheEntry(std::unique_ptr<AbstractTexture> tex,
std::unique_ptr<AbstractFramebuffer> fb); std::unique_ptr<AbstractFramebuffer> fb);