Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GE debugger: Cleaner resume from stepping. Fixes GE debugging in God of War #19728

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ void Core_RunLoopUntil(u64 globalticks) {
break; // Will loop around to go to RUNNING_GE or NEXTFRAME, which will exit.
case CORE_RUNNING_GE:
switch (gpu->ProcessDLQueue()) {
case DLResult::Break:
case DLResult::DebugBreak:
GPUStepping::EnterStepping();
break;
case DLResult::Error:
Expand Down
64 changes: 41 additions & 23 deletions GPU/GPUCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,13 +743,15 @@ int GPUCommon::GetNextListIndex() {
// This is now called when coreState == CORE_RUNNING_GE.
// TODO: It should return the next action.. (break into debugger or continue running)
DLResult GPUCommon::ProcessDLQueue() {
startingTicks = CoreTiming::GetTicks();
cyclesExecuted = 0;

// ?? Seems to be correct behaviour to process the list anyway?
if (startingTicks < busyTicks) {
DEBUG_LOG(Log::G3D, "Can't execute a list yet, still busy for %lld ticks", busyTicks - startingTicks);
//return;
if (!resumingFromDebugBreak_) {
startingTicks = CoreTiming::GetTicks();
cyclesExecuted = 0;

// ?? Seems to be correct behaviour to process the list anyway?
if (startingTicks < busyTicks) {
DEBUG_LOG(Log::G3D, "Can't execute a list yet, still busy for %lld ticks", busyTicks - startingTicks);
//return;
}
}

TimeCollector collectStat(&gpuStats.msProcessingDisplayLists, coreCollectDebugStats);
Expand All @@ -769,27 +771,41 @@ DLResult GPUCommon::ProcessDLQueue() {
return DLResult::Done;
}

// TODO: Need to be careful when *resuming* a list (when it wasn't from a stall...)
currentList = &list;
if (!resumingFromDebugBreak_) {
// TODO: Need to be careful when *resuming* a list (when it wasn't from a stall...)
currentList = &list;

if (!list.started && list.context.IsValid()) {
gstate.Save(list.context);
}
list.started = true;
if (!list.started && list.context.IsValid()) {
gstate.Save(list.context);
}
list.started = true;

gstate_c.offsetAddr = list.offsetAddr;
gstate_c.offsetAddr = list.offsetAddr;

cycleLastPC = list.pc;
cyclesExecuted += 60;
downcount = list.stall == 0 ? 0x0FFFFFFF : (list.stall - list.pc) / 4;
list.state = PSP_GE_DL_STATE_RUNNING;
list.interrupted = false;
cycleLastPC = list.pc;
cyclesExecuted += 60;
downcount = list.stall == 0 ? 0x0FFFFFFF : (list.stall - list.pc) / 4;
list.state = PSP_GE_DL_STATE_RUNNING;
list.interrupted = false;

gpuState = list.pc == list.stall ? GPUSTATE_STALL : GPUSTATE_RUNNING;
gpuState = list.pc == list.stall ? GPUSTATE_STALL : GPUSTATE_RUNNING;

// To enable breakpoints, we don't do fast matrix loads while debugger active.
debugRecording_ = GPUDebug::IsActive() || GPURecord::IsActive();
} else {
resumingFromDebugBreak_ = false;
// The bottom part of the gpuState loop below, that wasn't executed
// when we bailed.
downcount = list.stall == 0 ? 0x0FFFFFFF : (list.stall - list.pc) / 4;
if (gpuState == GPUSTATE_STALL && list.pc != list.stall) {
// Unstalled (Can this happen?)
gpuState = GPUSTATE_RUNNING;
}
// Proceed...
}

// To enable breakpoints, we don't do fast matrix loads while debugger active.
debugRecording_ = GPUDebug::IsActive() || GPURecord::IsActive();
const bool useFastRunLoop = !dumpThisFrame_ && !debugRecording_;

while (gpuState == GPUSTATE_RUNNING) {
if (list.pc == list.stall) {
gpuState = GPUSTATE_STALL;
Expand All @@ -806,7 +822,9 @@ DLResult GPUCommon::ProcessDLQueue() {
// TODO: Cycle counting might need some more care?
FinishDeferred();
_dbg_assert_(!GPURecord::IsActive());
return DLResult::Break;

resumingFromDebugBreak_ = true;
return DLResult::DebugBreak;
}
}

Expand Down
1 change: 1 addition & 0 deletions GPU/GPUCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ class GPUCommon : public GPUDebugInterface {
u32 cycleLastPC;
int cyclesExecuted;

bool resumingFromDebugBreak_ = false;
bool dumpNextFrame_ = false;
bool dumpThisFrame_ = false;
bool debugRecording_;
Expand Down
2 changes: 1 addition & 1 deletion GPU/GPUDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@ enum GPUInvalidationType {
enum class DLResult {
Done, // Or stall
Error,
Break, // used for stepping, breakpoints
DebugBreak, // used for stepping, breakpoints
};
Loading