@@ -1728,7 +1728,96 @@ void GSState::FlushPrim()
17281728 // Sometimes hardware doesn't get affected, likely due to the difference in how GPU's handle textures (Persona minimap).
17291729 if (PRIM->TME && (GSUtil::GetPrimClass (PRIM->PRIM ) == GS_PRIM_CLASS::GS_SPRITE_CLASS || m_vt.m_eq .z ))
17301730 {
1731- if (!PRIM->FST ) // STQ's
1731+ if (PRIM->FST && GSConfig.PreRoundSprites ) // UV's
1732+ {
1733+ // UV's on sprites only alter the final UV, I believe the problem is we're drawing too much (drawing stops earlier than we do)
1734+ // But this fixes Beyond Good adn Evil water and Dark Cloud 2's UI
1735+ if (GSUtil::GetPrimClass (PRIM->PRIM ) == GS_PRIM_CLASS::GS_SPRITE_CLASS)
1736+ {
1737+ for (u32 i = 0 ; i < m_index.tail ; i += 2 )
1738+ {
1739+ GSVertex* v1 = &m_vertex.buff [m_index.buff [i]];
1740+ GSVertex* v2 = &m_vertex.buff [m_index.buff [i + 1 ]];
1741+
1742+ GSVertex* vu1;
1743+ GSVertex* vu2;
1744+ GSVertex* vv1;
1745+ GSVertex* vv2;
1746+ if (v1->U > v2->U )
1747+ {
1748+ vu2 = v1;
1749+ vu1 = v2;
1750+ }
1751+ else
1752+ {
1753+ vu2 = v2;
1754+ vu1 = v1;
1755+ }
1756+
1757+ if (v1->V > v2->V )
1758+ {
1759+ vv2 = v1;
1760+ vv1 = v2;
1761+ }
1762+ else
1763+ {
1764+ vv2 = v2;
1765+ vv1 = v1;
1766+ }
1767+
1768+ GSVector2 pos_range (vu2->XYZ .X - vu1->XYZ .X , vv2->XYZ .Y - vv1->XYZ .Y );
1769+ const GSVector2 uv_range (vu2->U - vu1->U , vv2->V - vv1->V );
1770+ if (pos_range.x == 0 )
1771+ pos_range.x = 1 ;
1772+ if (pos_range.y == 0 )
1773+ pos_range.y = 1 ;
1774+ const GSVector2 grad (uv_range / pos_range);
1775+ bool isclamp_w = m_context->CLAMP .WMS > 0 && m_context->CLAMP .WMS < 3 ;
1776+ bool isclamp_h = m_context->CLAMP .WMT > 0 && m_context->CLAMP .WMT < 3 ;
1777+ int max_w = (m_context->CLAMP .WMS == 2 ) ? m_context->CLAMP .MAXU : ((1 << m_context->TEX0 .TW ) - 1 );
1778+ int max_h = (m_context->CLAMP .WMT == 2 ) ? m_context->CLAMP .MAXV : ((1 << m_context->TEX0 .TH ) - 1 );
1779+ int width = vu2->U >> 4 ;
1780+ int height = vv2->V >> 4 ;
1781+
1782+ if (m_context->CLAMP .WMS == 3 )
1783+ width = (width & m_context->CLAMP .MINU ) | m_context->CLAMP .MAXU ;
1784+
1785+ if (m_context->CLAMP .WMT == 3 )
1786+ height = (height & m_context->CLAMP .MINV ) | m_context->CLAMP .MAXV ;
1787+
1788+ if ((isclamp_w && width <= max_w && grad.x != 1 .0f ) || !isclamp_w)
1789+ {
1790+ if (vu2->U >= 0x1 && (!(vu2->U & 0xf ) || grad.x <= 1 .0f ))
1791+ {
1792+ vu2->U = (vu2->U - 1 );
1793+ /* if (!isclamp_w && ((vu2->XYZ.X - m_context->XYOFFSET.OFX) >> 4) < m_context->scissor.in.z)
1794+ vu2->XYZ.X -= 1;*/
1795+ }
1796+ }
1797+ else
1798+ vu2->U &= ~0xf ;
1799+
1800+ // Dark Cloud 2 tries to address wider than the TBW when in CLAMP mode (maybe some weird behaviour in HW?)
1801+ if ((vu2->U >> 4 ) > (int )(m_context->TEX0 .TBW * 64 ) && isclamp_w && (vu2->U >> 4 ) - 8 <= (int )(m_context->TEX0 .TBW * 64 ))
1802+ {
1803+ vu2->U = (m_context->TEX0 .TBW * 64 ) << 4 ;
1804+ }
1805+
1806+ if ((isclamp_h && height <= max_h && grad.y != 1 .0f ) || !isclamp_h)
1807+ {
1808+ if (vv2->V >= 0x1 && (!(vv2->V & 0xf ) || grad.y <= 1 .0f ))
1809+ {
1810+ vv2->V = (vv2->V - 1 );
1811+ /* if (!isclamp_h && ((vv2->XYZ.Y - m_context->XYOFFSET.OFY) >> 4) < m_context->scissor.in.w)
1812+ vv2->XYZ.Y -= 1;*/
1813+ }
1814+ }
1815+ else
1816+ vv2->V &= ~0xf ;
1817+ }
1818+ }
1819+ }
1820+ else if (!PRIM->FST ) // STQ's
17321821 {
17331822 const bool is_sprite = GSUtil::GetPrimClass (PRIM->PRIM ) == GS_PRIM_CLASS::GS_SPRITE_CLASS;
17341823 // ST's have the lowest 9 bits (or greater depending on exponent difference) rounding down (from hardware tests).
@@ -1782,7 +1871,6 @@ void GSState::FlushPrim()
17821871 if (unused > 0 )
17831872 {
17841873 memcpy (m_vertex.buff , buff, sizeof (GSVertex) * unused);
1785-
17861874 m_vertex.tail = unused;
17871875 m_vertex.next = next > head ? next - head : 0 ;
17881876
@@ -3671,7 +3759,6 @@ __forceinline void GSState::VertexKick(u32 skip)
36713759 const GSVector4i new_v1 (m_v.m [1 ]);
36723760
36733761 GSVector4i* RESTRICT tailptr = (GSVector4i*)&m_vertex.buff [tail];
3674-
36753762 tailptr[0 ] = new_v0;
36763763 tailptr[1 ] = new_v1;
36773764
0 commit comments