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: Highlight changed state values #15402

Merged
merged 4 commits into from
Feb 13, 2022
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
36 changes: 26 additions & 10 deletions GPU/Debugger/Stepping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ static GPUDebugBuffer bufferClut;
static int bufferLevel;
static u32 pauseSetCmdValue;

static GPUgstate lastGState;

static void SetPauseAction(PauseAction act, bool waitComplete = true) {
pauseLock.lock();
std::unique_lock<std::mutex> guard(actionLock);
Expand Down Expand Up @@ -133,6 +135,22 @@ static void RunPauseAction() {
pauseAction = PAUSE_BREAK;
}

static void StartStepping() {
if (lastGState.cmdmem[1] == 0) {
lastGState = gstate;
// Play it safe so we don't keep resetting.
lastGState.cmdmem[1] |= 0x01000000;
}
gpuDebug->NotifySteppingEnter();
isStepping = true;
}

static void StopStepping() {
gpuDebug->NotifySteppingExit();
lastGState = gstate;
isStepping = false;
}

bool SingleStep() {
std::unique_lock<std::mutex> guard(pauseLock);
if (coreState != CORE_RUNNING && coreState != CORE_NEXTFRAME && coreState != CORE_STEPPING) {
Expand All @@ -147,13 +165,9 @@ bool SingleStep() {
return false;
}

gpuDebug->NotifySteppingEnter();
isStepping = true;

StartStepping();
RunPauseAction();

gpuDebug->NotifySteppingExit();
isStepping = false;
StopStepping();
return true;
}

Expand All @@ -171,22 +185,20 @@ bool EnterStepping() {
return false;
}

gpuDebug->NotifySteppingEnter();
StartStepping();

// Just to be sure.
if (pauseAction == PAUSE_CONTINUE) {
pauseAction = PAUSE_BREAK;
}
isStepping = true;
stepCounter++;

do {
RunPauseAction();
pauseWait.wait(guard);
} while (pauseAction != PAUSE_CONTINUE);

gpuDebug->NotifySteppingExit();
isStepping = false;
StopStepping();
return true;
}

Expand Down Expand Up @@ -263,4 +275,8 @@ void ForceUnpause() {
actionWait.notify_all();
}

GPUgstate LastState() {
return lastGState;
}

} // namespace
3 changes: 3 additions & 0 deletions GPU/Debugger/Stepping.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Common/CommonTypes.h"
#include "Core/Core.h"
#include "GPU/Common/GPUDebugInterface.h"
#include "GPU/GPUState.h"

namespace GPUStepping {
// Should be called from the emu thread.
Expand All @@ -42,4 +43,6 @@ namespace GPUStepping {

void ResumeFromStepping();
void ForceUnpause();

GPUgstate LastState();
};
16 changes: 8 additions & 8 deletions Windows/Debugger/Debugger_Disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,17 +361,17 @@ BOOL CDisasm::DlgProc(UINT message, WPARAM wParam, LPARAM lParam)
leftTabs->HandleNotify(lParam);
break;
case IDC_BREAKPOINTLIST:
breakpointList->HandleNotify(lParam);
break;
SetWindowLongPtr(m_hDlg, DWLP_MSGRESULT, breakpointList->HandleNotify(lParam));
return TRUE;
case IDC_THREADLIST:
threadList->HandleNotify(lParam);
break;
SetWindowLongPtr(m_hDlg, DWLP_MSGRESULT, threadList->HandleNotify(lParam));
return TRUE;
case IDC_STACKFRAMES:
stackTraceView->HandleNotify(lParam);
break;
SetWindowLongPtr(m_hDlg, DWLP_MSGRESULT, stackTraceView->HandleNotify(lParam));
return TRUE;
case IDC_MODULELIST:
moduleList->HandleNotify(lParam);
break;
SetWindowLongPtr(m_hDlg, DWLP_MSGRESULT, moduleList->HandleNotify(lParam));
return TRUE;
case IDC_DEBUG_BOTTOMTABS:
bottomTabs->HandleNotify(lParam);
break;
Expand Down
8 changes: 4 additions & 4 deletions Windows/GEDebugger/TabDisplayLists.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,11 @@ BOOL TabDisplayLists::DlgProc(UINT message, WPARAM wParam, LPARAM lParam) {
switch (wParam)
{
case IDC_GEDBG_LISTS_STACK:
stack->HandleNotify(lParam);
break;
SetWindowLongPtr(m_hDlg, DWLP_MSGRESULT, stack->HandleNotify(lParam));
return TRUE;
case IDC_GEDBG_LISTS_ALLLISTS:
allLists->HandleNotify(lParam);
break;
SetWindowLongPtr(m_hDlg, DWLP_MSGRESULT, allLists->HandleNotify(lParam));
return TRUE;
}
break;

Expand Down
32 changes: 30 additions & 2 deletions Windows/GEDebugger/TabState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.

#include <commctrl.h>
#include "Common/CommonFuncs.h"
#include "Common/CommonTypes.h"
#include "Common/Log.h"
#include "Common/Data/Text/Parsers.h"
#include "Common/StringUtils.h"
#include "Windows/resource.h"
Expand All @@ -28,6 +30,7 @@
#include "GPU/GeDisasm.h"
#include "GPU/Common/GPUDebugInterface.h"
#include "GPU/Debugger/Breakpoints.h"
#include "GPU/Debugger/Stepping.h"

using namespace GPUBreakpoints;

Expand Down Expand Up @@ -1009,11 +1012,36 @@ void CtrlStateValues::OnRightClick(int row, int column, const POINT &point) {
}
}

bool CtrlStateValues::OnRowPrePaint(int row, LPNMLVCUSTOMDRAW msg) {
if (RowValuesChanged(row)) {
msg->clrText = RGB(255, 0, 0);
return true;
}
return false;
}

void CtrlStateValues::SetCmdValue(u32 op) {
SendMessage(GetParent(GetParent(GetHandle())), WM_GEDBG_SETCMDWPARAM, op, NULL);
Update();
}

bool CtrlStateValues::RowValuesChanged(int row) {
_assert_(gpuDebug != nullptr && row >= 0 && row < rowCount_);

const auto info = rows_[row];
const auto state = gpuDebug->GetGState();
const auto lastState = GPUStepping::LastState();

if (state.cmdmem[info.cmd] != lastState.cmdmem[info.cmd])
return true;
if (info.otherCmd && state.cmdmem[info.otherCmd] != lastState.cmdmem[info.otherCmd])
return true;
if (info.otherCmd2 && state.cmdmem[info.otherCmd2] != lastState.cmdmem[info.otherCmd2])
return true;

return false;
}

TabStateValues::TabStateValues(const TabStateRow *rows, int rowCount, LPCSTR dialogID, HINSTANCE _hInstance, HWND _hParent)
: Dialog(dialogID, _hInstance, _hParent) {
values = new CtrlStateValues(rows, rowCount, GetDlgItem(m_hDlg, IDC_GEDBG_VALUES));
Expand Down Expand Up @@ -1054,8 +1082,8 @@ BOOL TabStateValues::DlgProc(UINT message, WPARAM wParam, LPARAM lParam) {
switch (wParam)
{
case IDC_GEDBG_VALUES:
values->HandleNotify(lParam);
break;
SetWindowLongPtr(m_hDlg, DWLP_MSGRESULT, values->HandleNotify(lParam));
return TRUE;
}
break;
}
Expand Down
4 changes: 4 additions & 0 deletions Windows/GEDebugger/TabState.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ class CtrlStateValues: public GenericListControl {
void OnDoubleClick(int row, int column) override;
void OnRightClick(int row, int column, const POINT& point) override;

bool ListenRowPrePaint() override { return true; }
bool OnRowPrePaint(int row, LPNMLVCUSTOMDRAW msg) override;

private:
bool RowValuesChanged(int row);
void SetCmdValue(u32 op);

const TabStateRow *rows_;
Expand Down
63 changes: 54 additions & 9 deletions Windows/GEDebugger/TabVertices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.

#include <commctrl.h>
#include "Common/CommonTypes.h"
#include "Common/StringUtils.h"
#include "Core/System.h"
Expand All @@ -28,6 +29,7 @@
#include "GPU/GeDisasm.h"
#include "GPU/Common/GPUDebugInterface.h"
#include "GPU/Debugger/Breakpoints.h"
#include "GPU/Debugger/Stepping.h"

static const GenericListViewColumn vertexListCols[] = {
{ L"X", 0.1f },
Expand Down Expand Up @@ -355,8 +357,8 @@ BOOL TabVertices::DlgProc(UINT message, WPARAM wParam, LPARAM lParam) {
switch (wParam)
{
case IDC_GEDBG_VERTICES:
values->HandleNotify(lParam);
break;
SetWindowLongPtr(m_hDlg, DWLP_MSGRESULT, values->HandleNotify(lParam));
return TRUE;
}
break;
}
Expand All @@ -370,14 +372,57 @@ CtrlMatrixList::CtrlMatrixList(HWND hwnd)
Update();
}

bool CtrlMatrixList::GetValue(int row, int col, float &val) {
bool CtrlMatrixList::OnColPrePaint(int row, int col, LPNMLVCUSTOMDRAW msg) {
const auto state = gpuDebug->GetGState();
const auto lastState = GPUStepping::LastState();

bool changed = false;
if (col < MATRIXLIST_COL_0) {
for (int c = MATRIXLIST_COL_0; c <= MATRIXLIST_COL_3; ++c) {
changed = changed || ColChanged(lastState, state, row, c);
}
} else {
changed = ColChanged(lastState, state, row, col);
}

// At the column level, we have to reset the color back.
static int lastRow = -1;
static COLORREF rowDefaultText;
if (lastRow != row) {
rowDefaultText = msg->clrText;
lastRow = row;
}

if (changed) {
msg->clrText = RGB(255, 0, 0);
return true;
} else if (msg->clrText != rowDefaultText) {
msg->clrText = rowDefaultText;
return true;
}

return false;
}

bool CtrlMatrixList::ColChanged(const GPUgstate &lastState, const GPUgstate &state, int row, int col) {
union {
float f;
uint32_t u;
} newVal, oldVal;
if (!GetValue(state, row, col, newVal.f) || !GetValue(lastState, row, col, oldVal.f))
return false;

// If there's any difference in bits, highlight.
return newVal.u != oldVal.u;
}

bool CtrlMatrixList::GetValue(const GPUgstate &state, int row, int col, float &val) {
if (!gpuDebug || row < 0 || row >= MATRIXLIST_ROW_COUNT || col < 0 || col >= MATRIXLIST_COL_COUNT)
return false;

if (col < MATRIXLIST_COL_0)
col = MATRIXLIST_COL_0;

auto state = gpuDebug->GetGState();
if (row >= MATRIXLIST_ROW_BONE_0_0) {
int b = (row - MATRIXLIST_ROW_BONE_0_0) / 3;
int r = (row - MATRIXLIST_ROW_BONE_0_0) % 3;
Expand Down Expand Up @@ -419,7 +464,7 @@ void CtrlMatrixList::GetColumnText(wchar_t *dest, int row, int col) {
}

float val;
if (!GetValue(row, col, val)) {
if (!GetValue(gpuDebug->GetGState(), row, col, val)) {
wcscpy(dest, L"Invalid");
return;
}
Expand Down Expand Up @@ -534,7 +579,7 @@ void CtrlMatrixList::OnDoubleClick(int row, int column) {
}

float val;
if (!GetValue(row, column, val))
if (!GetValue(gpuDebug->GetGState(), row, column, val))
return;

std::string strvalue = StringFromFormat("%f", val);
Expand Down Expand Up @@ -594,7 +639,7 @@ void CtrlMatrixList::OnRightClick(int row, int column, const POINT &point) {
case ID_DISASM_COPYINSTRUCTIONDISASM:
{
float val;
if (GetValue(row, column, val)) {
if (GetValue(gpuDebug->GetGState(), row, column, val)) {
wchar_t dest[512];
swprintf(dest, 511, L"%f", val);
W32Util::CopyTextToClipboard(GetHandle(), dest);
Expand Down Expand Up @@ -652,8 +697,8 @@ BOOL TabMatrices::DlgProc(UINT message, WPARAM wParam, LPARAM lParam) {
switch (wParam)
{
case IDC_GEDBG_MATRICES:
values->HandleNotify(lParam);
break;
SetWindowLongPtr(m_hDlg, DWLP_MSGRESULT, values->HandleNotify(lParam));
return TRUE;
}
break;
}
Expand Down
6 changes: 5 additions & 1 deletion Windows/GEDebugger/TabVertices.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,12 @@ class CtrlMatrixList: public GenericListControl {
void OnDoubleClick(int row, int column) override;
void OnRightClick(int row, int column, const POINT &point) override;

bool ListenColPrePaint() override { return true; }
bool OnColPrePaint(int row, int col, LPNMLVCUSTOMDRAW msg) override;

private:
bool GetValue(int row, int col, float &val);
bool GetValue(const GPUgstate &state, int row, int col, float &val);
bool ColChanged(const GPUgstate &lastState, const GPUgstate &state, int row, int col);
void ToggleBreakpoint(int row);
};

Expand Down
Loading