Skip to content

Commit 25efd91

Browse files
committed
GS: Use integer to determine Z all equal in vertex trace.
1 parent ccce619 commit 25efd91

File tree

3 files changed

+17
-62
lines changed

3 files changed

+17
-62
lines changed

pcsx2/GS/GSState.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,11 @@ void GSState::DumpVertices(const std::string& filename)
540540
v2 = m_vt.m_max.t;
541541
file << "\tmax t (x,y,z,w): " << v2.x << DEL << v2.y << DEL << v2.z << DEL << v2.w << std::endl;
542542

543+
// FIXME: MAKE THIS A NEW PR
544+
// file << std::endl;
545+
// file << "\teq (r,g,b,a): " << m_vt.m_eq.r << DEL << m_vt.m_eq.g << DEL << m_vt.m_eq.b << DEL << m_vt.m_eq.a << std::endl;
546+
// file << "\teq (x,y,z,f): " << m_vt.m_eq.x << DEL << m_vt.m_eq.y << DEL << m_vt.m_eq.z << DEL << m_vt.m_eq.f << std::endl;
547+
// file << "\teq (s,t,q) : " << m_vt.m_eq.s << DEL << m_vt.m_eq.t << DEL << m_vt.m_eq.q << std::endl;
543548
file.close();
544549
}
545550

pcsx2/GS/Renderers/Common/GSVertexTrace.cpp

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,8 @@ void GSVertexTrace::Update(const void* vertex, const u16* index, int v_count, in
4343
m_max.c.a = 128;
4444
}
4545

46-
// FIXME: This could be moved into the FMM functions
47-
m_eq.value = (m_min.c == m_max.c).mask() | ((m_min.p == m_max.p).mask() << 16) | ((m_min.t == m_max.t).mask() << 20);
48-
4946
m_alpha.valid = false;
5047

51-
// FIXME: IF we just did the accurate STQ check, we could totally remove this
52-
// I'm not sure of the cost. In doubt let's do it only when depth is enabled
53-
if (m_state->m_context->TEST.ZTE == 1 && m_state->m_context->TEST.ZTST > ZTST_ALWAYS)
54-
{
55-
CorrectDepthTrace(vertex, v_count);
56-
}
57-
5848
if (tme)
5949
{
6050
const GIFRegTEX1& TEX1 = m_state->m_context->TEX1;
@@ -125,49 +115,3 @@ void GSVertexTrace::Update(const void* vertex, const u16* index, int v_count, in
125115
}
126116
}
127117
}
128-
129-
void GSVertexTrace::CorrectDepthTrace(const void* vertex, int count)
130-
{
131-
if (m_eq.z == 0)
132-
return;
133-
134-
// FindMinMax isn't accurate for the depth value. Lsb bit is always 0.
135-
// The code below will check that depth value is really constant
136-
// and will update m_min/m_max/m_eq accordingly
137-
//
138-
// Really impact Xenosaga3
139-
//
140-
// Hopefully function is barely called so AVX/SSE will be useless here
141-
142-
const GSVertex* RESTRICT v = (GSVertex*)vertex;
143-
144-
const int sprite_step = (m_primclass == GS_SPRITE_CLASS) ? 1 : 0;
145-
146-
u32 z = v[sprite_step].XYZ.Z;
147-
148-
if (z & 1)
149-
{
150-
// Check that first bit is always 1
151-
for (int i = sprite_step; i < count; i += (sprite_step + 1))
152-
{
153-
z &= v[i].XYZ.Z;
154-
}
155-
}
156-
else
157-
{
158-
// Check that first bit is always 0
159-
for (int i = sprite_step; i < count; i += (sprite_step + 1))
160-
{
161-
z |= v[i].XYZ.Z;
162-
}
163-
}
164-
165-
if (z == v[sprite_step].XYZ.Z)
166-
{
167-
m_eq.z = 1;
168-
}
169-
else
170-
{
171-
m_eq.z = 0;
172-
}
173-
}

pcsx2/GS/Renderers/Common/GSVertexTraceFMM.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// #define PRINTF(...) \
1212
// do \
1313
// { \
14-
// if (GSState::s_n == 4) { \
14+
// if (GSState::s_n == 10) { \
1515
// if (!debug_log) { \
1616
// debug_log = fopen("E:\\bad.log", "w"); \
1717
// } \
@@ -20,8 +20,6 @@
2020
// } \
2121
// } while (0)
2222

23-
24-
2523
class CURRENT_ISA::GSVertexTraceFMM
2624
{
2725
template <GS_PRIM_CLASS primclass, u32 iip, u32 tme, u32 fst, u32 color, bool flat_swapped>
@@ -127,6 +125,9 @@ void GSVertexTraceFMM::FindMinMax(GSVertexTrace& vt, const void* vertex, const u
127125
GSVector4 stq0 = GSVector4::cast(GSVector4i(v0.m[0]));
128126
GSVector4 stq1 = GSVector4::cast(GSVector4i(v1.m[0]));
129127

128+
// PRINTF("stq0: %f %f %f %f\n", stq0.x, stq0.y, stq0.z, stq0.w);
129+
// PRINTF("stq1: %f %f %f %f\n", stq1.x, stq1.y, stq1.z, stq1.w);
130+
130131
pxAssert(primclass != GS_SPRITE_CLASS || stq0.w == stq1.w);
131132

132133
GSVector4 q = stq0.wwww(stq1);
@@ -151,7 +152,6 @@ void GSVertexTraceFMM::FindMinMax(GSVertexTrace& vt, const void* vertex, const u
151152
tmax = tmax.max(st0.max(st1));
152153

153154
}
154-
// PRINTF("tmin: %f %f, tmax: %f %f\n", tmin.x, tmin.y, tmax.x, tmax.y);
155155
}
156156

157157
GSVector4i xyzf0(v0.m[1]);
@@ -218,8 +218,6 @@ void GSVertexTraceFMM::FindMinMax(GSVertexTrace& vt, const void* vertex, const u
218218
vt.m_min.p = (GSVector4(pmin) - o) * s;
219219
vt.m_max.p = (GSVector4(pmax) - o) * s;
220220

221-
// FIXME: We can fully determine m_eq here without having to correct depth trace, etc.
222-
223221
// Fix signed int conversion
224222
vt.m_min.p.z = (float)pmin.U32[2];
225223
vt.m_max.p.z = (float)pmax.U32[2];
@@ -254,4 +252,12 @@ void GSVertexTraceFMM::FindMinMax(GSVertexTrace& vt, const void* vertex, const u
254252
vt.m_min.c = GSVector4i::zero();
255253
vt.m_max.c = GSVector4i::zero();
256254
}
255+
256+
257+
// Use pmin==pmax integer comparison to rounding issues for Z
258+
// The cast is needed so that the mask operation gives 4 bits (instead of 16 for GSVector4i).
259+
const u32 p_eq = GSVector4::cast(pmin == pmax).mask();
260+
const u32 t_eq = (vt.m_min.t == vt.m_max.t).mask();
261+
const u32 c_eq = (vt.m_min.c == vt.m_max.c).mask();
262+
vt.m_eq.value = c_eq | (p_eq << 16) | (t_eq << 20);
257263
}

0 commit comments

Comments
 (0)