From 62c186e14b35d896d67172bc5092df2af59e715e Mon Sep 17 00:00:00 2001 From: iwubcode Date: Sat, 25 Jun 2022 00:42:17 -0500 Subject: VideoCommon: add UninitializeEFBMemory to mirror XFB function --- Source/Core/VideoCommon/TextureCacheBase.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'Source/Core/VideoCommon/TextureCacheBase.cpp') diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index 0ed5ffe014..195e4f9443 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -2225,15 +2225,7 @@ void TextureCacheBase::CopyRenderTargetToTexture( } else { - // Hack: Most games don't actually need the correct texture data in RAM - // and we can just keep a copy in VRAM. We zero the memory so we - // can check it hasn't changed before using our copy in VRAM. - u8* ptr = dst; - for (u32 i = 0; i < num_blocks_y; i++) - { - std::memset(ptr, 0, bytes_per_row); - ptr += dstStride; - } + UninitializeEFBMemory(dst, dstStride, bytes_per_row, num_blocks_y); } } @@ -2403,6 +2395,20 @@ void TextureCacheBase::ReleaseEFBCopyStagingTexture(std::unique_ptr Date: Sat, 5 Mar 2022 14:52:43 -0600 Subject: VideoCommon: trigger mod calls in TextureCacheBase (efb/xfb calls), VertexManagerBase (draw calls), and VertexShaderManager (projection calls) --- Source/Core/VideoCommon/TextureCacheBase.cpp | 54 ++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 10 deletions(-) (limited to 'Source/Core/VideoCommon/TextureCacheBase.cpp') diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index 195e4f9443..3bd6e2ae52 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -36,6 +36,7 @@ #include "VideoCommon/AbstractStagingTexture.h" #include "VideoCommon/BPMemory.h" #include "VideoCommon/FramebufferManager.h" +#include "VideoCommon/GraphicsModSystem/Runtime/FBInfo.h" #include "VideoCommon/HiresTextures.h" #include "VideoCommon/OpcodeDecoding.h" #include "VideoCommon/PixelShaderManager.h" @@ -255,6 +256,7 @@ void TextureCacheBase::SetBackupConfig(const VideoConfig& config) backup_config.gpu_texture_decoding = config.bEnableGPUTextureDecoding; backup_config.disable_vram_copies = config.bDisableCopyToVRAM; backup_config.arbitrary_mipmap_detection = config.bArbitraryMipmapDetection; + backup_config.graphics_mods = config.bGraphicMods; } TextureCacheBase::TCacheEntry* @@ -1205,15 +1207,15 @@ private: std::vector levels; }; -TextureCacheBase::TCacheEntry* TextureCacheBase::Load(const u32 stage) +TextureCacheBase::TCacheEntry* TextureCacheBase::Load(const TextureInfo& texture_info) { // if this stage was not invalidated by changes to texture registers, keep the current texture - if (TMEM::IsValid(stage) && bound_textures[stage]) + if (TMEM::IsValid(texture_info.GetStage()) && bound_textures[texture_info.GetStage()]) { - TCacheEntry* entry = bound_textures[stage]; + TCacheEntry* entry = bound_textures[texture_info.GetStage()]; // If the TMEM configuration is such that this texture is more or less guaranteed to still // be in TMEM, then we know we can reuse the old entry without even hashing the memory - if (TMEM::IsCached(stage)) + if (TMEM::IsCached(texture_info.GetStage())) { return entry; } @@ -1226,26 +1228,29 @@ TextureCacheBase::TCacheEntry* TextureCacheBase::Load(const u32 stage) } } - TextureInfo texture_info = TextureInfo::FromStage(stage); - auto entry = GetTexture(g_ActiveConfig.iSafeTextureCache_ColorSamples, texture_info); if (!entry) return nullptr; entry->frameCount = FRAMECOUNT_INVALID; - bound_textures[stage] = entry; + if (entry->texture_info_name.empty() && g_ActiveConfig.bGraphicMods) + { + entry->texture_info_name = texture_info.CalculateTextureName().GetFullName(); + } + bound_textures[texture_info.GetStage()] = entry; // We need to keep track of invalided textures until they have actually been replaced or // re-loaded - TMEM::Bind(stage, entry->NumBlocksX(), entry->NumBlocksY(), entry->GetNumLevels() > 1, - entry->format == TextureFormat::RGBA8); + TMEM::Bind(texture_info.GetStage(), entry->NumBlocksX(), entry->NumBlocksY(), + entry->GetNumLevels() > 1, entry->format == TextureFormat::RGBA8); return entry; } TextureCacheBase::TCacheEntry* -TextureCacheBase::GetTexture(const int textureCacheSafetyColorSampleSize, TextureInfo& texture_info) +TextureCacheBase::GetTexture(const int textureCacheSafetyColorSampleSize, + const TextureInfo& texture_info) { u32 expanded_width = texture_info.GetExpandedWidth(); u32 expanded_height = texture_info.GetExpandedHeight(); @@ -2119,6 +2124,35 @@ void TextureCacheBase::CopyRenderTargetToTexture( const u32 bytes_per_row = num_blocks_x * bytes_per_block; const u32 covered_range = num_blocks_y * dstStride; + if (g_ActiveConfig.bGraphicMods) + { + FBInfo info; + info.m_width = tex_w; + info.m_height = tex_h; + info.m_texture_format = baseFormat; + if (is_xfb_copy) + { + for (const auto action : g_renderer->GetGraphicsModManager().GetXFBActions(info)) + { + action->OnXFB(); + } + } + else + { + bool skip = false; + for (const auto action : g_renderer->GetGraphicsModManager().GetEFBActions(info)) + { + action->OnEFB(&skip, tex_w, tex_h, &scaled_tex_w, &scaled_tex_h); + } + if (skip == true) + { + if (copy_to_ram) + UninitializeEFBMemory(dst, dstStride, bytes_per_row, num_blocks_y); + return; + } + } + } + if (dstStride < bytes_per_row) { // This kind of efb copy results in a scrambled image. -- cgit v1.2.3 From 69839df1eb2a594b81bceb8cfac58ccbba286628 Mon Sep 17 00:00:00 2001 From: iwubcode Date: Tue, 15 Mar 2022 01:46:58 -0500 Subject: VideoCommon: support dynamically updating game mods at runtime --- Source/Core/VideoCommon/TextureCacheBase.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'Source/Core/VideoCommon/TextureCacheBase.cpp') diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index 3bd6e2ae52..9bbabb0252 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -154,6 +154,9 @@ void TextureCacheBase::OnConfigChanged(const VideoConfig& config) HiresTexture::Update(); } + const u32 change_count = + config.graphics_mod_config ? config.graphics_mod_config->GetChangeCount() : 0; + // TODO: Invalidating texcache is really stupid in some of these cases if (config.iSafeTextureCache_ColorSamples != backup_config.color_samples || config.bTexFmtOverlayEnable != backup_config.texfmt_overlay || @@ -161,7 +164,9 @@ void TextureCacheBase::OnConfigChanged(const VideoConfig& config) config.bHiresTextures != backup_config.hires_textures || config.bEnableGPUTextureDecoding != backup_config.gpu_texture_decoding || config.bDisableCopyToVRAM != backup_config.disable_vram_copies || - config.bArbitraryMipmapDetection != backup_config.arbitrary_mipmap_detection) + config.bArbitraryMipmapDetection != backup_config.arbitrary_mipmap_detection || + config.bGraphicMods != backup_config.graphics_mods || + change_count != backup_config.graphics_mod_change_count) { Invalidate(); TexDecoder_SetTexFmtOverlayOptions(config.bTexFmtOverlayEnable, config.bTexFmtOverlayCenter); @@ -257,6 +262,8 @@ void TextureCacheBase::SetBackupConfig(const VideoConfig& config) backup_config.disable_vram_copies = config.bDisableCopyToVRAM; backup_config.arbitrary_mipmap_detection = config.bArbitraryMipmapDetection; backup_config.graphics_mods = config.bGraphicMods; + backup_config.graphics_mod_change_count = + config.graphics_mod_config ? config.graphics_mod_config->GetChangeCount() : 0; } TextureCacheBase::TCacheEntry* -- cgit v1.2.3 From 1480b78f6478e4da9cc43e146d3b7377b7fe99df Mon Sep 17 00:00:00 2001 From: iwubcode Date: Thu, 26 May 2022 00:58:41 -0500 Subject: VideoCommon: dump EFB with size and texture format details and dump XFB with size details. Finally move count to front of image for XFB/EFB dumps so as to make it easier to see them in order. Change the count value prefix to 'n' --- Source/Core/VideoCommon/TextureCacheBase.cpp | 60 ++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 16 deletions(-) (limited to 'Source/Core/VideoCommon/TextureCacheBase.cpp') diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index 9bbabb0252..9eb6e09792 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -56,6 +56,8 @@ static const u64 TEXHASH_INVALID = 0; static const int TEXTURE_KILL_THRESHOLD = 64; static const int TEXTURE_POOL_KILL_THRESHOLD = 3; +static int xfb_count = 0; + std::unique_ptr g_texture_cache; TextureCacheBase::TCacheEntry::TCacheEntry(std::unique_ptr tex, @@ -1776,12 +1778,20 @@ TextureCacheBase::GetXFBTexture(u32 address, u32 width, u32 height, u32 stride, SETSTAT(g_stats.num_textures_alive, static_cast(textures_by_address.size())); INCSTAT(g_stats.num_textures_uploaded); - if (g_ActiveConfig.bDumpXFBTarget) + if (g_ActiveConfig.bDumpXFBTarget || g_ActiveConfig.bGraphicMods) { - // While this isn't really an xfb copy, we can treat it as such for dumping purposes - static int xfb_count = 0; - entry->texture->Save( - fmt::format("{}xfb_loaded_{}.png", File::GetUserPath(D_DUMPTEXTURES_IDX), xfb_count++), 0); + const std::string id = fmt::format("{}x{}", width, height); + if (g_ActiveConfig.bGraphicMods) + { + entry->texture_info_name = fmt::format("{}_{}", XFB_DUMP_PREFIX, id); + } + + if (g_ActiveConfig.bDumpXFBTarget) + { + entry->texture->Save(fmt::format("{}{}_n{:06}_{}.png", File::GetUserPath(D_DUMPTEXTURES_IDX), + XFB_DUMP_PREFIX, xfb_count++, id), + 0); + } } GetDisplayRectForXFBEntry(entry, width, height, display_rect); @@ -2209,20 +2219,38 @@ void TextureCacheBase::CopyRenderTargetToTexture( isIntensity, gamma, clamp_top, clamp_bottom, GetVRAMCopyFilterCoefficients(filter_coefficients)); - if (g_ActiveConfig.bDumpEFBTarget && !is_xfb_copy) + if (is_xfb_copy && (g_ActiveConfig.bDumpXFBTarget || g_ActiveConfig.bGraphicMods)) { - static int efb_count = 0; - entry->texture->Save( - fmt::format("{}efb_frame_{}.png", File::GetUserPath(D_DUMPTEXTURES_IDX), efb_count++), - 0); - } + const std::string id = fmt::format("{}x{}", tex_w, tex_h); + if (g_ActiveConfig.bGraphicMods) + { + entry->texture_info_name = fmt::format("{}_{}", XFB_DUMP_PREFIX, id); + } - if (g_ActiveConfig.bDumpXFBTarget && is_xfb_copy) + if (g_ActiveConfig.bDumpXFBTarget) + { + entry->texture->Save(fmt::format("{}{}_n{:06}_{}.png", + File::GetUserPath(D_DUMPTEXTURES_IDX), XFB_DUMP_PREFIX, + xfb_count++, id), + 0); + } + } + else if (g_ActiveConfig.bDumpEFBTarget || g_ActiveConfig.bGraphicMods) { - static int xfb_count = 0; - entry->texture->Save( - fmt::format("{}xfb_copy_{}.png", File::GetUserPath(D_DUMPTEXTURES_IDX), xfb_count++), - 0); + const std::string id = fmt::format("{}x{}_{}", tex_w, tex_h, static_cast(baseFormat)); + if (g_ActiveConfig.bGraphicMods) + { + entry->texture_info_name = fmt::format("{}_{}", EFB_DUMP_PREFIX, id); + } + + if (g_ActiveConfig.bDumpEFBTarget) + { + static int efb_count = 0; + entry->texture->Save(fmt::format("{}{}_n{:06}_{}.png", + File::GetUserPath(D_DUMPTEXTURES_IDX), EFB_DUMP_PREFIX, + efb_count++, id), + 0); + } } } } -- cgit v1.2.3