diff --git a/Source/Core/VideoCommon/Assets/CustomAsset.cpp b/Source/Core/VideoCommon/Assets/CustomAsset.cpp index 2b41d60a21..0fc495fe44 100644 --- a/Source/Core/VideoCommon/Assets/CustomAsset.cpp +++ b/Source/Core/VideoCommon/Assets/CustomAsset.cpp @@ -18,7 +18,7 @@ std::size_t CustomAsset::Load() { std::lock_guard lk(m_info_lock); m_bytes_loaded = load_information.m_bytes_loaded; - m_last_loaded_time = load_information.m_load_time; + m_last_loaded_time = ClockType::now(); return m_bytes_loaded; } return 0; @@ -36,12 +36,7 @@ std::size_t CustomAsset::Unload() return bytes_loaded; } -CustomAssetLibrary::TimeType CustomAsset::GetLastWriteTime() const -{ - return m_owning_library->GetLastAssetWriteTime(m_asset_id); -} - -const CustomAssetLibrary::TimeType& CustomAsset::GetLastLoadedTime() const +const CustomAsset::TimeType& CustomAsset::GetLastLoadedTime() const { std::lock_guard lk(m_info_lock); return m_last_loaded_time; diff --git a/Source/Core/VideoCommon/Assets/CustomAsset.h b/Source/Core/VideoCommon/Assets/CustomAsset.h index 505be254d8..451696d883 100644 --- a/Source/Core/VideoCommon/Assets/CustomAsset.h +++ b/Source/Core/VideoCommon/Assets/CustomAsset.h @@ -17,6 +17,9 @@ namespace VideoCommon class CustomAsset { public: + using ClockType = std::chrono::steady_clock; + using TimeType = ClockType::time_point; + CustomAsset(std::shared_ptr library, const CustomAssetLibrary::AssetID& asset_id, u64 session_id); virtual ~CustomAsset() = default; @@ -32,13 +35,8 @@ public: // returns the number of bytes unloaded std::size_t Unload(); - // Queries the last time the asset was modified or standard epoch time - // if the asset hasn't been modified yet - // Note: not thread safe, expected to be called by the loader - CustomAssetLibrary::TimeType GetLastWriteTime() const; - // Returns the time that the data was last loaded - const CustomAssetLibrary::TimeType& GetLastLoadedTime() const; + const TimeType& GetLastLoadedTime() const; // Returns an id that uniquely identifies this asset const CustomAssetLibrary::AssetID& GetAssetId() const; @@ -63,7 +61,7 @@ private: mutable std::mutex m_info_lock; std::size_t m_bytes_loaded = 0; - CustomAssetLibrary::TimeType m_last_loaded_time = {}; + TimeType m_last_loaded_time = {}; }; // An abstract class that is expected to @@ -115,7 +113,7 @@ template struct CachedAsset { std::shared_ptr m_asset; - VideoCommon::CustomAssetLibrary::TimeType m_cached_write_time; + CustomAsset::TimeType m_cached_write_time; }; } // namespace VideoCommon diff --git a/Source/Core/VideoCommon/Assets/CustomAssetLibrary.h b/Source/Core/VideoCommon/Assets/CustomAssetLibrary.h index b4831ea650..a846b67d27 100644 --- a/Source/Core/VideoCommon/Assets/CustomAssetLibrary.h +++ b/Source/Core/VideoCommon/Assets/CustomAssetLibrary.h @@ -21,15 +21,12 @@ struct TextureData; class CustomAssetLibrary { public: - using TimeType = std::chrono::system_clock::time_point; - // The AssetID is a unique identifier for a particular asset using AssetID = std::string; struct LoadInfo { std::size_t m_bytes_loaded = 0; - TimeType m_load_time = {}; }; virtual ~CustomAssetLibrary() = default; @@ -37,9 +34,6 @@ public: // Loads a texture, if there are no levels, bytes loaded will be empty virtual LoadInfo LoadTexture(const AssetID& asset_id, TextureData* data) = 0; - // Gets the last write time for a given asset id - virtual TimeType GetLastAssetWriteTime(const AssetID& asset_id) const = 0; - // Loads a texture as a game texture, providing additional checks like confirming // each mip level size is correct and that the format is consistent across the data LoadInfo LoadGameTexture(const AssetID& asset_id, TextureData* data); diff --git a/Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp b/Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp index 90d77d8ec9..149a646639 100644 --- a/Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp +++ b/Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.cpp @@ -23,20 +23,6 @@ namespace VideoCommon { namespace { -std::chrono::system_clock::time_point FileTimeToSysTime(std::filesystem::file_time_type file_time) -{ -#ifdef _WIN32 - return std::chrono::clock_cast(file_time); -#else - // Note: all compilers should switch to chrono::clock_cast - // once it is available for use - const auto system_time_now = std::chrono::system_clock::now(); - const auto file_time_now = decltype(file_time)::clock::now(); - return std::chrono::time_point_cast( - file_time - file_time_now + system_time_now); -#endif -} - std::size_t GetAssetSize(const CustomTextureData& data) { std::size_t total = 0; @@ -50,30 +36,6 @@ std::size_t GetAssetSize(const CustomTextureData& data) return total; } } // namespace -CustomAssetLibrary::TimeType -DirectFilesystemAssetLibrary::GetLastAssetWriteTime(const AssetID& asset_id) const -{ - std::lock_guard lk(m_lock); - if (auto iter = m_assetid_to_asset_map_path.find(asset_id); - iter != m_assetid_to_asset_map_path.end()) - { - const auto& asset_map_path = iter->second; - CustomAssetLibrary::TimeType max_entry; - for (const auto& [key, value] : asset_map_path) - { - std::error_code ec; - const auto tp = std::filesystem::last_write_time(value, ec); - if (ec) - continue; - auto tp_sys = FileTimeToSysTime(tp); - if (tp_sys > max_entry) - max_entry = tp_sys; - } - return max_entry; - } - - return {}; -} CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadPixelShader(const AssetID& asset_id, PixelShaderData* data) @@ -158,7 +120,7 @@ CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadPixelShader(const if (!PixelShaderData::FromJson(asset_id, root_obj, data)) return {}; - return LoadInfo{approx_mem_size, GetLastAssetWriteTime(asset_id)}; + return LoadInfo{approx_mem_size}; } CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadMaterial(const AssetID& asset_id, @@ -216,7 +178,7 @@ CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadMaterial(const As return {}; } - return LoadInfo{metadata_size, GetLastAssetWriteTime(asset_id)}; + return LoadInfo{metadata_size}; } CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadMesh(const AssetID& asset_id, @@ -311,7 +273,7 @@ CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadMesh(const AssetI if (!MeshData::FromJson(asset_id, root_obj, data)) return {}; - return LoadInfo{approx_mem_size, GetLastAssetWriteTime(asset_id)}; + return LoadInfo{approx_mem_size}; } CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadTexture(const AssetID& asset_id, @@ -395,7 +357,7 @@ CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadTexture(const Ass if (!LoadMips(texture_path->second, &data->m_texture.m_slices[0])) return {}; - return LoadInfo{GetAssetSize(data->m_texture) + metadata_size, GetLastAssetWriteTime(asset_id)}; + return LoadInfo{GetAssetSize(data->m_texture) + metadata_size}; } else if (ext == ".png") { @@ -426,7 +388,7 @@ CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadTexture(const Ass if (!LoadMips(texture_path->second, &slice)) return {}; - return LoadInfo{GetAssetSize(data->m_texture) + metadata_size, GetLastAssetWriteTime(asset_id)}; + return LoadInfo{GetAssetSize(data->m_texture) + metadata_size}; } ERROR_LOG_FMT(VIDEO, "Asset '{}' error - extension '{}' unknown!", asset_id, ext); diff --git a/Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.h b/Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.h index c4d99baf82..8c20fa4f42 100644 --- a/Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.h +++ b/Source/Core/VideoCommon/Assets/DirectFilesystemAssetLibrary.h @@ -25,9 +25,6 @@ public: LoadInfo LoadMaterial(const AssetID& asset_id, MaterialData* data) override; LoadInfo LoadMesh(const AssetID& asset_id, MeshData* data) override; - // Gets the latest time from amongst all the files in the asset map - TimeType GetLastAssetWriteTime(const AssetID& asset_id) const override; - // Assigns the asset id to a map of files, how this map is read is dependent on the data // For instance, a raw texture would expect the map to have a single entry and load that // file as the asset. But a model file data might have its data spread across multiple files