From df87506693471686140282e79f5513dfc27a7854 Mon Sep 17 00:00:00 2001 From: quou Date: Sun, 9 Feb 2025 15:19:20 +1100 Subject: make the PSO update when psos are created or destroyed --- editor.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 12 deletions(-) (limited to 'editor.cpp') diff --git a/editor.cpp b/editor.cpp index a06c4a9..455b194 100644 --- a/editor.cpp +++ b/editor.cpp @@ -10,10 +10,30 @@ extern "C" { #include "memory.h" #include "plat.h" +#include "str.h" } #include #include +#include + +template<> +struct std::hash { + size_t operator()(const Pipeline& k) const { + return (size_t)fnv1a64_2( + k.pipeline_hash, + (uint8_t*)&k.descriptor_resource_hash, + sizeof k.descriptor_resource_hash + ); + } +}; + +static bool operator==(const Pipeline& a, const Pipeline& b) { + return + a.pipeline_eq(b) && + a.desc_layout_eq(b) && + a.desc_resources_eq(b); +} struct Editor_PD : Physics_Debughook { void shrinkwrap( @@ -32,6 +52,8 @@ struct Editor_PD : Physics_Debughook { }; struct Editor_DD : Device_Debug_Hooks { + void on_pso_create(const Pipeline& pso) override; + void on_pso_destroy(const Pipeline& pso) override; }; static struct { @@ -58,7 +80,8 @@ static struct { v3f gf, gu, gr; std::vector shrinkwrap_points; std::vector projection_points; - std::vector psos; + std::unordered_map psos; + UI::Element* pso_tree; v3f projection_start, projection_end; } editor; @@ -71,8 +94,10 @@ static int dev_win_handler(UI::Element* e, const UI::Message& m) { return 0; } -static void create_pso_view(UI::Element* p, const Pipeline* pso) { +static void init_pso_view(UI::Element* content, const Pipeline* pso) { auto ui = editor.ui; + int rows[] = { 300, 300, 0 }; + UI::Table* p = ui->create_element(content, rows); auto disp_val = [&](UI::Element* parent, const char* name, const char* fmt, auto... vals) { char buf[64]; sprintf(buf, fmt, vals...); @@ -185,6 +210,17 @@ static void create_pso_view(UI::Element* p, const Pipeline* pso) { } } +static void create_pso_view(const Pipeline& pso) { + UI::Tree* tree; + char buf[32]; + UI* ui = editor.ui; + sprintf(buf, "0x%lx", pso.pipeline_hash); + tree = ui->create_element(editor.pso_tree, buf); + init_pso_view(tree, &pso); + tree->collapse(); + editor.psos[pso] = tree; +} + static int dev_btn_handler(UI::Element* e, const UI::Message& m) { (void)e; if (m.type == UI::Message::Type::click) { @@ -195,25 +231,19 @@ static int dev_btn_handler(UI::Element* e, const UI::Message& m) { ); editor.dev_win->handler = dev_win_handler; auto ui = editor.ui; - auto& psov = editor.psos; + std::vector psov; auto& hook = editor.device_debughook; auto content = ui->create_element( editor.dev_win->contents, "Pipeline State Objects" ); + editor.pso_tree = content; psov.clear(); psov.resize(hook.query_psos(0)); hook.query_psos(&psov[0]); + editor.psos.clear(); 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(); + create_pso_view(pso); } } return 0; @@ -681,3 +711,15 @@ void Editor_PD::projection( editor.projection_end = editor.projection_start + n; } } + +void Editor_DD::on_pso_create(const Pipeline& pso) { + if (!editor.dev_win) return; + create_pso_view(pso); +} + +void Editor_DD::on_pso_destroy(const Pipeline& pso) { + if (!editor.dev_win) return; + UI::Element* t = editor.psos[pso]; + t->destroy(); + editor.psos.erase(pso); +} -- cgit v1.2.3-54-g00ecf