Skip to content

Commit

Permalink
Merge pull request #10435 from unknownbrackets/debugger
Browse files Browse the repository at this point in the history
Fix issues with GE debugger prim preview
  • Loading branch information
hrydgard committed Dec 23, 2017
2 parents 0de5053 + 3c5816e commit 46c468f
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 136 deletions.
36 changes: 29 additions & 7 deletions Windows/GEDebugger/GEDebugger.cpp
Expand Up @@ -157,16 +157,27 @@ void CGEDebugger::SetupPreviews() {
PrimaryPreviewHover(x, y); PrimaryPreviewHover(x, y);
}); });
primaryWindow->SetRightClickMenu(subMenu, [&] (int cmd) { primaryWindow->SetRightClickMenu(subMenu, [&] (int cmd) {
HMENU subMenu = GetSubMenu(g_hPopupMenus, POPUP_SUBMENU_ID_GEDBG_PREVIEW);
switch (cmd) { switch (cmd) {
case 0:
// Setup.
CheckMenuItem(subMenu, ID_GEDBG_ENABLE_PREVIEW, MF_BYCOMMAND | ((previewsEnabled_ & 1) ? MF_CHECKED : MF_UNCHECKED));
break;
case ID_GEDBG_EXPORT_IMAGE: case ID_GEDBG_EXPORT_IMAGE:
PreviewExport(primaryBuffer_); PreviewExport(primaryBuffer_);
break; break;
case ID_GEDBG_ENABLE_PREVIEW:
previewsEnabled_ ^= 1;
primaryWindow->Redraw();
default: default:
break; break;
} }


return true; return true;
}); });
primaryWindow->SetRedrawCallback([&] {
HandleRedraw(1);
});
primaryWindow->Clear(); primaryWindow->Clear();
} }
if (secondWindow == nullptr) { if (secondWindow == nullptr) {
Expand All @@ -178,16 +189,27 @@ void CGEDebugger::SetupPreviews() {
SecondPreviewHover(x, y); SecondPreviewHover(x, y);
}); });
secondWindow->SetRightClickMenu(subMenu, [&] (int cmd) { secondWindow->SetRightClickMenu(subMenu, [&] (int cmd) {
HMENU subMenu = GetSubMenu(g_hPopupMenus, POPUP_SUBMENU_ID_GEDBG_PREVIEW);
switch (cmd) { switch (cmd) {
case 0:
// Setup.
CheckMenuItem(subMenu, ID_GEDBG_ENABLE_PREVIEW, MF_BYCOMMAND | ((previewsEnabled_ & 2) ? MF_CHECKED : MF_UNCHECKED));
break;
case ID_GEDBG_EXPORT_IMAGE: case ID_GEDBG_EXPORT_IMAGE:
PreviewExport(secondBuffer_); PreviewExport(secondBuffer_);
break; break;
case ID_GEDBG_ENABLE_PREVIEW:
previewsEnabled_ ^= 2;
secondWindow->Redraw();
default: default:
break; break;
} }


return true; return true;
}); });
secondWindow->SetRedrawCallback([&] {
HandleRedraw(2);
});
secondWindow->Clear(); secondWindow->Clear();
} }
} }
Expand Down Expand Up @@ -258,19 +280,18 @@ void CGEDebugger::UpdatePreviews() {
state = gpuDebug->GetGState(); state = gpuDebug->GetGState();
} }


updating_ = true;
UpdateTextureLevel(textureLevel_); UpdateTextureLevel(textureLevel_);
UpdatePrimaryPreview(state); UpdatePrimaryPreview(state);
UpdateSecondPreview(state); UpdateSecondPreview(state);


u32 primOp = PrimPreviewOp();
if (primOp != 0) {
UpdatePrimPreview(primOp, 3);
}

DisplayList list; DisplayList list;
if (gpuDebug != nullptr && gpuDebug->GetCurrentDisplayList(list)) { if (gpuDebug != nullptr && gpuDebug->GetCurrentDisplayList(list)) {
const u32 op = Memory::Read_U32(list.pc);
const u32 cmd = op >> 24;
// TODO: Bezier/spline?
if (cmd == GE_CMD_PRIM && !showClut_) {
UpdatePrimPreview(op);
}

displayList->setDisplayList(list); displayList->setDisplayList(list);
} }


Expand All @@ -282,6 +303,7 @@ void CGEDebugger::UpdatePreviews() {
matrices->Update(); matrices->Update();
lists->Update(); lists->Update();
watch->Update(); watch->Update();
updating_ = false;
} }


u32 CGEDebugger::TexturePreviewFlags(const GPUgstate &state) { u32 CGEDebugger::TexturePreviewFlags(const GPUgstate &state) {
Expand Down
6 changes: 5 additions & 1 deletion Windows/GEDebugger/GEDebugger.h
Expand Up @@ -70,8 +70,10 @@ class CGEDebugger : public Dialog {
void UpdatePreviews(); void UpdatePreviews();
void UpdatePrimaryPreview(const GPUgstate &state); void UpdatePrimaryPreview(const GPUgstate &state);
void UpdateSecondPreview(const GPUgstate &state); void UpdateSecondPreview(const GPUgstate &state);
void UpdatePrimPreview(u32 op); u32 PrimPreviewOp();
void UpdatePrimPreview(u32 op, int which);
void CleanupPrimPreview(); void CleanupPrimPreview();
void HandleRedraw(int which);
void UpdateSize(WORD width, WORD height); void UpdateSize(WORD width, WORD height);
void SavePosition(); void SavePosition();
void SetBreakNext(BreakNextType type); void SetBreakNext(BreakNextType type);
Expand Down Expand Up @@ -106,6 +108,8 @@ class CGEDebugger : public Dialog {
const GPUDebugBuffer *primaryBuffer_ = nullptr; const GPUDebugBuffer *primaryBuffer_ = nullptr;
const GPUDebugBuffer *secondBuffer_ = nullptr; const GPUDebugBuffer *secondBuffer_ = nullptr;


bool updating_ = false;
int previewsEnabled_ = 3;
int minWidth_; int minWidth_;
int minHeight_; int minHeight_;
}; };
27 changes: 21 additions & 6 deletions Windows/GEDebugger/SimpleGLWindow.cpp
Expand Up @@ -68,8 +68,7 @@ static const char basic_vs[] =
"}\n"; "}\n";


SimpleGLWindow::SimpleGLWindow(HWND wnd) SimpleGLWindow::SimpleGLWindow(HWND wnd)
: hWnd_(wnd), valid_(false), drawProgram_(nullptr), vao_(0), tex_(0), flags_(0), zoom_(false), : hWnd_(wnd) {
dragging_(false), offsetX_(0), offsetY_(0), reformatBuf_(nullptr), hoverCallback_(nullptr) {
SetWindowLongPtr(wnd, GWLP_USERDATA, (LONG_PTR) this); SetWindowLongPtr(wnd, GWLP_USERDATA, (LONG_PTR) this);
} }


Expand Down Expand Up @@ -365,10 +364,23 @@ void SimpleGLWindow::GetContentSize(float &x, float &y, float &fw, float &fh) {
void SimpleGLWindow::Redraw(bool andSwap) { void SimpleGLWindow::Redraw(bool andSwap) {
DrawChecker(); DrawChecker();


if (tw_ == 0 && th_ == 0) { auto swapWithCallback = [andSwap, this]() {
if (andSwap) { if (andSwap) {
Swap(); swapped_ = false;
if (redrawCallback_ && !inRedrawCallback_) {
inRedrawCallback_ = true;
redrawCallback_();
inRedrawCallback_ = false;
}
// In case the callback swaps, don't do it twice.
if (!swapped_) {
Swap();
}
} }
};

if (tw_ == 0 && th_ == 0) {
swapWithCallback();
return; return;
} }


Expand Down Expand Up @@ -412,7 +424,7 @@ void SimpleGLWindow::Redraw(bool andSwap) {
glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, vao_ ? 0 : indices); glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, vao_ ? 0 : indices);


if (andSwap) { if (andSwap) {
Swap(); swapWithCallback();
} }
} }


Expand All @@ -423,7 +435,9 @@ void SimpleGLWindow::Clear() {
} }


void SimpleGLWindow::Begin() { void SimpleGLWindow::Begin() {
Redraw(false); if (!inRedrawCallback_) {
Redraw(false);
}


if (vao_) { if (vao_) {
glBindVertexArray(0); glBindVertexArray(0);
Expand Down Expand Up @@ -549,6 +563,7 @@ bool SimpleGLWindow::RightClick(int mouseX, int mouseY) {
POINT pt{mouseX, mouseY}; POINT pt{mouseX, mouseY};
ClientToScreen(hWnd_, &pt); ClientToScreen(hWnd_, &pt);


rightClickCallback_(0);
int result = TrackPopupMenuEx(rightClickMenu_, TPM_RIGHTBUTTON | TPM_RETURNCMD, pt.x, pt.y, hWnd_, 0); int result = TrackPopupMenuEx(rightClickMenu_, TPM_RIGHTBUTTON | TPM_RETURNCMD, pt.x, pt.y, hWnd_, 0);
if (result != 0) { if (result != 0) {
rightClickCallback_(result); rightClickCallback_(result);
Expand Down
37 changes: 23 additions & 14 deletions Windows/GEDebugger/SimpleGLWindow.h
Expand Up @@ -81,6 +81,7 @@ struct SimpleGLWindow {
} }


void Swap() { void Swap() {
swapped_ = true;
SwapBuffers(hDC_); SwapBuffers(hDC_);
} }


Expand All @@ -106,10 +107,15 @@ struct SimpleGLWindow {


void GetContentSize(float &x, float &y, float &fw, float &fh); void GetContentSize(float &x, float &y, float &fw, float &fh);


void SetRedrawCallback(std::function<void()> callback) {
redrawCallback_ = callback;
}

void SetHoverCallback(std::function<void(int, int)> hoverCallback) { void SetHoverCallback(std::function<void(int, int)> hoverCallback) {
hoverCallback_ = hoverCallback; hoverCallback_ = hoverCallback;
} }


// Called first with 0 that it's opening, then the selected item.
void SetRightClickMenu(HMENU menu, std::function<void(int)> callback) { void SetRightClickMenu(HMENU menu, std::function<void(int)> callback) {
rightClickCallback_ = callback; rightClickCallback_ = callback;
rightClickMenu_ = menu; rightClickMenu_ = menu;
Expand All @@ -134,7 +140,7 @@ struct SimpleGLWindow {
HWND hWnd_; HWND hWnd_;
HDC hDC_; HDC hDC_;
HGLRC hGLRC_; HGLRC hGLRC_;
bool valid_; bool valid_ = false;
// Width and height of the window. // Width and height of the window.
int w_; int w_;
int h_; int h_;
Expand All @@ -143,25 +149,28 @@ struct SimpleGLWindow {
int th_; int th_;
bool tflipped_; bool tflipped_;


GLSLProgram *drawProgram_; GLSLProgram *drawProgram_ = nullptr;
GLuint vao_; GLuint vao_ = 0;
GLuint ibuf_; GLuint ibuf_ = 0;
GLuint vbuf_; GLuint vbuf_ = 0;
GLuint checker_; GLuint checker_ = 0;
GLuint tex_; GLuint tex_ = 0;
u32 flags_; u32 flags_ = 0;
// Disable shrink (toggled by double click.) // Disable shrink (toggled by double click.)
bool zoom_; bool zoom_ = false;
bool dragging_; bool dragging_ = false;
bool inRedrawCallback_ = false;
bool swapped_ = false;
int dragStartX_; int dragStartX_;
int dragStartY_; int dragStartY_;
u32 dragLastUpdate_; u32 dragLastUpdate_;
// Offset to position the texture is drawn at. // Offset to position the texture is drawn at.
int offsetX_; int offsetX_ = 0;
int offsetY_; int offsetY_ = 0;
u32 *reformatBuf_; u32 *reformatBuf_ = nullptr;
u32 reformatBufSize_; u32 reformatBufSize_ = 0;


std::function<void()> redrawCallback_;
std::function<void(int, int)> hoverCallback_; std::function<void(int, int)> hoverCallback_;
std::function<void(int)> rightClickCallback_; std::function<void(int)> rightClickCallback_;
HMENU rightClickMenu_; HMENU rightClickMenu_;
Expand Down

0 comments on commit 46c468f

Please sign in to comment.