diff --git a/GPU/Debugger/Debugger.cpp b/GPU/Debugger/Debugger.cpp index 088836c2ff44..2d5da1af3aed 100644 --- a/GPU/Debugger/Debugger.cpp +++ b/GPU/Debugger/Debugger.cpp @@ -25,6 +25,11 @@ namespace GPUDebug { static bool active = false; static bool inited = false; static BreakNext breakNext = BreakNext::NONE; +static int breakAtCount = -1; + +static int primsLastFrame = 0; +static int primsThisFrame = 0; +static int thisFlipNum = 0; static void Init() { if (!inited) { @@ -40,6 +45,7 @@ void SetActive(bool flag) { active = flag; if (!active) { breakNext = BreakNext::NONE; + breakAtCount = -1; GPUStepping::ResumeFromStepping(); } } @@ -51,9 +57,10 @@ bool IsActive() { void SetBreakNext(BreakNext next) { SetActive(true); breakNext = next; + breakAtCount = -1; if (next == BreakNext::TEX) { GPUBreakpoints::AddTextureChangeTempBreakpoint(); - } else if (next == BreakNext::PRIM) { + } else if (next == BreakNext::PRIM || next == BreakNext::COUNT) { GPUBreakpoints::AddCmdBreakpoint(GE_CMD_PRIM, true); GPUBreakpoints::AddCmdBreakpoint(GE_CMD_BEZIER, true); GPUBreakpoints::AddCmdBreakpoint(GE_CMD_SPLINE, true); @@ -64,11 +71,39 @@ void SetBreakNext(BreakNext next) { GPUStepping::ResumeFromStepping(); } +void SetBreakCount(int c, bool relative) { + if (relative) { + breakAtCount = primsThisFrame + c; + } else { + breakAtCount = c; + } +} + +static bool IsBreakpoint(u32 pc, u32 op) { + if (breakNext == BreakNext::OP) { + return true; + } else if (breakNext == BreakNext::COUNT) { + return primsThisFrame == breakAtCount; + } else { + return GPUBreakpoints::IsBreakpoint(pc, op); + } +} + void NotifyCommand(u32 pc) { if (!active) return; u32 op = Memory::ReadUnchecked_U32(pc); - if (breakNext == BreakNext::OP || GPUBreakpoints::IsBreakpoint(pc, op)) { + u32 cmd = op >> 24; + if (thisFlipNum != gpuStats.numFlips) { + primsLastFrame = primsThisFrame; + primsThisFrame = 0; + thisFlipNum = gpuStats.numFlips; + } + if (cmd == GE_CMD_PRIM || cmd == GE_CMD_BEZIER || cmd == GE_CMD_SPLINE) { + primsThisFrame++; + } + + if (IsBreakpoint(pc, op)) { GPUBreakpoints::ClearTempBreakpoints(); auto info = gpuDebug->DissassembleOp(pc); @@ -100,4 +135,12 @@ void NotifyTextureAttachment(u32 texaddr) { return; } +int PrimsThisFrame() { + return primsThisFrame; +} + +int PrimsLastFrame() { + return primsLastFrame; +} + } diff --git a/GPU/Debugger/Debugger.h b/GPU/Debugger/Debugger.h index 2a45f93ba0b8..15be467cdacc 100644 --- a/GPU/Debugger/Debugger.h +++ b/GPU/Debugger/Debugger.h @@ -30,12 +30,14 @@ enum class BreakNext { FRAME, PRIM, CURVE, + COUNT, }; void SetActive(bool flag); bool IsActive(); void SetBreakNext(BreakNext next); +void SetBreakCount(int c, bool relative = false); // While debugging is active, these may block. void NotifyCommand(u32 pc); @@ -43,4 +45,7 @@ void NotifyDraw(); void NotifyDisplay(u32 framebuf, u32 stride, int format); void NotifyTextureAttachment(u32 texaddr); +int PrimsThisFrame(); +int PrimsLastFrame(); + } diff --git a/GPU/Debugger/Stepping.cpp b/GPU/Debugger/Stepping.cpp index b27749655640..bf5ddb483479 100644 --- a/GPU/Debugger/Stepping.cpp +++ b/GPU/Debugger/Stepping.cpp @@ -38,6 +38,7 @@ enum PauseAction { }; static bool isStepping; +// Number of times we've entered stepping, to detect a resume asynchronously. static int stepCounter = 0; static std::mutex pauseLock; diff --git a/Windows/GEDebugger/GEDebugger.cpp b/Windows/GEDebugger/GEDebugger.cpp index e36fe84a52cb..57f122694ed1 100644 --- a/Windows/GEDebugger/GEDebugger.cpp +++ b/Windows/GEDebugger/GEDebugger.cpp @@ -20,6 +20,7 @@ #include #include +#include "base/stringutil.h" #include "Common/ColorConv.h" #include "Core/Config.h" #include "Core/Screenshot.h" @@ -291,6 +292,10 @@ void CGEDebugger::UpdatePreviews() { displayList->setDisplayList(list); } + wchar_t primCounter[1024]{}; + swprintf(primCounter, ARRAY_SIZE(primCounter), L"%d/%d", PrimsThisFrame(), PrimsLastFrame()); + SetDlgItemText(m_hDlg, IDC_GEDBG_PRIMCOUNTER, primCounter); + flags->Update(); lighting->Update(); textureState->Update(); @@ -720,6 +725,25 @@ BOOL CGEDebugger::DlgProc(UINT message, WPARAM wParam, LPARAM lParam) { SetBreakNext(BreakNext::CURVE); break; + case IDC_GEDBG_STEPCOUNT: + { + std::string value; + int count; + if (InputBox_GetString(GetModuleHandle(NULL), m_hDlg, L"Prim count", "", value)) { + if (value.length() > 1 && value[0] == '+' && TryParse(value.substr(1), &count)) { + SetBreakNext(BreakNext::COUNT); + SetBreakCount(count, true); + } else if (value.length() > 1 && value[0] == '-' && TryParse(value.substr(1), &count)) { + SetBreakNext(BreakNext::COUNT); + SetBreakCount(-count, true); + } else if (TryParse(value, &count)) { + SetBreakNext(BreakNext::COUNT); + SetBreakCount(count); + } + } + } + break; + case IDC_GEDBG_BREAKTEX: { GPUDebug::SetActive(true); @@ -778,6 +802,7 @@ BOOL CGEDebugger::DlgProc(UINT message, WPARAM wParam, LPARAM lParam) { secondWindow->Clear(); SetDlgItemText(m_hDlg, IDC_GEDBG_FRAMEBUFADDR, L""); SetDlgItemText(m_hDlg, IDC_GEDBG_TEXADDR, L""); + SetDlgItemText(m_hDlg, IDC_GEDBG_PRIMCOUNTER, L""); SetBreakNext(BreakNext::NONE); break; diff --git a/Windows/ppsspp.rc b/Windows/ppsspp.rc index 4d3ae58dcf59..195f92eb05cb 100644 --- a/Windows/ppsspp.rc +++ b/Windows/ppsspp.rc @@ -210,14 +210,16 @@ EXSTYLE WS_EX_ACCEPTFILES | WS_EX_TOOLWINDOW CAPTION "GE" FONT 8, "MS Shell Dlg", 0, 0, 0x1 BEGIN - PUSHBUTTON "Step &Frame",IDC_GEDBG_STEPFRAME,10,2,48,14 - PUSHBUTTON "Step &Tex",IDC_GEDBG_STEPTEX,62,2,48,14 - PUSHBUTTON "Step &Draw",IDC_GEDBG_STEPDRAW,114,2,48,14 - PUSHBUTTON "Step &Prim",IDC_GEDBG_STEPPRIM,166,2,48,14 - PUSHBUTTON "Step &Curve",IDC_GEDBG_STEPCURVE,218,2,48,14 - PUSHBUTTON "Step &Into",IDC_GEDBG_STEP,270,2,48,14 - PUSHBUTTON "&Resume",IDC_GEDBG_RESUME,322,2,48,14 - PUSHBUTTON "Rec&ord",IDC_GEDBG_RECORD,440,2,48,14 + PUSHBUTTON "Step &Frame",IDC_GEDBG_STEPFRAME,10,2,44,14 + PUSHBUTTON "Step &Tex",IDC_GEDBG_STEPTEX,55,2,44,14 + PUSHBUTTON "Step &Draw",IDC_GEDBG_STEPDRAW,100,2,44,14 + PUSHBUTTON "Step &Prim",IDC_GEDBG_STEPPRIM,145,2,44,14 + PUSHBUTTON "Step &Curve",IDC_GEDBG_STEPCURVE,190,2,44,14 + PUSHBUTTON "Step &Into",IDC_GEDBG_STEP,235,2,44,14 + PUSHBUTTON "Step Cou&nt",IDC_GEDBG_STEPCOUNT,280,2,44,14 + EDITTEXT IDC_GEDBG_PRIMCOUNTER,325,4,50,12,ES_READONLY | NOT WS_BORDER + PUSHBUTTON "&Resume",IDC_GEDBG_RESUME,396,2,44,14 + PUSHBUTTON "Rec&ord",IDC_GEDBG_RECORD,444,2,44,14 CONTROL "",IDC_GEDBG_TEX,"SimpleGLWindow",WS_CHILD | WS_VISIBLE,10,20,128,128 CONTROL "",IDC_GEDBG_FRAME,"SimpleGLWindow",WS_CHILD | WS_VISIBLE,148,20,256,136 CONTROL "",IDC_GEDBG_MAINTAB,"SysTabControl32",TCS_TABS | TCS_FOCUSNEVER,10,216,480,180 diff --git a/Windows/resource.h b/Windows/resource.h index 7ae3fc5b4534..ee64c5759f60 100644 --- a/Windows/resource.h +++ b/Windows/resource.h @@ -165,6 +165,7 @@ #define IDC_GEDBG_SHOWCLUT 1198 #define IDC_BREAKPOINT_LOG_FORMAT 1199 #define IDC_SHOWOFFSETS 1200 +#define IDC_GEDBG_PRIMCOUNTER 1201 #define ID_SHADERS_BASE 5000 @@ -362,6 +363,7 @@ #define ID_OPTIONS_TEXTUREFILTERING_MENU 40196 #define ID_OPTIONS_SCREENFILTER_MENU 40197 #define ID_OPTIONS_TEXTURESCALING_MENU 40198 +#define IDC_GEDBG_STEPCOUNT 40199 // Dummy option to let the buffered rendering hotkey cycle through all the options. #define ID_OPTIONS_BUFFEREDRENDERINGDUMMY 40500 @@ -374,8 +376,8 @@ #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 256 -#define _APS_NEXT_COMMAND_VALUE 40199 -#define _APS_NEXT_CONTROL_VALUE 1200 +#define _APS_NEXT_COMMAND_VALUE 40200 +#define _APS_NEXT_CONTROL_VALUE 1202 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif