Skip to content

Commit

Permalink
GS: Fix reload texture replacements hotkey
Browse files Browse the repository at this point in the history
Also skips tossing targets, they can get kept around for less jank.
  • Loading branch information
stenzek committed Nov 5, 2023
1 parent 66b779a commit cd5a916
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 33 deletions.
16 changes: 11 additions & 5 deletions pcsx2/GS/GS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ bool GSreopen(bool recreate_device, bool recreate_renderer, const Pcsx2Config::G
else
{
// Make sure nothing is left over.
g_gs_renderer->PurgeTextureCache();
g_gs_renderer->PurgeTextureCache(true, true, true);
g_gs_renderer->PurgePool();
}

Expand Down Expand Up @@ -759,7 +759,7 @@ void GSUpdateConfig(const Pcsx2Config::GSOptions& new_config)
{
if (GSConfig.UserHacks_ReadTCOnClose)
g_gs_renderer->ReadbackTextureCache();
g_gs_renderer->PurgeTextureCache();
g_gs_renderer->PurgeTextureCache(true, true, true);
g_gs_renderer->PurgePool();
}

Expand All @@ -776,7 +776,7 @@ void GSUpdateConfig(const Pcsx2Config::GSOptions& new_config)
if (GSConfig.LoadTextureReplacements != old_config.LoadTextureReplacements ||
GSConfig.DumpReplaceableTextures != old_config.DumpReplaceableTextures)
{
g_gs_renderer->PurgeTextureCache();
g_gs_renderer->PurgeTextureCache(true, false, true);
}

if (GSConfig.OsdShowGPU != old_config.OsdShowGPU)
Expand Down Expand Up @@ -1118,7 +1118,7 @@ BEGIN_HOTKEY_LIST(g_gs_hotkeys){"Screenshot", TRANSLATE_NOOP("Hotkeys", "Graphic

MTGS::RunOnGSThread([new_level]() {
GSConfig.HWMipmap = new_level;
g_gs_renderer->PurgeTextureCache();
g_gs_renderer->PurgeTextureCache(true, false, true);
g_gs_renderer->PurgePool();
});
}},
Expand Down Expand Up @@ -1190,7 +1190,13 @@ BEGIN_HOTKEY_LIST(g_gs_hotkeys){"Screenshot", TRANSLATE_NOOP("Hotkeys", "Graphic
{
Host::AddKeyedOSDMessage("ReloadTextureReplacements",
TRANSLATE_STR("Hotkeys", "Reloading texture replacements..."), Host::OSD_INFO_DURATION);
MTGS::RunOnGSThread([]() { GSTextureReplacements::ReloadReplacementMap(); });
MTGS::RunOnGSThread([]() {
if (!g_gs_renderer)
return;

GSTextureReplacements::ReloadReplacementMap();
g_gs_renderer->PurgeTextureCache(true, false, true);
});
}
}
}},
Expand Down
2 changes: 1 addition & 1 deletion pcsx2/GS/GSState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2269,7 +2269,7 @@ void GSState::ReadLocalMemoryUnsync(u8* mem, int qwc, GIFRegBITBLTBUF BITBLTBUF,
}
}

void GSState::PurgeTextureCache()
void GSState::PurgeTextureCache(bool sources, bool targets, bool hash_cache)
{
}

Expand Down
2 changes: 1 addition & 1 deletion pcsx2/GS/GSState.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ class GSState : public GSAlignedClass<32>
bool TestDrawChanged();
void FlushWrite();
virtual void Draw() = 0;
virtual void PurgeTextureCache();
virtual void PurgeTextureCache(bool sources, bool targets, bool hash_cache);
virtual void ReadbackTextureCache();
virtual void InvalidateVideoMem(const GIFRegBITBLTBUF& BITBLTBUF, const GSVector4i& r) {}
virtual void InvalidateLocalMem(const GIFRegBITBLTBUF& BITBLTBUF, const GSVector4i& r, bool clut = false) {}
Expand Down
10 changes: 5 additions & 5 deletions pcsx2/GS/Renderers/HW/GSRendererHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ GSRendererHW::~GSRendererHW()

void GSRendererHW::Destroy()
{
g_texture_cache->RemoveAll();
g_texture_cache->RemoveAll(true, true, true);
GSRenderer::Destroy();
}

void GSRendererHW::PurgeTextureCache()
void GSRendererHW::PurgeTextureCache(bool sources, bool targets, bool hash_cache)
{
g_texture_cache->RemoveAll();
g_texture_cache->RemoveAll(sources, targets, hash_cache);
}

void GSRendererHW::ReadbackTextureCache()
Expand Down Expand Up @@ -92,7 +92,7 @@ void GSRendererHW::Reset(bool hardware_reset)
if (!hardware_reset)
g_texture_cache->ReadbackAll();

g_texture_cache->RemoveAll();
g_texture_cache->RemoveAll(true, true, true);

GSRenderer::Reset(hardware_reset);
}
Expand Down Expand Up @@ -144,7 +144,7 @@ void GSRendererHW::VSync(u32 field, bool registers_written, bool idle_frame)
fmt::format(TRANSLATE_FS("GS", "Hash cache has used {:.2f} MB of VRAM, disabling."),
static_cast<float>(g_texture_cache->GetHashCacheMemoryUsage()) / 1048576.0f),
Host::OSD_ERROR_DURATION);
g_texture_cache->RemoveAll();
g_texture_cache->RemoveAll(true, false, true);
g_gs_device->PurgePool();
GSConfig.TexturePreloading = TexturePreloadingLevel::Partial;
}
Expand Down
2 changes: 1 addition & 1 deletion pcsx2/GS/Renderers/HW/GSRendererHW.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class GSRendererHW : public GSRenderer
void Move() override;
void Draw() override;

void PurgeTextureCache() override;
void PurgeTextureCache(bool sources, bool targets, bool hash_cache) override;
void ReadbackTextureCache() override;
GSTexture* LookupPaletteSource(u32 CBP, u32 CPSM, u32 CBW, GSVector2i& offset, float* scale, const GSVector2i& size) override;

Expand Down
45 changes: 26 additions & 19 deletions pcsx2/GS/Renderers/HW/GSTextureCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ GSTextureCache::GSTextureCache()

GSTextureCache::~GSTextureCache()
{
RemoveAll();
RemoveAll(true, true, true);

s_hash_cache_purge_list = {};
_aligned_free(s_unswizzle_buffer);
Expand All @@ -66,32 +66,39 @@ void GSTextureCache::ReadbackAll()
}
}

void GSTextureCache::RemoveAll()
void GSTextureCache::RemoveAll(bool sources, bool targets, bool hash_cache)
{
m_src.RemoveAll();

for (int type = 0; type < 2; type++)
if (sources || targets)
{
for (auto t : m_dst[type])
delete t;

m_dst[type].clear();
m_src.RemoveAll();
m_palette_map.Clear();
m_source_memory_usage = 0;
}

for (auto it : m_hash_cache)
g_gs_device->Recycle(it.second.texture);
if (targets)
{
for (int type = 0; type < 2; type++)
{
for (auto t : m_dst[type])
delete t;

m_hash_cache.clear();
m_hash_cache_memory_usage = 0;
m_hash_cache_replacement_memory_usage = 0;
m_dst[type].clear();
}

m_palette_map.Clear();
m_target_heights.clear();
m_target_heights.clear();
m_surface_offset_cache.clear();
m_target_memory_usage = 0;
}

m_source_memory_usage = 0;
m_target_memory_usage = 0;
if (hash_cache)
{
for (auto it : m_hash_cache)
g_gs_device->Recycle(it.second.texture);

m_surface_offset_cache.clear();
m_hash_cache.clear();
m_hash_cache_memory_usage = 0;
m_hash_cache_replacement_memory_usage = 0;
}
}

bool GSTextureCache::FullRectDirty(Target* target, u32 rgba_mask)
Expand Down
2 changes: 1 addition & 1 deletion pcsx2/GS/Renderers/HW/GSTextureCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ class GSTextureCache

void Read(Target* t, const GSVector4i& r);
void Read(Source* t, const GSVector4i& r);
void RemoveAll();
void RemoveAll(bool sources, bool targets, bool hash_cache);
void ReadbackAll();
void AddDirtyRectTarget(Target* target, GSVector4i rect, u32 psm, u32 bw, RGBAMask rgba, bool req_linear = false);
void ResizeTarget(Target* t, GSVector4i rect, u32 tbp, u32 psm, u32 tbw);
Expand Down

0 comments on commit cd5a916

Please sign in to comment.