From ed8e1aa6dbb758fc38900abeb804286aed3ece3d Mon Sep 17 00:00:00 2001 From: Stenzek Date: Tue, 16 Apr 2024 22:44:01 +1000 Subject: [PATCH] GS/HW: Cross-reference RT alpha with CLUT for P8H --- pcsx2/GS/Renderers/HW/GSTextureCache.cpp | 12 ++++++++++++ pcsx2/GS/Renderers/HW/GSTextureCache.h | 1 + 2 files changed, 13 insertions(+) diff --git a/pcsx2/GS/Renderers/HW/GSTextureCache.cpp b/pcsx2/GS/Renderers/HW/GSTextureCache.cpp index 12dc478199..66de8f6b8e 100644 --- a/pcsx2/GS/Renderers/HW/GSTextureCache.cpp +++ b/pcsx2/GS/Renderers/HW/GSTextureCache.cpp @@ -6510,6 +6510,12 @@ void GSTextureCache::AttachPaletteToSource(Source* s, u16 pal, bool need_gs_text { s->m_alpha_minmax = s->m_palette_obj->GetAlphaMinMax(); s->m_valid_alpha_minmax = true; + + // Pretty unlikely, but if we know the RT's alpha, we can reduce the range of the palette to only the alpha's RT range. + if (s->m_TEX0.PSM == PSMT8H && s->m_from_target && s->m_from_target->HasValidAlpha()) + { + s->m_alpha_minmax = s->m_palette_obj->GetAlphaMinMax(static_cast(s->m_from_target->m_alpha_min), static_cast(s->m_from_target->m_alpha_max)); + } } } @@ -6779,6 +6785,12 @@ GSTextureCache::Palette::~Palette() _aligned_free(m_clut); } +std::pair GSTextureCache::Palette::GetAlphaMinMax(u8 min_index, u8 max_index) const +{ + pxAssert(min_index <= max_index); + return GSGetRGBA8AlphaMinMax(m_clut + min_index, max_index - min_index + 1, 1, 0); +} + GSTexture* GSTextureCache::Palette::GetPaletteGSTexture() { return m_tex_palette; diff --git a/pcsx2/GS/Renderers/HW/GSTextureCache.h b/pcsx2/GS/Renderers/HW/GSTextureCache.h index ac2be37cb6..fa2fb0a8b2 100644 --- a/pcsx2/GS/Renderers/HW/GSTextureCache.h +++ b/pcsx2/GS/Renderers/HW/GSTextureCache.h @@ -177,6 +177,7 @@ public: ~Palette(); __fi std::pair GetAlphaMinMax() const { return m_alpha_minmax; } + std::pair GetAlphaMinMax(u8 min_index, u8 max_index) const; // Disable copy constructor and copy operator Palette(const Palette&) = delete;