Skip to content

Commit

Permalink
GS: Properly check load condition when reloading CLUT
Browse files Browse the repository at this point in the history
  • Loading branch information
refractionpcsx2 committed Oct 30, 2023
1 parent f350f99 commit bb9e1c5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
29 changes: 22 additions & 7 deletions pcsx2/GS/GSClut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,8 @@ bool GSClut::InvalidateRange(u32 start_block, u32 end_block, bool is_draw)
return m_write.dirty;
}

bool GSClut::WriteTest(const GIFRegTEX0& TEX0, const GIFRegTEXCLUT& TEXCLUT)
bool GSClut::CanLoadCLUT(const GIFRegTEX0& TEX0, const bool update_CBP)
{
// Check if PSM is an indexed format BEFORE the load condition, updating CBP0/1 on an invalid format is not allowed
// and can break games. Corvette (NTSC) is a good example of this.
if ((TEX0.PSM & 0x7) < 3)
return false;

Expand All @@ -182,20 +180,24 @@ bool GSClut::WriteTest(const GIFRegTEX0& TEX0, const GIFRegTEXCLUT& TEXCLUT)
case 1:
break;
case 2:
m_CBP[0] = TEX0.CBP;
if (update_CBP)
m_CBP[0] = TEX0.CBP;
break;
case 3:
m_CBP[1] = TEX0.CBP;
if (update_CBP)
m_CBP[1] = TEX0.CBP;
break;
case 4:
if (m_CBP[0] == TEX0.CBP)
return false;
m_CBP[0] = TEX0.CBP;
if(update_CBP)
m_CBP[0] = TEX0.CBP;
break;
case 5:
if (m_CBP[1] == TEX0.CBP)
return false;
m_CBP[1] = TEX0.CBP;
if (update_CBP)
m_CBP[1] = TEX0.CBP;
break;
case 6:
return false; // ffx2 menu.
Expand All @@ -205,6 +207,19 @@ bool GSClut::WriteTest(const GIFRegTEX0& TEX0, const GIFRegTEXCLUT& TEXCLUT)
__assume(0);
}

return true;
}

bool GSClut::WriteTest(const GIFRegTEX0& TEX0, const GIFRegTEXCLUT& TEXCLUT)
{
// Check if PSM is an indexed format BEFORE the load condition, updating CBP0/1 on an invalid format is not allowed
// and can break games. Corvette (NTSC) is a good example of this.
if ((TEX0.PSM & 0x7) < 3)
return false;

if (!CanLoadCLUT(TEX0, true))
return false;

// CLUT only reloads if PSM is a valid index type, avoid unnecessary flushes.
return m_write.IsDirty(TEX0, TEXCLUT);
}
Expand Down
1 change: 1 addition & 0 deletions pcsx2/GS/GSClut.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class alignas(32) GSClut final : public GSAlignedClass<32>
u32 GetCLUTCBP();
u32 GetCLUTCPSM();
void SetNextCLUTTEX0(u64 CBP);
bool CanLoadCLUT(const GIFRegTEX0& TEX0, const bool update_CBP = false);
bool WriteTest(const GIFRegTEX0& TEX0, const GIFRegTEXCLUT& TEXCLUT);
void Write(const GIFRegTEX0& TEX0, const GIFRegTEXCLUT& TEXCLUT);
//void Read(const GIFRegTEX0& TEX0);
Expand Down
2 changes: 1 addition & 1 deletion pcsx2/GS/GSState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ void GSState::ApplyTEX0(GIFRegTEX0& TEX0)

GL_REG("Apply TEX0_%d = 0x%x_%x", i, TEX0.U32[1], TEX0.U32[0]);

if ((TEX0.PSM & 0x7) >= 3 && TEX0.CLD)
if ((TEX0.PSM & 0x7) >= 3 && m_mem.m_clut.CanLoadCLUT(TEX0))
{
m_mem.m_clut.ClearDrawInvalidity();
m_mem.m_clut.SetNextCLUTTEX0(TEX0.U64);
Expand Down

0 comments on commit bb9e1c5

Please sign in to comment.