Skip to content

Commit

Permalink
Merge pull request #19724 from hrydgard/vertex-preview
Browse files Browse the repository at this point in the history
Implement vertex preview in the new Ge debugger
  • Loading branch information
hrydgard authored Dec 13, 2024
2 parents 50fd2ea + 5aeef92 commit 4c1ff68
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 9 deletions.
4 changes: 2 additions & 2 deletions GPU/Debugger/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ static void ExpandSpline(int &count, int op, const std::vector<SimpleVertex> &si
FreeAlignedMemory(cpoints.col);
}

bool GetPrimPreview(u32 op, int which, GEPrimitiveType &prim, std::vector<GPUDebugVertex> &vertices, std::vector<u16> &indices, int &count) {
bool GetPrimPreview(u32 op, GEPrimitiveType &prim, std::vector<GPUDebugVertex> &vertices, std::vector<u16> &indices, int &count) {
u32 prim_type = GE_PRIM_INVALID;
int count_u = 0;
int count_v = 0;
Expand All @@ -857,7 +857,7 @@ bool GetPrimPreview(u32 op, int which, GEPrimitiveType &prim, std::vector<GPUDeb
ERROR_LOG(Log::G3D, "Invalid debugging environment, shutting down?");
return false;
}
if (count == 0 || which == 0) {
if (count == 0) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion GPU/Debugger/State.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ void FormatVertColRaw(VertexDecoder *decoder, char *dest, size_t destSize, int r
// These are utilities used by the debugger vertex preview.

// Later I hope to re-use more of the real logic.
bool GetPrimPreview(u32 op, int which, GEPrimitiveType &prim, std::vector<GPUDebugVertex> &vertices, std::vector<u16> &indices, int &count);
bool GetPrimPreview(u32 op, GEPrimitiveType &prim, std::vector<GPUDebugVertex> &vertices, std::vector<u16> &indices, int &count);
void DescribePixel(u32 pix, GPUDebugBufferFormat fmt, int x, int y, char desc[256]);
void DescribePixelRGBA(u32 pix, GPUDebugBufferFormat fmt, int x, int y, char desc[256]);
4 changes: 2 additions & 2 deletions UI/ImDebugger/ImDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -902,14 +902,14 @@ void ImDebugger::Frame(MIPSDebugInterface *mipsDebug, GPUDebugInterface *gpuDebu

if (lastCpuStepCount_ != Core_GetSteppingCounter()) {
lastCpuStepCount_ = Core_GetSteppingCounter();
disasm_.View().NotifyStep();
disasm_.NotifyStep();
}

if (lastGpuStepCount_ != GPUStepping::GetSteppingCounter()) {
// A GPU step has happened since last time. This means that we should re-center the cursor.
// Snapshot();
lastGpuStepCount_ = GPUStepping::GetSteppingCounter();
geDebugger_.View().NotifyStep();
geDebugger_.NotifyStep();
}

ImControl control{};
Expand Down
3 changes: 3 additions & 0 deletions UI/ImDebugger/ImDebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class ImDisasmWindow {
ImDisasmView &View() {
return disasmView_;
}
void NotifyStep() {
disasmView_.NotifyStep();
}
void DirtySymbolMap() {
symsDirty_ = true;
}
Expand Down
71 changes: 69 additions & 2 deletions UI/ImDebugger/ImGe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,26 @@ void ImGeDebuggerWindow::Draw(ImConfig &cfg, ImControl &control, GPUDebugInterfa

ImGui::SameLine();

u32 op = 0;
DisplayList list;
if (gpuDebug->GetCurrentDisplayList(list)) {
op = Memory::Read_U32(list.pc);
bool isOnPrim = (op >> 24) == GE_CMD_PRIM;
if (isOnPrim) {
if (reloadPreview_) {
GetPrimPreview(op, previewPrim_, previewVertices_, previewIndices_, previewCount_);
reloadPreview_ = false;
}
} else {
previewCount_ = 0;
}
}

ImGui::BeginChild("texture/fb view"); // Leave room for 1 line below us


ImDrawList *drawList = ImGui::GetWindowDrawList();

if (coreState == CORE_STEPPING_GE) {
FramebufferManagerCommon *fbman = gpuDebug->GetFramebufferManagerCommon();
u32 fbptr = gstate.getFrameBufAddress();
Expand All @@ -384,8 +402,31 @@ void ImGeDebuggerWindow::Draw(ImConfig &cfg, ImControl &control, GPUDebugInterfa
if (ImGui::BeginTabBar("aspects")) {
if (ImGui::BeginTabItem("Color")) {
ImTextureID texId = ImGui_ImplThin3d_AddFBAsTextureTemp(vfb->fbo, Draw::FB_COLOR_BIT, ImGuiPipeline::TexturedOpaque);
const ImVec2 p0 = ImGui::GetCursorScreenPos();
ImGui::Image(texId, ImVec2(vfb->width, vfb->height));
// TODO: Draw vertex preview on top!
// Draw vertex preview on top!
if (previewCount_) {
switch (previewPrim_) {
case GE_PRIM_TRIANGLES:
case GE_PRIM_RECTANGLES:
{
for (int i = 0; i < previewCount_ - 2; i += 3) {
const auto &v1 = previewIndices_.empty() ? previewVertices_[i] : previewVertices_[previewIndices_[i]];
const auto &v2 = previewIndices_.empty() ? previewVertices_[i + 1] : previewVertices_[previewIndices_[i + 1]];
const auto &v3 = previewIndices_.empty() ? previewVertices_[i + 2] : previewVertices_[previewIndices_[i + 2]];
drawList->AddTriangleFilled(
ImVec2(p0.x + v1.x, p0.y + v1.y),
ImVec2(p0.x + v2.x, p0.y + v2.y),
ImVec2(p0.x + v3.x, p0.y + v3.y), ImColor(0x600000FF));
}
break;
}
default:
// TODO: Support lines etc.
break;
}
}

ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Depth")) {
Expand Down Expand Up @@ -415,7 +456,33 @@ void ImGeDebuggerWindow::Draw(ImConfig &cfg, ImControl &control, GPUDebugInterfa
void *nativeView = texcache->GetNativeTextureView(tex, true);
ImTextureID texId = ImGui_ImplThin3d_AddNativeTextureTemp(nativeView);

ImGui::Image(texId, ImVec2(128, 128));
const ImVec2 p0 = ImGui::GetCursorScreenPos();
float texW = dimWidth(tex->dim);
float texH = dimHeight(tex->dim);
ImGui::Image(texId, ImVec2(texW, texH));

// Draw UVs of vertex preview on top of the texture!
if (previewCount_) {
switch (previewPrim_) {
case GE_PRIM_TRIANGLES:
case GE_PRIM_RECTANGLES:
{
for (int i = 0; i < previewCount_ - 2; i += 3) {
const auto &v1 = previewIndices_.empty() ? previewVertices_[i] : previewVertices_[previewIndices_[i]];
const auto &v2 = previewIndices_.empty() ? previewVertices_[i + 1] : previewVertices_[previewIndices_[i + 1]];
const auto &v3 = previewIndices_.empty() ? previewVertices_[i + 2] : previewVertices_[previewIndices_[i + 2]];
drawList->AddTriangleFilled(
ImVec2(p0.x + v1.u * texW, p0.y + v1.v * texH),
ImVec2(p0.x + v2.u * texW, p0.y + v2.v * texH),
ImVec2(p0.x + v3.u * texW, p0.y + v3.v * texH), ImColor(0x600000FF));
}
break;
}
default:
// TODO: Support lines etc.
break;
}
}

// Let's display the current CLUT.

Expand Down
12 changes: 11 additions & 1 deletion UI/ImDebugger/ImGe.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#pragma once

#include "GPU/Common/GPUDebugInterface.h"

// GE-related windows of the ImDebugger

struct ImConfig;
struct ImControl;

class FramebufferManagerCommon;
class TextureCacheCommon;
class GPUDebugInterface;

void DrawFramebuffersWindow(ImConfig &cfg, FramebufferManagerCommon *framebufferManager);
void DrawTexturesWindow(ImConfig &cfg, TextureCacheCommon *textureCache);
Expand Down Expand Up @@ -57,8 +58,17 @@ class ImGeDebuggerWindow {
const char *Title() const {
return "GE Debugger";
}
void NotifyStep() {
reloadPreview_ = true;
disasmView_.NotifyStep();
}

private:
ImGeDisasmView disasmView_;
int showBannerInFrames_ = 0;
bool reloadPreview_ = false;
GEPrimitiveType previewPrim_;
std::vector<u16> previewIndices_;
std::vector<GPUDebugVertex> previewVertices_;
int previewCount_ = 0;
};
6 changes: 5 additions & 1 deletion Windows/GEDebugger/VertexPreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,16 @@ u32 CGEDebugger::PrimPreviewOp() {
void CGEDebugger::UpdatePrimPreview(u32 op, int which) {
which &= previewsEnabled_;

if (which == 0) {
return;
}

static std::vector<GPUDebugVertex> vertices;
static std::vector<u16> indices;

int count = 0;
GEPrimitiveType prim;
if (!GetPrimPreview(op, which, prim, vertices, indices, count)) {
if (!GetPrimPreview(op, prim, vertices, indices, count)) {
return;
}

Expand Down

0 comments on commit 4c1ff68

Please sign in to comment.