Skip to content

Commit 34c4629

Browse files
committed
temp-commit
1 parent 9a9d41c commit 34c4629

File tree

11 files changed

+262
-33
lines changed

11 files changed

+262
-33
lines changed

pcsx2-gsrunner/Main.cpp

Lines changed: 121 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,35 @@
4646

4747
#include "svnrev.h"
4848

49+
#include "debug.h"
50+
51+
#if MY_DEBUG || MY_DUMP
52+
#define DEBUG_FILE_STR "hack"
53+
#define DEBUG_DUMP_DIR "C:\\Users\\tchan\\Desktop\\ps2_debug\\" DEBUG_FILE_STR "-dump-all"
54+
#define DEBUG_RANGE_FILE_CALC "C:\\Users\\tchan\\Desktop\\log_files\\pointsRange_" DEBUG_FILE_STR "_calc.txt"
55+
#define DEBUG_RANGE_FILE_SW "C:\\Users\\tchan\\Desktop\\log_files\\pointsRange_" DEBUG_FILE_STR "_sw.txt"
56+
#define DEBUG_LIST_FILE_CALC "C:\\Users\\tchan\\Desktop\\log_files\\pointsList_" DEBUG_FILE_STR "_calc_%d.txt"
57+
#define DEBUG_LIST_FILE_SW "C:\\Users\\tchan\\Desktop\\log_files\\pointsList_" DEBUG_FILE_STR "_sw_%d.txt"
58+
#define DEBUG_ORIG_FILE_CALC "C:\\Users\\tchan\\Desktop\\log_files\\pointsOrig_" DEBUG_FILE_STR "_calc_%d.txt"
59+
#define DEBUG_ORIG_FILE_SW "C:\\Users\\tchan\\Desktop\\log_files\\pointsOrig_" DEBUG_FILE_STR "_sw_%d.txt"
60+
61+
bool savePoints = false;
62+
bool dumpAll = true;
63+
int dump_frame_0 = 5072;
64+
int dump_frame_1 = 5074;
65+
int s_n_debug = -1;
66+
int s_n_exit = -1;
67+
int primID = 0;
68+
int* primIDSW = 0;
69+
std::map<int, std::tuple<int, int, int, int>> pointsCalcRange;
70+
std::map<int, std::tuple<int, int, int, int>> pointsSWRange;
71+
std::vector<std::tuple<int, int, int, int, int>> pointsCalcDebug;
72+
std::vector<std::tuple<int, int, int, int, int>> pointsSWDebug;
73+
std::map<std::tuple<int, int>, std::tuple<double, double, double, double>> pointsCalcDebugOrig;
74+
std::map<std::tuple<int, int>, std::tuple<double, double, double, double>> pointsSWDebugOrig;
75+
std::string debugDumpDir = DEBUG_DUMP_DIR;
76+
#endif
77+
4978
namespace GSRunner
5079
{
5180
static void InitializeConsole();
@@ -134,6 +163,20 @@ bool GSRunner::InitializeConfig()
134163
si.SetBoolValue("EmuCore/GS", "OsdShowResolution", true);
135164
si.SetBoolValue("EmuCore/GS", "OsdShowGSStats", true);
136165

166+
#if MY_DEBUG || MY_DUMP
167+
if (dumpAll)
168+
{
169+
si.SetBoolValue("EmuCore/GS", "dump", true);
170+
si.SetIntValue("EmuCore/GS", "saven", 0);
171+
si.SetIntValue("EmuCore/GS", "savel", -1);
172+
si.SetBoolValue("EmuCore/GS", "save", true);
173+
si.SetBoolValue("EmuCore/GS", "savef", true);
174+
si.SetBoolValue("EmuCore/GS", "savet", true);
175+
si.SetBoolValue("EmuCore/GS", "savez", true);
176+
si.SetStringValue("EmuCore/GS", "HWDumpDirectory", debugDumpDir.c_str());
177+
si.SetStringValue("EmuCore/GS", "SWDumpDirectory", debugDumpDir.c_str());
178+
}
179+
#endif
137180
// remove memory cards, so we don't have sharing violations
138181
for (u32 i = 0; i < 2; i++)
139182
{
@@ -465,6 +508,7 @@ void GSRunner::InitializeConsole()
465508

466509
bool GSRunner::ParseCommandLineArgs(int argc, char* argv[], VMBootParameters& params)
467510
{
511+
std::string dumpdir; // Save from argument -dumpdir for creating sub-directories
468512
bool no_more_args = false;
469513
for (int i = 1; i < argc; i++)
470514
{
@@ -485,7 +529,7 @@ bool GSRunner::ParseCommandLineArgs(int argc, char* argv[], VMBootParameters& pa
485529
}
486530
else if (CHECK_ARG_PARAM("-dumpdir"))
487531
{
488-
s_output_prefix = StringUtil::StripWhitespace(argv[++i]);
532+
dumpdir = s_output_prefix = StringUtil::StripWhitespace(argv[++i]);
489533
if (s_output_prefix.empty())
490534
{
491535
Console.Error("Invalid dump directory specified.");
@@ -500,6 +544,74 @@ bool GSRunner::ParseCommandLineArgs(int argc, char* argv[], VMBootParameters& pa
500544

501545
continue;
502546
}
547+
else if (CHECK_ARG_PARAM("-dump"))
548+
{
549+
std::string str(argv[++i]);
550+
551+
s_settings_interface.SetBoolValue("EmuCore/GS", "dump", true);
552+
s_settings_interface.SetIntValue("EmuCore/GS", "saven", 0);
553+
s_settings_interface.SetIntValue("EmuCore/GS", "savel", -1);
554+
s_settings_interface.SetIntValue("EmuCore/GS", "savenf", 5000); // 5000 is the first frame
555+
s_settings_interface.SetIntValue("EmuCore/GS", "savelf", -1);
556+
557+
if (str.find("rt") != std::string::npos)
558+
s_settings_interface.SetBoolValue("EmuCore/GS", "save", true);
559+
if (str.find("f") != std::string::npos)
560+
s_settings_interface.SetBoolValue("EmuCore/GS", "savef", true);
561+
if (str.find("tex") != std::string::npos)
562+
s_settings_interface.SetBoolValue("EmuCore/GS", "savet", true);
563+
if (str.find("z") != std::string::npos)
564+
s_settings_interface.SetBoolValue("EmuCore/GS", "savez", true);
565+
continue;
566+
}
567+
else if (CHECK_ARG_PARAM("-dumprange"))
568+
{
569+
std::string str(argv[++i]);
570+
571+
std::vector<std::string_view> split = StringUtil::SplitString(str, ',');
572+
int start = 0;
573+
int num = -1;
574+
if (split.size() > 0)
575+
{
576+
start = StringUtil::FromChars<int>(split[0]).value_or(0);
577+
}
578+
if (split.size() > 1)
579+
{
580+
num = StringUtil::FromChars<int>(split[1]).value_or(-1);
581+
}
582+
s_settings_interface.SetIntValue("EmuCore/GS", "saven", start);
583+
s_settings_interface.SetIntValue("EmuCore/GS", "savel", num);
584+
continue;
585+
}
586+
else if (CHECK_ARG_PARAM("-dumprangef"))
587+
{
588+
std::string str(argv[++i]);
589+
590+
std::vector<std::string_view> split = StringUtil::SplitString(str, ',');
591+
int start = 0;
592+
int num = -1;
593+
if (split.size() > 0)
594+
{
595+
start = StringUtil::FromChars<int>(split[0]).value_or(0);
596+
}
597+
if (split.size() > 1)
598+
{
599+
num = StringUtil::FromChars<int>(split[1]).value_or(-1);
600+
}
601+
s_settings_interface.SetIntValue("EmuCore/GS", "savenf", start + 4999); // 5000 is the first frame
602+
s_settings_interface.SetIntValue("EmuCore/GS", "savelf", num);
603+
continue;
604+
}
605+
else if (CHECK_ARG_PARAM("-dumpdirhw"))
606+
{
607+
s_settings_interface.SetStringValue("EmuCore/GS", "HWDumpDirectory", argv[++i]);
608+
continue;
609+
}
610+
else if (CHECK_ARG_PARAM("-dumpdirsw"))
611+
{
612+
s_settings_interface.SetStringValue("EmuCore/GS", "SWDumpDirectory", argv[++i]);
613+
continue;
614+
}
503615
else if (CHECK_ARG_PARAM("-loop"))
504616
{
505617
s_loop_count = StringUtil::FromChars<s32>(argv[++i]).value_or(0);
@@ -643,6 +755,14 @@ bool GSRunner::ParseCommandLineArgs(int argc, char* argv[], VMBootParameters& pa
643755
return false;
644756
}
645757

758+
if (s_settings_interface.GetBoolValue("EmuCore/GS", "dump") && !dumpdir.empty())
759+
{
760+
if (s_settings_interface.GetStringValue("EmuCore/GS", "HWDumpDirectory").empty())
761+
s_settings_interface.SetStringValue("EmuCore/GS", "HWDumpDirectory", dumpdir.c_str());
762+
if (s_settings_interface.GetStringValue("EmuCore/GS", "SWDumpDirectory").empty())
763+
s_settings_interface.SetStringValue("EmuCore/GS", "SWDumpDirectory", dumpdir.c_str());
764+
}
765+
646766
// set up the frame dump directory
647767
if (!s_output_prefix.empty())
648768
{

pcsx2/Config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,8 @@ struct Pcsx2Config
822822

823823
int SaveN = 0;
824824
int SaveL = 5000;
825+
int SaveNF = 0;
826+
int SaveLF = -1;
825827

826828
s8 ExclusiveFullscreenControl = -1;
827829
GSScreenshotSize ScreenshotSize = GSScreenshotSize::WindowResolution;

pcsx2/GS/GSState.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <iomanip>
1919
#include <bit>
2020

21+
#include "debug.h"
22+
2123
int GSState::s_n = 0;
2224
int GSState::s_last_transfer_draw_n = 0;
2325
int GSState::s_transfer_n = 0;
@@ -443,7 +445,7 @@ void GSState::DumpVertices(const std::string& filename)
443445
file << std::fixed << std::setprecision(4);
444446
for (u32 i = 0; i < count; ++i)
445447
{
446-
file << "\t" << "v" << i << ": ";
448+
file << "\t" << std::dec << "v" << i << ": ";
447449
GSVertex v = buffer[m_index.buff[i]];
448450

449451
const float x = (v.XYZ.X - (int)m_context->XYOFFSET.OFX) / 16.0f;
@@ -461,7 +463,7 @@ void GSState::DumpVertices(const std::string& filename)
461463
file << std::fixed << std::setprecision(6);
462464
for (u32 i = 0; i < count; ++i)
463465
{
464-
file << "\t" << "v" << i << ": ";
466+
file << "\t" << std::dec << "v" << i << ": ";
465467
GSVertex v = buffer[m_index.buff[i]];
466468

467469
file << std::setfill('0') << std::setw(3) << unsigned(v.RGBAQ.R) << DEL;
@@ -479,7 +481,7 @@ void GSState::DumpVertices(const std::string& filename)
479481
file << "TEXTURE COORDS (" << qualifier << ")" << std::endl;;
480482
for (u32 i = 0; i < count; ++i)
481483
{
482-
file << "\t" << "v" << i << ": ";
484+
file << "\t" << "v" << std::dec << i << ": ";
483485
const GSVertex v = buffer[m_index.buff[i]];
484486

485487
// note
@@ -1994,7 +1996,7 @@ void GSState::InitReadFIFO(u8* mem, int len)
19941996
// Read the image all in one go.
19951997
m_mem.ReadImageX(m_tr.x, m_tr.y, m_tr.buff, m_tr.total, m_env.BITBLTBUF, m_env.TRXPOS, m_env.TRXREG);
19961998

1997-
if (GSConfig.DumpGSData && GSConfig.SaveRT && s_n >= GSConfig.SaveN)
1999+
if (GSConfig.DumpGSData && GSConfig.SaveRT && s_n >= GSConfig.SaveN && g_perfmon.GetFrame() >= GSConfig.SaveNF)
19982000
{
19992001
const std::string s(GetDrawDumpPath(
20002002
"%05d_read_%05x_%d_%d_%d_%d_%d_%d.bmp",
@@ -3831,10 +3833,10 @@ GSState::TextureMinMaxResult GSState::GetTextureMinMax(GIFRegTEX0 TEX0, GIFRegCL
38313833

38323834
u8 uses_border = 0;
38333835

3834-
if (m_vt.m_max.t.x >= FLT_MAX || m_vt.m_min.t.x <= -FLT_MAX ||
3835-
m_vt.m_max.t.y >= FLT_MAX || m_vt.m_min.t.y <= -FLT_MAX)
3836+
if (m_vt.m_max.t.x >= 2047 || m_vt.m_min.t.x <= -2047 ||
3837+
m_vt.m_max.t.y >= 2047 || m_vt.m_min.t.y <= -2047)
38363838
{
3837-
// If any of the min/max values are +-FLT_MAX we can't rely on them
3839+
// If any of the min/max values are +/-2047 we can't rely on them
38383840
// so just assume full texture.
38393841
uses_border = 0xF;
38403842
}

pcsx2/GS/Renderers/Common/GSVertexTraceFMM.cpp

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,36 @@ void GSVertexTraceFMM::FindMinMax(GSVertexTrace& vt, const void* vertex, const u
138138

139139
stq0 = st.xyww(primclass == GS_SPRITE_CLASS ? stq1 : stq0);
140140
stq1 = st.zwww(stq1);
141-
142-
tmin = tmin.min(stq0.min(stq1));
143-
tmax = tmax.max(stq0.max(stq1));
141+
142+
// Check for NaNs
143+
GSVector4 temp_min = stq0.min(stq1);
144+
GSVector4 temp_max = stq0.max(stq1);
145+
temp_min.x = std::isnan(temp_min.x) ? s_minmax.x : temp_min.x;
146+
temp_min.y = std::isnan(temp_min.y) ? s_minmax.x : temp_min.y;
147+
temp_max.x = std::isnan(temp_max.x) ? s_minmax.y : temp_max.x;
148+
temp_max.y = std::isnan(temp_max.y) ? s_minmax.y : temp_max.y;
149+
150+
tmin = tmin.min(temp_min);
151+
tmax = tmax.max(temp_max);
144152
}
145153
else
146154
{
147155
GSVector4i uv0(v0.m[1]);
148156
GSVector4i uv1(v1.m[1]);
149157

150-
GSVector4 st0 = GSVector4(uv0.uph16()).xyxy();
151-
GSVector4 st1 = GSVector4(uv1.uph16()).xyxy();
158+
GSVector4 st0 = GSVector4(uv0.uph16());
159+
GSVector4 st1 = GSVector4(uv1.uph16());
160+
161+
// Check for NaNs
162+
GSVector4 temp_min = stq0.min(stq1);
163+
GSVector4 temp_max = stq0.max(stq1);
164+
temp_min.x = std::isnan(temp_min.x) ? s_minmax.x : temp_min.x;
165+
temp_min.y = std::isnan(temp_min.y) ? s_minmax.x : temp_min.y;
166+
temp_max.x = std::isnan(temp_max.x) ? s_minmax.y : temp_max.x;
167+
temp_max.y = std::isnan(temp_max.y) ? s_minmax.y : temp_max.y;
152168

153-
tmin = tmin.min(st0.min(st1));
154-
tmax = tmax.max(st0.max(st1));
169+
tmin = tmin.min(temp_min.xyxy());
170+
tmax = tmax.max(temp_max.xyxy());
155171
}
156172
}
157173

@@ -247,11 +263,11 @@ void GSVertexTraceFMM::FindMinMax(GSVertexTrace& vt, const void* vertex, const u
247263
vt.m_min.t = tmin * s;
248264
vt.m_max.t = tmax * s;
249265

250-
// Clamp the min/max values to the min/max valid UV values
266+
// Clamp the min/max UV values to the min/max valid UV values.
251267
// This is needed in certain cases where buggy GS input results
252268
// in huge floating points values for ST.
253-
vt.m_min.t = vt.m_min.t.min(GSVector4(2047.0f)).max(GSVector4(-2047.0f)).xyxy(vt.m_min.t);
254-
vt.m_max.t = vt.m_max.t.min(GSVector4(2047.0f)).max(GSVector4(-2047.0f)).xyxy(vt.m_max.t);
269+
vt.m_min.t = vt.m_min.t.min(GSVector4(2047.0f)).max(GSVector4(-2047.0f)).xyzw(vt.m_min.t);
270+
vt.m_max.t = vt.m_max.t.min(GSVector4(2047.0f)).max(GSVector4(-2047.0f)).xyzw(vt.m_max.t);
255271
}
256272
else
257273
{

pcsx2/GS/Renderers/SW/GSDrawScanline.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010

1111
#include <fstream>
1212

13+
#include "debug.h"
14+
1315
// Comment to disable all dynamic code generation.
16+
#if MY_DEBUG == 0
1417
#define ENABLE_JIT_RASTERIZER
18+
#endif
1519

1620
#if MULTI_ISA_COMPILE_ONCE
1721
// Lack of a better home

pcsx2/GS/Renderers/SW/GSRasterizer.cpp

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,9 +614,53 @@ void GSRasterizer::DrawTriangle(const GSVertexSW* vertex, const u16* index)
614614
i[1] = index[s_ysort[m1][1]];
615615
i[2] = index[s_ysort[m1][2]];
616616

617-
const GSVertexSW& v0 = vertex[i[0]];
618-
const GSVertexSW& v1 = vertex[i[1]];
619-
const GSVertexSW& v2 = vertex[i[2]];
617+
GSVertexSW v0 = vertex[i[0]];
618+
GSVertexSW v1 = vertex[i[1]];
619+
GSVertexSW v2 = vertex[i[2]];
620+
621+
622+
// Handle possible large/infinite ST coords
623+
if (m_local.gd->sel.fst == 0)
624+
{
625+
//bool nan_s = std::isnan(v0.t.x / v0.t.z) || std::isnan(v1.t.x / v1.t.z) || std::isnan(v2.t.x / v2.t.z);
626+
//bool nan_t = std::isnan(v0.t.y / v0.t.z) || std::isnan(v1.t.y / v1.t.z) || std::isnan(v2.t.y / v2.t.z);
627+
//bool large_s = (v0.t.x / v0.t.z) > 1e30 || (v1.t.x / v1.t.z) > 1e30 || (v2.t.x / v2.t.z) > 1e30;
628+
//bool small_s = (v0.t.x / v0.t.z) < -1e30 || (v1.t.x / v1.t.z) < -1e30 || (v2.t.x / v2.t.z) < -1e30;
629+
//bool large_t = (v0.t.y / v0.t.z) > 1e30 || (v1.t.y / v1.t.z) > 1e30 || (v2.t.y / v2.t.z) > 1e30;
630+
//bool small_t = (v0.t.y / v0.t.z) < -1e30 || (v1.t.y / v1.t.z) < -1e30 || (v2.t.y / v2.t.z) < -1e30;
631+
//if (nan_s || (large_s && small_s))
632+
//{
633+
// // Not sure what to do here
634+
//}
635+
//else if (large_s)
636+
//{
637+
// v0.t.x = 2047.0f * 65536.0f * v0.t.z;
638+
// v1.t.x = 2047.0f * 65536.0f * v1.t.z;
639+
// v2.t.x = 2047.0f * 65536.0f * v2.t.z;
640+
//}
641+
//else if (small_s)
642+
//{
643+
// v0.t.x = -2047.0f * 65536.0f * v0.t.z;
644+
// v1.t.x = -2047.0f * 65536.0f * v1.t.z;
645+
// v2.t.x = -2047.0f * 65536.0f * v2.t.z;
646+
//}
647+
//if (nan_t || (large_t && small_t))
648+
//{
649+
// // Not sure what to do here so just give 0
650+
//}
651+
//else if (large_t)
652+
//{
653+
// v0.t.y = 2047.0f * 65536.0f * v0.t.z;
654+
// v1.t.y = 2047.0f * 65536.0f * v1.t.z;
655+
// v2.t.y = 2047.0f * 65536.0f * v2.t.z;
656+
//}
657+
//else if (small_t)
658+
//{
659+
// v0.t.y = -2047.0f * 65536.0f * v0.t.z;
660+
// v1.t.y = -2047.0f * 65536.0f * v1.t.z;
661+
// v2.t.y = -2047.0f * 65536.0f * v2.t.z;
662+
//}
663+
}
620664

621665
y0011 = v0.p.yyyy(v1.p);
622666
y1221 = v1.p.yyyy(v2.p).xzzx();

0 commit comments

Comments
 (0)