gsdx: fix Q NaN value

Avoid potential undefined results
This commit is contained in:
Gregory Hainaut 2016-04-26 19:09:32 +02:00
parent 726b901dc5
commit df70b8bb0e
1 changed files with 7 additions and 14 deletions

View File

@ -515,11 +515,13 @@ void GSState::GIFPackedRegHandlerSTQ(const GIFPackedReg* RESTRICT r)
GSVector4i::storel(&m_v.ST, st);
q = q.blend8(GSVector4i::cast(GSVector4::m_one), q == GSVector4i::zero()); // character shadow in Vexx, q = 0 (st also 0 on the first 16 vertices), setting it to 1.0f to avoid div by zero later
// character shadow in Vexx, q = 0 (st also 0 on the first 16 vertices), setting it to 1.0f to avoid div by zero later
q = q.blend8(GSVector4i::cast(GSVector4::m_one), q == GSVector4i::zero());
// Suikoden 4 creates some nan for Q. Let's avoid undefined behavior (See GIFRegHandlerRGBAQ)
q = GSVector4i::cast(GSVector4::cast(q).replace_nan(GSVector4::m_max));
*(int*)&m_q = GSVector4i::store(q);
ASSERT(!std::isnan(m_q)); // See GIFRegHandlerRGBAQ
ASSERT(!std::isnan(m_v.ST.S)); // See GIFRegHandlerRGBAQ
ASSERT(!std::isnan(m_v.ST.T)); // See GIFRegHandlerRGBAQ
@ -732,15 +734,6 @@ void GSState::GIFRegHandlerRGBAQ(const GIFReg* RESTRICT r)
q = GSVector4i::cast(GSVector4::cast(q).replace_nan(GSVector4::m_max));
m_v.RGBAQ = rgbaq.upl32(q);
/*
// Silent Hill output a nan in Q to emulate the flash light. Unfortunately it
// breaks GSVertexTrace code that rely on min/max.
if (std::isnan(m_v.RGBAQ.Q))
{
m_v.RGBAQ.Q = std::numeric_limits<float>::max();
}
*/
}
void GSState::GIFRegHandlerST(const GIFReg* RESTRICT r)