Skip to content

Commit

Permalink
temp-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
TJnotJT committed Jan 22, 2025
1 parent 9a9d41c commit 9f59b3f
Show file tree
Hide file tree
Showing 9 changed files with 268 additions and 26 deletions.
122 changes: 121 additions & 1 deletion pcsx2-gsrunner/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,35 @@

#include "svnrev.h"

#include "debug.h"

#if MY_DEBUG || MY_DUMP
#define DEBUG_FILE_STR "hack"
#define DEBUG_DUMP_DIR "C:\\Users\\tchan\\Desktop\\ps2_debug\\" DEBUG_FILE_STR "-dump-all"
#define DEBUG_RANGE_FILE_CALC "C:\\Users\\tchan\\Desktop\\log_files\\pointsRange_" DEBUG_FILE_STR "_calc.txt"
#define DEBUG_RANGE_FILE_SW "C:\\Users\\tchan\\Desktop\\log_files\\pointsRange_" DEBUG_FILE_STR "_sw.txt"
#define DEBUG_LIST_FILE_CALC "C:\\Users\\tchan\\Desktop\\log_files\\pointsList_" DEBUG_FILE_STR "_calc_%d.txt"
#define DEBUG_LIST_FILE_SW "C:\\Users\\tchan\\Desktop\\log_files\\pointsList_" DEBUG_FILE_STR "_sw_%d.txt"
#define DEBUG_ORIG_FILE_CALC "C:\\Users\\tchan\\Desktop\\log_files\\pointsOrig_" DEBUG_FILE_STR "_calc_%d.txt"
#define DEBUG_ORIG_FILE_SW "C:\\Users\\tchan\\Desktop\\log_files\\pointsOrig_" DEBUG_FILE_STR "_sw_%d.txt"

bool savePoints = false;
bool dumpAll = true;
int dump_frame_0 = 5072;
int dump_frame_1 = 5074;
int s_n_debug = -1;
int s_n_exit = -1;
int primID = 0;
int* primIDSW = 0;
std::map<int, std::tuple<int, int, int, int>> pointsCalcRange;
std::map<int, std::tuple<int, int, int, int>> pointsSWRange;
std::vector<std::tuple<int, int, int, int, int>> pointsCalcDebug;
std::vector<std::tuple<int, int, int, int, int>> pointsSWDebug;
std::map<std::tuple<int, int>, std::tuple<double, double, double, double>> pointsCalcDebugOrig;
std::map<std::tuple<int, int>, std::tuple<double, double, double, double>> pointsSWDebugOrig;
std::string debugDumpDir = DEBUG_DUMP_DIR;
#endif

namespace GSRunner
{
static void InitializeConsole();
Expand Down Expand Up @@ -134,6 +163,20 @@ bool GSRunner::InitializeConfig()
si.SetBoolValue("EmuCore/GS", "OsdShowResolution", true);
si.SetBoolValue("EmuCore/GS", "OsdShowGSStats", true);

#if MY_DEBUG || MY_DUMP
if (dumpAll)
{
si.SetBoolValue("EmuCore/GS", "dump", true);
si.SetIntValue("EmuCore/GS", "saven", 0);
si.SetIntValue("EmuCore/GS", "savel", -1);
si.SetBoolValue("EmuCore/GS", "save", true);
si.SetBoolValue("EmuCore/GS", "savef", true);
si.SetBoolValue("EmuCore/GS", "savet", true);
si.SetBoolValue("EmuCore/GS", "savez", true);
si.SetStringValue("EmuCore/GS", "HWDumpDirectory", debugDumpDir.c_str());
si.SetStringValue("EmuCore/GS", "SWDumpDirectory", debugDumpDir.c_str());
}
#endif
// remove memory cards, so we don't have sharing violations
for (u32 i = 0; i < 2; i++)
{
Expand Down Expand Up @@ -465,6 +508,7 @@ void GSRunner::InitializeConsole()

bool GSRunner::ParseCommandLineArgs(int argc, char* argv[], VMBootParameters& params)
{
std::string dumpdir; // Save from argument -dumpdir for creating sub-directories
bool no_more_args = false;
for (int i = 1; i < argc; i++)
{
Expand All @@ -485,7 +529,7 @@ bool GSRunner::ParseCommandLineArgs(int argc, char* argv[], VMBootParameters& pa
}
else if (CHECK_ARG_PARAM("-dumpdir"))
{
s_output_prefix = StringUtil::StripWhitespace(argv[++i]);
dumpdir = s_output_prefix = StringUtil::StripWhitespace(argv[++i]);
if (s_output_prefix.empty())
{
Console.Error("Invalid dump directory specified.");
Expand All @@ -500,6 +544,74 @@ bool GSRunner::ParseCommandLineArgs(int argc, char* argv[], VMBootParameters& pa

continue;
}
else if (CHECK_ARG_PARAM("-dump"))
{
std::string str(argv[++i]);

s_settings_interface.SetBoolValue("EmuCore/GS", "dump", true);
s_settings_interface.SetIntValue("EmuCore/GS", "saven", 0);
s_settings_interface.SetIntValue("EmuCore/GS", "savel", -1);
s_settings_interface.SetIntValue("EmuCore/GS", "savenf", 5000); // 5000 is the first frame
s_settings_interface.SetIntValue("EmuCore/GS", "savelf", -1);

if (str.find("rt") != std::string::npos)
s_settings_interface.SetBoolValue("EmuCore/GS", "save", true);
if (str.find("f") != std::string::npos)
s_settings_interface.SetBoolValue("EmuCore/GS", "savef", true);
if (str.find("tex") != std::string::npos)
s_settings_interface.SetBoolValue("EmuCore/GS", "savet", true);
if (str.find("z") != std::string::npos)
s_settings_interface.SetBoolValue("EmuCore/GS", "savez", true);
continue;
}
else if (CHECK_ARG_PARAM("-dumprange"))
{
std::string str(argv[++i]);

std::vector<std::string_view> split = StringUtil::SplitString(str, ',');
int start = 0;
int num = -1;
if (split.size() > 0)
{
start = StringUtil::FromChars<int>(split[0]).value_or(0);
}
if (split.size() > 1)
{
num = StringUtil::FromChars<int>(split[1]).value_or(-1);
}
s_settings_interface.SetIntValue("EmuCore/GS", "saven", start);
s_settings_interface.SetIntValue("EmuCore/GS", "savel", num);
continue;
}
else if (CHECK_ARG_PARAM("-dumprangef"))
{
std::string str(argv[++i]);

std::vector<std::string_view> split = StringUtil::SplitString(str, ',');
int start = 0;
int num = -1;
if (split.size() > 0)
{
start = StringUtil::FromChars<int>(split[0]).value_or(0);
}
if (split.size() > 1)
{
num = StringUtil::FromChars<int>(split[1]).value_or(-1);
}
s_settings_interface.SetIntValue("EmuCore/GS", "savenf", start + 4999); // 5000 is the first frame
s_settings_interface.SetIntValue("EmuCore/GS", "savelf", num);
continue;
}
else if (CHECK_ARG_PARAM("-dumpdirhw"))
{
s_settings_interface.SetStringValue("EmuCore/GS", "HWDumpDirectory", argv[++i]);
continue;
}
else if (CHECK_ARG_PARAM("-dumpdirsw"))
{
s_settings_interface.SetStringValue("EmuCore/GS", "SWDumpDirectory", argv[++i]);
continue;
}
else if (CHECK_ARG_PARAM("-loop"))
{
s_loop_count = StringUtil::FromChars<s32>(argv[++i]).value_or(0);
Expand Down Expand Up @@ -643,6 +755,14 @@ bool GSRunner::ParseCommandLineArgs(int argc, char* argv[], VMBootParameters& pa
return false;
}

if (s_settings_interface.GetBoolValue("EmuCore/GS", "dump") && !dumpdir.empty())
{
if (s_settings_interface.GetStringValue("EmuCore/GS", "HWDumpDirectory").empty())
s_settings_interface.SetStringValue("EmuCore/GS", "HWDumpDirectory", dumpdir.c_str());
if (s_settings_interface.GetStringValue("EmuCore/GS", "SWDumpDirectory").empty())
s_settings_interface.SetStringValue("EmuCore/GS", "SWDumpDirectory", dumpdir.c_str());
}

// set up the frame dump directory
if (!s_output_prefix.empty())
{
Expand Down
2 changes: 2 additions & 0 deletions pcsx2/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,8 @@ struct Pcsx2Config

int SaveN = 0;
int SaveL = 5000;
int SaveNF = 0;
int SaveLF = -1;

s8 ExclusiveFullscreenControl = -1;
GSScreenshotSize ScreenshotSize = GSScreenshotSize::WindowResolution;
Expand Down
16 changes: 9 additions & 7 deletions pcsx2/GS/GSState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <iomanip>
#include <bit>

#include "debug.h"

int GSState::s_n = 0;
int GSState::s_last_transfer_draw_n = 0;
int GSState::s_transfer_n = 0;
Expand Down Expand Up @@ -443,7 +445,7 @@ void GSState::DumpVertices(const std::string& filename)
file << std::fixed << std::setprecision(4);
for (u32 i = 0; i < count; ++i)
{
file << "\t" << "v" << i << ": ";
file << "\t" << std::dec << "v" << i << ": ";
GSVertex v = buffer[m_index.buff[i]];

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

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

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

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

u8 uses_border = 0;

if (m_vt.m_max.t.x >= FLT_MAX || m_vt.m_min.t.x <= -FLT_MAX ||
m_vt.m_max.t.y >= FLT_MAX || m_vt.m_min.t.y <= -FLT_MAX)
if (m_vt.m_max.t.x >= 2047 || m_vt.m_min.t.x <= -2047 ||
m_vt.m_max.t.y >= 2047 || m_vt.m_min.t.y <= -2047)
{
// If any of the min/max values are +-FLT_MAX we can't rely on them
// If any of the min/max values are +/-2047 we can't rely on them
// so just assume full texture.
uses_border = 0xF;
}
Expand Down
43 changes: 38 additions & 5 deletions pcsx2/GS/Renderers/Common/GSVertexTraceFMM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "GS/GSState.h"
#include <cfloat>

#define USE_HACK_TJTJ 1

class CURRENT_ISA::GSVertexTraceFMM
{
static constexpr GSVector4 s_minmax = GSVector4::cxpr(FLT_MAX, -FLT_MAX, 0.f, 0.f);
Expand Down Expand Up @@ -139,8 +141,20 @@ void GSVertexTraceFMM::FindMinMax(GSVertexTrace& vt, const void* vertex, const u
stq0 = st.xyww(primclass == GS_SPRITE_CLASS ? stq1 : stq0);
stq1 = st.zwww(stq1);

tmin = tmin.min(stq0.min(stq1));
tmax = tmax.max(stq0.max(stq1));
GSVector4 temp_min = stq0.min(stq1);
GSVector4 temp_max = stq0.max(stq1);
if (std::isnan(temp_min.x) || std::isnan(temp_min.y) || std::isnan(temp_max.x) || std::isnan(temp_max.y))
{
fprintf(stderr, "FOUND NAN %d\n", GSState::s_n);
}
#if USE_HACK_TJTJ
temp_min.x = std::isnan(temp_min.x) ? s_minmax.x : temp_min.x;
temp_min.y = std::isnan(temp_min.y) ? s_minmax.x : temp_min.y;
temp_max.x = std::isnan(temp_max.x) ? s_minmax.y : temp_max.x;
temp_max.y = std::isnan(temp_max.y) ? s_minmax.y : temp_max.y;
#endif
tmin = tmin.min(temp_min);
tmax = tmax.max(temp_max);
}
else
{
Expand Down Expand Up @@ -246,12 +260,29 @@ void GSVertexTraceFMM::FindMinMax(GSVertexTrace& vt, const void* vertex, const u

vt.m_min.t = tmin * s;
vt.m_max.t = tmax * s;

if (vt.m_min.t.x < (-2047.0f) || vt.m_min.t.y < (-2047.0f) || vt.m_max.t.x > (2047.0f) || vt.m_max.t.y > (2047.0f))
{
fprintf(stderr, "LARGE VALUES %d\n", GSState::s_n);
}
#if USE_HACK_TJTJ
// Clamp the min/max values to the min/max valid UV values
// This is needed in certain cases where buggy GS input results
// in huge floating points values for ST.
vt.m_min.t = vt.m_min.t.min(GSVector4(2047.0f)).max(GSVector4(-2047.0f)).xyxy(vt.m_min.t);
vt.m_max.t = vt.m_max.t.min(GSVector4(2047.0f)).max(GSVector4(-2047.0f)).xyxy(vt.m_max.t);
//vt.m_min.t.x = std::isnan(vt.m_min.t.x) ? -2047.0f : vt.m_min.t.x;
//vt.m_min.t.y = std::isnan(vt.m_min.t.y) ? -2047.0f : vt.m_min.t.y;
//vt.m_max.t.x = std::isnan(vt.m_max.t.x) ? 2047.0f : vt.m_max.t.x;
//vt.m_max.t.y = std::isnan(vt.m_max.t.y) ? 2047.0f : vt.m_max.t.y;
GSVector4 min0 = vt.m_min.t;
GSVector4 max0 = vt.m_max.t;

vt.m_min.t = vt.m_min.t.min(GSVector4(2047.0f)).max(GSVector4(-2047.0f)).xyzw(vt.m_min.t);
vt.m_max.t = vt.m_max.t.min(GSVector4(2047.0f)).max(GSVector4(-2047.0f)).xyzw(vt.m_max.t);

if (!(min0 == vt.m_min.t).alltrue() || !(max0 == vt.m_max.t).alltrue())
{
fprintf(stderr, "LARGE VALUES %d\n", GSState::s_n);
}
#endif
}
else
{
Expand All @@ -270,3 +301,5 @@ void GSVertexTraceFMM::FindMinMax(GSVertexTrace& vt, const void* vertex, const u
vt.m_max.c = GSVector4i::zero();
}
}

#undef USE_HACK_TJTJ
4 changes: 4 additions & 0 deletions pcsx2/GS/Renderers/SW/GSDrawScanline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@

#include <fstream>

#include "debug.h"

// Comment to disable all dynamic code generation.
#if MY_DEBUG == 0
#define ENABLE_JIT_RASTERIZER
#endif

#if MULTI_ISA_COMPILE_ONCE
// Lack of a better home
Expand Down
50 changes: 47 additions & 3 deletions pcsx2/GS/Renderers/SW/GSRasterizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,9 +614,53 @@ 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]];
GSVertexSW v0 = vertex[i[0]];
GSVertexSW v1 = vertex[i[1]];
GSVertexSW v2 = vertex[i[2]];


// Handle possible large/infinite ST coords
if (m_local.gd->sel.fst == 0)
{
//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);
//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);
//bool large_s = (v0.t.x / v0.t.z) > 1e30 || (v1.t.x / v1.t.z) > 1e30 || (v2.t.x / v2.t.z) > 1e30;
//bool small_s = (v0.t.x / v0.t.z) < -1e30 || (v1.t.x / v1.t.z) < -1e30 || (v2.t.x / v2.t.z) < -1e30;
//bool large_t = (v0.t.y / v0.t.z) > 1e30 || (v1.t.y / v1.t.z) > 1e30 || (v2.t.y / v2.t.z) > 1e30;
//bool small_t = (v0.t.y / v0.t.z) < -1e30 || (v1.t.y / v1.t.z) < -1e30 || (v2.t.y / v2.t.z) < -1e30;
//if (nan_s || (large_s && small_s))
//{
// // Not sure what to do here
//}
//else if (large_s)
//{
// v0.t.x = 2047.0f * 65536.0f * v0.t.z;
// v1.t.x = 2047.0f * 65536.0f * v1.t.z;
// v2.t.x = 2047.0f * 65536.0f * v2.t.z;
//}
//else if (small_s)
//{
// v0.t.x = -2047.0f * 65536.0f * v0.t.z;
// v1.t.x = -2047.0f * 65536.0f * v1.t.z;
// v2.t.x = -2047.0f * 65536.0f * v2.t.z;
//}
//if (nan_t || (large_t && small_t))
//{
// // Not sure what to do here so just give 0
//}
//else if (large_t)
//{
// v0.t.y = 2047.0f * 65536.0f * v0.t.z;
// v1.t.y = 2047.0f * 65536.0f * v1.t.z;
// v2.t.y = 2047.0f * 65536.0f * v2.t.z;
//}
//else if (small_t)
//{
// v0.t.y = -2047.0f * 65536.0f * v0.t.z;
// v1.t.y = -2047.0f * 65536.0f * v1.t.z;
// v2.t.y = -2047.0f * 65536.0f * v2.t.z;
//}
}

y0011 = v0.p.yyyy(v1.p);
y1221 = v1.p.yyyy(v2.p).xzzx();
Expand Down
Loading

0 comments on commit 9f59b3f

Please sign in to comment.