From 09f9e107076c6f867f6d2b67eb1e4ac3bf0ca674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 15 Dec 2024 19:17:48 +0100 Subject: [PATCH] Fixes to depth display --- UI/ImDebugger/ImDebugger.cpp | 8 +++++++- UI/ImDebugger/ImDebugger.h | 1 + UI/ImDebugger/ImGe.cpp | 28 ++++++++++++++++++++++++---- UI/ImDebugger/ImGe.h | 3 ++- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/UI/ImDebugger/ImDebugger.cpp b/UI/ImDebugger/ImDebugger.cpp index a8b2a615ab..2285bc3a63 100644 --- a/UI/ImDebugger/ImDebugger.cpp +++ b/UI/ImDebugger/ImDebugger.cpp @@ -125,7 +125,7 @@ void DrawSchedulerView(ImConfig &cfg) { static void DrawGPRs(ImConfig &config, ImControl &control, const MIPSDebugInterface *mipsDebug, const ImSnapshotState &prev) { ImGui::SetNextWindowSize(ImVec2(320, 600), ImGuiCond_FirstUseEver); - if (!ImGui::Begin("MIPS GPRs", &config.vfpuOpen)) { + if (!ImGui::Begin("MIPS GPRs", &config.gprOpen)) { ImGui::End(); return; } @@ -962,6 +962,7 @@ void ImDebugger::Frame(MIPSDebugInterface *mipsDebug, GPUDebugInterface *gpuDebu // A GPU step has happened since last time. This means that we should re-center the cursor. // Snapshot(); lastGpuStepCount_ = GPUStepping::GetSteppingCounter(); + SnapshotGPU(gpuDebug); geDebugger_.NotifyStep(); } @@ -1224,6 +1225,11 @@ void ImDebugger::Snapshot(MIPSState *mips) { newSnapshot_.lo = mips->lo; newSnapshot_.hi = mips->hi; newSnapshot_.ll = mips->llBit; + pixelViewer_.Snapshot(); +} + +void ImDebugger::SnapshotGPU(GPUDebugInterface *gpuDebug) { + pixelViewer_.Snapshot(); } void ImMemWindow::Draw(MIPSDebugInterface *mipsDebug, ImConfig &cfg, ImControl &control, int index) { diff --git a/UI/ImDebugger/ImDebugger.h b/UI/ImDebugger/ImDebugger.h index 816276f583..5a70c073a1 100644 --- a/UI/ImDebugger/ImDebugger.h +++ b/UI/ImDebugger/ImDebugger.h @@ -188,6 +188,7 @@ public: // Should be called just before starting a step or run, so that things can // save state that they can later compare with, to highlight changes. void Snapshot(MIPSState *mips); + void SnapshotGPU(GPUDebugInterface *mips); private: Path ConfigPath(); diff --git a/UI/ImDebugger/ImGe.cpp b/UI/ImDebugger/ImGe.cpp index 0afe84c1a6..d0fa09d3d5 100644 --- a/UI/ImDebugger/ImGe.cpp +++ b/UI/ImDebugger/ImGe.cpp @@ -150,6 +150,14 @@ void ImGePixelViewer::Draw(ImConfig &cfg, ImControl &control, GPUDebugInterface if (ImGui::InputScalar("Stride", ImGuiDataType_U16, &stride_)) { dirty_ = true; } + if (format_ == GE_FORMAT_DEPTH16) { + if (ImGui::SliderFloat("Scale", &scale_, 0.5f, 256.0f, "%.2f", ImGuiSliderFlags_Logarithmic)) { + dirty_ = true; + } + } + if (ImGui::Button("Refresh")) { + dirty_ = true; + } } ImGui::EndChild(); @@ -232,18 +240,29 @@ void ImGePixelViewer::UpdateTexture(Draw::DrawContext *draw) { ConvertRGBA4444ToRGBA8888((u32 *)dst, (const u16 *)src, width_); break; case GE_FORMAT_DEPTH16: + { + uint16_t *src16 = (uint16_t *)src; + float scale = scale_ / 256.0f; for (int x = 0; x < width_; x++) { // Just pick off the upper bits by adding 1 to the byte address // We don't visualize the lower bits for now, although we could - should add a scale slider like RenderDoc. - u8 val = src[x + 1]; + float fval = (float)src16[x] * scale; + u8 val; + if (fval < 0.0f) { + val = 0; + } else if (fval >= 255.0f) { + val = 255; + } else { + val = (u8)fval; + } dst[0] = val; dst[1] = val; dst[2] = val; dst[3] = 0xFF; - src += 2; dst += 4; } break; + } default: memset(buf, 0x80, width_ * height_ * 4); break; @@ -719,7 +738,7 @@ void ImGeDebuggerWindow::Draw(ImConfig &cfg, ImControl &control, GPUDebugInterfa ImGui::Text("(texturing not enabled"); } else { TextureCacheCommon *texcache = gpuDebug->GetTextureCacheCommon(); - TexCacheEntry *tex = texcache->SetTexture(); + TexCacheEntry *tex = texcache ? texcache->SetTexture() : nullptr; if (tex) { ImGui::Text("Texture: "); texcache->ApplyTexture(); @@ -743,6 +762,7 @@ void ImGeDebuggerWindow::Draw(ImConfig &cfg, ImControl &control, GPUDebugInterfa drawList->PopClipRect(); } else { ImGui::Text("(no valid texture bound)"); + // In software mode, we should just decode the texture here. // TODO: List some of the texture params here. } } @@ -995,7 +1015,7 @@ void ImGeStateWindow::Draw(ImConfig &cfg, ImControl &control, GPUDebugInterface // Special handling for pointer and pointer/width entries - create an address control if (info.fmt == CMD_FMT_PTRWIDTH) { - const u32 val = value | (otherValue & 0x00FF0000) << 8; + const u32 val = (value & 0xFFFFFF) | (otherValue & 0x00FF0000) << 8; ImClickableAddress(val, control, ImCmd::NONE); ImGui::SameLine(); ImGui::Text("w=%d", otherValue & 0xFFFF); diff --git a/UI/ImDebugger/ImGe.h b/UI/ImDebugger/ImGe.h index cf9f68f6e2..696e641632 100644 --- a/UI/ImDebugger/ImGe.h +++ b/UI/ImDebugger/ImGe.h @@ -74,10 +74,11 @@ public: private: void UpdateTexture(Draw::DrawContext *draw); Draw::Texture *texture_ = nullptr; - GEBufferFormat format_; + GEBufferFormat format_ = GE_FORMAT_565; bool dirty_ = true; bool useAlpha_ = false; bool showAlpha_ = false; + float scale_ = 1.0f; uint32_t addr_ = 0x04000000; uint16_t stride_ = 512; uint16_t width_ = 480;