diff --git a/CMakeLists.txt b/CMakeLists.txt index eadfe3cb74..f6735209f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1539,6 +1539,8 @@ list(APPEND NativeAppSource UI/ImDebugger/ImMemView.h UI/ImDebugger/ImStructViewer.cpp UI/ImDebugger/ImStructViewer.h + UI/ImDebugger/ImJitViewer.cpp + UI/ImDebugger/ImJitViewer.h UI/DiscordIntegration.cpp UI/NativeApp.cpp UI/BackgroundAudio.h diff --git a/UI/ImDebugger/ImConsole.h b/UI/ImDebugger/ImConsole.h index b6f93fde7d..5a3e80f58d 100644 --- a/UI/ImDebugger/ImConsole.h +++ b/UI/ImDebugger/ImConsole.h @@ -5,6 +5,8 @@ #include "ext/imgui/imgui.h" +struct ImConfig; + // Adapted from the ImGui demo. class ImConsole { public: diff --git a/UI/ImDebugger/ImDebugger.cpp b/UI/ImDebugger/ImDebugger.cpp index 3d84a4b622..e5e8c859fb 100644 --- a/UI/ImDebugger/ImDebugger.cpp +++ b/UI/ImDebugger/ImDebugger.cpp @@ -2395,6 +2395,7 @@ void ImDebugger::Frame(MIPSDebugInterface *mipsDebug, GPUDebugInterface *gpuDebu ImGui::MenuItem("Callstacks", nullptr, &cfg_.callstackOpen); ImGui::MenuItem("Breakpoints", nullptr, &cfg_.breakpointsOpen); ImGui::MenuItem("Watch", nullptr, &cfg_.watchOpen); + ImGui::MenuItem("JIT viewer", nullptr, &cfg_.jitViewerOpen); ImGui::EndMenu(); } if (ImGui::BeginMenu("Symbols")) { @@ -2621,6 +2622,10 @@ void ImDebugger::Frame(MIPSDebugInterface *mipsDebug, GPUDebugInterface *gpuDebu logWindow_.Draw(cfg_); } + if (cfg_.jitViewerOpen) { + jitViewer_.Draw(cfg_, control); + } + if (cfg_.displayOpen) { DrawDisplayWindow(cfg_, gpuDebug->GetFramebufferManagerCommon()); } diff --git a/UI/ImDebugger/ImDebugger.h b/UI/ImDebugger/ImDebugger.h index a609afcba5..651c59c188 100644 --- a/UI/ImDebugger/ImDebugger.h +++ b/UI/ImDebugger/ImDebugger.h @@ -20,6 +20,7 @@ #include "UI/ImDebugger/ImDisasmView.h" #include "UI/ImDebugger/ImMemView.h" #include "UI/ImDebugger/ImStructViewer.h" +#include "UI/ImDebugger/ImJitViewer.h" #include "UI/ImDebugger/ImGe.h" #include "UI/ImDebugger/ImConsole.h" @@ -90,6 +91,7 @@ struct ImConfig { bool luaConsoleOpen; bool audioOutOpen; bool paramSFOOpen; + bool jitViewerOpen; // HLE explorer settings // bool filterByUsed = true; @@ -216,6 +218,7 @@ private: ImAtracToolWindow atracToolWindow_; ImConsole luaConsole_; ImLogWindow logWindow_; + ImJitViewerWindow jitViewer_; ImSnapshotState newSnapshot_; ImSnapshotState snapshot_; diff --git a/UI/ImDebugger/ImJitViewer.cpp b/UI/ImDebugger/ImJitViewer.cpp new file mode 100644 index 0000000000..656b46c026 --- /dev/null +++ b/UI/ImDebugger/ImJitViewer.cpp @@ -0,0 +1,110 @@ +#include "ppsspp_config.h" + +#include "UI/ImDebugger/ImJitViewer.h" +#include "UI/ImDebugger/ImDebugger.h" +#include "Core/Config.h" + +#include "Core/MIPS/JitCommon/JitBlockCache.h" +#include "Core/MIPS/JitCommon/JitCommon.h" +#include "Core/MIPS/JitCommon/JitState.h" + +void ImJitViewerWindow::Draw(ImConfig &cfg, ImControl &control) { + ImGui::SetNextWindowSize(ImVec2(500, 400), ImGuiCond_FirstUseEver); + if (!ImGui::Begin("JitViewer", &cfg.jitViewerOpen)) { + ImGui::End(); + return; + } + + const CPUCore core = (CPUCore)g_Config.iCpuCore; + + if (core == CPUCore::INTERPRETER) { + ImGui::TextUnformatted("JIT Viewer is only available with JIT or IR-based CPU cores."); + ImGui::End(); + return; + } + + // Options menu + if (ImGui::BeginPopup("Options")) { + // ImGui::Checkbox("Auto-scroll", &AutoScroll); + ImGui::EndPopup(); + } + +#if PPSSPP_ARCH(X64) + const char *TARGET = "X86-64"; +#elif PPSSPP_ARCH(X86) + const char *TARGET = "X86"; +#elif PPSSPP_ARCH(ARM64) + + const char *TARGET = "ARM64"; +#elif PPSSPP_ARCH(ARM32) + const char *TARGET = "ARM32"; +#else + cosnt char *TARGET = "TARGET"; +#endif + + // Three or four columns: One table for blocks that can be sorted in various ways, + // then the remaining are either MIPS/IR/TARGET or MIPS/TARGET or MIPS/IR depending on the JIT type. + int numColumns = 3; + if (core == CPUCore::JIT_IR) { + numColumns = 4; + } + + if (ImGui::BeginTable("columns", 3, ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersH | ImGuiTableFlags_Resizable)) { + ImGui::TableSetupColumn("Blocks"); + ImGui::TableSetupColumn("MIPS"); + if (core == CPUCore::JIT_IR || core == CPUCore::IR_INTERPRETER) { + ImGui::TableSetupColumn("IR"); + } + if (core == CPUCore::JIT_IR || core == CPUCore::JIT) { + ImGui::TableSetupColumn(TARGET); + } + + ImGui::TableHeadersRow(); + + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + + ImGui::Text("Blocklist"); + JitBlockCacheDebugInterface *blockCacheDebug = MIPSComp::jit->GetBlockCacheDebugInterface(); + int64_t sumTotalNanos = 0; + int64_t sumExecutions = 0; + bool profiling = blockCacheDebug->SupportsProfiling(); + for (int i = 0; i < blockCacheDebug->GetNumBlocks(); i++) { + if (!blockCacheDebug->IsValidBlock(i)) { + continue; + } + JitBlockMeta meta = blockCacheDebug->GetBlockMeta(i); + ImGui::Text("%08x %d", meta.addr, meta.sizeInBytes); + } + + ImGui::TableNextColumn(); + + ImGui::Text("MIPS"); + + if (core == CPUCore::JIT_IR || core == CPUCore::IR_INTERPRETER) { + + ImGui::TableNextColumn(); + + ImGui::Text("IR"); + } + if (core == CPUCore::JIT_IR || core == CPUCore::JIT) { + ImGui::TableNextColumn(); + ImGui::Text("Target asm"); + } + + /* + if (ImGui::BeginTable("blocks", 1, ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersH | ImGuiTableFlags_ScrollY)) { + + + for (auto &block : blocks) { + char label[64]; + snprintf(label, sizeof(label), "0x%08X", block.startAddress); + if (ImGui::Selectable(label, false, ImGuiSelectableFlags_SpanAllColumns)) { + ", 3) + */ + + ImGui::EndTable(); + } + + ImGui::End(); +} diff --git a/UI/ImDebugger/ImJitViewer.h b/UI/ImDebugger/ImJitViewer.h new file mode 100644 index 0000000000..e08ef3919e --- /dev/null +++ b/UI/ImDebugger/ImJitViewer.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include +#include "ext/imgui/imgui.h" + +#include "Core/Debugger/DebugInterface.h" + +struct ImConfig; +struct ImControl; + +class ImJitViewerWindow { +public: + void Draw(ImConfig &cfg, ImControl &control); + const char *Title() const { + return "JIT Viewer"; + } +}; diff --git a/UI/UI.vcxproj b/UI/UI.vcxproj index 9f1cd0b02c..42ad2df168 100644 --- a/UI/UI.vcxproj +++ b/UI/UI.vcxproj @@ -49,6 +49,7 @@ + @@ -99,6 +100,7 @@ + diff --git a/UI/UI.vcxproj.filters b/UI/UI.vcxproj.filters index 1a2c87e1f4..3d8693dd36 100644 --- a/UI/UI.vcxproj.filters +++ b/UI/UI.vcxproj.filters @@ -126,6 +126,9 @@ Screens + + ImDebugger + @@ -252,6 +255,9 @@ Screens + + ImDebugger +