gsdump: move all gui porcelains to main thread and code reorg

This commit is contained in:
Gauvain 'GovanifY' Roussel-Tarbouriech 2021-03-09 15:21:45 +01:00 committed by Kojin
parent 1248aa95cb
commit 475e5865d7
2 changed files with 112 additions and 92 deletions

View File

@ -48,6 +48,8 @@ namespace GSDump
bool isRunning = false; bool isRunning = false;
} }
wxDEFINE_EVENT(EVT_CLOSE_DUMP, wxCommandEvent);
using namespace pxSizerFlags; using namespace pxSizerFlags;
// -------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------
@ -135,6 +137,7 @@ Dialogs::GSDumpDialog::GSDumpDialog(wxWindow* parent)
Bind(wxEVT_BUTTON, &Dialogs::GSDumpDialog::ToVSync, this, ID_RUN_VSYNC); Bind(wxEVT_BUTTON, &Dialogs::GSDumpDialog::ToVSync, this, ID_RUN_VSYNC);
Bind(wxEVT_TREE_SEL_CHANGED, &Dialogs::GSDumpDialog::ParsePacket, this, ID_SEL_PACKET); Bind(wxEVT_TREE_SEL_CHANGED, &Dialogs::GSDumpDialog::ParsePacket, this, ID_SEL_PACKET);
Bind(wxEVT_CHECKBOX, &Dialogs::GSDumpDialog::CheckDebug, this, ID_DEBUG_MODE); Bind(wxEVT_CHECKBOX, &Dialogs::GSDumpDialog::CheckDebug, this, ID_DEBUG_MODE);
Bind(EVT_CLOSE_DUMP, &Dialogs::GSDumpDialog::CloseDump, this);
} }
void Dialogs::GSDumpDialog::GetDumpsList() void Dialogs::GSDumpDialog::GetDumpsList()
@ -172,6 +175,31 @@ void Dialogs::GSDumpDialog::SelectedDump(wxListEvent& evt)
m_selected_dump = wxString(filename); m_selected_dump = wxString(filename);
} }
void Dialogs::GSDumpDialog::PathChanged(wxFileSystemWatcherEvent& event)
{
int type = event.GetChangeType();
if (type == wxFSW_EVENT_CREATE || type == wxFSW_EVENT_DELETE || type == wxFSW_EVENT_RENAME)
GetDumpsList();
}
void Dialogs::GSDumpDialog::CloseDump(wxCommandEvent& event)
{
m_debug_mode->Disable();
m_start->Disable();
m_step->Disable();
m_selection->Disable();
m_vsync->Disable();
m_gif_list->DeleteAllItems();
m_gif_packet->DeleteAllItems();
m_debug_mode->SetValue(false);
m_run->Enable();
}
// --------------------------------------------------------------------------------------
// GSDumpDialog GUI Buttons
// --------------------------------------------------------------------------------------
void Dialogs::GSDumpDialog::RunDump(wxCommandEvent& event) void Dialogs::GSDumpDialog::RunDump(wxCommandEvent& event)
{ {
if (!m_run->IsEnabled()) if (!m_run->IsEnabled())
@ -187,59 +215,32 @@ void Dialogs::GSDumpDialog::RunDump(wxCommandEvent& event)
} }
m_run->Disable(); m_run->Disable();
m_debug_mode->Enable(); m_debug_mode->Enable();
m_thread->m_renderer = m_renderer_overrides->GetSelection();
m_thread->Start(); m_thread->Start();
return; return;
} }
void Dialogs::GSDumpDialog::ProcessDumpEvent(const GSData& event, char* regs) void Dialogs::GSDumpDialog::CheckDebug(wxCommandEvent& event)
{ {
switch (event.id) if (m_debug_mode->GetValue())
{ {
case Transfer: GenPacketList();
{ m_start->Enable();
switch (event.path) m_step->Enable();
{ m_selection->Enable();
case Path1Old: m_vsync->Enable();
{
std::unique_ptr<char[]> data(new char[16384]);
int addr = 16384 - event.length;
memcpy(data.get(), event.data.get() + addr, event.length);
GSgifTransfer1((u32*)data.get(), addr);
break;
}
case Path1New:
GSgifTransfer((u32*)event.data.get(), event.length / 16);
break;
case Path2:
GSgifTransfer2((u32*)event.data.get(), event.length / 16);
break;
case Path3:
GSgifTransfer3((u32*)event.data.get(), event.length / 16);
break;
default:
break;
}
break;
}
case VSync:
{
GSvsync((*((int*)(regs + 4096)) & 0x2000) > 0 ? (u8)1 : (u8)0);
g_FrameCount++;
Pcsx2App* app = (Pcsx2App*)wxApp::GetInstance();
if (app)
app->FpsManager.DoFrame();
break;
}
case ReadFIFO2:
{
std::unique_ptr<char[]> arr(new char[*((int*)event.data.get())]);
GSreadFIFO2((u64*)arr.get(), *((int*)event.data.get()));
break;
}
case Registers:
memcpy(regs, event.data.get(), 8192);
break;
} }
else
{
m_gif_list->DeleteAllItems();
m_gif_packet->DeleteAllItems();
m_gif_list->Refresh();
m_start->Disable();
m_step->Disable();
m_selection->Disable();
m_vsync->Disable();
}
m_thread->m_debug = m_debug_mode->GetValue();
} }
void Dialogs::GSDumpDialog::StepPacket(wxCommandEvent& event) void Dialogs::GSDumpDialog::StepPacket(wxCommandEvent& event)
@ -275,6 +276,10 @@ void Dialogs::GSDumpDialog::ToStart(wxCommandEvent& event)
m_button_events.push_back(GSEvent{RunCursor, 0}); m_button_events.push_back(GSEvent{RunCursor, 0});
} }
// --------------------------------------------------------------------------------------
// GSDumpDialog Packet Parsing
// --------------------------------------------------------------------------------------
void Dialogs::GSDumpDialog::GenPacketList() void Dialogs::GSDumpDialog::GenPacketList()
{ {
int i = 0; int i = 0;
@ -421,8 +426,7 @@ void Dialogs::GSDumpDialog::GenPacketInfo(GSData& dump)
void Dialogs::GSDumpDialog::ParsePacket(wxTreeEvent& event) void Dialogs::GSDumpDialog::ParsePacket(wxTreeEvent& event)
{ {
int id = wxAtoi(m_gif_list->GetItemText(event.GetItem()).BeforeFirst('-')); GenPacketInfo(m_dump_packets[wxAtoi(m_gif_list->GetItemText(event.GetItem()).BeforeFirst('-'))]);
GenPacketInfo(m_dump_packets[id]);
} }
void Dialogs::GSDumpDialog::ParseTreeReg(wxTreeItemId& id, GIFReg reg, u128 data, bool packed) void Dialogs::GSDumpDialog::ParseTreeReg(wxTreeItemId& id, GIFReg reg, u128 data, bool packed)
@ -607,28 +611,61 @@ void Dialogs::GSDumpDialog::ParseTreePrim(wxTreeItemId& id, u32 prim)
m_gif_packet->AppendItem(id, el); m_gif_packet->AppendItem(id, el);
} }
void Dialogs::GSDumpDialog::CheckDebug(wxCommandEvent& event) void Dialogs::GSDumpDialog::ProcessDumpEvent(const GSData& event, char* regs)
{ {
if (m_debug_mode->GetValue()) switch (event.id)
{ {
GenPacketList(); case Transfer:
m_start->Enable(); {
m_step->Enable(); switch (event.path)
m_selection->Enable(); {
m_vsync->Enable(); case Path1Old:
} {
else std::unique_ptr<char[]> data(new char[16384]);
{ int addr = 16384 - event.length;
m_gif_list->DeleteAllItems(); memcpy(data.get(), event.data.get() + addr, event.length);
m_gif_packet->DeleteAllItems(); GSgifTransfer1((u32*)data.get(), addr);
m_gif_list->Refresh(); break;
m_start->Disable(); }
m_step->Disable(); case Path1New:
m_selection->Disable(); GSgifTransfer((u32*)event.data.get(), event.length / 16);
m_vsync->Disable(); break;
case Path2:
GSgifTransfer2((u32*)event.data.get(), event.length / 16);
break;
case Path3:
GSgifTransfer3((u32*)event.data.get(), event.length / 16);
break;
default:
break;
}
break;
}
case VSync:
{
GSvsync((*((int*)(regs + 4096)) & 0x2000) > 0 ? (u8)1 : (u8)0);
g_FrameCount++;
Pcsx2App* app = (Pcsx2App*)wxApp::GetInstance();
if (app)
app->FpsManager.DoFrame();
break;
}
case ReadFIFO2:
{
std::unique_ptr<char[]> arr(new char[*((int*)event.data.get())]);
GSreadFIFO2((u64*)arr.get(), *((int*)event.data.get()));
break;
}
case Registers:
memcpy(regs, event.data.get(), 8192);
break;
} }
} }
// --------------------------------------------------------------------------------------
// GSThread Implementation
// --------------------------------------------------------------------------------------
Dialogs::GSDumpDialog::GSThread::GSThread(GSDumpDialog* dlg) Dialogs::GSDumpDialog::GSThread::GSThread(GSDumpDialog* dlg)
: pxThread("GSDump") : pxThread("GSDump")
, m_root_window(dlg) , m_root_window(dlg)
@ -646,17 +683,11 @@ Dialogs::GSDumpDialog::GSThread::~GSThread()
void Dialogs::GSDumpDialog::GSThread::OnStop() void Dialogs::GSDumpDialog::GSThread::OnStop()
{ {
m_root_window->m_debug_mode->Disable();
m_root_window->m_start->Disable();
m_root_window->m_step->Disable();
m_root_window->m_selection->Disable();
m_root_window->m_vsync->Disable();
m_root_window->m_gif_list->DeleteAllItems();
m_root_window->m_gif_packet->DeleteAllItems();
m_root_window->m_button_events.clear(); m_root_window->m_button_events.clear();
m_root_window->m_debug_mode->SetValue(false);
m_root_window->m_run->Enable();
m_dump_file->Close(); m_dump_file->Close();
wxCommandEvent event(EVT_CLOSE_DUMP);
wxPostEvent(m_root_window, event);
} }
void Dialogs::GSDumpDialog::GSThread::ExecuteTaskInThread() void Dialogs::GSDumpDialog::GSThread::ExecuteTaskInThread()
@ -664,7 +695,7 @@ void Dialogs::GSDumpDialog::GSThread::ExecuteTaskInThread()
GSDump::isRunning = true; GSDump::isRunning = true;
u32 crc = 0, ss = 0; u32 crc = 0, ss = 0;
s8 renderer_override = 0; s8 renderer_override = 0;
switch (m_root_window->m_renderer_overrides->GetSelection()) switch (m_renderer)
{ {
// OGL SW // OGL SW
case 1: case 1:
@ -694,7 +725,7 @@ void Dialogs::GSDumpDialog::GSThread::ExecuteTaskInThread()
freezeData fd = {(int)ss, (s8*)state_data.get()}; freezeData fd = {(int)ss, (s8*)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()) while (m_dump_file->Tell() < m_dump_file->Length())
{ {
GSType id = Transfer; GSType id = Transfer;
m_dump_file->Read(&id, 1); m_dump_file->Read(&id, 1);
@ -735,12 +766,6 @@ void Dialogs::GSDumpDialog::GSThread::ExecuteTaskInThread()
} }
} }
if (m_root_window->m_debug_mode->GetValue())
m_root_window->GenPacketList();
//return here to debug pre gs
//return;
GetCorePlugins().Init(); GetCorePlugins().Init();
sApp.OpenGsPanel(); sApp.OpenGsPanel();
@ -776,7 +801,7 @@ void Dialogs::GSDumpDialog::GSThread::ExecuteTaskInThread()
while (GSDump::isRunning) while (GSDump::isRunning)
{ {
if (m_root_window->m_debug_mode->GetValue()) if (m_debug)
{ {
if (m_root_window->m_button_events.size() > 0) if (m_root_window->m_button_events.size() > 0)
{ {
@ -849,12 +874,4 @@ void Dialogs::GSDumpDialog::GSThread::ExecuteTaskInThread()
OnStop(); OnStop();
return; return;
} }
void Dialogs::GSDumpDialog::PathChanged(wxFileSystemWatcherEvent& event)
{
int type = event.GetChangeType();
if (type == wxFSW_EVENT_CREATE || type == wxFSW_EVENT_DELETE || type == wxFSW_EVENT_RENAME)
GetDumpsList();
}

View File

@ -349,6 +349,7 @@ namespace Dialogs
void GenPacketInfo(GSData& dump); void GenPacketInfo(GSData& dump);
void ParseTreeReg(wxTreeItemId& id, GIFReg reg, u128 data, bool packed); void ParseTreeReg(wxTreeItemId& id, GIFReg reg, u128 data, bool packed);
void ParseTreePrim(wxTreeItemId& id, u32 prim); void ParseTreePrim(wxTreeItemId& id, u32 prim);
void CloseDump(wxCommandEvent& event);
class GSThread : public pxThread class GSThread : public pxThread
{ {
protected: protected:
@ -359,6 +360,8 @@ namespace Dialogs
GSDumpDialog* m_root_window; GSDumpDialog* m_root_window;
public: public:
int m_renderer = 0;
bool m_debug = false;
size_t m_debug_index; size_t m_debug_index;
std::unique_ptr<pxInputStream> m_dump_file; std::unique_ptr<pxInputStream> m_dump_file;
GSThread(GSDumpDialog* dlg); GSThread(GSDumpDialog* dlg);