add gfx debugger support (#4345)

Co-authored-by: Malkierian <malkierian@gmail.com>
This commit is contained in:
Archez 2024-10-18 11:05:31 +09:00 committed by GitHub
parent ed32a2820c
commit f1841a20f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 48 additions and 12 deletions

View File

@ -130,9 +130,13 @@ include(CMake/GlobalSettingsInclude.cmake OPTIONAL)
set_property(GLOBAL PROPERTY USE_FOLDERS ON) set_property(GLOBAL PROPERTY USE_FOLDERS ON)
################################################################################ ################################################################################
# Set GBI version # Set LUS vars
################################################################################ ################################################################################
# Enable the Gfx debugger in LUS to use libgfxd from ZAPDTR
set(GFX_DEBUG_DISASSEMBLER ON)
# Tell LUS we're using F3DEX_GBI_2 (in a way that doesn't break libgfxd)
set(GBI_UCODE F3DEX_GBI_2) set(GBI_UCODE F3DEX_GBI_2)
################################################################################ ################################################################################

View File

@ -1433,6 +1433,12 @@ extern "C" void Graph_ProcessGfxCommands(Gfx* commands) {
int threshold = CVarGetInteger(CVAR_SETTING("ExtraLatencyThreshold"), 80); int threshold = CVarGetInteger(CVAR_SETTING("ExtraLatencyThreshold"), 80);
wnd->SetMaximumFrameLatency(threshold > 0 && target_fps >= threshold ? 2 : 1); wnd->SetMaximumFrameLatency(threshold > 0 && target_fps >= threshold ? 2 : 1);
// When the gfx debugger is active, only run with the final mtx
if (GfxDebuggerIsDebugging()) {
mtx_replacements.clear();
mtx_replacements.emplace_back();
}
RunCommands(commands, mtx_replacements); RunCommands(commands, mtx_replacements);
last_fps = fps; last_fps = fps;

View File

@ -113,6 +113,7 @@ namespace SohGui {
std::shared_ptr<Ship::GuiWindow> mConsoleWindow; std::shared_ptr<Ship::GuiWindow> mConsoleWindow;
std::shared_ptr<Ship::GuiWindow> mStatsWindow; std::shared_ptr<Ship::GuiWindow> mStatsWindow;
std::shared_ptr<Ship::GuiWindow> mGfxDebuggerWindow;
std::shared_ptr<Ship::GuiWindow> mInputEditorWindow; std::shared_ptr<Ship::GuiWindow> mInputEditorWindow;
std::shared_ptr<AudioEditor> mAudioEditorWindow; std::shared_ptr<AudioEditor> mAudioEditorWindow;
@ -161,6 +162,11 @@ namespace SohGui {
SPDLOG_ERROR("Could not find console window"); SPDLOG_ERROR("Could not find console window");
} }
mGfxDebuggerWindow = gui->GetGuiWindow("GfxDebuggerWindow");
if (mGfxDebuggerWindow == nullptr) {
SPDLOG_ERROR("Could not find input GfxDebuggerWindow");
}
mInputEditorWindow = gui->GetGuiWindow("Controller Configuration"); mInputEditorWindow = gui->GetGuiWindow("Controller Configuration");
if (mInputEditorWindow == nullptr) { if (mInputEditorWindow == nullptr) {
SPDLOG_ERROR("Could not find input editor window"); SPDLOG_ERROR("Could not find input editor window");
@ -237,6 +243,7 @@ namespace SohGui {
mInputEditorWindow = nullptr; mInputEditorWindow = nullptr;
mStatsWindow = nullptr; mStatsWindow = nullptr;
mConsoleWindow = nullptr; mConsoleWindow = nullptr;
mGfxDebuggerWindow = nullptr;
mSohMenuBar = nullptr; mSohMenuBar = nullptr;
mInputViewer = nullptr; mInputViewer = nullptr;
mInputViewerSettings = nullptr; mInputViewerSettings = nullptr;

View File

@ -217,6 +217,7 @@ void DrawShipMenu() {
} }
extern std::shared_ptr<Ship::GuiWindow> mInputEditorWindow; extern std::shared_ptr<Ship::GuiWindow> mInputEditorWindow;
extern std::shared_ptr<Ship::GuiWindow> mGfxDebuggerWindow;
extern std::shared_ptr<InputViewer> mInputViewer; extern std::shared_ptr<InputViewer> mInputViewer;
extern std::shared_ptr<InputViewerSettingsWindow> mInputViewerSettings; extern std::shared_ptr<InputViewerSettingsWindow> mInputViewerSettings;
extern std::shared_ptr<AdvancedResolutionSettings::AdvancedResolutionSettingsWindow> mAdvancedResolutionSettingsWindow; extern std::shared_ptr<AdvancedResolutionSettings::AdvancedResolutionSettingsWindow> mAdvancedResolutionSettingsWindow;
@ -1971,6 +1972,12 @@ void DrawDeveloperToolsMenu() {
mMessageViewerWindow->ToggleVisibility(); mMessageViewerWindow->ToggleVisibility();
} }
} }
UIWidgets::Spacer(0);
if (mGfxDebuggerWindow) {
if (ImGui::Button(GetWindowButtonText("Gfx Debugger", CVarGetInteger(CVAR_WINDOW("GfxDebugger"), 0)).c_str(), ImVec2(-1.0f, 0.0f))) {
mGfxDebuggerWindow->ToggleVisibility();
}
}
ImGui::PopStyleVar(3); ImGui::PopStyleVar(3);
ImGui::PopStyleColor(1); ImGui::PopStyleColor(1);

View File

@ -15,6 +15,15 @@
#define GFXPOOL_HEAD_MAGIC 0x1234 #define GFXPOOL_HEAD_MAGIC 0x1234
#define GFXPOOL_TAIL_MAGIC 0x5678 #define GFXPOOL_TAIL_MAGIC 0x5678
// SOH [Port] Game State management for our render loop
static struct RunFrameContext {
GraphicsContext gfxCtx;
GameState* gameState;
GameStateOverlay* nextOvl;
GameStateOverlay* ovl;
int state;
} runFrameContext;
OSTime sGraphUpdateTime; OSTime sGraphUpdateTime;
OSTime sGraphSetTaskTime; OSTime sGraphSetTaskTime;
FaultClient sGraphFaultClient; FaultClient sGraphFaultClient;
@ -271,6 +280,12 @@ void Graph_TaskSet00(GraphicsContext* gfxCtx) {
void Graph_Update(GraphicsContext* gfxCtx, GameState* gameState) { void Graph_Update(GraphicsContext* gfxCtx, GameState* gameState) {
u32 problem; u32 problem;
// Skip game frame updates while gfx debugger is active, and execute with the last frame's DL buffer
if (GfxDebuggerIsDebugging()) {
Graph_ProcessGfxCommands(runFrameContext.gfxCtx.workBuffer);
return;
}
gameState->unk_A0 = 0; gameState->unk_A0 = 0;
Graph_InitTHGA(gfxCtx); Graph_InitTHGA(gfxCtx);
@ -443,15 +458,6 @@ void Graph_Update(GraphicsContext* gfxCtx, GameState* gameState) {
uint64_t GetFrequency(); uint64_t GetFrequency();
uint64_t GetPerfCounter(); uint64_t GetPerfCounter();
static struct RunFrameContext {
GraphicsContext gfxCtx;
GameState* gameState;
GameStateOverlay* nextOvl;
GameStateOverlay* ovl;
int state;
} runFrameContext;
extern AudioMgr gAudioMgr; extern AudioMgr gAudioMgr;
extern void ProcessSaveStateRequests(void); extern void ProcessSaveStateRequests(void);
@ -515,6 +521,10 @@ static void RunFrame()
Graph_Update(&runFrameContext.gfxCtx, runFrameContext.gameState); Graph_Update(&runFrameContext.gfxCtx, runFrameContext.gameState);
//ticksB = GetPerfCounter(); //ticksB = GetPerfCounter();
if (GfxDebuggerIsDebuggingRequested()) {
GfxDebuggerDebugDisplayList(runFrameContext.gfxCtx.workBuffer);
}
Graph_ProcessGfxCommands(runFrameContext.gfxCtx.workBuffer); Graph_ProcessGfxCommands(runFrameContext.gfxCtx.workBuffer);
@ -565,7 +575,8 @@ void* Graph_Alloc2(GraphicsContext* gfxCtx, size_t size) {
} }
void Graph_OpenDisps(Gfx** dispRefs, GraphicsContext* gfxCtx, const char* file, s32 line) { void Graph_OpenDisps(Gfx** dispRefs, GraphicsContext* gfxCtx, const char* file, s32 line) {
if (HREG(80) == 7 && HREG(82) != 4) { // SOH [Debugging] Force open/close disp string handling on so that the graphics debugger can leverage it
if (true || HREG(80) == 7 && HREG(82) != 4) {
dispRefs[0] = gfxCtx->polyOpa.p; dispRefs[0] = gfxCtx->polyOpa.p;
dispRefs[1] = gfxCtx->polyXlu.p; dispRefs[1] = gfxCtx->polyXlu.p;
dispRefs[2] = gfxCtx->overlay.p; dispRefs[2] = gfxCtx->overlay.p;
@ -577,7 +588,8 @@ void Graph_OpenDisps(Gfx** dispRefs, GraphicsContext* gfxCtx, const char* file,
} }
void Graph_CloseDisps(Gfx** dispRefs, GraphicsContext* gfxCtx, const char* file, s32 line) { void Graph_CloseDisps(Gfx** dispRefs, GraphicsContext* gfxCtx, const char* file, s32 line) {
if (HREG(80) == 7 && HREG(82) != 4) { // SOH [Debugging] Force open/close disp string handling on so that the graphics debugger can leverage it
if (true || HREG(80) == 7 && HREG(82) != 4) {
if (dispRefs[0] + 1 == gfxCtx->polyOpa.p) { if (dispRefs[0] + 1 == gfxCtx->polyOpa.p) {
gfxCtx->polyOpa.p = dispRefs[0]; gfxCtx->polyOpa.p = dispRefs[0];
} else { } else {