mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-04-20 11:35:54 +00:00
VideoCommon: use CustomResourceManager in the texture cache and hook up to our hires textures
This commit is contained in:
parent
c0a9f8f8de
commit
bce50d88f2
4 changed files with 53 additions and 120 deletions
|
@ -25,7 +25,7 @@
|
|||
#include "Core/ConfigManager.h"
|
||||
#include "Core/System.h"
|
||||
#include "VideoCommon/Assets/CustomAsset.h"
|
||||
#include "VideoCommon/Assets/CustomAssetLoader.h"
|
||||
#include "VideoCommon/Assets/CustomResourceManager.h"
|
||||
#include "VideoCommon/Assets/DirectFilesystemAssetLibrary.h"
|
||||
#include "VideoCommon/OnScreenDisplay.h"
|
||||
#include "VideoCommon/VideoConfig.h"
|
||||
|
@ -95,8 +95,6 @@ void HiresTexture::Update()
|
|||
GetTextureDirectoriesWithGameId(File::GetUserPath(D_HIRESTEXTURES_IDX), game_id);
|
||||
const std::vector<std::string> extensions{".png", ".dds"};
|
||||
|
||||
auto& system = Core::System::GetInstance();
|
||||
|
||||
for (const auto& texture_directory : texture_directories)
|
||||
{
|
||||
const auto texture_paths =
|
||||
|
@ -130,10 +128,10 @@ void HiresTexture::Update()
|
|||
|
||||
if (g_ActiveConfig.bCacheHiresTextures)
|
||||
{
|
||||
auto hires_texture = std::make_shared<HiresTexture>(
|
||||
has_arbitrary_mipmaps,
|
||||
system.GetCustomAssetLoader().LoadGameTexture(filename, s_file_library));
|
||||
s_hires_texture_cache.try_emplace(filename, std::move(hires_texture));
|
||||
auto hires_texture =
|
||||
std::make_shared<HiresTexture>(has_arbitrary_mipmaps, std::move(filename));
|
||||
static_cast<void>(hires_texture->LoadTexture());
|
||||
s_hires_texture_cache.try_emplace(hires_texture->GetId(), hires_texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -167,7 +165,7 @@ void HiresTexture::Clear()
|
|||
|
||||
std::shared_ptr<HiresTexture> HiresTexture::Search(const TextureInfo& texture_info)
|
||||
{
|
||||
const auto [base_filename, has_arb_mipmaps] = GetNameArbPair(texture_info);
|
||||
auto [base_filename, has_arb_mipmaps] = GetNameArbPair(texture_info);
|
||||
if (base_filename == "")
|
||||
return nullptr;
|
||||
|
||||
|
@ -177,24 +175,27 @@ std::shared_ptr<HiresTexture> HiresTexture::Search(const TextureInfo& texture_in
|
|||
}
|
||||
else
|
||||
{
|
||||
auto& system = Core::System::GetInstance();
|
||||
auto hires_texture = std::make_shared<HiresTexture>(
|
||||
has_arb_mipmaps,
|
||||
system.GetCustomAssetLoader().LoadGameTexture(base_filename, s_file_library));
|
||||
auto hires_texture = std::make_shared<HiresTexture>(has_arb_mipmaps, std::move(base_filename));
|
||||
if (g_ActiveConfig.bCacheHiresTextures)
|
||||
{
|
||||
s_hires_texture_cache.try_emplace(base_filename, hires_texture);
|
||||
s_hires_texture_cache.try_emplace(hires_texture->GetId(), hires_texture);
|
||||
}
|
||||
return hires_texture;
|
||||
}
|
||||
}
|
||||
|
||||
HiresTexture::HiresTexture(bool has_arbitrary_mipmaps,
|
||||
std::shared_ptr<VideoCommon::GameTextureAsset> asset)
|
||||
: m_has_arbitrary_mipmaps(has_arbitrary_mipmaps), m_game_texture(std::move(asset))
|
||||
HiresTexture::HiresTexture(bool has_arbitrary_mipmaps, std::string id)
|
||||
: m_has_arbitrary_mipmaps(has_arbitrary_mipmaps), m_id(std::move(id))
|
||||
{
|
||||
}
|
||||
|
||||
VideoCommon::CustomTextureData* HiresTexture::LoadTexture() const
|
||||
{
|
||||
auto& system = Core::System::GetInstance();
|
||||
auto& custom_resource_manager = system.GetCustomResourceManager();
|
||||
return custom_resource_manager.GetTextureDataFromAsset(m_id, s_file_library);
|
||||
}
|
||||
|
||||
std::set<std::string> GetTextureDirectoriesWithGameId(const std::string& root_directory,
|
||||
const std::string& game_id)
|
||||
{
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "VideoCommon/Assets/CustomTextureData.h"
|
||||
#include "VideoCommon/Assets/TextureAsset.h"
|
||||
#include "VideoCommon/TextureConfig.h"
|
||||
#include "VideoCommon/TextureInfo.h"
|
||||
|
||||
|
@ -27,12 +26,13 @@ public:
|
|||
static void Shutdown();
|
||||
static std::shared_ptr<HiresTexture> Search(const TextureInfo& texture_info);
|
||||
|
||||
HiresTexture(bool has_arbitrary_mipmaps, std::shared_ptr<VideoCommon::GameTextureAsset> asset);
|
||||
HiresTexture(bool has_arbitrary_mipmaps, std::string id);
|
||||
|
||||
bool HasArbitraryMipmaps() const { return m_has_arbitrary_mipmaps; }
|
||||
const std::shared_ptr<VideoCommon::GameTextureAsset>& GetAsset() const { return m_game_texture; }
|
||||
VideoCommon::CustomTextureData* LoadTexture() const;
|
||||
const std::string& GetId() const { return m_id; }
|
||||
|
||||
private:
|
||||
bool m_has_arbitrary_mipmaps = false;
|
||||
std::shared_ptr<VideoCommon::GameTextureAsset> m_game_texture;
|
||||
std::string m_id;
|
||||
};
|
||||
|
|
|
@ -36,13 +36,13 @@
|
|||
#include "VideoCommon/AbstractFramebuffer.h"
|
||||
#include "VideoCommon/AbstractGfx.h"
|
||||
#include "VideoCommon/AbstractStagingTexture.h"
|
||||
#include "VideoCommon/Assets/CustomResourceManager.h"
|
||||
#include "VideoCommon/Assets/CustomTextureData.h"
|
||||
#include "VideoCommon/BPMemory.h"
|
||||
#include "VideoCommon/FramebufferManager.h"
|
||||
#include "VideoCommon/GraphicsModSystem/Runtime/FBInfo.h"
|
||||
#include "VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionData.h"
|
||||
#include "VideoCommon/GraphicsModSystem/Runtime/GraphicsModManager.h"
|
||||
#include "VideoCommon/HiresTextures.h"
|
||||
#include "VideoCommon/OpcodeDecoding.h"
|
||||
#include "VideoCommon/PixelShaderManager.h"
|
||||
#include "VideoCommon/Present.h"
|
||||
|
@ -261,25 +261,10 @@ void TextureCacheBase::SetBackupConfig(const VideoConfig& config)
|
|||
|
||||
bool TextureCacheBase::DidLinkedAssetsChange(const TCacheEntry& entry)
|
||||
{
|
||||
for (const auto& cached_asset : entry.linked_game_texture_assets)
|
||||
{
|
||||
if (cached_asset.m_asset)
|
||||
{
|
||||
if (cached_asset.m_asset->GetLastLoadedTime() > cached_asset.m_cached_write_time)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (!entry.hires_texture)
|
||||
return false;
|
||||
|
||||
for (const auto& cached_asset : entry.linked_asset_dependencies)
|
||||
{
|
||||
if (cached_asset.m_asset)
|
||||
{
|
||||
if (cached_asset.m_asset->GetLastLoadedTime() > cached_asset.m_cached_write_time)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return entry.last_custom_texture_data != entry.hires_texture->LoadTexture();
|
||||
}
|
||||
|
||||
RcTcacheEntry TextureCacheBase::ApplyPaletteToEntry(RcTcacheEntry& entry, const u8* palette,
|
||||
|
@ -1568,80 +1553,42 @@ RcTcacheEntry TextureCacheBase::GetTexture(const int textureCacheSafetyColorSamp
|
|||
InvalidateTexture(oldest_entry);
|
||||
}
|
||||
|
||||
std::vector<VideoCommon::CachedAsset<VideoCommon::GameTextureAsset>> cached_game_assets;
|
||||
std::vector<std::shared_ptr<VideoCommon::TextureData>> data_for_assets;
|
||||
std::shared_ptr<HiresTexture> hires_texture;
|
||||
bool has_arbitrary_mipmaps = false;
|
||||
bool skip_texture_dump = false;
|
||||
std::shared_ptr<HiresTexture> hires_texture;
|
||||
VideoCommon::CustomTextureData* custom_texture_data = nullptr;
|
||||
if (g_ActiveConfig.bHiresTextures)
|
||||
{
|
||||
hires_texture = HiresTexture::Search(texture_info);
|
||||
if (hires_texture)
|
||||
{
|
||||
auto asset = hires_texture->GetAsset();
|
||||
const auto loaded_time = asset->GetLastLoadedTime();
|
||||
cached_game_assets.push_back(
|
||||
VideoCommon::CachedAsset<VideoCommon::GameTextureAsset>{std::move(asset), loaded_time});
|
||||
has_arbitrary_mipmaps = hires_texture->HasArbitraryMipmaps();
|
||||
custom_texture_data = hires_texture->LoadTexture();
|
||||
skip_texture_dump = true;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<VideoCommon::CachedAsset<VideoCommon::CustomAsset>> additional_dependencies;
|
||||
|
||||
std::string texture_name = "";
|
||||
|
||||
if (g_ActiveConfig.bGraphicMods)
|
||||
{
|
||||
u32 height = texture_info.GetRawHeight();
|
||||
u32 width = texture_info.GetRawWidth();
|
||||
if (hires_texture)
|
||||
{
|
||||
auto asset = hires_texture->GetAsset();
|
||||
if (asset)
|
||||
{
|
||||
auto data = asset->GetData();
|
||||
if (data)
|
||||
{
|
||||
if (!data->m_texture.m_slices.empty())
|
||||
{
|
||||
if (!data->m_texture.m_slices[0].m_levels.empty())
|
||||
{
|
||||
height = data->m_texture.m_slices[0].m_levels[0].height;
|
||||
width = data->m_texture.m_slices[0].m_levels[0].width;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
texture_name = texture_info.CalculateTextureName().GetFullName();
|
||||
GraphicsModActionData::TextureCreate texture_create{
|
||||
texture_name, width, height, &cached_game_assets, &additional_dependencies};
|
||||
GraphicsModActionData::TextureCreate texture_create{texture_name, width, height, nullptr,
|
||||
nullptr};
|
||||
for (const auto& action : g_graphics_mod_manager->GetTextureCreateActions(texture_name))
|
||||
{
|
||||
action->OnTextureCreate(&texture_create);
|
||||
}
|
||||
}
|
||||
|
||||
data_for_assets.reserve(cached_game_assets.size());
|
||||
for (auto& cached_asset : cached_game_assets)
|
||||
{
|
||||
auto data = cached_asset.m_asset->GetData();
|
||||
if (data)
|
||||
{
|
||||
if (cached_asset.m_asset->Validate(texture_info.GetRawWidth(), texture_info.GetRawHeight()))
|
||||
{
|
||||
data_for_assets.push_back(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto entry =
|
||||
CreateTextureEntry(TextureCreationInfo{base_hash, full_hash, bytes_per_block, palette_size},
|
||||
texture_info, textureCacheSafetyColorSampleSize,
|
||||
std::move(data_for_assets), has_arbitrary_mipmaps, skip_texture_dump);
|
||||
entry->linked_game_texture_assets = std::move(cached_game_assets);
|
||||
entry->linked_asset_dependencies = std::move(additional_dependencies);
|
||||
texture_info, textureCacheSafetyColorSampleSize, custom_texture_data,
|
||||
has_arbitrary_mipmaps, skip_texture_dump);
|
||||
entry->hires_texture = std::move(hires_texture);
|
||||
entry->last_custom_texture_data = custom_texture_data;
|
||||
entry->texture_info_name = std::move(texture_name);
|
||||
return entry;
|
||||
}
|
||||
|
@ -1651,8 +1598,7 @@ RcTcacheEntry TextureCacheBase::GetTexture(const int textureCacheSafetyColorSamp
|
|||
// expected because each texture is loaded into a texture array
|
||||
RcTcacheEntry TextureCacheBase::CreateTextureEntry(
|
||||
const TextureCreationInfo& creation_info, const TextureInfo& texture_info,
|
||||
const int safety_color_sample_size,
|
||||
std::vector<std::shared_ptr<VideoCommon::TextureData>> assets_data,
|
||||
const int safety_color_sample_size, VideoCommon::CustomTextureData* custom_texture_data,
|
||||
const bool custom_arbitrary_mipmaps, bool skip_texture_dump)
|
||||
{
|
||||
#ifdef __APPLE__
|
||||
|
@ -1662,36 +1608,22 @@ RcTcacheEntry TextureCacheBase::CreateTextureEntry(
|
|||
#endif
|
||||
|
||||
RcTcacheEntry entry;
|
||||
if (!assets_data.empty())
|
||||
if (custom_texture_data)
|
||||
{
|
||||
const auto calculate_max_levels = [&]() {
|
||||
const auto max_element = std::max_element(
|
||||
assets_data.begin(), assets_data.end(), [](const auto& lhs, const auto& rhs) {
|
||||
return lhs->m_texture.m_slices[0].m_levels.size() <
|
||||
rhs->m_texture.m_slices[0].m_levels.size();
|
||||
});
|
||||
return (*max_element)->m_texture.m_slices[0].m_levels.size();
|
||||
};
|
||||
const u32 texLevels = no_mips ? 1 : (u32)calculate_max_levels();
|
||||
const auto& first_level = assets_data[0]->m_texture.m_slices[0].m_levels[0];
|
||||
const TextureConfig config(first_level.width, first_level.height, texLevels,
|
||||
static_cast<u32>(assets_data.size()), 1, first_level.format, 0,
|
||||
AbstractTextureType::Texture_2DArray);
|
||||
const u32 texLevels = no_mips ? 1 : (u32)custom_texture_data->m_slices[0].m_levels.size();
|
||||
const auto& first_level = custom_texture_data->m_slices[0].m_levels[0];
|
||||
const TextureConfig config(first_level.width, first_level.height, texLevels, 1, 1,
|
||||
first_level.format, 0, AbstractTextureType::Texture_2DArray);
|
||||
entry = AllocateCacheEntry(config);
|
||||
if (!entry) [[unlikely]]
|
||||
return entry;
|
||||
for (u32 data_index = 0; data_index < static_cast<u32>(assets_data.size()); data_index++)
|
||||
const auto& slice = custom_texture_data->m_slices[0];
|
||||
for (u32 level_index = 0;
|
||||
level_index < std::min(texLevels, static_cast<u32>(slice.m_levels.size())); ++level_index)
|
||||
{
|
||||
const auto& asset = assets_data[data_index];
|
||||
const auto& slice = asset->m_texture.m_slices[0];
|
||||
for (u32 level_index = 0;
|
||||
level_index < std::min(texLevels, static_cast<u32>(slice.m_levels.size()));
|
||||
++level_index)
|
||||
{
|
||||
const auto& level = slice.m_levels[level_index];
|
||||
entry->texture->Load(level_index, level.width, level.height, level.row_length,
|
||||
level.data.data(), level.data.size(), data_index);
|
||||
}
|
||||
const auto& level = slice.m_levels[level_index];
|
||||
entry->texture->Load(level_index, level.width, level.height, level.row_length,
|
||||
level.data.data(), level.data.size());
|
||||
}
|
||||
|
||||
entry->has_arbitrary_mips = custom_arbitrary_mipmaps;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "VideoCommon/AbstractTexture.h"
|
||||
#include "VideoCommon/Assets/CustomAsset.h"
|
||||
#include "VideoCommon/BPMemory.h"
|
||||
#include "VideoCommon/HiresTextures.h"
|
||||
#include "VideoCommon/TextureConfig.h"
|
||||
#include "VideoCommon/TextureDecoder.h"
|
||||
#include "VideoCommon/TextureInfo.h"
|
||||
|
@ -167,8 +168,8 @@ struct TCacheEntry
|
|||
|
||||
std::string texture_info_name = "";
|
||||
|
||||
std::vector<VideoCommon::CachedAsset<VideoCommon::GameTextureAsset>> linked_game_texture_assets;
|
||||
std::vector<VideoCommon::CachedAsset<VideoCommon::CustomAsset>> linked_asset_dependencies;
|
||||
VideoCommon::CustomTextureData* last_custom_texture_data;
|
||||
std::shared_ptr<HiresTexture> hires_texture;
|
||||
|
||||
explicit TCacheEntry(std::unique_ptr<AbstractTexture> tex,
|
||||
std::unique_ptr<AbstractFramebuffer> fb);
|
||||
|
@ -351,11 +352,10 @@ private:
|
|||
|
||||
void SetBackupConfig(const VideoConfig& config);
|
||||
|
||||
RcTcacheEntry
|
||||
CreateTextureEntry(const TextureCreationInfo& creation_info, const TextureInfo& texture_info,
|
||||
int safety_color_sample_size,
|
||||
std::vector<std::shared_ptr<VideoCommon::TextureData>> assets_data,
|
||||
bool custom_arbitrary_mipmaps, bool skip_texture_dump);
|
||||
RcTcacheEntry CreateTextureEntry(const TextureCreationInfo& creation_info,
|
||||
const TextureInfo& texture_info, int safety_color_sample_size,
|
||||
VideoCommon::CustomTextureData* custom_texture_data,
|
||||
bool custom_arbitrary_mipmaps, bool skip_texture_dump);
|
||||
|
||||
RcTcacheEntry GetXFBFromCache(u32 address, u32 width, u32 height, u32 stride);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue