2018-09-01 08:32:03 -07:00
|
|
|
// Copyright (c) 2018- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
2020-10-04 09:29:36 +02:00
|
|
|
#include "Common/Log.h"
|
2018-09-01 09:41:20 -07:00
|
|
|
#include "GPU/GPU.h"
|
|
|
|
#include "GPU/Debugger/Breakpoints.h"
|
2018-09-01 08:32:03 -07:00
|
|
|
#include "GPU/Debugger/Debugger.h"
|
2018-09-01 09:41:20 -07:00
|
|
|
#include "GPU/Debugger/Stepping.h"
|
2018-09-01 08:32:03 -07:00
|
|
|
|
|
|
|
namespace GPUDebug {
|
|
|
|
|
|
|
|
static bool active = false;
|
2018-09-01 09:41:20 -07:00
|
|
|
static bool inited = false;
|
|
|
|
static BreakNext breakNext = BreakNext::NONE;
|
2018-12-01 06:40:27 -08:00
|
|
|
static int breakAtCount = -1;
|
2018-09-01 09:41:20 -07:00
|
|
|
|
2018-12-01 06:26:35 -08:00
|
|
|
static int primsLastFrame = 0;
|
|
|
|
static int primsThisFrame = 0;
|
|
|
|
static int thisFlipNum = 0;
|
|
|
|
|
2018-09-01 09:41:20 -07:00
|
|
|
static void Init() {
|
|
|
|
if (!inited) {
|
|
|
|
GPUBreakpoints::Init();
|
|
|
|
Core_ListenStopRequest(&GPUStepping::ForceUnpause);
|
|
|
|
inited = true;
|
|
|
|
}
|
|
|
|
}
|
2018-09-01 08:32:03 -07:00
|
|
|
|
|
|
|
void SetActive(bool flag) {
|
2018-09-01 09:41:20 -07:00
|
|
|
Init();
|
|
|
|
|
2018-09-01 08:32:03 -07:00
|
|
|
active = flag;
|
2018-09-01 09:41:20 -07:00
|
|
|
if (!active) {
|
|
|
|
breakNext = BreakNext::NONE;
|
2018-12-01 06:40:27 -08:00
|
|
|
breakAtCount = -1;
|
2018-09-01 09:41:20 -07:00
|
|
|
GPUStepping::ResumeFromStepping();
|
|
|
|
}
|
2018-09-01 08:32:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IsActive() {
|
|
|
|
return active;
|
|
|
|
}
|
|
|
|
|
2018-09-01 09:41:20 -07:00
|
|
|
void SetBreakNext(BreakNext next) {
|
|
|
|
SetActive(true);
|
|
|
|
breakNext = next;
|
2018-12-01 06:40:27 -08:00
|
|
|
breakAtCount = -1;
|
2018-09-01 09:41:20 -07:00
|
|
|
if (next == BreakNext::TEX) {
|
|
|
|
GPUBreakpoints::AddTextureChangeTempBreakpoint();
|
2018-12-01 06:40:27 -08:00
|
|
|
} else if (next == BreakNext::PRIM || next == BreakNext::COUNT) {
|
2018-09-01 09:41:20 -07:00
|
|
|
GPUBreakpoints::AddCmdBreakpoint(GE_CMD_PRIM, true);
|
|
|
|
GPUBreakpoints::AddCmdBreakpoint(GE_CMD_BEZIER, true);
|
|
|
|
GPUBreakpoints::AddCmdBreakpoint(GE_CMD_SPLINE, true);
|
2018-10-01 11:40:21 +09:00
|
|
|
} else if (next == BreakNext::CURVE) {
|
|
|
|
GPUBreakpoints::AddCmdBreakpoint(GE_CMD_BEZIER, true);
|
|
|
|
GPUBreakpoints::AddCmdBreakpoint(GE_CMD_SPLINE, true);
|
2018-09-01 09:41:20 -07:00
|
|
|
}
|
|
|
|
GPUStepping::ResumeFromStepping();
|
|
|
|
}
|
|
|
|
|
2018-12-01 15:50:20 -08:00
|
|
|
void SetBreakCount(int c, bool relative) {
|
|
|
|
if (relative) {
|
|
|
|
breakAtCount = primsThisFrame + c;
|
|
|
|
} else {
|
|
|
|
breakAtCount = c;
|
|
|
|
}
|
2018-12-01 06:40:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-01 08:32:03 -07:00
|
|
|
void NotifyCommand(u32 pc) {
|
2018-09-01 09:41:20 -07:00
|
|
|
if (!active)
|
|
|
|
return;
|
|
|
|
u32 op = Memory::ReadUnchecked_U32(pc);
|
2018-12-01 06:26:35 -08:00
|
|
|
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++;
|
|
|
|
}
|
|
|
|
|
2018-12-01 06:40:27 -08:00
|
|
|
if (IsBreakpoint(pc, op)) {
|
2018-09-01 09:41:20 -07:00
|
|
|
GPUBreakpoints::ClearTempBreakpoints();
|
|
|
|
|
|
|
|
auto info = gpuDebug->DissassembleOp(pc);
|
|
|
|
NOTICE_LOG(G3D, "Waiting at %08x, %s", pc, info.desc.c_str());
|
|
|
|
GPUStepping::EnterStepping();
|
|
|
|
}
|
2018-09-01 08:32:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void NotifyDraw() {
|
2018-09-01 09:41:20 -07:00
|
|
|
if (!active)
|
|
|
|
return;
|
|
|
|
if (breakNext == BreakNext::DRAW) {
|
|
|
|
NOTICE_LOG(G3D, "Waiting at a draw");
|
|
|
|
GPUStepping::EnterStepping();
|
|
|
|
}
|
2018-09-01 08:32:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void NotifyDisplay(u32 framebuf, u32 stride, int format) {
|
2018-09-01 09:41:20 -07:00
|
|
|
if (!active)
|
|
|
|
return;
|
|
|
|
if (breakNext == BreakNext::FRAME) {
|
|
|
|
// This should work fine, start stepping at the first op of the new frame.
|
|
|
|
breakNext = BreakNext::OP;
|
|
|
|
}
|
2018-09-01 08:32:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void NotifyTextureAttachment(u32 texaddr) {
|
2018-09-01 09:41:20 -07:00
|
|
|
if (!active)
|
|
|
|
return;
|
2018-09-01 08:32:03 -07:00
|
|
|
}
|
|
|
|
|
2018-12-01 06:26:35 -08:00
|
|
|
int PrimsThisFrame() {
|
|
|
|
return primsThisFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
int PrimsLastFrame() {
|
|
|
|
return primsLastFrame;
|
|
|
|
}
|
|
|
|
|
2018-09-01 08:32:03 -07:00
|
|
|
}
|