diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 9dac04aebf..5ff7fc33a1 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -44,10 +44,6 @@ #include "GPU/GPUState.h" #include "Core/Util/PPGeDraw.h" -#include "ext/imgui/imgui.h" -#include "ext/imgui/imgui_internal.h" -#include "ext/imgui/imgui_impl_thin3d.h" - // Videos should be updated every few frames, so we forget quickly. #define VIDEO_DECIMATE_AGE 4 @@ -3077,127 +3073,3 @@ CheckAlphaResult TextureCacheCommon::CheckCLUTAlpha(const uint8_t *pixelData, GE return CheckAlpha32((const u32 *)pixelData, w, 0xFF000000); } } - -void TextureCacheCommon::DrawImGuiDebug(uint64_t &selectedTextureId) const { - ImVec2 avail = ImGui::GetContentRegionAvail(); - auto &style = ImGui::GetStyle(); - ImGui::BeginChild("left", ImVec2(140.0f, 0.0f), ImGuiChildFlags_ResizeX); - float window_visible_x2 = ImGui::GetCursorScreenPos().x + ImGui::GetContentRegionAvail().x; - - // Global texture stats - int replacementStateCounts[(int)ReplacementState::COUNT]{}; - if (!secondCache_.empty()) { - ImGui::Text("Primary Cache"); - } - - for (auto &iter : cache_) { - u64 id = iter.first; - const TexCacheEntry *entry = iter.second.get(); - void *nativeView = GetNativeTextureView(iter.second.get(), true); - int w = 128; - int h = 128; - - if (entry->replacedTexture) { - replacementStateCounts[(int)entry->replacedTexture->State()]++; - } - - ImTextureID texId = ImGui_ImplThin3d_AddNativeTextureTemp(nativeView); - float last_button_x2 = ImGui::GetItemRectMax().x; - float next_button_x2 = last_button_x2 + style.ItemSpacing.x + w; // Expected position if next button was on same line - if (next_button_x2 < window_visible_x2) - ImGui::SameLine(); - - float x = ImGui::GetCursorPosX(); - if (ImGui::Selectable(("##Image" + std::to_string(id)).c_str(), selectedTextureId == id, 0, ImVec2(w, h))) { - selectedTextureId = id; // Update the selected index if clicked - } - - ImGui::SameLine(); - ImGui::SetCursorPosX(x + 2.0f); - ImGui::Image(texId, ImVec2(128, 128)); - } - - if (!secondCache_.empty()) { - ImGui::Text("Secondary Cache (%d): TODO", (int)secondCache_.size()); - // TODO - } - - ImGui::EndChild(); - - ImGui::SameLine(); - ImGui::BeginChild("right", ImVec2(0.f, 0.0f)); - if (ImGui::CollapsingHeader("Texture", nullptr, ImGuiTreeNodeFlags_DefaultOpen)) { - if (selectedTextureId) { - auto iter = cache_.find(selectedTextureId); - if (iter != cache_.end()) { - void *nativeView = GetNativeTextureView(iter->second.get(), true); - ImTextureID texId = ImGui_ImplThin3d_AddNativeTextureTemp(nativeView); - const TexCacheEntry *entry = iter->second.get(); - int dim = entry->dim; - int w = dimWidth(dim); - int h = dimHeight(dim); - ImGui::Image(texId, ImVec2(w, h)); - ImGui::Text("%08x: %dx%d, %d mips, %s", (uint32_t)(selectedTextureId & 0xFFFFFFFF), w, h, entry->maxLevel + 1, GeTextureFormatToString((GETextureFormat)entry->format)); - ImGui::Text("Stride: %d", entry->bufw); - ImGui::Text("Status: %08x", entry->status); // TODO: Show the flags - ImGui::Text("Hash: %08x", entry->fullhash); - ImGui::Text("CLUT Hash: %08x", entry->cluthash); - ImGui::Text("Minihash: %08x", entry->minihash); - ImGui::Text("MaxSeenV: %08x", entry->maxSeenV); - if (entry->replacedTexture) { - if (ImGui::CollapsingHeader("Replacement", ImGuiTreeNodeFlags_DefaultOpen)) { - const auto &desc = entry->replacedTexture->Desc(); - ImGui::Text("State: %s", StateString(entry->replacedTexture->State())); - // ImGui::Text("Original: %dx%d (%dx%d)", desc.w, desc.h, desc.newW, desc.newH); - if (entry->replacedTexture->State() == ReplacementState::ACTIVE) { - int w, h; - entry->replacedTexture->GetSize(0, &w, &h); - int numLevels = entry->replacedTexture->NumLevels(); - ImGui::Text("Replaced: %dx%d, %d mip levels", w, h, numLevels); - ImGui::Text("Level 0 size: %d bytes, format: %s", entry->replacedTexture->GetLevelDataSizeAfterCopy(0), Draw::DataFormatToString(entry->replacedTexture->Format())); - } - ImGui::Text("Key: %08x_%08x", (u32)(desc.cachekey >> 32), (u32)desc.cachekey); - ImGui::Text("Hashfiles: %s", desc.hashfiles.c_str()); - ImGui::Text("Base: %s", desc.basePath.c_str()); - ImGui::Text("Alpha status: %02x", entry->replacedTexture->AlphaStatus()); - } - } else { - ImGui::Text("Not replaced"); - } - ImGui::Text("Frames until next full hash: %08x", entry->framesUntilNextFullHash); // TODO: Show the flags - } else { - selectedTextureId = 0; - } - } else { - ImGui::Text("(no texture selected)"); - } - } - - if (ImGui::CollapsingHeader("Texture Cache State", nullptr, ImGuiTreeNodeFlags_DefaultOpen)) { - ImGui::Text("Cache: %d textures, size est %d", (int)cache_.size(), cacheSizeEstimate_); - if (!secondCache_.empty()) { - ImGui::Text("Second: %d textures, size est %d", (int)secondCache_.size(), secondCacheSizeEstimate_); - } - ImGui::Text("Standard/shader scale factor: %d/%d", standardScaleFactor_, shaderScaleFactor_); - ImGui::Text("Texels scaled this frame: %d", texelsScaledThisFrame_); - ImGui::Text("Low memory mode: %d", (int)lowMemoryMode_); - if (ImGui::CollapsingHeader("Texture Replacement", ImGuiTreeNodeFlags_DefaultOpen)) { - ImGui::Text("Frame time/budget: %0.3f/%0.3f ms", replacementTimeThisFrame_ * 1000.0f, replacementFrameBudgetSeconds_ * 1000.0f); - ImGui::Text("UNLOADED: %d PENDING: %d NOT_FOUND: %d ACTIVE: %d CANCEL_INIT: %d", - replacementStateCounts[(int)ReplacementState::UNLOADED], - replacementStateCounts[(int)ReplacementState::PENDING], - replacementStateCounts[(int)ReplacementState::NOT_FOUND], - replacementStateCounts[(int)ReplacementState::ACTIVE], - replacementStateCounts[(int)ReplacementState::CANCEL_INIT]); - } - if (videos_.size()) { - if (ImGui::CollapsingHeader("Tracked video playback memory")) { - for (auto &video : videos_) { - ImGui::Text("%08x: %d flips, size = %d", video.addr, video.flips, video.size); - } - } - } - } - - ImGui::EndChild(); -} diff --git a/GPU/Common/TextureCacheCommon.h b/GPU/Common/TextureCacheCommon.h index 597cecfa79..0f64d27182 100644 --- a/GPU/Common/TextureCacheCommon.h +++ b/GPU/Common/TextureCacheCommon.h @@ -384,9 +384,25 @@ public: virtual void DeviceLost() = 0; virtual void DeviceRestore(Draw::DrawContext *draw) = 0; - virtual void DrawImGuiDebug(uint64_t &selectedTextureId) const; - + // Accessors for the debugger. virtual void *GetNativeTextureView(const TexCacheEntry *entry, bool flat) const = 0; + + const TexCache &Cache() const { return cache_; } + const TexCache &SecondCache() const { return secondCache_; } + + const size_t CacheSizeEstimate() const { return cacheSizeEstimate_; } + const size_t SecondCacheSizeEstimate() const { return secondCacheSizeEstimate_; } + + struct VideoInfo { + u32 addr; + u32 size; + int flips; + }; + + const std::vector &Videos() const { + return videos_; + } + protected: bool PrepareBuildTexture(BuildTexturePlan &plan, TexCacheEntry *entry); @@ -505,11 +521,6 @@ protected: TexCache secondCache_; u32 secondCacheSizeEstimate_ = 0; - struct VideoInfo { - u32 addr; - u32 size; - int flips; - }; std::vector videos_; AlignedVector tmpTexBuf32_; diff --git a/UI/ImDebugger/ImGe.cpp b/UI/ImDebugger/ImGe.cpp index 89d0c256fe..a6c999ec82 100644 --- a/UI/ImDebugger/ImGe.cpp +++ b/UI/ImDebugger/ImGe.cpp @@ -27,13 +27,13 @@ void DrawFramebuffersWindow(ImConfig &cfg, FramebufferManagerCommon *framebuffer return; } - if (framebufferManager) { - framebufferManager->DrawImGuiDebug(cfg.selectedFramebuffer); - } else { - // Although technically, we could track them... + if (!framebufferManager) { ImGui::TextUnformatted("(Framebuffers not available in software mode)"); + ImGui::End(); + return; } + framebufferManager->DrawImGuiDebug(cfg.selectedFramebuffer); ImGui::End(); } @@ -44,12 +44,135 @@ void DrawTexturesWindow(ImConfig &cfg, TextureCacheCommon *textureCache) { return; } - if (textureCache) { - textureCache->DrawImGuiDebug(cfg.selectedTexAddr); - } else { + if (!textureCache) { ImGui::TextUnformatted("Texture cache not available"); + ImGui::End(); + return; } + ImVec2 avail = ImGui::GetContentRegionAvail(); + auto &style = ImGui::GetStyle(); + ImGui::BeginChild("left", ImVec2(140.0f, 0.0f), ImGuiChildFlags_ResizeX); + float window_visible_x2 = ImGui::GetCursorScreenPos().x + ImGui::GetContentRegionAvail().x; + + // Global texture stats + int replacementStateCounts[(int)ReplacementState::COUNT]{}; + if (!textureCache->SecondCache().empty()) { + ImGui::Text("Primary Cache"); + } + + for (auto &iter : textureCache->Cache()) { + u64 id = iter.first; + const TexCacheEntry *entry = iter.second.get(); + void *nativeView = textureCache->GetNativeTextureView(iter.second.get(), true); + int w = 128; + int h = 128; + + if (entry->replacedTexture) { + replacementStateCounts[(int)entry->replacedTexture->State()]++; + } + + ImTextureID texId = ImGui_ImplThin3d_AddNativeTextureTemp(nativeView); + float last_button_x2 = ImGui::GetItemRectMax().x; + float next_button_x2 = last_button_x2 + style.ItemSpacing.x + w; // Expected position if next button was on same line + if (next_button_x2 < window_visible_x2) + ImGui::SameLine(); + + float x = ImGui::GetCursorPosX(); + if (ImGui::Selectable(("##Image" + std::to_string(id)).c_str(), cfg.selectedTexAddr == id, 0, ImVec2(w, h))) { + cfg.selectedTexAddr = id; // Update the selected index if clicked + } + + ImGui::SameLine(); + ImGui::SetCursorPosX(x + 2.0f); + ImGui::Image(texId, ImVec2(128, 128)); + } + + if (!textureCache->SecondCache().empty()) { + ImGui::Text("Secondary Cache (%d): TODO", (int)textureCache->SecondCache().size()); + // TODO + } + + ImGui::EndChild(); + + ImGui::SameLine(); + ImGui::BeginChild("right", ImVec2(0.f, 0.0f)); + if (ImGui::CollapsingHeader("Texture", nullptr, ImGuiTreeNodeFlags_DefaultOpen)) { + if (cfg.selectedTexAddr) { + auto iter = textureCache->Cache().find(cfg.selectedTexAddr); + if (iter != textureCache->Cache().end()) { + void *nativeView = textureCache->GetNativeTextureView(iter->second.get(), true); + ImTextureID texId = ImGui_ImplThin3d_AddNativeTextureTemp(nativeView); + const TexCacheEntry *entry = iter->second.get(); + int dim = entry->dim; + int w = dimWidth(dim); + int h = dimHeight(dim); + ImGui::Image(texId, ImVec2(w, h)); + ImGui::Text("%08x: %dx%d, %d mips, %s", (uint32_t)(cfg.selectedTexAddr & 0xFFFFFFFF), w, h, entry->maxLevel + 1, GeTextureFormatToString((GETextureFormat)entry->format)); + ImGui::Text("Stride: %d", entry->bufw); + ImGui::Text("Status: %08x", entry->status); // TODO: Show the flags + ImGui::Text("Hash: %08x", entry->fullhash); + ImGui::Text("CLUT Hash: %08x", entry->cluthash); + ImGui::Text("Minihash: %08x", entry->minihash); + ImGui::Text("MaxSeenV: %08x", entry->maxSeenV); + if (entry->replacedTexture) { + if (ImGui::CollapsingHeader("Replacement", ImGuiTreeNodeFlags_DefaultOpen)) { + const auto &desc = entry->replacedTexture->Desc(); + ImGui::Text("State: %s", StateString(entry->replacedTexture->State())); + // ImGui::Text("Original: %dx%d (%dx%d)", desc.w, desc.h, desc.newW, desc.newH); + if (entry->replacedTexture->State() == ReplacementState::ACTIVE) { + int w, h; + entry->replacedTexture->GetSize(0, &w, &h); + int numLevels = entry->replacedTexture->NumLevels(); + ImGui::Text("Replaced: %dx%d, %d mip levels", w, h, numLevels); + ImGui::Text("Level 0 size: %d bytes, format: %s", entry->replacedTexture->GetLevelDataSizeAfterCopy(0), Draw::DataFormatToString(entry->replacedTexture->Format())); + } + ImGui::Text("Key: %08x_%08x", (u32)(desc.cachekey >> 32), (u32)desc.cachekey); + ImGui::Text("Hashfiles: %s", desc.hashfiles.c_str()); + ImGui::Text("Base: %s", desc.basePath.c_str()); + ImGui::Text("Alpha status: %02x", entry->replacedTexture->AlphaStatus()); + } + } else { + ImGui::Text("Not replaced"); + } + ImGui::Text("Frames until next full hash: %08x", entry->framesUntilNextFullHash); // TODO: Show the flags + } else { + cfg.selectedTexAddr = 0; + } + } else { + ImGui::Text("(no texture selected)"); + } + } + + if (ImGui::CollapsingHeader("Texture Cache State", nullptr, ImGuiTreeNodeFlags_DefaultOpen)) { + ImGui::Text("Cache: %d textures, size est %d", (int)textureCache->Cache().size(), textureCache->CacheSizeEstimate()); + if (!textureCache->SecondCache().empty()) { + ImGui::Text("Second: %d textures, size est %d", (int)textureCache->SecondCache().size(), textureCache->SecondCacheSizeEstimate()); + } + /* + ImGui::Text("Standard/shader scale factor: %d/%d", standardScaleFactor_, shaderScaleFactor_); + ImGui::Text("Texels scaled this frame: %d", texelsScaledThisFrame_); + ImGui::Text("Low memory mode: %d", (int)lowMemoryMode_); + */ + if (ImGui::CollapsingHeader("Texture Replacement", ImGuiTreeNodeFlags_DefaultOpen)) { + // ImGui::Text("Frame time/budget: %0.3f/%0.3f ms", replacementTimeThisFrame_ * 1000.0f, replacementFrameBudgetSeconds_ * 1000.0f); + ImGui::Text("UNLOADED: %d PENDING: %d NOT_FOUND: %d ACTIVE: %d CANCEL_INIT: %d", + replacementStateCounts[(int)ReplacementState::UNLOADED], + replacementStateCounts[(int)ReplacementState::PENDING], + replacementStateCounts[(int)ReplacementState::NOT_FOUND], + replacementStateCounts[(int)ReplacementState::ACTIVE], + replacementStateCounts[(int)ReplacementState::CANCEL_INIT]); + } + if (textureCache->Videos().size()) { + if (ImGui::CollapsingHeader("Tracked video playback memory")) { + for (auto &video : textureCache->Videos()) { + ImGui::Text("%08x: %d flips, size = %d", video.addr, video.flips, video.size); + } + } + } + } + + ImGui::EndChild(); ImGui::End(); }