Skip to content

Commit

Permalink
temp-debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
TJnotJT committed Jan 31, 2025
1 parent 7f89851 commit 3ba6085
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pcsx2/GS/Renderers/SW/GSDrawScanline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <fstream>

// Comment to disable all dynamic code generation.
#define ENABLE_JIT_RASTERIZER
//#define ENABLE_JIT_RASTERIZER

#if MULTI_ISA_COMPILE_ONCE
// Lack of a better home
Expand Down
108 changes: 87 additions & 21 deletions pcsx2/GS/Renderers/SW/GSRasterizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,12 +614,75 @@ void GSRasterizer::DrawTriangle(const GSVertexSW* vertex, const u16* index)
i[1] = index[s_ysort[m1][1]];
i[2] = index[s_ysort[m1][2]];

const GSVertexSW& v0 = vertex[i[0]];
const GSVertexSW& v1 = vertex[i[1]];
const GSVertexSW& v2 = vertex[i[2]];
//const GSVertexSW& v0 = vertex[i[0]];
//const GSVertexSW& v1 = vertex[i[1]];
//const GSVertexSW& v2 = vertex[i[2]];

GSVertexSW v[3] = { vertex[i[0]], vertex[i[1]], vertex[i[2]] };

// Handle possible large/infinite ST coords
bool nan_s, nan_t, large_s, small_s, large_t, small_t;

Check notice on line 624 in pcsx2/GS/Renderers/SW/GSRasterizer.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

pcsx2/GS/Renderers/SW/GSRasterizer.cpp#L624

The scope of the variable 'nan_s' can be reduced.
if (m_local.gd->sel.fb && m_local.gd->sel.tfx != TFX_NONE)
{
if (m_local.gd->sel.fst == 0)
{
nan_s = std::isnan(v[0].t.x / v[0].t.z) || std::isnan(v[1].t.x / v[1].t.z) || std::isnan(v[2].t.x / v[2].t.z);
nan_t = std::isnan(v[0].t.y / v[0].t.z) || std::isnan(v[1].t.y / v[1].t.z) || std::isnan(v[2].t.y / v[2].t.z);
large_s = (v[0].t.x / v[0].t.z) > 1e30 || (v[1].t.x / v[1].t.z) > 1e30 || (v[2].t.x / v[2].t.z) > 1e30;
small_s = (v[0].t.x / v[0].t.z) < -1e30 || (v[1].t.x / v[1].t.z) < -1e30 || (v[2].t.x / v[2].t.z) < -1e30;
large_t = (v[0].t.y / v[0].t.z) > 1e30 || (v[1].t.y / v[1].t.z) > 1e30 || (v[2].t.y / v[2].t.z) > 1e30;
small_t = (v[0].t.y / v[0].t.z) < -1e30 || (v[1].t.y / v[1].t.z) < -1e30 || (v[2].t.y / v[2].t.z) < -1e30;
}
else
{
nan_s = std::isnan(v[0].t.x) || std::isnan(v[1].t.x) || std::isnan(v[2].t.x);
nan_t = std::isnan(v[0].t.y) || std::isnan(v[1].t.y) || std::isnan(v[2].t.y);
large_s = (v[0].t.x) > 1e30 || (v[1].t.x) > 1e30 || (v[2].t.x) > 1e30;
small_s = (v[0].t.x) < -1e30 || (v[1].t.x) < -1e30 || (v[2].t.x) < -1e30;
large_t = (v[0].t.y) > 1e30 || (v[1].t.y) > 1e30 || (v[2].t.y) > 1e30;
small_t = (v[0].t.y) < -1e30 || (v[1].t.y) < -1e30 || (v[2].t.y) < -1e30;
}

y0011 = v0.p.yyyy(v1.p);
y1221 = v1.p.yyyy(v2.p).xzzx();
if (nan_s || (large_s && small_s))
{
return; // cull the triangle
}
else if (large_s)
{
return;
v[0].t.x = 2047.0f * 65536.0f * v[0].t.z;

Check notice on line 653 in pcsx2/GS/Renderers/SW/GSRasterizer.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

pcsx2/GS/Renderers/SW/GSRasterizer.cpp#L653

Statements following 'return' will never be executed.
v[1].t.x = 2047.0f * 65536.0f * v[1].t.z;
v[2].t.x = 2047.0f * 65536.0f * v[2].t.z;
}
else if (small_s)
{
return;
v[0].t.x = -2047.0f * 65536.0f * v[0].t.z;

Check notice on line 660 in pcsx2/GS/Renderers/SW/GSRasterizer.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

pcsx2/GS/Renderers/SW/GSRasterizer.cpp#L660

Statements following 'return' will never be executed.
v[1].t.x = -2047.0f * 65536.0f * v[1].t.z;
v[2].t.x = -2047.0f * 65536.0f * v[2].t.z;
}
if (nan_t || (large_t && small_t))
{
return; // cull the triangle
}
else if (large_t)
{
return;
v[0].t.y = 2047.0f * 65536.0f * v[0].t.z;

Check notice on line 671 in pcsx2/GS/Renderers/SW/GSRasterizer.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

pcsx2/GS/Renderers/SW/GSRasterizer.cpp#L671

Statements following 'return' will never be executed.
v[1].t.y = 2047.0f * 65536.0f * v[1].t.z;
v[2].t.y = 2047.0f * 65536.0f * v[2].t.z;
}
else if (small_t)
{
return;
v[0].t.y = -2047.0f * 65536.0f * v[0].t.z;

Check notice on line 678 in pcsx2/GS/Renderers/SW/GSRasterizer.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

pcsx2/GS/Renderers/SW/GSRasterizer.cpp#L678

Statements following 'return' will never be executed.
v[1].t.y = -2047.0f * 65536.0f * v[1].t.z;
v[2].t.y = -2047.0f * 65536.0f * v[2].t.z;
}
}

y0011 = v[0].p.yyyy(v[1].p);
y1221 = v[1].p.yyyy(v[2].p).xzzx();

m1 = (y0011 == y1221).mask() & 7;

Expand All @@ -635,9 +698,9 @@ void GSRasterizer::DrawTriangle(const GSVertexSW* vertex, const u16* index)
GSVector4 tbmin = tbf.min(m_fscissor_y);
GSVector4i tb = GSVector4i(tbmax.xzyw(tbmin)); // max(y0, t) max(y1, t) min(y1, b) min(y2, b)

GSVertexSW dv0 = v1 - v0;
GSVertexSW dv1 = v2 - v0;
GSVertexSW dv2 = v2 - v1;
GSVertexSW dv0 = v[1] - v[0];
GSVertexSW dv1 = v[2] - v[0];
GSVertexSW dv2 = v[2] - v[1];

GSVector4 cross = GSVector4::loadl(&dv0.p) * GSVector4::loadl(&dv1.p).yxwz();

Expand Down Expand Up @@ -672,38 +735,40 @@ void GSRasterizer::DrawTriangle(const GSVertexSW* vertex, const u16* index)
{
if (tb.y < tb.w)
{
edge = vertex[i[1 - m2]];
edge = v[1 - m2]; // NEED TO FIX HERE!!!

edge.p.y = vertex[i[m2]].p.x;
edge.p.y = v[m2].p.x;
dedge.p = ddx[!m2 << 1].yzzw(dedge.p);

DrawTriangleSection(tb.x, tb.w, edge, dedge, dscan, vertex[i[1 - m2]].p);
DrawTriangleSection(tb.x, tb.w, edge, dedge, dscan, v[1 - m2].p);
}
}
else
{
if (tb.x < tb.z)
{
edge = v0;
edge = v[0];

edge.p.y = edge.p.x;
dedge.p = ddx[m2].xyzw(dedge.p);

DrawTriangleSection(tb.x, tb.z, edge, dedge, dscan, v0.p);
DrawTriangleSection(tb.x, tb.z, edge, dedge, dscan, v[0].p);
}

if (tb.y < tb.w)
{
edge = v1;
edge = v[1];

edge.p = (v0.p.xxxx() + ddx[m2] * dv0.p.yyyy()).xyzw(edge.p);
edge.p = (v[0].p.xxxx() + ddx[m2] * dv0.p.yyyy()).xyzw(edge.p);
dedge.p = ddx[!m2 << 1].yzzw(dedge.p);

DrawTriangleSection(tb.y, tb.w, edge, dedge, dscan, v1.p);
DrawTriangleSection(tb.y, tb.w, edge, dedge, dscan, v[1].p);
}
}

Flush(vertex, index, dscan);
u16 idx[3] = {0, 1, 2};
//Flush(vertex, index, dscan);
Flush(vertex, idx, dscan);

if (HasEdge())
{
Expand All @@ -714,11 +779,12 @@ void GSRasterizer::DrawTriangle(const GSVertexSW* vertex, const u16* index)
int orientation = a.mask();
int side = ((a | b) ^ c).mask() ^ 2; // evil

DrawEdge(v0, v1, dv0, orientation & 1, side & 1);
DrawEdge(v0, v2, dv1, orientation & 2, side & 2);
DrawEdge(v1, v2, dv2, orientation & 4, side & 4);
DrawEdge(v[0], v[1], dv0, orientation & 1, side & 1);
DrawEdge(v[0], v[2], dv1, orientation & 2, side & 2);
DrawEdge(v[1], v[2], dv2, orientation & 4, side & 4);

Flush(vertex, index, GSVertexSW::zero(), true);
//Flush(vertex, index, GSVertexSW::zero(), true);
Flush(vertex, idx, GSVertexSW::zero(), true);
}
}

Expand Down
1 change: 1 addition & 0 deletions pcsx2/GS/Renderers/SW/GSRendererSW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ MULTI_ISA_UNSHARED_IMPL;

GSRenderer* CURRENT_ISA::makeGSRendererSW(int threads)
{
threads = 0;
return new GSRendererSW(threads);
}

Expand Down

0 comments on commit 3ba6085

Please sign in to comment.