Skip to content

Commit 28bd2ef

Browse files
committed
GS: Clamp UV coordinates in vertex trace to prevent floating to integer casting overflow.
1 parent 6a0f811 commit 28bd2ef

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

pcsx2/GS/GSState.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3924,6 +3924,8 @@ GSState::TextureMinMaxResult GSState::GetTextureMinMax(GIFRegTEX0 TEX0, GIFRegCL
39243924
}
39253925
}
39263926

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

pcsx2/GS/Renderers/Common/GSVertexTraceFMM.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,12 @@ void GSVertexTraceFMM::FindMinMax(GSVertexTrace& vt, const void* vertex, const u
246246

247247
vt.m_min.t = tmin * s;
248248
vt.m_max.t = tmax * s;
249+
250+
// Clamp the min/max values to the min/max valid UV values
251+
// This is needed in certain cases where buggy GS input results
252+
// in huge floating points values for ST.
253+
vt.m_min.t = vt.m_min.t.min(GSVector4(2047.0)).max(GSVector4(-2047.0)).xyxy(vt.m_min.t);
254+
vt.m_max.t = vt.m_max.t.min(GSVector4(2047.0)).max(GSVector4(-2047.0)).xyxy(vt.m_max.t);
249255
}
250256
else
251257
{

0 commit comments

Comments
 (0)