Skip to content

Commit

Permalink
GS: Clamp UV coordinates in vertex trace to prevent floating to integ…
Browse files Browse the repository at this point in the history
…er casting overflow.
  • Loading branch information
TJnotJT committed Jan 16, 2025
1 parent 6a0f811 commit 28bd2ef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pcsx2/GS/GSState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3924,6 +3924,8 @@ GSState::TextureMinMaxResult GSState::GetTextureMinMax(GIFRegTEX0 TEX0, GIFRegCL
}
}


// Sometimes ST get huge values (possibly game or emulation bugs) so clamp to
const GSVector4i uv = GSVector4i(st.floor());
uses_border = GSVector4::cast((uv < vr).blend32<0xc>(uv >= vr)).mask();

Expand Down
6 changes: 6 additions & 0 deletions pcsx2/GS/Renderers/Common/GSVertexTraceFMM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ void GSVertexTraceFMM::FindMinMax(GSVertexTrace& vt, const void* vertex, const u

vt.m_min.t = tmin * s;
vt.m_max.t = tmax * s;

// Clamp the min/max values to the min/max valid UV values
// This is needed in certain cases where buggy GS input results
// in huge floating points values for ST.
vt.m_min.t = vt.m_min.t.min(GSVector4(2047.0)).max(GSVector4(-2047.0)).xyxy(vt.m_min.t);
vt.m_max.t = vt.m_max.t.min(GSVector4(2047.0)).max(GSVector4(-2047.0)).xyxy(vt.m_max.t);
}
else
{
Expand Down

0 comments on commit 28bd2ef

Please sign in to comment.