Add heap imgui

This commit is contained in:
PJB3005
2026-03-01 22:23:30 +01:00
parent 891a80b87c
commit d83267098e
18 changed files with 206 additions and 18 deletions
+1
View File
@@ -1331,6 +1331,7 @@ set(DUSK_FILES
src/dusk/imgui/imgui.hpp
src/dusk/imgui/processes.cpp
src/dusk/imgui/debug_overlay.cpp
src/dusk/imgui/heaps.cpp
src/dusk/offset_ptr.cpp
src/dolphin/os/OSContext.cpp
src/dolphin/os/OSThread.cpp
+13
View File
@@ -141,6 +141,10 @@ protected:
/* 0x68 */ bool mErrorFlag;
/* 0x69 */ bool mInitFlag;
#if TARGET_PC
char mName[32];
#endif
public:
static bool initArena(char** memory, u32* size, int maxHeaps);
static bool initArena2(char** memory, u32* size, int maxHeaps);
@@ -209,6 +213,15 @@ public:
#endif
static JKRErrorHandler mErrorHandler;
#if TARGET_PC
void setName(const char* name);
const char* getName() const;
#define JKRHEAP_NAME(heap, name) (heap)->setName(name)
#else
#define JKRHEAP_NAME(heap, name)
#endif
};
#ifndef TARGET_PC
+12 -2
View File
@@ -819,10 +819,20 @@ struct ProcName {
};
#define X(name) { name, #name },
inline ProcName procNames[] = {
inline const ProcName procNames[] = {
ALL_PROCS
};
#undef name
#undef X
inline const char* GetProcName(unsigned int id) {
for (auto procName : procNames) {
if (procName.id == id) {
return procName.name;
}
}
return nullptr;
}
#endif
+2
View File
@@ -294,8 +294,10 @@ JASMemChunkPool<1024, JASThreadingModel::ObjectLevelLockable>* JASKernel::sComma
void JASKernel::setupRootHeap(JKRSolidHeap* heap, u32 size) {
JUT_ASSERT(784, heap);
sSystemHeap = JKRExpHeap::create(size, heap, false);
JKRHEAP_NAME(sSystemHeap, "JASKernel::sSystemHeap");
JUT_ASSERT(787, sSystemHeap);
sCommandHeap = new (heap, 0) JASMemChunkPool<1024, JASThreadingModel::ObjectLevelLockable>();
JKRHEAP_NAME(sSystemHeap, "JASKernel::sCommandHeap");
JUT_ASSERT(790, sCommandHeap);
JASDram = heap;
}
+2
View File
@@ -45,7 +45,9 @@ void JFWSystem::firstInit() {
OSInit();
DVDInit();
rootHeap = JKRExpHeap::createRoot(CSetUpParam::maxStdHeaps, false);
JKRHEAP_NAME(rootHeap, "Root");
systemHeap = JKRExpHeap::create(CSetUpParam::sysHeapSize, rootHeap, false);
JKRHEAP_NAME(systemHeap, "System");
}
JKRThread* JFWSystem::mainThread;
+17
View File
@@ -6,6 +6,11 @@
#include "JSystem/JSystem.h" // IWYU pragma: keep
#include "JSystem/JKernel/JKRHeap.h"
#if TARGET_PC
#include <algorithm>
#endif
#include "JSystem/JUtility/JUTAssert.h"
#include "JSystem/JUtility/JUTException.h"
#ifdef __MWERKS__
@@ -83,6 +88,10 @@ JKRHeap::JKRHeap(void* data, u32 size, JKRHeap* parent, bool errorFlag)
mDebugFill = sDefaultFillFlag;
mCheckMemoryFilled = data_80451380;
mInitFlag = false;
#if TARGET_PC
memset(mName, 0, sizeof(mName));
#endif
}
JKRHeap::~JKRHeap() {
@@ -668,4 +677,12 @@ void JKRHeap::setCurrentHeap(JKRHeap* heap) {
JKRHeap* JKRHeap::getCurrentHeap() {
return sCurrentHeap;
}
void JKRHeap::setName(const char* name) {
size_t len = strlen(name);
memcpy(mName, name, std::max(len, sizeof(mName)-1));
}
const char* JKRHeap::getName() const {
return mName;
}
#endif
+1
View File
@@ -173,6 +173,7 @@ dAttention_c::dAttention_c(fopAc_ac_c* i_player, u32 i_padNo) {
mAttnBlockTimer = 0;
heap = mDoExt_createSolidHeapFromGameToCurrent(0x9000, 0);
JKRHEAP_NAME(heap, "dAttention_c::heap");
JUT_ASSERT(0x198, heap != NULL);
J3DModelData* modelDataR = (J3DModelData*)dComIfG_getObjectRes("Always", 0x25);
+2
View File
@@ -24,6 +24,7 @@
#include "f_op/f_op_kankyo.h"
#include "m_Do/m_Do_graphic.h"
#include "m_Do/m_Do_lib.h"
#include "JSystem/JKernel/JKRSolidHeap.h"
#include <cstdlib>
#include <cstring>
@@ -1168,6 +1169,7 @@ static void undwater_init() {
JUT_ASSERT(1867, modelData2 != NULL);
g_env_light.undwater_ef_heap = mDoExt_createSolidHeapFromGameToCurrent(0x600, 0x20);
JKRHEAP_NAME(g_env_light.undwater_ef_heap, "g_env_light.undwater_ef_heap");
if (g_env_light.undwater_ef_heap != NULL) {
g_env_light.undwater_ef_model = mDoExt_J3DModel__create(modelData2, 0x80000, 0x11020202);
+2
View File
@@ -1201,6 +1201,7 @@ void dPa_control_c::createCommon(void const* param_0) {
OS_REPORT("常駐パーティクルリソースサイズ<%d>\n", heapSize);
#endif
mHeap = mDoExt_createSolidHeapFromSystem(0, 0);
JKRHEAP_NAME(mHeap, "dPa_control_c::mHeap");
JUT_ASSERT(2518, mHeap != NULL);
mCommonResMng = new (mHeap, 0) JPAResourceManager(param_0, mHeap);
JUT_ASSERT(2521, mCommonResMng != NULL);
@@ -1226,6 +1227,7 @@ void dPa_control_c::createCommon(void const* param_0) {
void dPa_control_c::createRoomScene() {
mSceneHeap = mDoExt_createSolidHeapFromGame(0, 0);
JKRHEAP_NAME(mSceneHeap, "dPa_control_c::mSceneHeap");
JUT_ASSERT(2573, mSceneHeap != NULL);
mSceneResMng = new (mSceneHeap, 0) JPAResourceManager(m_sceneRes, mSceneHeap);
JUT_ASSERT(2576, mSceneResMng != NULL);
+6
View File
@@ -640,6 +640,12 @@ int dRes_info_c::setRes() {
u32 heapSize = mDataHeap->getHeapSize();
DCStoreRangeNoSync(mDataHeap->getStartAddr(), heapSize);
#if TARGET_PC
char buf[32];
snprintf(buf, sizeof(buf), "Arc %s", mArchiveName);
JKRHEAP_NAME(mDataHeap, buf);
#endif
}
return 0;
+1
View File
@@ -31,6 +31,7 @@ void imgui_main(const AuroraInfo *info)
DuskImguiDebugOverlay(info);
DuskImguiProcesses();
DuskImguiHeaps();
ImGui::EndMainMenuBar();
}
+5 -5
View File
@@ -49,7 +49,7 @@ static void ImGuiStringViewText(std::string_view text)
ImGui::TextUnformatted(text.data(), text.data() + text.size());
}
static std::string BytesToString(size_t bytes)
std::string BytesToString(size_t bytes)
{
constexpr std::array suffixes{"B"sv, "KB"sv, "MB"sv, "GB"sv, "TB"sv, "PB"sv, "EB"sv};
uint32_t s = 0;
@@ -66,20 +66,20 @@ static std::string BytesToString(size_t bytes)
return fmt::format(FMT_STRING("{:.1f}{}"), count, suffixes[s]);
}
static bool DebugOverlayActive = false;
static bool Active = false;
void DuskImguiDebugOverlay(const AuroraInfo *info) {
if (ImGui::BeginMenu(MenuView)) {
ImGui::MenuItem("Debug overlay", "F3", &DebugOverlayActive);
ImGui::MenuItem("Debug overlay", "F3", &Active);
ImGui::EndMenu();
}
if (ImGui::IsKeyPressed(ImGuiKey_F3)) {
DebugOverlayActive = !DebugOverlayActive;
Active = !Active;
}
if (!DebugOverlayActive) {
if (!Active) {
return;
}
+112
View File
@@ -0,0 +1,112 @@
#include <array>
#include "JSystem/JFramework/JFWSystem.h"
#include "JSystem/JKernel/JKRHeap.h"
#include "imgui.h"
#include "imgui.hpp"
static bool Active = false;
static void DrawTableCore();
void DuskImguiHeaps() {
if (ImGui::BeginMenu(MenuView)) {
ImGui::MenuItem("Heaps", "F4", &Active);
ImGui::EndMenu();
}
if (ImGui::IsKeyPressed(ImGuiKey_F4)) {
Active = !Active;
}
if (!Active) {
return;
}
if (ImGui::Begin("Heaps", &Active)) {
if (ImGui::BeginTable(
"heaps",
5,
ImGuiTableFlags_RowBg | ImGuiTableFlags_Resizable)) {
DrawTableCore();
ImGui::EndTable();
}
}
ImGui::End();
}
static void DrawHeap(JKRHeap* heap, int depth = 0);
static void DrawTableCore() {
ImGui::TableNextRow(ImGuiTableRowFlags_Headers);
ImGui::TableNextColumn();
ImGui::TextUnformatted("Heap name");
ImGui::TableNextColumn();
ImGui::TextUnformatted("Use%");
ImGui::TableNextColumn();
ImGui::TextUnformatted("Available");
ImGui::TableNextColumn();
ImGui::TextUnformatted("Total");
ImGui::TableNextColumn();
ImGui::TextUnformatted("Type");
DrawHeap(reinterpret_cast<JKRHeap*>(JFWSystem::rootHeap));
}
static std::array<char, 4> GetHeapType(JKRHeap* heap) {
auto type = heap->getHeapType();
return {
(char)(type >> 24 & 0xFF),
(char)(type >> 16 & 0xFF),
(char)(type >> 8 & 0xFF),
(char)(type >> 0 & 0xFF),
};
}
static const char* GetHeapName(const JKRHeap* heap) {
const auto name = heap->getName();
if (strlen(name) == 0) {
return "Unknown";
}
return name;
}
static void DrawHeap(JKRHeap* heap, const int depth) {
ImGui::TableNextRow();
ImGui::TableNextColumn();
auto indentSize = depth * 16;
if (indentSize != 0)
ImGui::Indent(indentSize);
ImGui::TextUnformatted(GetHeapName(heap));
if (indentSize != 0)
ImGui::Unindent(indentSize);
ImGui::TableNextColumn();
ImGui::ProgressBar(
1 - (f32)heap->getFreeSize() / (f32)heap->getSize(),
ImVec2(ImGui::GetContentRegionAvail().x, 0));
ImGui::TableNextColumn();
auto freeSizeString = BytesToString(heap->getFreeSize());
ImGui::TextUnformatted(freeSizeString.c_str());
ImGui::TableNextColumn();
auto totalSizeString = BytesToString(heap->getSize());
ImGui::TextUnformatted(totalSizeString.c_str());
ImGui::TableNextColumn();
auto typeString = GetHeapType(heap);
ImGui::TextUnformatted(typeString.data(), typeString.data() + 4);
const JSUTree<JKRHeap>& tree = heap->getHeapTree();
for (JSUTreeIterator iter(tree.getFirstChild()); iter != tree.getEndChild(); ++iter) {
DrawHeap(*iter, depth + 1);
}
}
+4
View File
@@ -2,10 +2,14 @@
#define DUSK_IMGUI_HPP
#include <aurora/aurora.h>
#include <string>
inline const char* MenuView = "View";
void DuskImguiDebugOverlay(const AuroraInfo *info);
void DuskImguiProcesses();
void DuskImguiHeaps();
std::string BytesToString(size_t bytes);
#endif // DUSK_IMGUI_HPP
+1 -11
View File
@@ -13,16 +13,6 @@
#include "imgui.hpp"
#include "imgui_internal.h"
static const char* getProcName(s16 id) {
for (auto procName : procNames) {
if (procName.id == id) {
return procName.name;
}
}
return nullptr;
}
bool showTreeRecursive;
static int ShowProcess(void* p, void*) {
@@ -35,7 +25,7 @@ static int ShowProcess(void* p, void*) {
ImVec2 vec = {avail.x, 0};
if (ImGui::BeginChild(buf, vec, ImGuiChildFlags_Border | ImGuiChildFlags_AutoResizeY)) {
ImGui::Text("[%d] %s", proc->id, getProcName(proc->profname));
ImGui::Text("[%d] %s", proc->id, GetProcName(proc->profname));
ImGui::Text("init_state: %d, create_phase: %d", proc->state.init_state, proc->state.create_phase);
const char* ofTypeName = "unknown";
+17
View File
@@ -3,6 +3,11 @@
* Actor Manager
*/
#if TARGET_PC
#define PROCS_DUMP_NAMES 1
#include "d/d_procname.h"
#endif
#include "d/dolzel.h" // IWYU pragma: keep
#include "JSystem/J3DGraphBase/J3DMaterial.h"
@@ -727,6 +732,18 @@ u8 var_r30 = fopAcM::HeapAdjustEntry;
#endif
fopAcM::HeapAdjustUnk = var_r31;
fopAcM::HeapAdjustEntry = var_r30;
#if TARGET_PC
char buf[32];
snprintf(
buf,
sizeof(buf),
"Actor %d (%s)",
i_actor->id,
GetProcName(i_actor->profname));
JKRHEAP_NAME(i_actor->heap, buf);
#endif
return result;
}
+7
View File
@@ -670,6 +670,7 @@ static JKRExpHeap* DbPrintHeap;
JKRExpHeap* mDoExt_createDbPrintHeap(u32 heapSize, JKRHeap* parentHeap) {
JUT_ASSERT(1693, DbPrintHeap == NULL || heapSize == 0);
DbPrintHeap = JKRExpHeap::create(heapSize, parentHeap, true);
JKRHEAP_NAME(DbPrintHeap, "DbPrintHeap");
return DbPrintHeap;
}
@@ -683,6 +684,7 @@ static intptr_t safeGameHeapSize = -1;
JKRExpHeap* mDoExt_createGameHeap(u32 heapSize, JKRHeap* parentHeap) {
JUT_ASSERT(1739, gameHeap == NULL || heapSize == 0);
gameHeap = JKRExpHeap::create(heapSize, parentHeap, true);
JKRHEAP_NAME(gameHeap, "gameHeap");
gameHeap->setAllocationMode(JKRExpHeap::ALLOC_MODE_1);
return gameHeap;
}
@@ -715,6 +717,7 @@ intptr_t safeZeldaHeapSize = -1;
JKRExpHeap* mDoExt_createZeldaHeap(u32 heapSize, JKRHeap* parentHeap) {
JUT_ASSERT(1815, zeldaHeap == NULL || heapSize == 0);
zeldaHeap = JKRExpHeap::create(heapSize, parentHeap, true);
JKRHEAP_NAME(zeldaHeap, "zeldaHeap");
return zeldaHeap;
}
@@ -748,6 +751,7 @@ intptr_t safeCommandHeapSize = -1;
JKRExpHeap* mDoExt_createCommandHeap(u32 heapSize, JKRHeap* parentHeap) {
JUT_ASSERT(1894, commandHeap == 0 || heapSize == 0);
commandHeap = JKRExpHeap::create(heapSize, parentHeap, true);
JKRHEAP_NAME(commandHeap, "commandHeap");
return commandHeap;
}
@@ -774,6 +778,7 @@ intptr_t safeArchiveHeapSize = -1;
JKRExpHeap* mDoExt_createArchiveHeap(u32 heapSize, JKRHeap* parentHeap) {
JUT_ASSERT(1966, archiveHeap == 0 || heapSize == 0);
archiveHeap = JKRExpHeap::create(heapSize, parentHeap, true);
JKRHEAP_NAME(archiveHeap, "archiveHeap");
archiveHeap->setAllocationMode(JKRExpHeap::ALLOC_MODE_1);
return archiveHeap;
}
@@ -811,6 +816,7 @@ intptr_t safeJ2dHeapSize = -1;
JKRExpHeap* mDoExt_createJ2dHeap(u32 heapSize, JKRHeap* parentHeap) {
JUT_ASSERT(2059, j2dHeap == 0 || heapSize == 0);
j2dHeap = JKRExpHeap::create(heapSize, parentHeap, true);
JKRHEAP_NAME(j2dHeap, "j2dHeap");
j2dHeap->setAllocationMode(JKRExpHeap::ALLOC_MODE_1);
return j2dHeap;
}
@@ -843,6 +849,7 @@ static JKRExpHeap* HostIOHeap;
JKRHeap* mDoExt_createHostIOHeap(u32 heapSize, JKRHeap* parentHeap) {
JUT_ASSERT(2142, HostIOHeap == 0 || heapSize == 0);
HostIOHeap = JKRExpHeap::create(heapSize, parentHeap, true);
JKRHEAP_NAME(HostIOHeap, "HostIOHeap");
return HostIOHeap;
}
+1
View File
@@ -164,6 +164,7 @@ void main01(void) {
cDyl_InitAsync();
g_mDoAud_audioHeap = JKRCreateSolidHeap(audioHeapSize, JKRGetCurrentHeap(), false);
JKRHEAP_NAME(g_mDoAud_audioHeap, "g_mDoAud_audioHeap");
if (DUSK_AUDIO_DISABLED) {
// Pretend the audio engine initialized already. This is a lie, but needed to boot.