ImDebugger: Add a basic texture browser

This commit is contained in:
Henrik Rydgård committed 2024-11-29 19:30:38 +01:00
1 parent 27f08d705b
commit e4adc112ff
21 files changed
+152 -18

No files matched your search

+2
View File
@@ -1600,6 +1600,8 @@ void VKContext::DrawIndexedClippedBatchUP(const void *vdata, int vertexCount, co
BindTexture(0, draw.bindTexture);
} else if (draw.bindFramebufferAsTex) {
BindFramebufferAsTexture(draw.bindFramebufferAsTex, 0, FBChannel::FB_COLOR_BIT, 0);
} else if (draw.bindNativeTexture) {
BindNativeTexture(0, draw.bindNativeTexture);
}
Draw::SamplerState *sstate = draw.samplerState;
BindSamplerStates(0, 1, &sstate);
+3
View File
@@ -705,6 +705,7 @@ struct ClippedDraw {
s16 cliph;
Draw::Texture *bindTexture;
Draw::Framebuffer *bindFramebufferAsTex;
void *bindNativeTexture;
Draw::SamplerState *samplerState;
Draw::Pipeline *pipeline;
};
@@ -822,6 +823,8 @@ public:
// Data types:
// * Vulkan: VkImageView
// * D3D11: ID3D11ShaderResourceView*
// * OpenGL: GLRTexture
// * D3D9: LPDIRECT3DTEXTURE9
virtual void BindNativeTexture(int sampler, void *nativeTexture) = 0;
// Only supports a single dynamic uniform buffer, for maximum compatibility with the old APIs and ease of emulation.
+2
View File
@@ -26,6 +26,7 @@
#include "GPU/GPUInterface.h"
class FramebufferManagerCommon;
class TextureCacheCommon;
struct GPUDebugOp {
u32 pc;
@@ -223,6 +224,7 @@ public:
// TODO: Make a proper debug interface instead of accessing directly?
virtual FramebufferManagerCommon *GetFramebufferManagerCommon() = 0;
virtual TextureCacheCommon *GetTextureCacheCommon() = 0;
virtual bool GetCurrentSimpleVertices(int count, std::vector<GPUDebugVertex> &vertices, std::vector<u16> &indices) {
return false;
+65 -1
View File
@@ -38,6 +38,7 @@
#include "GPU/Common/TextureDecoder.h"
#include "GPU/Common/ShaderId.h"
#include "GPU/Common/GPUStateUtils.h"
#include "GPU/ge_constants.h"
#include "GPU/Debugger/Debugger.h"
#include "GPU/Debugger/Record.h"
#include "GPU/GPUCommon.h"
@@ -45,6 +46,10 @@
#include "GPU/GPUState.h"
#include "Core/Util/PPGeDraw.h"
#include "ext/imgui/imgui.h"
#include "ext/imgui/imgui_impl_thin3d.h"
#if defined(_M_SSE)
#include <emmintrin.h>
#endif
@@ -2473,7 +2478,7 @@ void TextureCacheCommon::ApplyTextureDepal(TexCacheEntry *entry) {
Draw::Viewport viewport{ 0.0f, 0.0f, (float)texWidth, (float)texHeight, 0.0f, 1.0f };
draw_->SetViewport(viewport);
draw_->BindNativeTexture(0, GetNativeTextureView(entry));
draw_->BindNativeTexture(0, GetNativeTextureView(entry, false));
draw_->BindFramebufferAsTexture(dynamicClutFbo_, 1, Draw::FB_COLOR_BIT, 0);
Draw::SamplerState *nearest = textureShaderCache_->GetSampler(false);
Draw::SamplerState *clutSampler = textureShaderCache_->GetSampler(false);
@@ -3056,3 +3061,62 @@ 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::GetWindowPos().x + ImGui::GetWindowContentRegionMax().x;
for (auto &iter : cache_) {
u64 id = iter.first;
void *nativeView = GetNativeTextureView(iter.second.get(), true);
int w = 128;
int h = 128;
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));
}
ImGui::EndChild();
ImGui::SameLine();
ImGui::BeginChild("right", ImVec2(0.f, 0.0f));
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", 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);
ImGui::Text("Replaced: %s", entry->replacedTexture ? "true" : "false");
ImGui::Text("Frames until next full hash: %08x", entry->framesUntilNextFullHash); // TODO: Show the flags
} else {
selectedTextureId = 0;
}
} else {
ImGui::Text("(no texture selected)");
}
ImGui::EndChild();
}
+3 -1
View File
@@ -379,8 +379,10 @@ public:
virtual void DeviceLost() = 0;
virtual void DeviceRestore(Draw::DrawContext *draw) = 0;
virtual void DrawImGuiDebug(uint64_t &selectedTextureId) const;
protected:
virtual void *GetNativeTextureView(const TexCacheEntry *entry) = 0;
virtual void *GetNativeTextureView(const TexCacheEntry *entry, bool flat) const = 0;
bool PrepareBuildTexture(BuildTexturePlan &plan, TexCacheEntry *entry);
virtual void BindTexture(TexCacheEntry *entry) = 0;
+1 -1
View File
@@ -535,7 +535,7 @@ bool TextureCacheD3D11::GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level
return true;
}
void *TextureCacheD3D11::GetNativeTextureView(const TexCacheEntry *entry) {
void *TextureCacheD3D11::GetNativeTextureView(const TexCacheEntry *entry, bool flat) const {
ID3D11ShaderResourceView *textureView = DxView(entry);
return (void *)textureView;
}
+3 -3
View File
@@ -61,7 +61,7 @@ protected:
void ReleaseTexture(TexCacheEntry *entry, bool delete_them) override;
void BindAsClutTexture(Draw::Texture *tex, bool smooth) override;
void ApplySamplingParams(const SamplerCacheKey &key) override;
void *GetNativeTextureView(const TexCacheEntry *entry) override;
void *GetNativeTextureView(const TexCacheEntry *entry, bool flat) const override;
private:
DXGI_FORMAT GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const;
@@ -72,10 +72,10 @@ private:
ID3D11Device *device_;
ID3D11DeviceContext *context_;
ID3D11Resource *&DxTex(const TexCacheEntry *entry) {
ID3D11Resource *&DxTex(const TexCacheEntry *entry) const {
return (ID3D11Resource *&)entry->texturePtr;
}
ID3D11ShaderResourceView *DxView(const TexCacheEntry *entry) {
ID3D11ShaderResourceView *DxView(const TexCacheEntry *entry) const {
return (ID3D11ShaderResourceView *)entry->textureView;
}
+1 -1
View File
@@ -436,7 +436,7 @@ bool TextureCacheDX9::GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level,
return success;
}
void *TextureCacheDX9::GetNativeTextureView(const TexCacheEntry *entry) {
void *TextureCacheDX9::GetNativeTextureView(const TexCacheEntry *entry, bool flat) const {
LPDIRECT3DBASETEXTURE9 tex = DxTex(entry);
return (void *)tex;
}
+1 -1
View File
@@ -51,7 +51,7 @@ protected:
void Unbind() override;
void ReleaseTexture(TexCacheEntry *entry, bool delete_them) override;
void BindAsClutTexture(Draw::Texture *tex, bool smooth) override;
void *GetNativeTextureView(const TexCacheEntry *entry) override;
void *GetNativeTextureView(const TexCacheEntry *entry, bool flat) const override;
private:
void ApplySamplingParams(const SamplerCacheKey &key) override;
+1 -1
View File
@@ -433,7 +433,7 @@ void TextureCacheGLES::DeviceRestore(Draw::DrawContext *draw) {
textureShaderCache_->DeviceRestore(draw);
}
void *TextureCacheGLES::GetNativeTextureView(const TexCacheEntry *entry) {
void *TextureCacheGLES::GetNativeTextureView(const TexCacheEntry *entry, bool flat) const {
GLRTexture *tex = entry->textureName;
return (void *)tex;
}
+1 -1
View File
@@ -63,7 +63,7 @@ protected:
void ReleaseTexture(TexCacheEntry *entry, bool delete_them) override;
void BindAsClutTexture(Draw::Texture *tex, bool smooth) override;
void *GetNativeTextureView(const TexCacheEntry *entry) override;
void *GetNativeTextureView(const TexCacheEntry *entry, bool flat) const override;
private:
void ApplySamplingParams(const SamplerCacheKey &key) override;
+4
View File
@@ -185,6 +185,10 @@ public:
return nullptr;
}
TextureCacheCommon *GetTextureCacheCommon() override {
return nullptr;
}
std::vector<std::string> DebugGetShaderIDs(DebugShaderType shader) override { return std::vector<std::string>(); };
std::string DebugGetShaderString(std::string id, DebugShaderType shader, DebugShaderStringType stringType) override {
return "N/A";
+3
View File
@@ -31,6 +31,9 @@ public:
FramebufferManagerCommon *GetFramebufferManagerCommon() override {
return framebufferManager_;
}
TextureCacheCommon *GetTextureCacheCommon() override {
return textureCache_;
}
// Using string because it's generic - makes no assumptions on the size of the shader IDs of this backend.
std::vector<std::string> DebugGetShaderIDs(DebugShaderType shader) override;
+2 -2
View File
@@ -867,7 +867,7 @@ std::string TextureCacheVulkan::DebugGetSamplerString(const std::string &id, Deb
return samplerCache_.DebugGetSamplerString(id, stringType);
}
void *TextureCacheVulkan::GetNativeTextureView(const TexCacheEntry *entry) {
VkImageView view = entry->vkTex->GetImageArrayView();
void *TextureCacheVulkan::GetNativeTextureView(const TexCacheEntry *entry, bool flat) const {
VkImageView view = flat ? entry->vkTex->GetImageView() : entry->vkTex->GetImageArrayView();
return (void *)view;
}
+1 -1
View File
@@ -90,7 +90,7 @@ protected:
void BindAsClutTexture(Draw::Texture *tex, bool smooth) override;
void ApplySamplingParams(const SamplerCacheKey &key) override;
void BoundFramebufferTexture() override;
void *GetNativeTextureView(const TexCacheEntry *entry) override;
void *GetNativeTextureView(const TexCacheEntry *entry, bool flat) const override;
private:
void LoadVulkanTextureLevel(TexCacheEntry &entry, uint8_t *writePtr, int rowPitch, int level, int scaleFactor, VkFormat dstFmt);
+6
View File
@@ -822,6 +822,7 @@ void ImDebugger::Frame(MIPSDebugInterface *mipsDebug, GPUDebugInterface *gpuDebu
}
if (ImGui::BeginMenu("Graphics")) {
ImGui::MenuItem("Display Output", nullptr, &cfg_.displayOpen);
ImGui::MenuItem("Textures", nullptr, &cfg_.texturesOpen);
ImGui::MenuItem("Framebuffers", nullptr, &cfg_.framebuffersOpen);
// More to come here...
ImGui::EndMenu();
@@ -902,6 +903,10 @@ void ImDebugger::Frame(MIPSDebugInterface *mipsDebug, GPUDebugInterface *gpuDebu
DrawFramebuffersWindow(cfg_, gpuDebug->GetFramebufferManagerCommon());
}
if (cfg_.texturesOpen) {
DrawTexturesWindow(cfg_, gpuDebug->GetTextureCacheCommon());
}
if (cfg_.displayOpen) {
DrawDisplayWindow(cfg_, gpuDebug->GetFramebufferManagerCommon());
}
@@ -1115,6 +1120,7 @@ void ImConfig::SyncConfig(IniFile *ini, bool save) {
sync.Sync("filesystemBrowserOpen", &filesystemBrowserOpen, false);
sync.Sync("kernelObjectsOpen", &kernelObjectsOpen, false);
sync.Sync("audioChannelsOpen", &audioChannelsOpen, false);
sync.Sync("texturesOpen", &texturesOpen, false);
sync.SetSection(ini->GetOrCreateSection("Settings"));
sync.Sync("displayLatched", &displayLatched, false);
+2
View File
@@ -71,6 +71,7 @@ struct ImConfig {
bool audioDecodersOpen;
bool structViewerOpen;
bool framebuffersOpen;
bool texturesOpen;
bool displayOpen;
bool styleEditorOpen;
bool filesystemBrowserOpen;
@@ -86,6 +87,7 @@ struct ImConfig {
int selectedFramebuffer = -1;
int selectedBreakpoint = -1;
int selectedMemCheck = -1;
uint64_t selectedTexAddr = 0;
bool displayLatched = false;
+12
View File
@@ -3,6 +3,7 @@
#include "UI/ImDebugger/ImGe.h"
#include "UI/ImDebugger/ImDebugger.h"
#include "GPU/Common/FramebufferManagerCommon.h"
#include "GPU/Common/TextureCacheCommon.h"
#include "Core/HLE/sceDisplay.h"
@@ -17,6 +18,17 @@ void DrawFramebuffersWindow(ImConfig &cfg, FramebufferManagerCommon *framebuffer
ImGui::End();
}
void DrawTexturesWindow(ImConfig &cfg, TextureCacheCommon *textureCache) {
if (!ImGui::Begin("Textures", &cfg.texturesOpen)) {
ImGui::End();
return;
}
textureCache->DrawImGuiDebug(cfg.selectedTexAddr);
ImGui::End();
}
void DrawDisplayWindow(ImConfig &cfg, FramebufferManagerCommon *framebufferManager) {
if (!ImGui::Begin("Display", &cfg.framebuffersOpen)) {
ImGui::End();
+2
View File
@@ -5,8 +5,10 @@
struct ImConfig;
class FramebufferManagerCommon;
class TextureCacheCommon;
void DrawFramebuffersWindow(ImConfig &cfg, FramebufferManagerCommon *framebufferManager);
void DrawTexturesWindow(ImConfig &cfg, TextureCacheCommon *textureCache);
void DrawDisplayWindow(ImConfig &cfg, FramebufferManagerCommon *framebufferManager);
class ImGeDebugger {
+36 -5
View File
@@ -12,9 +12,16 @@ static Lin::Matrix4x4 g_drawMatrix;
static ImFont *g_proportionalFont = nullptr;
static ImFont *g_fixedFont = nullptr;
enum class RegisteredTextureType {
Framebuffer,
Texture,
NativeTexture,
};
struct RegisteredTexture {
bool isFramebuffer;
RegisteredTextureType type;
union {
void *nativeTexture;
Draw::Texture *texture;
struct {
Draw::Framebuffer *framebuffer;
@@ -79,6 +86,7 @@ void ImGui_ImplThin3d_RenderDrawData(ImDrawData* draw_data, Draw::DrawContext *d
std::vector<Draw::ClippedDraw> draws;
Draw::Texture *boundTexture;
Draw::Framebuffer *boundFBAsTexture;
void *boundNativeTexture;
Draw::Pipeline *boundPipeline = bd->pipelines[0];
Draw::SamplerState *boundSampler = bd->fontSampler;
@@ -95,18 +103,29 @@ void ImGui_ImplThin3d_RenderDrawData(ImDrawData* draw_data, Draw::DrawContext *d
if (!pcmd->TextureId) {
// Default
boundTexture = bd->fontImage;
boundNativeTexture = nullptr;
boundFBAsTexture = nullptr;
boundPipeline = bd->pipelines[0];
boundSampler = bd->fontSampler;
} else {
size_t index = (size_t)pcmd->TextureId - TEX_ID_OFFSET;
_dbg_assert_(index < bd->tempTextures.size());
if (bd->tempTextures[index].framebuffer) {
switch (bd->tempTextures[index].type) {
case RegisteredTextureType::Framebuffer:
boundFBAsTexture = bd->tempTextures[index].framebuffer;
boundTexture = nullptr;
} else {
boundNativeTexture = nullptr;
break;
case RegisteredTextureType::Texture:
boundTexture = bd->tempTextures[index].texture;
boundFBAsTexture = nullptr;
boundNativeTexture = nullptr;
break;
case RegisteredTextureType::NativeTexture:
boundTexture = nullptr;
boundFBAsTexture = nullptr;
boundNativeTexture = bd->tempTextures[index].nativeTexture;;
break;
}
boundPipeline = bd->pipelines[(int)bd->tempTextures[index].pipeline];
boundSampler = bd->fontSampler;
@@ -128,6 +147,7 @@ void ImGui_ImplThin3d_RenderDrawData(ImDrawData* draw_data, Draw::DrawContext *d
clippedDraw.pipeline = boundPipeline;
clippedDraw.bindTexture = boundTexture;
clippedDraw.bindFramebufferAsTex = boundFBAsTexture;
clippedDraw.bindNativeTexture = boundNativeTexture;
clippedDraw.samplerState = boundSampler;
clippedDraw.clipx = clip_min.x;
clippedDraw.clipy = clip_min.y;
@@ -309,10 +329,21 @@ void ImGui_ImplThin3d_NewFrame(Draw::DrawContext *draw, Lin::Matrix4x4 drawMatri
g_drawMatrix = drawMatrix;
}
ImTextureID ImGui_ImplThin3d_AddNativeTextureTemp(void *texture, ImGuiPipeline pipeline) {
BackendData* bd = ImGui_ImplThin3d_GetBackendData();
RegisteredTexture tex{ RegisteredTextureType::NativeTexture};
tex.nativeTexture = texture;
tex.pipeline = pipeline;
bd->tempTextures.push_back(tex);
return (ImTextureID)(uint64_t)(TEX_ID_OFFSET + bd->tempTextures.size() - 1);
}
ImTextureID ImGui_ImplThin3d_AddTextureTemp(Draw::Texture *texture, ImGuiPipeline pipeline) {
BackendData* bd = ImGui_ImplThin3d_GetBackendData();
RegisteredTexture tex{ false };
RegisteredTexture tex{ RegisteredTextureType::Texture };
tex.texture = texture;
tex.pipeline = pipeline;
@@ -323,7 +354,7 @@ ImTextureID ImGui_ImplThin3d_AddTextureTemp(Draw::Texture *texture, ImGuiPipelin
ImTextureID ImGui_ImplThin3d_AddFBAsTextureTemp(Draw::Framebuffer *framebuffer, Draw::FBChannel aspect, ImGuiPipeline pipeline) {
BackendData* bd = ImGui_ImplThin3d_GetBackendData();
RegisteredTexture tex{ true };
RegisteredTexture tex{ RegisteredTextureType::Framebuffer };
tex.framebuffer = framebuffer;
tex.aspect = aspect;
tex.pipeline = pipeline;
+1
View File
@@ -49,6 +49,7 @@ enum class ImGuiPipeline {
// These register a texture for imgui drawing, but just for the current frame.
// Textures are unregistered again in RenderDrawData. This is just simpler.
IMGUI_IMPL_API ImTextureID ImGui_ImplThin3d_AddTextureTemp(Draw::Texture *texture, ImGuiPipeline pipeline = ImGuiPipeline::TexturedAlphaBlend);
IMGUI_IMPL_API ImTextureID ImGui_ImplThin3d_AddNativeTextureTemp(void *texture, ImGuiPipeline pipeline = ImGuiPipeline::TexturedAlphaBlend);
IMGUI_IMPL_API ImTextureID ImGui_ImplThin3d_AddFBAsTextureTemp(Draw::Framebuffer *framebuffer, Draw::FBChannel aspect = Draw::FB_COLOR_BIT, ImGuiPipeline pipeline = ImGuiPipeline::TexturedAlphaBlend);
void ImGui_PushFixedFont();