2013-09-22 10:27:09 -07:00
|
|
|
// Copyright (c) 2012- 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/.
|
|
|
|
|
2013-09-22 19:05:33 -07:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <set>
|
|
|
|
|
2013-09-22 10:27:09 -07:00
|
|
|
#include "native/base/mutex.h"
|
2013-09-22 11:03:29 -07:00
|
|
|
#include "Windows/GEDebugger/GEDebugger.h"
|
2013-09-22 19:05:33 -07:00
|
|
|
#include "Windows/GEDebugger/SimpleGLWindow.h"
|
2013-09-25 15:24:53 +02:00
|
|
|
#include "Windows/GEDebugger/CtrlDisplayListView.h"
|
2013-09-22 10:27:09 -07:00
|
|
|
#include "Windows/WindowsHost.h"
|
2013-09-27 13:11:11 +02:00
|
|
|
#include "Windows/WndMainWindow.h"
|
2013-09-22 19:05:33 -07:00
|
|
|
#include "Windows/main.h"
|
2013-09-22 10:27:09 -07:00
|
|
|
#include "GPU/GPUInterface.h"
|
|
|
|
#include "GPU/Common/GPUDebugInterface.h"
|
|
|
|
#include "GPU/GPUState.h"
|
2013-09-28 16:04:56 +02:00
|
|
|
#include "Core/Config.h"
|
2013-09-27 13:11:11 +02:00
|
|
|
#include <windowsx.h>
|
|
|
|
#include <commctrl.h>
|
2013-09-29 01:02:05 +02:00
|
|
|
#include "TabDisplayLists.h"
|
2013-09-22 10:27:09 -07:00
|
|
|
|
2013-09-22 19:05:33 -07:00
|
|
|
enum PauseAction {
|
|
|
|
PAUSE_CONTINUE,
|
|
|
|
PAUSE_GETFRAMEBUF,
|
2013-09-27 22:41:44 -07:00
|
|
|
PAUSE_GETTEX,
|
2013-09-22 19:05:33 -07:00
|
|
|
};
|
|
|
|
|
2013-09-22 10:27:09 -07:00
|
|
|
static bool attached = false;
|
|
|
|
// TODO
|
|
|
|
static bool textureCaching = true;
|
|
|
|
static recursive_mutex pauseLock;
|
|
|
|
static condition_variable pauseWait;
|
2013-09-22 19:05:33 -07:00
|
|
|
static PauseAction pauseAction = PAUSE_CONTINUE;
|
|
|
|
static recursive_mutex actionLock;
|
|
|
|
static condition_variable actionWait;
|
|
|
|
|
|
|
|
static std::vector<bool> breakCmds;
|
|
|
|
static std::set<u32> breakPCs;
|
|
|
|
static bool breakNextOp = false;
|
|
|
|
static bool breakNextDraw = false;
|
|
|
|
|
|
|
|
static bool bufferResult;
|
2013-09-27 22:41:44 -07:00
|
|
|
static GPUDebugBuffer bufferFrame;
|
|
|
|
static GPUDebugBuffer bufferTex;
|
2013-09-22 19:05:33 -07:00
|
|
|
|
|
|
|
// TODO: Simplify and move out of windows stuff, just block in a common way for everyone.
|
|
|
|
|
2013-09-27 22:41:44 -07:00
|
|
|
void CGEDebugger::Init() {
|
|
|
|
SimpleGLWindow::RegisterClass();
|
2013-09-25 15:24:53 +02:00
|
|
|
CtrlDisplayListView::registerClass();
|
2013-09-24 20:06:25 +02:00
|
|
|
}
|
|
|
|
|
2013-09-22 19:05:33 -07:00
|
|
|
static void SetPauseAction(PauseAction act) {
|
|
|
|
{
|
|
|
|
lock_guard guard(pauseLock);
|
|
|
|
actionLock.lock();
|
|
|
|
pauseAction = act;
|
|
|
|
}
|
|
|
|
|
|
|
|
pauseWait.notify_one();
|
|
|
|
actionWait.wait(actionLock);
|
|
|
|
actionLock.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void RunPauseAction() {
|
|
|
|
lock_guard guard(actionLock);
|
|
|
|
|
|
|
|
switch (pauseAction) {
|
|
|
|
case PAUSE_CONTINUE:
|
2013-09-23 01:19:13 -07:00
|
|
|
// Don't notify, just go back, woke up by accident.
|
|
|
|
return;
|
2013-09-22 19:05:33 -07:00
|
|
|
|
|
|
|
case PAUSE_GETFRAMEBUF:
|
2013-09-27 22:41:44 -07:00
|
|
|
bufferResult = gpuDebug->GetCurrentFramebuffer(bufferFrame);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PAUSE_GETTEX:
|
|
|
|
bufferResult = gpuDebug->GetCurrentTexture(bufferTex);
|
2013-09-22 19:05:33 -07:00
|
|
|
break;
|
|
|
|
}
|
2013-09-22 10:27:09 -07:00
|
|
|
|
2013-09-22 19:05:33 -07:00
|
|
|
actionWait.notify_one();
|
|
|
|
pauseAction = PAUSE_CONTINUE;
|
|
|
|
}
|
2013-09-27 15:38:20 +02:00
|
|
|
|
2013-09-28 00:32:45 -07:00
|
|
|
static void ForceUnpause() {
|
|
|
|
lock_guard guard(pauseLock);
|
|
|
|
lock_guard actionGuard(actionLock);
|
|
|
|
pauseAction = PAUSE_CONTINUE;
|
|
|
|
pauseWait.notify_one();
|
|
|
|
}
|
|
|
|
|
2013-09-22 10:27:09 -07:00
|
|
|
CGEDebugger::CGEDebugger(HINSTANCE _hInstance, HWND _hParent)
|
2013-09-27 22:41:44 -07:00
|
|
|
: Dialog((LPCSTR)IDD_GEDEBUGGER, _hInstance, _hParent), frameWindow(NULL), texWindow(NULL) {
|
2013-09-22 19:05:33 -07:00
|
|
|
breakCmds.resize(256, false);
|
2013-09-28 00:32:45 -07:00
|
|
|
Core_ListenShutdown(ForceUnpause);
|
2013-09-24 20:06:25 +02:00
|
|
|
|
2013-09-28 16:04:56 +02:00
|
|
|
// minimum size = a little more than the default
|
|
|
|
RECT windowRect;
|
|
|
|
GetWindowRect(m_hDlg,&windowRect);
|
|
|
|
minWidth = windowRect.right-windowRect.left+10;
|
|
|
|
minHeight = windowRect.bottom-windowRect.top+10;
|
|
|
|
|
2013-09-24 20:06:25 +02:00
|
|
|
// it's ugly, but .rc coordinates don't match actual pixels and it screws
|
|
|
|
// up both the size and the aspect ratio
|
|
|
|
// TODO: Could be scrollable in case the framebuf is larger? Also should be better positioned.
|
|
|
|
RECT frameRect;
|
|
|
|
HWND frameWnd = GetDlgItem(m_hDlg,IDC_GEDBG_FRAME);
|
|
|
|
|
|
|
|
GetWindowRect(frameWnd,&frameRect);
|
|
|
|
MapWindowPoints(HWND_DESKTOP,m_hDlg,(LPPOINT)&frameRect,2);
|
|
|
|
MoveWindow(frameWnd,frameRect.left,frameRect.top,512,272,TRUE);
|
2013-09-27 13:11:11 +02:00
|
|
|
|
2013-09-28 20:57:02 +02:00
|
|
|
tabs = new TabControl(GetDlgItem(m_hDlg,IDC_GEDBG_MAINTAB));
|
|
|
|
HWND wnd = tabs->AddTabWindow(L"CtrlDisplayListView",L"Display List");
|
2013-09-27 18:03:08 +02:00
|
|
|
displayList = CtrlDisplayListView::getFrom(wnd);
|
2013-09-28 16:04:56 +02:00
|
|
|
|
2013-09-29 01:02:05 +02:00
|
|
|
lists = new TabDisplayLists(_hInstance,m_hDlg);
|
|
|
|
tabs->AddTabDialog(lists,L"Lists");
|
|
|
|
|
2013-09-28 16:04:56 +02:00
|
|
|
// set window position
|
|
|
|
int x = g_Config.iGEWindowX == -1 ? windowRect.left : g_Config.iGEWindowX;
|
|
|
|
int y = g_Config.iGEWindowY == -1 ? windowRect.top : g_Config.iGEWindowY;
|
|
|
|
int w = g_Config.iGEWindowW == -1 ? minWidth : g_Config.iGEWindowW;
|
|
|
|
int h = g_Config.iGEWindowH == -1 ? minHeight : g_Config.iGEWindowH;
|
|
|
|
MoveWindow(m_hDlg,x,y,w,h,FALSE);
|
2013-09-22 19:05:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
CGEDebugger::~CGEDebugger() {
|
|
|
|
delete frameWindow;
|
2013-09-27 22:41:44 -07:00
|
|
|
delete texWindow;
|
2013-09-22 10:27:09 -07:00
|
|
|
}
|
|
|
|
|
2013-09-27 22:41:44 -07:00
|
|
|
void CGEDebugger::SetupPreviews() {
|
2013-09-23 23:45:17 -07:00
|
|
|
if (frameWindow == NULL) {
|
2013-09-27 22:41:44 -07:00
|
|
|
frameWindow = SimpleGLWindow::GetFrom(GetDlgItem(m_hDlg, IDC_GEDBG_FRAME));
|
2013-09-27 23:52:06 -07:00
|
|
|
frameWindow->Initialize(SimpleGLWindow::ALPHA_IGNORE | SimpleGLWindow::RESIZE_SHRINK_CENTER);
|
2013-09-23 23:45:17 -07:00
|
|
|
// TODO: Why doesn't this work?
|
|
|
|
frameWindow->Clear();
|
|
|
|
}
|
2013-09-27 22:41:44 -07:00
|
|
|
if (texWindow == NULL) {
|
|
|
|
texWindow = SimpleGLWindow::GetFrom(GetDlgItem(m_hDlg, IDC_GEDBG_TEX));
|
2013-09-27 23:52:06 -07:00
|
|
|
texWindow->Initialize(SimpleGLWindow::ALPHA_BLEND | SimpleGLWindow::RESIZE_SHRINK_CENTER);
|
2013-09-27 22:41:44 -07:00
|
|
|
// TODO: Why doesn't this work?
|
|
|
|
texWindow->Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGEDebugger::UpdatePreviews() {
|
|
|
|
// TODO: Do something different if not paused?
|
|
|
|
|
|
|
|
bufferResult = false;
|
|
|
|
SetPauseAction(PAUSE_GETFRAMEBUF);
|
|
|
|
|
|
|
|
if (bufferResult) {
|
|
|
|
auto fmt = SimpleGLWindow::Format(bufferFrame.GetFormat());
|
2013-09-27 23:52:06 -07:00
|
|
|
frameWindow->Draw(bufferFrame.GetData(), bufferFrame.GetStride(), bufferFrame.GetHeight(), bufferFrame.GetFlipped(), fmt);
|
2013-09-27 22:41:44 -07:00
|
|
|
} else {
|
|
|
|
ERROR_LOG(COMMON, "Unable to get framebuffer.");
|
|
|
|
frameWindow->Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
bufferResult = false;
|
|
|
|
SetPauseAction(PAUSE_GETTEX);
|
|
|
|
|
|
|
|
if (bufferResult) {
|
|
|
|
auto fmt = SimpleGLWindow::Format(bufferTex.GetFormat());
|
2013-09-27 23:52:06 -07:00
|
|
|
texWindow->Draw(bufferTex.GetData(), bufferTex.GetStride(), bufferTex.GetHeight(), bufferTex.GetFlipped(), fmt);
|
2013-09-27 22:41:44 -07:00
|
|
|
} else {
|
|
|
|
ERROR_LOG(COMMON, "Unable to get texture.");
|
|
|
|
texWindow->Clear();
|
|
|
|
}
|
2013-09-27 23:45:15 -07:00
|
|
|
|
|
|
|
DisplayList list;
|
|
|
|
if (gpuDebug->GetCurrentDisplayList(list)) {
|
|
|
|
displayList->setDisplayList(list);
|
|
|
|
}
|
2013-09-29 01:02:05 +02:00
|
|
|
|
|
|
|
lists->Update();
|
2013-09-23 23:45:17 -07:00
|
|
|
}
|
|
|
|
|
2013-09-28 16:04:56 +02:00
|
|
|
void CGEDebugger::UpdateSize(WORD width, WORD height)
|
|
|
|
{
|
|
|
|
// only resize the tab for now
|
|
|
|
HWND tabControl = GetDlgItem(m_hDlg, IDC_GEDBG_MAINTAB);
|
|
|
|
|
|
|
|
RECT tabRect;
|
|
|
|
GetWindowRect(tabControl,&tabRect);
|
|
|
|
MapWindowPoints(HWND_DESKTOP,m_hDlg,(LPPOINT)&tabRect,2);
|
|
|
|
|
|
|
|
tabRect.right = tabRect.left + (width-tabRect.left*2); // assume same gap on both sides
|
|
|
|
tabRect.bottom = tabRect.top + (height-tabRect.top-tabRect.left); // assume same gap on bottom too
|
|
|
|
MoveWindow(tabControl,tabRect.left,tabRect.top,tabRect.right-tabRect.left,tabRect.bottom-tabRect.top,TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGEDebugger::SavePosition()
|
|
|
|
{
|
|
|
|
RECT rc;
|
|
|
|
if (GetWindowRect(m_hDlg, &rc))
|
|
|
|
{
|
|
|
|
g_Config.iGEWindowX = rc.left;
|
|
|
|
g_Config.iGEWindowY = rc.top;
|
|
|
|
g_Config.iGEWindowW = rc.right - rc.left;
|
|
|
|
g_Config.iGEWindowH = rc.bottom - rc.top;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-27 18:03:08 +02:00
|
|
|
BOOL CGEDebugger::DlgProc(UINT message, WPARAM wParam, LPARAM lParam) {
|
2013-09-22 10:27:09 -07:00
|
|
|
switch (message) {
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
return TRUE;
|
|
|
|
|
2013-09-28 16:04:56 +02:00
|
|
|
case WM_GETMINMAXINFO:
|
|
|
|
{
|
|
|
|
MINMAXINFO* minmax = (MINMAXINFO*) lParam;
|
|
|
|
minmax->ptMinTrackSize.x = minWidth;
|
|
|
|
minmax->ptMinTrackSize.y = minHeight;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
|
2013-09-22 10:27:09 -07:00
|
|
|
case WM_SIZE:
|
2013-09-28 16:04:56 +02:00
|
|
|
UpdateSize(LOWORD(lParam), HIWORD(lParam));
|
|
|
|
SavePosition();
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WM_MOVE:
|
|
|
|
SavePosition();
|
2013-09-22 10:27:09 -07:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case WM_CLOSE:
|
|
|
|
Show(false);
|
|
|
|
return TRUE;
|
|
|
|
|
2013-09-23 23:45:17 -07:00
|
|
|
case WM_SHOWWINDOW:
|
2013-09-27 22:41:44 -07:00
|
|
|
SetupPreviews();
|
2013-09-23 23:45:17 -07:00
|
|
|
break;
|
|
|
|
|
2013-09-28 14:34:08 +02:00
|
|
|
case WM_ACTIVATE:
|
|
|
|
if (wParam == WA_ACTIVE || wParam == WA_CLICKACTIVE) {
|
|
|
|
g_activeWindow = WINDOW_GEDEBUGGER;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-09-27 13:11:11 +02:00
|
|
|
case WM_NOTIFY:
|
|
|
|
switch (wParam)
|
|
|
|
{
|
|
|
|
case IDC_GEDBG_MAINTAB:
|
2013-09-28 20:57:02 +02:00
|
|
|
tabs->HandleNotify(lParam);
|
2013-09-27 13:11:11 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-09-22 10:27:09 -07:00
|
|
|
case WM_COMMAND:
|
|
|
|
switch (LOWORD(wParam)) {
|
2013-09-27 23:45:15 -07:00
|
|
|
case IDC_GEDBG_STEPDRAW:
|
2013-09-22 10:27:09 -07:00
|
|
|
attached = true;
|
2013-09-27 22:41:44 -07:00
|
|
|
SetupPreviews();
|
2013-09-25 15:24:53 +02:00
|
|
|
|
2013-09-22 19:05:33 -07:00
|
|
|
pauseWait.notify_one();
|
2013-09-27 23:45:15 -07:00
|
|
|
breakNextOp = false;
|
2013-09-22 19:05:33 -07:00
|
|
|
breakNextDraw = true;
|
2013-09-27 23:45:15 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IDC_GEDBG_STEP:
|
2013-09-28 14:34:08 +02:00
|
|
|
SendMessage(m_hDlg,WM_GEDBG_STEPDISPLAYLIST,0,0);
|
2013-09-22 10:27:09 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IDC_GEDBG_RESUME:
|
2013-09-22 19:05:33 -07:00
|
|
|
frameWindow->Clear();
|
2013-09-27 22:41:44 -07:00
|
|
|
texWindow->Clear();
|
2013-09-22 10:27:09 -07:00
|
|
|
// TODO: detach? Should probably have separate UI, or just on activate?
|
2013-09-27 23:45:15 -07:00
|
|
|
breakNextOp = false;
|
2013-09-22 19:05:33 -07:00
|
|
|
breakNextDraw = false;
|
2013-09-22 10:27:09 -07:00
|
|
|
pauseWait.notify_one();
|
|
|
|
break;
|
|
|
|
}
|
2013-09-22 19:05:33 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_GEDBG_BREAK_CMD:
|
|
|
|
{
|
|
|
|
u32 pc = (u32)wParam;
|
|
|
|
auto info = gpuDebug->DissassembleOp(pc);
|
|
|
|
NOTICE_LOG(COMMON, "Waiting at %08x, %s", pc, info.desc.c_str());
|
2013-09-27 22:41:44 -07:00
|
|
|
UpdatePreviews();
|
2013-09-22 19:05:33 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_GEDBG_BREAK_DRAW:
|
|
|
|
{
|
|
|
|
NOTICE_LOG(COMMON, "Waiting at a draw");
|
2013-09-27 22:41:44 -07:00
|
|
|
UpdatePreviews();
|
2013-09-22 19:05:33 -07:00
|
|
|
}
|
|
|
|
break;
|
2013-09-28 14:34:08 +02:00
|
|
|
|
|
|
|
case WM_GEDBG_STEPDISPLAYLIST:
|
|
|
|
attached = true;
|
|
|
|
SetupPreviews();
|
|
|
|
|
|
|
|
pauseWait.notify_one();
|
|
|
|
breakNextOp = true;
|
|
|
|
breakNextDraw = false;
|
|
|
|
break;
|
2013-09-22 10:27:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The below WindowsHost methods are called on the GPU thread.
|
|
|
|
|
|
|
|
bool WindowsHost::GPUDebuggingActive() {
|
|
|
|
return attached;
|
|
|
|
}
|
|
|
|
|
2013-09-22 19:05:33 -07:00
|
|
|
static void PauseWithMessage(UINT msg, WPARAM wParam = NULL, LPARAM lParam = NULL) {
|
|
|
|
lock_guard guard(pauseLock);
|
2013-09-28 00:32:45 -07:00
|
|
|
if (Core_IsInactive()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-22 19:05:33 -07:00
|
|
|
PostMessage(geDebuggerWindow->GetDlgHandle(), msg, wParam, lParam);
|
|
|
|
|
|
|
|
do {
|
|
|
|
RunPauseAction();
|
2013-09-22 10:27:09 -07:00
|
|
|
pauseWait.wait(pauseLock);
|
2013-09-22 19:05:33 -07:00
|
|
|
} while (pauseAction != PAUSE_CONTINUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowsHost::GPUNotifyCommand(u32 pc) {
|
|
|
|
u32 op = Memory::ReadUnchecked_U32(pc);
|
|
|
|
u8 cmd = op >> 24;
|
|
|
|
|
|
|
|
const bool breakPC = breakPCs.find(pc) != breakPCs.end();
|
|
|
|
if (breakNextOp || breakCmds[cmd] || breakPC) {
|
|
|
|
PauseWithMessage(WM_GEDBG_BREAK_CMD, (WPARAM) pc);
|
2013-09-22 10:27:09 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowsHost::GPUNotifyDisplay(u32 framebuf, u32 stride, int format) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void WindowsHost::GPUNotifyDraw() {
|
2013-09-22 19:05:33 -07:00
|
|
|
if (breakNextDraw) {
|
|
|
|
PauseWithMessage(WM_GEDBG_BREAK_DRAW);
|
|
|
|
}
|
2013-09-22 10:27:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void WindowsHost::GPUNotifyTextureAttachment(u32 addr) {
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WindowsHost::GPUAllowTextureCache(u32 addr) {
|
|
|
|
return textureCaching;
|
|
|
|
}
|