mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-06-27 17:39:34 -06:00
VideoCommon: remove 'GetLastAssetWriteTime' and switch to a steady_clock for asset times
This commit is contained in:
@ -18,7 +18,7 @@ std::size_t CustomAsset::Load()
|
|||||||
{
|
{
|
||||||
std::lock_guard lk(m_info_lock);
|
std::lock_guard lk(m_info_lock);
|
||||||
m_bytes_loaded = load_information.m_bytes_loaded;
|
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 m_bytes_loaded;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -36,12 +36,7 @@ std::size_t CustomAsset::Unload()
|
|||||||
return bytes_loaded;
|
return bytes_loaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
CustomAssetLibrary::TimeType CustomAsset::GetLastWriteTime() const
|
const CustomAsset::TimeType& CustomAsset::GetLastLoadedTime() const
|
||||||
{
|
|
||||||
return m_owning_library->GetLastAssetWriteTime(m_asset_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
const CustomAssetLibrary::TimeType& CustomAsset::GetLastLoadedTime() const
|
|
||||||
{
|
{
|
||||||
std::lock_guard lk(m_info_lock);
|
std::lock_guard lk(m_info_lock);
|
||||||
return m_last_loaded_time;
|
return m_last_loaded_time;
|
||||||
|
@ -17,6 +17,9 @@ namespace VideoCommon
|
|||||||
class CustomAsset
|
class CustomAsset
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
using ClockType = std::chrono::steady_clock;
|
||||||
|
using TimeType = ClockType::time_point;
|
||||||
|
|
||||||
CustomAsset(std::shared_ptr<CustomAssetLibrary> library,
|
CustomAsset(std::shared_ptr<CustomAssetLibrary> library,
|
||||||
const CustomAssetLibrary::AssetID& asset_id, u64 session_id);
|
const CustomAssetLibrary::AssetID& asset_id, u64 session_id);
|
||||||
virtual ~CustomAsset() = default;
|
virtual ~CustomAsset() = default;
|
||||||
@ -32,13 +35,8 @@ public:
|
|||||||
// returns the number of bytes unloaded
|
// returns the number of bytes unloaded
|
||||||
std::size_t Unload();
|
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
|
// 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
|
// Returns an id that uniquely identifies this asset
|
||||||
const CustomAssetLibrary::AssetID& GetAssetId() const;
|
const CustomAssetLibrary::AssetID& GetAssetId() const;
|
||||||
@ -63,7 +61,7 @@ private:
|
|||||||
|
|
||||||
mutable std::mutex m_info_lock;
|
mutable std::mutex m_info_lock;
|
||||||
std::size_t m_bytes_loaded = 0;
|
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
|
// An abstract class that is expected to
|
||||||
@ -115,7 +113,7 @@ template <typename AssetType>
|
|||||||
struct CachedAsset
|
struct CachedAsset
|
||||||
{
|
{
|
||||||
std::shared_ptr<AssetType> m_asset;
|
std::shared_ptr<AssetType> m_asset;
|
||||||
VideoCommon::CustomAssetLibrary::TimeType m_cached_write_time;
|
CustomAsset::TimeType m_cached_write_time;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace VideoCommon
|
} // namespace VideoCommon
|
||||||
|
@ -21,15 +21,12 @@ struct TextureData;
|
|||||||
class CustomAssetLibrary
|
class CustomAssetLibrary
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using TimeType = std::chrono::system_clock::time_point;
|
|
||||||
|
|
||||||
// The AssetID is a unique identifier for a particular asset
|
// The AssetID is a unique identifier for a particular asset
|
||||||
using AssetID = std::string;
|
using AssetID = std::string;
|
||||||
|
|
||||||
struct LoadInfo
|
struct LoadInfo
|
||||||
{
|
{
|
||||||
std::size_t m_bytes_loaded = 0;
|
std::size_t m_bytes_loaded = 0;
|
||||||
TimeType m_load_time = {};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual ~CustomAssetLibrary() = default;
|
virtual ~CustomAssetLibrary() = default;
|
||||||
@ -37,9 +34,6 @@ public:
|
|||||||
// Loads a texture, if there are no levels, bytes loaded will be empty
|
// Loads a texture, if there are no levels, bytes loaded will be empty
|
||||||
virtual LoadInfo LoadTexture(const AssetID& asset_id, TextureData* data) = 0;
|
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
|
// 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
|
// each mip level size is correct and that the format is consistent across the data
|
||||||
LoadInfo LoadGameTexture(const AssetID& asset_id, TextureData* data);
|
LoadInfo LoadGameTexture(const AssetID& asset_id, TextureData* data);
|
||||||
|
@ -23,20 +23,6 @@ namespace VideoCommon
|
|||||||
{
|
{
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
std::chrono::system_clock::time_point FileTimeToSysTime(std::filesystem::file_time_type file_time)
|
|
||||||
{
|
|
||||||
#ifdef _WIN32
|
|
||||||
return std::chrono::clock_cast<std::chrono::system_clock>(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<std::chrono::system_clock::duration>(
|
|
||||||
file_time - file_time_now + system_time_now);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
std::size_t GetAssetSize(const CustomTextureData& data)
|
std::size_t GetAssetSize(const CustomTextureData& data)
|
||||||
{
|
{
|
||||||
std::size_t total = 0;
|
std::size_t total = 0;
|
||||||
@ -50,30 +36,6 @@ std::size_t GetAssetSize(const CustomTextureData& data)
|
|||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
} // namespace
|
} // 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,
|
CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadPixelShader(const AssetID& asset_id,
|
||||||
PixelShaderData* data)
|
PixelShaderData* data)
|
||||||
@ -158,7 +120,7 @@ CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadPixelShader(const
|
|||||||
if (!PixelShaderData::FromJson(asset_id, root_obj, data))
|
if (!PixelShaderData::FromJson(asset_id, root_obj, data))
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
return LoadInfo{approx_mem_size, GetLastAssetWriteTime(asset_id)};
|
return LoadInfo{approx_mem_size};
|
||||||
}
|
}
|
||||||
|
|
||||||
CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadMaterial(const AssetID& asset_id,
|
CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadMaterial(const AssetID& asset_id,
|
||||||
@ -216,7 +178,7 @@ CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadMaterial(const As
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return LoadInfo{metadata_size, GetLastAssetWriteTime(asset_id)};
|
return LoadInfo{metadata_size};
|
||||||
}
|
}
|
||||||
|
|
||||||
CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadMesh(const AssetID& asset_id,
|
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))
|
if (!MeshData::FromJson(asset_id, root_obj, data))
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
return LoadInfo{approx_mem_size, GetLastAssetWriteTime(asset_id)};
|
return LoadInfo{approx_mem_size};
|
||||||
}
|
}
|
||||||
|
|
||||||
CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadTexture(const AssetID& asset_id,
|
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]))
|
if (!LoadMips(texture_path->second, &data->m_texture.m_slices[0]))
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
return LoadInfo{GetAssetSize(data->m_texture) + metadata_size, GetLastAssetWriteTime(asset_id)};
|
return LoadInfo{GetAssetSize(data->m_texture) + metadata_size};
|
||||||
}
|
}
|
||||||
else if (ext == ".png")
|
else if (ext == ".png")
|
||||||
{
|
{
|
||||||
@ -426,7 +388,7 @@ CustomAssetLibrary::LoadInfo DirectFilesystemAssetLibrary::LoadTexture(const Ass
|
|||||||
if (!LoadMips(texture_path->second, &slice))
|
if (!LoadMips(texture_path->second, &slice))
|
||||||
return {};
|
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);
|
ERROR_LOG_FMT(VIDEO, "Asset '{}' error - extension '{}' unknown!", asset_id, ext);
|
||||||
|
@ -25,9 +25,6 @@ public:
|
|||||||
LoadInfo LoadMaterial(const AssetID& asset_id, MaterialData* data) override;
|
LoadInfo LoadMaterial(const AssetID& asset_id, MaterialData* data) override;
|
||||||
LoadInfo LoadMesh(const AssetID& asset_id, MeshData* 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
|
// 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
|
// 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
|
// file as the asset. But a model file data might have its data spread across multiple files
|
||||||
|
Reference in New Issue
Block a user