From 0539bb4a3ea4afed58c2a43a98c51baea760815d Mon Sep 17 00:00:00 2001 From: iwubcode Date: Sun, 2 Jul 2023 13:35:05 -0500 Subject: [PATCH] VideoCommon: call into graphics mods create texture callback, providing additional asset dependencies that trigger the texture to be reloaded --- .../Runtime/GraphicsModActionData.h | 9 ++++ Source/Core/VideoCommon/TextureCacheBase.cpp | 44 +++++++++++++++++++ Source/Core/VideoCommon/TextureCacheBase.h | 1 + 3 files changed, 54 insertions(+) diff --git a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionData.h b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionData.h index 48de0e5368..2b1408dcc9 100644 --- a/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionData.h +++ b/Source/Core/VideoCommon/GraphicsModSystem/Runtime/GraphicsModActionData.h @@ -4,9 +4,11 @@ #pragma once #include +#include #include "Common/CommonTypes.h" #include "Common/Matrix.h" +#include "VideoCommon/Assets/TextureAsset.h" namespace GraphicsModActionData { @@ -34,5 +36,12 @@ struct TextureLoad }; struct TextureCreate { + std::string_view texture_name; + u32 texture_width; + u32 texture_height; + std::vector>* custom_textures; + + // Dependencies needed to reload the texture and trigger this create again + std::vector>* additional_dependencies; }; } // namespace GraphicsModActionData diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index 5dc00a9733..7ad97f94db 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -272,6 +272,15 @@ bool TextureCacheBase::DidLinkedAssetsChange(const TCacheEntry& entry) } } + 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; } @@ -1612,6 +1621,39 @@ RcTcacheEntry TextureCacheBase::GetTexture(const int textureCacheSafetyColorSamp } } + std::vector> 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_levels.empty()) + { + height = data->m_levels[0].height; + width = data->m_levels[0].width; + } + } + } + } + texture_name = texture_info.CalculateTextureName().GetFullName(); + GraphicsModActionData::TextureCreate texture_create{ + texture_name, width, height, &cached_game_assets, &additional_dependencies}; + for (const auto& action : g_graphics_mod_manager->GetTextureCreateActions(texture_name)) + { + action->OnTextureCreate(&texture_create); + } + } + for (auto& cached_asset : cached_game_assets) { auto data = cached_asset.m_asset->GetData(); @@ -1628,6 +1670,8 @@ RcTcacheEntry TextureCacheBase::GetTexture(const int textureCacheSafetyColorSamp TextureCreationInfo{base_hash, full_hash, bytes_per_block, palette_size}, texture_info, textureCacheSafetyColorSampleSize, std::move(data_for_assets), has_arbitrary_mipmaps); entry->linked_game_texture_assets = std::move(cached_game_assets); + entry->linked_asset_dependencies = std::move(additional_dependencies); + entry->texture_info_name = std::move(texture_name); return entry; } diff --git a/Source/Core/VideoCommon/TextureCacheBase.h b/Source/Core/VideoCommon/TextureCacheBase.h index db5e11ea29..65b0d2b469 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.h +++ b/Source/Core/VideoCommon/TextureCacheBase.h @@ -168,6 +168,7 @@ struct TCacheEntry std::string texture_info_name = ""; std::vector> linked_game_texture_assets; + std::vector> linked_asset_dependencies; explicit TCacheEntry(std::unique_ptr tex, std::unique_ptr fb);