From f896ddae74cb64141b35529b01f484f90bdb1c80 Mon Sep 17 00:00:00 2001 From: Slendi Date: Sat, 10 Jan 2026 15:32:15 +0200 Subject: [PATCH] Add tracy Signed-off-by: Slendi --- flake.lock | 10 ++++---- flake.nix | 1 + meson.build | 62 ++++++++++++++++++++++++++++++--------------- meson_options.txt | 1 + src/Application.cpp | 13 ++++++++++ src/Util.h | 1 - 6 files changed, 62 insertions(+), 26 deletions(-) diff --git a/flake.lock b/flake.lock index c9fc10a..94b2497 100644 --- a/flake.lock +++ b/flake.lock @@ -20,12 +20,12 @@ }, "nixpkgs": { "locked": { - "lastModified": 1764517877, - "narHash": "sha256-pp3uT4hHijIC8JUK5MEqeAWmParJrgBVzHLNfJDZxg4=", - "rev": "2d293cbfa5a793b4c50d17c05ef9e385b90edf6c", - "revCount": 904649, + "lastModified": 1767892417, + "narHash": "sha256-dhhvQY67aboBk8b0/u0XB6vwHdgbROZT3fJAjyNh5Ww=", + "rev": "3497aa5c9457a9d88d71fa93a4a8368816fbeeba", + "revCount": 924538, "type": "tarball", - "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.904649%2Brev-2d293cbfa5a793b4c50d17c05ef9e385b90edf6c/019ad7f2-e8f3-79e9-ad92-dd7a45c069d3/source.tar.gz?rev=2d293cbfa5a793b4c50d17c05ef9e385b90edf6c&revCount=904649" + "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.924538%2Brev-3497aa5c9457a9d88d71fa93a4a8368816fbeeba/019ba2f6-9b41-7674-b81c-5f768968b13a/source.tar.gz?rev=3497aa5c9457a9d88d71fa93a4a8368816fbeeba&revCount=924538" }, "original": { "type": "tarball", diff --git a/flake.nix b/flake.nix index 24e482a..5f5a943 100644 --- a/flake.nix +++ b/flake.nix @@ -51,6 +51,7 @@ doxygen gtest cppcheck + tracy ] ++ buildInputs ++ nativeBuildInputs diff --git a/meson.build b/meson.build index 1fff1b6..ceed1c8 100644 --- a/meson.build +++ b/meson.build @@ -18,13 +18,13 @@ fastgltf = cmake.subproject('fastgltf', options: fastgltf_opts) cc = meson.get_compiler('cpp') -wayland_dep = dependency('wayland-server') -vulkan_dep = dependency('vulkan') -openxr_dep = dependency('openxr') -zlib_dep = dependency('zlib') -sdl3_dep = dependency('sdl3') -libinput_dep = dependency('libinput') -libudev_dep = dependency('libudev') +wayland_dep = dependency('wayland-server', include_type: 'system') +vulkan_dep = dependency('vulkan', include_type: 'system') +openxr_dep = dependency('openxr', include_type: 'system') +zlib_dep = dependency('zlib', include_type: 'system') +sdl3_dep = dependency('sdl3', include_type: 'system') +libinput_dep = dependency('libinput', include_type: 'system') +libudev_dep = dependency('libudev', include_type: 'system') imgui_src = files( 'thirdparty/imgui/imgui.cpp', 'thirdparty/imgui/imgui_draw.cpp', @@ -37,9 +37,25 @@ fastgltf_dep = fastgltf.dependency('fastgltf') vkbootstrap_dev = get_option('vkbootstrap_dev') vkbootstrap_lib = get_option('vkbootstrap_lib') +tracy_enable = get_option('tracy_enable') + +if tracy_enable and get_option('buildtype') != 'debugoptimized' + warning('Profiling builds should set --buildtype=debugoptimized') +endif + +tracy = disabler() +if tracy_enable + tracy_proj = subproject('tracy', default_options: [ + 'default_library=static', + 'warning_level=0', + 'werror=false', + ]) + tracy = tracy_proj.get_variable('tracy_dep') +endif vkbootstrap_inc = include_directories( - join_paths(vkbootstrap_dev, 'include') + join_paths(vkbootstrap_dev, 'include'), + is_system: true, ) vkbootstrap_dep = cc.find_library( @@ -78,6 +94,7 @@ add_project_arguments( '-Wno-exit-time-destructors', '-Wno-zero-as-null-pointer-constant', '-Wno-unused-macros', + '-Wno-reserved-macro-identifier', '-Wno-suggest-override', '-Wno-macro-redefined', '-DVULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE', @@ -114,6 +131,21 @@ imgui_lib = static_library('imgui', ], ) +exe_deps = [ + wayland_dep, + vulkan_dep, + openxr_dep, + vkbootstrap_dep, + zlib_dep, + sdl3_dep, + fastgltf_dep, + libinput_dep, + libudev_dep, +] +if tracy_enable + exe_deps += tracy +endif + exe = executable('vr-compositor', [ 'src/main.cpp', @@ -136,18 +168,8 @@ exe = executable('vr-compositor', 'thirdparty/smath/include' ], link_with: imgui_lib, - dependencies: [ - wayland_dep, - vulkan_dep, - openxr_dep, - vkbootstrap_dep, - zlib_dep, - sdl3_dep, - fastgltf_dep, - libinput_dep, - libudev_dep, - ], + dependencies: exe_deps, cpp_args: [ - '--embed-dir=' + join_paths(meson.project_build_root(), 'shaders') + '--embed-dir=' + join_paths(meson.project_build_root(), 'shaders'), ], ) diff --git a/meson_options.txt b/meson_options.txt index f31337e..2aa94c5 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,2 +1,3 @@ option('vkbootstrap_dev', type: 'string', description: 'vk-bootstrap dev output path') option('vkbootstrap_lib', type: 'string', description: 'vk-bootstrap lib output path') +option('tracy_enable', type: 'boolean', value: false, description: 'Enable profiling') diff --git a/src/Application.cpp b/src/Application.cpp index bf3cb95..837af72 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -30,6 +30,10 @@ #include "Util.h" #include "VulkanRenderer.h" +#if defined(TRACY_ENABLE) +# include +#endif + namespace { int open_restricted(char const *path, int flags, void * /*user_data*/) @@ -424,6 +428,9 @@ auto Application::run() -> void uint64_t last { 0 }; float fps { 0.0f }; while (m_running) { +#if defined(TRACY_ENABLE) + ZoneScopedN("Frame"); +#endif uint64_t now { SDL_GetTicks() }; uint64_t dt { now - last }; float dt_seconds { static_cast(dt) / 1000.0f }; @@ -613,6 +620,9 @@ auto Application::run() -> void ImGui::Render(); m_renderer->render([&](VulkanRenderer::GL &gl) { +#if defined(TRACY_ENABLE) + ZoneScopedN("Render"); +#endif auto view { smath::matrix_look_at( m_camera.position, m_camera.target, m_camera.up) }; auto const draw_extent = m_renderer->draw_extent(); @@ -670,6 +680,9 @@ auto Application::run() -> void gl.draw_sphere(m_camera.target, 0.01f); }); +#if defined(TRACY_ENABLE) + FrameMark; +#endif } } diff --git a/src/Util.h b/src/Util.h index 0a66496..5f02434 100644 --- a/src/Util.h +++ b/src/Util.h @@ -2,7 +2,6 @@ #include -#include #include template struct privDefer {