gs: implement sstate handler functions

This commit is contained in:
Gauvain 'GovanifY' Roussel-Tarbouriech 2021-05-14 11:28:43 +02:00 committed by Kojin
parent 83a28ddab1
commit fbf10dcdf5
2 changed files with 108 additions and 41 deletions

View File

@ -976,9 +976,7 @@ void GSReplay(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
const std::string f{lpszCmdLine};
const bool is_xz = f.size() >= 4 && f.compare(f.size() - 3, 3, ".xz") == 0;
auto file = is_xz
? std::unique_ptr<GSDumpFile>{std::make_unique<GSDumpLzma>(lpszCmdLine, nullptr)}
: std::unique_ptr<GSDumpFile>{std::make_unique<GSDumpRaw>(lpszCmdLine, nullptr)};
auto file = is_xz ? std::unique_ptr<GSDumpFile>{std::make_unique<GSDumpLzma>(lpszCmdLine, nullptr)} : std::unique_ptr<GSDumpFile>{std::make_unique<GSDumpRaw>(lpszCmdLine, nullptr)};
GSinit();
@ -1071,17 +1069,26 @@ void GSReplay(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
case 0:
switch (p.param)
{
case 0: GSgifTransfer1(p.buff.data(), p.addr); break;
case 1: GSgifTransfer2(p.buff.data(), p.size / 16); break;
case 2: GSgifTransfer3(p.buff.data(), p.size / 16); break;
case 3: GSgifTransfer(p.buff.data(), p.size / 16); break;
case 0:
GSgifTransfer1(p.buff.data(), p.addr);
break;
case 1:
GSgifTransfer2(p.buff.data(), p.size / 16);
break;
case 2:
GSgifTransfer3(p.buff.data(), p.size / 16);
break;
case 3:
GSgifTransfer(p.buff.data(), p.size / 16);
break;
}
break;
case 1:
GSvsync(p.param);
break;
case 2:
if(buff.size() < p.size) buff.resize(p.size);
if (buff.size() < p.size)
buff.resize(p.size);
GSreadFIFO2(p.buff.data(), p.size / 16);
break;
case 3:
@ -1107,7 +1114,11 @@ void GSBenchmark(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
{
GSLocalMemory* mem = new GSLocalMemory();
static struct {int psm; const char* name;} s_format[] =
static struct
{
int psm;
const char* name;
} s_format[] =
{
{PSM_PSMCT32, "32"},
{PSM_PSMCT24, "24"},
@ -1377,9 +1388,7 @@ void GSReplay(char* lpszCmdLine, int renderer)
else
f.replace(f.end() - 3, f.end(), "_repack.gs");
GSDumpFile* file = is_xz
? (GSDumpFile*) new GSDumpLzma(lpszCmdLine, repack_dump ? f.c_str() : nullptr)
: (GSDumpFile*) new GSDumpRaw(lpszCmdLine, repack_dump ? f.c_str() : nullptr);
GSDumpFile* file = is_xz ? (GSDumpFile*)new GSDumpLzma(lpszCmdLine, repack_dump ? f.c_str() : nullptr) : (GSDumpFile*)new GSDumpRaw(lpszCmdLine, repack_dump ? f.c_str() : nullptr);
uint32 crc;
file->Read(&crc, 4);
@ -1473,10 +1482,18 @@ void GSReplay(char* lpszCmdLine, int renderer)
switch (p->param)
{
case 0: GSgifTransfer1(&p->buff[0], p->addr); break;
case 1: GSgifTransfer2(&p->buff[0], p->size / 16); break;
case 2: GSgifTransfer3(&p->buff[0], p->size / 16); break;
case 3: GSgifTransfer(&p->buff[0], p->size / 16); break;
case 0:
GSgifTransfer1(&p->buff[0], p->addr);
break;
case 1:
GSgifTransfer2(&p->buff[0], p->size / 16);
break;
case 2:
GSgifTransfer3(&p->buff[0], p->size / 16);
break;
case 3:
GSgifTransfer(&p->buff[0], p->size / 16);
break;
}
break;
@ -2289,3 +2306,49 @@ GSRendererType GSApp::GetCurrentRendererType() const
{
return m_current_renderer_type;
}
void GSDoFreezeOut(void* dest)
{
freezeData fP = {0, (s8*)dest};
if (GSfreeze(FREEZE_SIZE, &fP) != 0)
return;
if (!fP.size)
return;
Console.Indent().WriteLn("Saving GS");
if (GSfreeze(FREEZE_SAVE, &fP) != 0)
throw std::runtime_error(" * GS: Error saving state!\n");
}
void GSDoFreezeIn(pxInputStream& infp)
{
freezeData fP = {0, nullptr};
if (GSfreeze(FREEZE_SIZE, &fP) != 0)
fP.size = 0;
Console.Indent().WriteLn("Loading GS");
if (!infp.IsOk() || !infp.Length())
{
// no state data to read, but GS expects some state data?
// Issue a warning to console...
if (fP.size != 0)
Console.Indent().Warning("Warning: No data for GS found. Status may be unpredictable.");
return;
// Note: Size mismatch check could also be done here on loading, but
// some plugins may have built-in version support for non-native formats or
// older versions of a different size... or could give different sizes depending
// on the status of the plugin when loading, so let's ignore it.
}
ScopedAlloc<s8> data(fP.size);
fP.data = data.GetPtr();
infp.Read(fP.data, fP.size);
if (GSfreeze(FREEZE_LOAD, &fP) != 0)
throw std::runtime_error(" * GS: Error loading state!\n");
}

View File

@ -1967,3 +1967,7 @@ struct GSErrorGlVertexArrayTooSmall : GSError
extern GSApp theApp;
extern bool gsopen_done;
void GSDoFreezeOut(void* dest);
void GSDoFreezeIn(pxInputStream& infp);