Skip to content

Commit

Permalink
GS/HW: Cross-reference RT alpha with CLUT for P8H
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Apr 17, 2024
1 parent 8e8581c commit ed8e1aa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pcsx2/GS/Renderers/HW/GSTextureCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>(s->m_from_target->m_alpha_min), static_cast<u8>(s->m_from_target->m_alpha_max));
}
}
}

Expand Down Expand Up @@ -6779,6 +6785,12 @@ GSTextureCache::Palette::~Palette()
_aligned_free(m_clut);
}

std::pair<u8, u8> 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;
Expand Down
1 change: 1 addition & 0 deletions pcsx2/GS/Renderers/HW/GSTextureCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class GSTextureCache
~Palette();

__fi std::pair<u8, u8> GetAlphaMinMax() const { return m_alpha_minmax; }
std::pair<u8, u8> GetAlphaMinMax(u8 min_index, u8 max_index) const;

// Disable copy constructor and copy operator
Palette(const Palette&) = delete;
Expand Down

0 comments on commit ed8e1aa

Please sign in to comment.