GSDumpDialog: Cache length instead of querying every packet

Length() internally calls fseek() to end, ftell(), and fseek() back
again (really slow).

Shaves several seconds off loading large gs dumps.
This commit is contained in:
Connor McLaughlin 2021-12-28 16:41:17 +10:00 committed by refractionpcsx2
parent 6ee029e14b
commit c192ecf6b7
1 changed files with 18 additions and 5 deletions

View File

@ -735,17 +735,29 @@ void Dialogs::GSDumpDialog::GSThread::ExecuteTaskInThread()
freezeData fd = {(int)ss, (u8*)state_data.get()}; freezeData fd = {(int)ss, (u8*)state_data.get()};
m_root_window->m_dump_packets.clear(); m_root_window->m_dump_packets.clear();
while (m_dump_file->Tell() < m_dump_file->Length()) // Calling Length() internally does fseek() -> ftell() -> fseek(). Slow.
// Calling ftell() for Tell() doesn't seem to be very cheap either.
// So we track the position ourselves.
const wxFileOffset length = m_dump_file->Length();
wxFileOffset pos = m_dump_file->Tell();
#define READ_FROM_DUMP_FILE(var, size) \
do \
{ \
m_dump_file->Read(var, size); \
pos += size; \
} while (0)
while (pos < length)
{ {
GSType id; GSType id;
GSTransferPath id_transfer = Dummy; GSTransferPath id_transfer = Dummy;
m_dump_file->Read(&id, 1); READ_FROM_DUMP_FILE(&id, 1);
s32 size = 0; s32 size = 0;
switch (id) switch (id)
{ {
case Transfer: case Transfer:
m_dump_file->Read(&id_transfer, 1); READ_FROM_DUMP_FILE(&id_transfer, 1);
m_dump_file->Read(&size, 4); READ_FROM_DUMP_FILE(&size, 4);
break; break;
case VSync: case VSync:
size = 1; size = 1;
@ -758,9 +770,10 @@ void Dialogs::GSDumpDialog::GSThread::ExecuteTaskInThread()
break; break;
} }
std::unique_ptr<char[]> data(new char[size]); std::unique_ptr<char[]> data(new char[size]);
m_dump_file->Read(data.get(), size); READ_FROM_DUMP_FILE(data.get(), size);
m_root_window->m_dump_packets.push_back({id, std::move(data), size, id_transfer}); m_root_window->m_dump_packets.push_back({id, std::move(data), size, id_transfer});
} }
#undef READ_FROM_DUMP_FILE
GSinit(); GSinit();
sApp.OpenGsPanel(); sApp.OpenGsPanel();