From e96b78208bac8c813063bf5eaf1ba4410ed7600e Mon Sep 17 00:00:00 2001 From: Harrand Date: Sat, 16 Nov 2024 14:59:50 +0000 Subject: [PATCH] [imgui] removed imgui completely. i changed my mind --- .gitmodules | 3 - CMakeLists.txt | 5 +- demo/tz/tz_triangle_demo.cpp | 3 - include/tz/imgui.hpp | 13 -- lib/CMakeLists.txt | 12 -- lib/imgui | 1 - src/tz/gpu/rhi_vulkan.cpp | 1 - src/tz/imgui.cpp | 250 ----------------------------------- src/tz/imgui.fragment.tzsl | 17 --- src/tz/imgui.vertex.tzsl | 47 ------- src/tz/topaz.cpp | 3 - 11 files changed, 1 insertion(+), 354 deletions(-) delete mode 100644 include/tz/imgui.hpp delete mode 160000 lib/imgui delete mode 100644 src/tz/imgui.cpp delete mode 100644 src/tz/imgui.fragment.tzsl delete mode 100644 src/tz/imgui.vertex.tzsl diff --git a/.gitmodules b/.gitmodules index 2977494ee2..ecb4194338 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,6 +13,3 @@ [submodule "lib/lua"] path = lib/lua url = https://github.com/lua/lua -[submodule "lib/imgui"] - path = lib/imgui - url = https://github.com/ocornut/imgui diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e3ab7c3bf..8d963c33a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,6 @@ topaz_add_library( TARGET topaz SOURCES src/tz/topaz.cpp - src/tz/imgui.cpp src/tz/core/error.cpp src/tz/core/job.cpp src/tz/core/lua.cpp @@ -50,8 +49,6 @@ topaz_add_library( src/tz/io/image.cpp src/tz/ren/quad.cpp SHADERS - src/tz/imgui.vertex.tzsl - src/tz/imgui.fragment.tzsl src/tz/ren/quad.vertex.tzsl src/tz/ren/quad.fragment.tzsl DEFINE_PACKAGE @@ -59,7 +56,7 @@ topaz_add_library( target_include_directories(topaz PUBLIC ${PROJECT_SOURCE_DIR}/include) target_link_libraries(topaz PRIVATE VulkanMemoryAllocator concurrentqueue stb_image lua) -target_link_libraries(topaz PUBLIC textc_lib imgui) +target_link_libraries(topaz PUBLIC textc_lib) ###################### ## TOPAZ - SETTINGS ## diff --git a/demo/tz/tz_triangle_demo.cpp b/demo/tz/tz_triangle_demo.cpp index 5c1ff37889..5b253c1667 100644 --- a/demo/tz/tz_triangle_demo.cpp +++ b/demo/tz/tz_triangle_demo.cpp @@ -5,8 +5,6 @@ #include "tz/gpu/graph.hpp" #include "tz/gpu/shader.hpp" -#include "tz/imgui.hpp" - #include ImportedShaderHeader(triangle, vertex) #include ImportedShaderHeader(triangle, fragment) @@ -41,7 +39,6 @@ int tz_main() tz::gpu::graph_handle graph = tz::gpu::create_graph("Main Graph"); tz::gpu::graph_add_pass(graph, pass); - //tz::gpu::graph_add_subgraph(graph, tz::imgui_render_graph()); tz::gpu::graph_add_pass(graph, tz::gpu::present_pass); while(tz::os::window_is_open()) diff --git a/include/tz/imgui.hpp b/include/tz/imgui.hpp deleted file mode 100644 index 899e3d3359..0000000000 --- a/include/tz/imgui.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "imgui.h" -#include "tz/gpu/graph.hpp" - -namespace tz -{ - namespace detail - { - void imgui_initialise(); - void imgui_terminate(); - } - - tz::gpu::graph_handle imgui_render_graph(); -} \ No newline at end of file diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index f4e65c73aa..8712bf1336 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -38,17 +38,5 @@ add_library(lua STATIC ) target_include_directories(lua PUBLIC "${PROJECT_SOURCE_DIR}/lib/lua") -add_library(imgui STATIC - imgui/imgui.cpp - imgui/imgui_demo.cpp - imgui/imgui_draw.cpp - imgui/imgui_tables.cpp - imgui/imgui_widgets.cpp - - imgui/misc/cpp/imgui_stdlib.cpp -) -target_include_directories(imgui PUBLIC "${PROJECT_SOURCE_DIR}/lib/imgui") -target_compile_definitions(imgui PUBLIC "-DIMGUI_USER_CONFIG=\"${PROJECT_SOURCE_DIR}/lib/topaz_imgui_config.hpp\"") - add_library(stb_image INTERFACE) target_include_directories(stb_image INTERFACE stb) \ No newline at end of file diff --git a/lib/imgui b/lib/imgui deleted file mode 160000 index 8be0723fb7..0000000000 --- a/lib/imgui +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8be0723fb7a626f0fad6e70a2ad9139e442c4008 diff --git a/src/tz/gpu/rhi_vulkan.cpp b/src/tz/gpu/rhi_vulkan.cpp index 1d471c59d6..77be5b2d42 100644 --- a/src/tz/gpu/rhi_vulkan.cpp +++ b/src/tz/gpu/rhi_vulkan.cpp @@ -3337,7 +3337,6 @@ namespace tz::gpu #endif // go through timeline and record all gpu work. - // any of these may or may not try to blit (transfer) an image into our current swapchain image. for(std::size_t i = 0; i < graph.timeline.size(); i++) { const auto& entry = graph.timeline[i]; diff --git a/src/tz/imgui.cpp b/src/tz/imgui.cpp deleted file mode 100644 index 9c1e9477e8..0000000000 --- a/src/tz/imgui.cpp +++ /dev/null @@ -1,250 +0,0 @@ -#include "tz/imgui.hpp" -#include "tz/core/trs.hpp" -#include "tz/topaz.hpp" -#include "tz/core/memory.hpp" -#include "tz/core/matrix.hpp" -#include "tz/gpu/hardware.hpp" -#include "tz/gpu/resource.hpp" -#include "tz/gpu/shader.hpp" -#include "tz/gpu/pass.hpp" -#include -#include -#include - -#include ImportedShaderHeader(imgui, vertex) -#include ImportedShaderHeader(imgui, fragment) - -namespace tz -{ - namespace detail - { - struct shader_data - { - tz::m4f vp = tz::m4f::iden(); - std::uint32_t index_offset = 0; - std::uint32_t vertex_offset = 0; - std::uint32_t texture_id = 0; - }; - // imgui backend initialise. - struct render_data - { - tz::gpu::resource_handle vertex_buffer = tz::nullhand; - tz::gpu::resource_handle index_buffer = tz::nullhand; - - tz::gpu::resource_handle font_image = tz::nullhand; - tz::gpu::shader_handle shader = tz::nullhand; - - std::vector data_buffers = {}; - - std::vector passes = {}; - tz::gpu::graph_handle graph = tz::nullhand; - } render; - - void impl_write_vertices_and_indices(ImDrawData* draw); - void impl_push_pass(); - void impl_pop_pass(); - void impl_on_render(tz::gpu::graph_handle graph); - - void imgui_initialise() - { - ImGui::CreateContext(); - if(!gpu::hardware_in_use()) - { - gpu::use_hardware(gpu::find_best_hardware()); - } - - ImGuiIO& io = ImGui::GetIO(); - io.BackendPlatformName = "Topaz"; - io.BackendRendererName = "Topaz"; - - // make font texture resource. - unsigned char* fontptr; - int fontw, fonth; - io.Fonts->GetTexDataAsRGBA32(&fontptr, &fontw, &fonth); - std::span fontdata{fontptr, static_cast(fontw * fonth * 4u)}; - - // reserve initially 1024 vertices (and indices). - static_assert(sizeof(tz::gpu::index_t) == sizeof(ImDrawIdx)); - std::array initial_indices; - std::array initial_vertices; - render.vertex_buffer = tz_must(tz::gpu::create_buffer({ - .data = tz::view_bytes(initial_vertices), - .name = "ImGui Vertex Buffer", - .flags = tz::gpu::buffer_flag::dynamic_access - })); - - render.index_buffer = tz_must(tz::gpu::create_buffer({ - .data = tz::view_bytes(initial_indices), - .name = "ImGui Index Buffer", - .flags = tz::gpu::buffer_flag::dynamic_access - })); - - render.font_image = tz_must(tz::gpu::create_image - ({ - .width = static_cast(fontw), - .height = static_cast(fonth), - .data = std::as_bytes(fontdata), - .name = "ImGui Font image" - })); - - render.shader = tz_must(tz::gpu::create_graphics_shader( - ImportedShaderSource(imgui, vertex), - ImportedShaderSource(imgui, fragment) - )); - - // empty graph for now, because we dont know what imgui wants to draw until we end the frame. - render.graph = tz::gpu::create_graph("ImGui Render Graph"); - tz::gpu::graph_set_execute_callback(render.graph, impl_on_render); - } - - void imgui_terminate() - { - for(tz::gpu::pass_handle pass : render.passes) - { - tz::gpu::destroy_pass(pass); - } - tz_must(tz::gpu::destroy_resource(render.font_image)); - tz_must(tz::gpu::destroy_resource(render.index_buffer)); - tz_must(tz::gpu::destroy_resource(render.vertex_buffer)); - tz::gpu::destroy_shader(render.shader); - ImGui::DestroyContext(); - } - - // impl bits - - void impl_on_render(gpu::graph_handle graph) - { - (void)graph; - // we have a graph that could be completely wrong. - ImGui::Render(); - ImDrawData* draws = ImGui::GetDrawData(); - if(draws == nullptr) - { - return; - } - - while(std::cmp_greater(draws->CmdListsCount, render.passes.size())) - { - impl_push_pass(); - } - while(std::cmp_less(draws->CmdListsCount, render.passes.size())) - { - impl_pop_pass(); - } - impl_write_vertices_and_indices(draws); - } - - void impl_write_vertices_and_indices(ImDrawData* draw) - { - ImGuiIO io = ImGui::GetIO(); - - const auto req_idx_size = static_cast(draw->TotalIdxCount) * sizeof(ImDrawIdx); - const auto req_vtx_size = static_cast(draw->TotalVtxCount) * sizeof(ImDrawVert); - - if(tz::gpu::resource_size(render.vertex_buffer) < req_vtx_size) - { - tz::gpu::buffer_resize(render.vertex_buffer, req_vtx_size); - } - if(tz::gpu::resource_size(render.index_buffer) < req_idx_size) - { - tz::gpu::buffer_resize(render.index_buffer, req_idx_size); - } - std::size_t vtx_cursor = 0; - std::size_t idx_cursor = 0; - - std::vector new_vertices(draw->TotalVtxCount); - std::vector new_indices(draw->TotalIdxCount); - for(std::size_t i = 0; std::cmp_less(i, draw->CmdListsCount); i++) - { - const ImDrawList* cmd = draw->CmdLists[i]; - - auto data = *reinterpret_cast(tz::gpu::resource_read(render.data_buffers[i]).data()); - data.vertex_offset = vtx_cursor; - data.index_offset = idx_cursor; - data.vp = tz::matrix_ortho( - -io.DisplaySize.x * 0.5f, - io.DisplaySize.x * 0.5f, - -io.DisplaySize.y * 0.5f, - io.DisplaySize.y * 0.5f, - -0.1f, - 0.1f - ); - tz::gpu::resource_write(render.data_buffers[i], std::as_bytes(std::span(&data, 1))); - - std::copy(cmd->VtxBuffer.Data, cmd->VtxBuffer.Data + cmd->VtxBuffer.Size, new_vertices.data() + vtx_cursor); - vtx_cursor += cmd->VtxBuffer.Size; - - std::copy(cmd->IdxBuffer.Data, cmd->IdxBuffer.Data + cmd->IdxBuffer.Size, new_indices.data() + idx_cursor); - idx_cursor += cmd->IdxBuffer.Size; - - tz::gpu::pass_set_triangle_count(render.passes[i], cmd->IdxBuffer.Size / 3); - } - - tz::gpu::resource_write(render.vertex_buffer, tz::view_bytes(new_vertices)); - tz::gpu::resource_write(render.index_buffer, tz::view_bytes(new_indices)); - } - - void impl_push_pass() - { - shader_data data; - std::span span(&data, 1); - std::string data_buf_name = std::format("ImGui Data Buffer {}", render.data_buffers.size()); - render.data_buffers.push_back(tz_must(tz::gpu::create_buffer - ({ - .data = std::as_bytes(span), - .name = data_buf_name.c_str(), - .flags = tz::gpu::buffer_flag::dynamic_access, - }))); - tz::gpu::resource_handle resources[] = - { - render.vertex_buffer, - render.index_buffer, - render.data_buffers[render.passes.size()], - render.font_image - }; - - tz::gpu::resource_handle colour_targets[] = - { - tz::gpu::window_resource - }; - - std::string pass_name = std::format("ImGui Pass {}", render.passes.size()); - - render.passes.push_back(tz_must(tz::gpu::create_pass({ - .graphics = - { - .colour_targets = colour_targets, - .culling = tz::gpu::cull::none, - .flags = tz::gpu::graphics_flag::dont_clear | tz::gpu::graphics_flag::no_depth_test, - }, - .shader = render.shader, - .resources = resources, - .name = pass_name.c_str() - }))); - - auto sz = render.passes.size(); - std::vector deps; - deps.reserve(1); - if(sz >= 2) - { - deps.push_back(render.passes[sz - 2]); - } - tz::gpu::graph_add_pass(render.graph, render.passes[sz - 1], deps); - } - - void impl_pop_pass() - { - tz::gpu::destroy_resource(render.data_buffers.back()); - render.data_buffers.pop_back(); - tz::gpu::destroy_pass(render.passes.back()); - render.passes.pop_back(); - tz_error("todo: implement graph remove pass"); - } - } - - tz::gpu::graph_handle imgui_render_graph() - { - return detail::render.graph; - } - -} \ No newline at end of file diff --git a/src/tz/imgui.fragment.tzsl b/src/tz/imgui.fragment.tzsl deleted file mode 100644 index b0792940b2..0000000000 --- a/src/tz/imgui.fragment.tzsl +++ /dev/null @@ -1,17 +0,0 @@ -shader(type = fragment); - -input(id = 0) vec2 uv; -input(id = 1) vec4 col; -input(id = 2, flat) uint texid; - -output(id = 0) vec4 out::colour; - -void main() -{ - float texa = sample(texid, uv).a; - out::colour = col.rgba * texa; - if(texa < 0.1f) - { - discard; - } -} \ No newline at end of file diff --git a/src/tz/imgui.vertex.tzsl b/src/tz/imgui.vertex.tzsl deleted file mode 100644 index 5d9d2641b5..0000000000 --- a/src/tz/imgui.vertex.tzsl +++ /dev/null @@ -1,47 +0,0 @@ -shader(type = vertex); - -struct ImGuiVertex -{ - float px, py; - float uvx, uvy; - uint col; -}; - -buffer(id = 0) const vertex -{ - ImGuiVertex data[]; -}; - -buffer(id = 1) const index -{ - uint data[]; -}; - -buffer(id = 2) const render -{ - mat4 vp; - uint index_offset; - uint vertex_offset; - uint texture_id; -}; - -output(id = 0) vec2 vtx_uv; -output(id = 1) vec4 vtx_col; -output(id = 2) uint vtx_texid; - -void main() -{ - uint index = index.data[in::vertex_id + render.index_offset]; - ImGuiVertex vtx = vertex.data[index + render.vertex_offset]; - out::position = render.vp * vec4(vtx.px, vtx.py, 0.0f, 1.0f); - - vtx_uv = vec2(vtx.uvx, vtx.uvy); - - vtx_col = vec4(0.0); - vtx_col.a = ((vtx.col >> 24) & 0xFF) / 255.0f; - vtx_col.b = ((vtx.col >> 16) & 0xFF) / 255.0f; - vtx_col.g = ((vtx.col >> 8) & 0xFF) / 255.0f; - vtx_col.r = ((vtx.col) & 0xFF) / 255.0f; - - vtx_texid = render.texture_id; -} \ No newline at end of file diff --git a/src/tz/topaz.cpp b/src/tz/topaz.cpp index 8443600da8..f99b935349 100644 --- a/src/tz/topaz.cpp +++ b/src/tz/topaz.cpp @@ -1,5 +1,4 @@ #include "tz/topaz.hpp" -#include "tz/imgui.hpp" namespace tz { @@ -9,12 +8,10 @@ namespace tz detail::lua_initialise_all_threads(); os::initialise(); gpu::initialise(info); - detail::imgui_initialise(); } void terminate() { - detail::imgui_terminate(); gpu::terminate(); os::terminate(); detail::job_system_terminate();