From d669f045808a6cfe74498aff0a9428dee6c57a51 Mon Sep 17 00:00:00 2001 From: quou Date: Sun, 9 Feb 2025 14:58:14 +1100 Subject: device debugger --- c2.cpp | 4 +- editor.cpp | 177 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- editor.hpp | 2 +- 3 files changed, 177 insertions(+), 6 deletions(-) diff --git a/c2.cpp b/c2.cpp index 0beec9d..c98f5b9 100644 --- a/c2.cpp +++ b/c2.cpp @@ -711,7 +711,7 @@ struct C2 : public App { world = (World*)arena_alloc(arena, sizeof *world); world->init(arena); ui = UI::create(this, &ui_arena); - init_editor(ui, world); + init_editor(dev, ui, world); lr.init(dev, &assets); assert(per_frame != 0); vbo = upload_verts(dev); @@ -843,8 +843,8 @@ struct C2 : public App { Context& ctx = dev->get_ctx(); - ctx.debug_push("autism triangle"); ctx.submit(draw, pip, pass); + ctx.debug_push("autism triangle"); ctx.debug_pop(); pb.begin_rp(); diff --git a/editor.cpp b/editor.cpp index 32e4498..a06c4a9 100644 --- a/editor.cpp +++ b/editor.cpp @@ -12,6 +12,7 @@ extern "C" { #include "plat.h" } +#include #include struct Editor_PD : Physics_Debughook { @@ -30,13 +31,17 @@ struct Editor_PD : Physics_Debughook { ) override; }; +struct Editor_DD : Device_Debug_Hooks { +}; + static struct { Editor_Settings settings; Editor_PD physics_debughook; + Editor_DD device_debughook; UI* ui; UI::Toolbar* toolbar; - UI::Button* mat_btn, * ent_btn, * phy_btn; - UI::Modal* mat_win, * ent_win, * phy_win; + UI::Button* mat_btn, * ent_btn, * phy_btn, * dev_btn; + UI::Modal* mat_win, * ent_win, * phy_win, * dev_win; UI::Label* mat_name, * spl; UI::Slider* metalness_input; UI::Slider* roughness_input; @@ -53,9 +58,167 @@ static struct { v3f gf, gu, gr; std::vector shrinkwrap_points; std::vector projection_points; + std::vector psos; v3f projection_start, projection_end; } editor; +static int dev_win_handler(UI::Element* e, const UI::Message& m) { + (void)e; + if (m.type == UI::Message::Type::destroy) { + editor.dev_btn->enable(); + editor.dev_win = 0; + } + return 0; +} + +static void create_pso_view(UI::Element* p, const Pipeline* pso) { + auto ui = editor.ui; + auto disp_val = [&](UI::Element* parent, const char* name, const char* fmt, auto... vals) { + char buf[64]; + sprintf(buf, fmt, vals...); + ui->create_element(parent, name); + ui->create_element(parent, buf); + }; + auto disp_bool = [&](UI::Element* parent, const char* name, bool v) { + disp_val(parent, name, v? "Yes": "No"); + }; + auto disp_enum = [&](UI::Element* parent, const char* name, int v, auto... s) { + const char* arr[] = { s... }; + disp_val(parent, name, "%s", arr[v]); + }; + disp_val(p, "PSO Hash", "%llx", pso->pipeline_hash); + disp_val(p, "Descriptor Resource Hash", "%llx", pso->descriptor_resource_hash); + disp_val( + p, + "Viewport", + "%d %d %d %d", + pso->viewport[0], + pso->viewport[1], + pso->viewport[2], + pso->viewport[3] + ); + disp_val( + p, + "Scissor", + "%d %d %d %d", + pso->scissor[0], + pso->scissor[1], + pso->scissor[2], + pso->scissor[3] + ); + disp_bool(p, "Depth Test", pso->depth_test); + disp_bool(p, "Depth Write", pso->depth_write); + disp_bool(p, "Blend Enable", pso->blend_enable); + disp_enum(p, "Depth Mode", (int)pso->depth_mode, + "Less", + "Less Equal", + "Equal", + "Greater", + "Greater Equal", + "Always", + "Never" + ); + disp_enum(p, "Geometry Type", (int)pso->geo, + "Triangles", + "Lines", + "Points" + ); + auto disp_blend = [&](const char* n, int v) { + disp_enum(p, n, v, + "Zero", + "One", + "Src Colour", + "Inv_src_colour", + "Dst_colour", + "Inv_dst_colour", + "Src_alpha", + "Inv_src_alpha", + "Dst_alpha", + "Inv_dst_alpha" + ); + }; + auto disp_blend_mode = [&](const char* n, int v) { + disp_enum(p, n, v, + "Add", + "Subtract", + "Reverse Subtract", + "Min", + "Max" + ); + }; + disp_blend("Colour Blend Source", (int)pso->blend_src); + disp_blend("Colour Blend Destination", (int)pso->blend_dst); + disp_blend_mode("Colour Blend Mode", (int)pso->blend_mode); + disp_blend("Alpha Blend Source", (int)pso->blend_src_alpha); + disp_blend("Alpha Blend Destination", (int)pso->blend_dst_alpha); + disp_blend_mode("Alpha Blend Mode", (int)pso->blend_mode_alpha); + disp_val(p, "Vertex Format ID", "%d", (int)pso->vertex_format.index); + disp_val(p, "Shader ID", "%d", (int)pso->shader.index); + auto dt = ui->create_element(p, "Descriptors"); + for (int i = 0; i < pso->descriptor_count; i++) { + int rows[] = { 300, 300, 0 }; + const Descriptor& d = pso->descriptors[i]; + char buf[32]; + sprintf(buf, "%d", d.slot); + auto tree = ui->create_element(dt, buf); + auto table = ui->create_element(tree, rows); + disp_enum(table, "Type", (int)d.type, + "Texture", + "Constant Buffer" + ); + switch (d.type) { + case Descriptor::Type::texture: { + Texture_Descriptor& tex = + *(Texture_Descriptor*)d.payload; + disp_val(table, "Texture ID", "%d", (int)tex.texture.index); + disp_val(table, "Sampler ID", "%d", (int)tex.sampler.index); + } break; + case Descriptor::Type::constant_buffer: { + Constant_Buffer_Descriptor& cb = + *(Constant_Buffer_Descriptor*)d.payload; + disp_val(table, "Offset", "%d", cb.offset); + disp_val(table, "Size", "%d", cb.size); + disp_val(table, "Buffer ID", "%d", (int)cb.buffer.index); + } break; + } + tree->collapse(); + } +} + +static int dev_btn_handler(UI::Element* e, const UI::Message& m) { + (void)e; + if (m.type == UI::Message::Type::click) { + editor.dev_btn->disable(); + editor.dev_win = editor.ui->create_element( + editor.ui->root, + "Device Debugger" + ); + editor.dev_win->handler = dev_win_handler; + auto ui = editor.ui; + auto& psov = editor.psos; + auto& hook = editor.device_debughook; + auto content = ui->create_element( + editor.dev_win->contents, + "Pipeline State Objects" + ); + psov.clear(); + psov.resize(hook.query_psos(0)); + hook.query_psos(&psov[0]); + for (auto& pso : psov) { + UI::Tree* tree; + UI::Table* table; + int rows[] = { 300, 300, 0 }; + char buf[32]; + sprintf(buf, "0x%lx", pso.pipeline_hash); + tree = ui->create_element(content, buf); + table = ui->create_element(tree, rows); + create_pso_view(table, &pso); + tree->collapse(); + } + } + return 0; +} + static int mat_win_handler(UI::Element* e, const UI::Message& m) { (void)e; if (m.type == UI::Message::Type::destroy) { @@ -266,7 +429,9 @@ static int phy_btn_handler(UI::Element* e, const UI::Message& m) { return 0; } -void init_editor(UI* ui, World* world) { +void init_editor(Device* d, UI* ui, World* world) { + editor.device_debughook.dev = d; + d->hooks = &editor.device_debughook; editor.ui = ui; editor.toolbar = ui->create_element(ui->root); editor.mat_btn = ui->create_element( @@ -284,9 +449,15 @@ void init_editor(UI* ui, World* world) { "Physics Debugger" ); editor.phy_btn->handler = phy_btn_handler; + editor.dev_btn = ui->create_element( + editor.toolbar, + "Device Debugger" + ); + editor.dev_btn->handler = dev_btn_handler; editor.mat_win = 0; editor.ent_win = 0; editor.phy_win = 0; + editor.dev_win = 0; editor.debug_sat_axis = 0; editor.world = world; editor.dragging_gizmo = 0; diff --git a/editor.hpp b/editor.hpp index ba64a49..39b695f 100644 --- a/editor.hpp +++ b/editor.hpp @@ -14,7 +14,7 @@ struct Editor_Settings { bool debug_sat; }; -void init_editor(UI* ui, World* w); +void init_editor(Device* d, UI* ui, World* w); void deinit_editor(); void editor_on_select(Entity_Id e, int m); void editor_update(const App& app, const Camera& cam); -- cgit v1.2.3-54-g00ecf