From d7f0cb2d5e8e323438aca197ff0b8f4659115ed3 Mon Sep 17 00:00:00 2001 From: jacob Date: Tue, 1 Jul 2025 17:08:32 -0500 Subject: [PATCH] move tracy src file compilation from build system to src file --- build.c | 22 ++++------------------ src/prof_tracy.cpp | 8 ++++++++ src/prof_tracy.h | 25 ++++++++++++++++--------- src/sys_win32.c | 3 ++- 4 files changed, 30 insertions(+), 28 deletions(-) create mode 100644 src/prof_tracy.cpp diff --git a/build.c b/build.c index 9959084b..9ccf87c5 100644 --- a/build.c +++ b/build.c @@ -328,8 +328,8 @@ void OnBuild(StringList cli_args) String tracy_env_var_name = Lit("TRACY_SRC_PATH"); String tracy_src_dir_path = OS_GetEnvVar(&perm, tracy_env_var_name); - String tracy_public_dir_path = StringF(&perm, Lit("%F%F"), FmtStr(tracy_src_dir_path), FmtStr(Lit("/public"))); - String tracy_include_path = StringF(&perm, Lit("%F%F"), FmtStr(tracy_public_dir_path), FmtStr(Lit("/tracy/TracyC.h"))); + String tracy_client_header_path = OS_GetAbsPath(&perm, StringF(&perm, Lit("%F%F"), FmtStr(tracy_src_dir_path), FmtStr(Lit("/public/tracy/TracyC.h")))); + String tracy_client_src_path = OS_GetAbsPath(&perm, StringF(&perm, Lit("%F%F"), FmtStr(tracy_src_dir_path), FmtStr(Lit("/public/TracyClient.cpp")))); { typedef enum ArgState { ArgState_None, @@ -589,13 +589,8 @@ void OnBuild(StringList cli_args) Error(StringF(&perm, Lit("Profiling is enabled but tracy directory \"%F\" does not exist (set by environment variable \"%F\")"), FmtStr(tracy_src_dir_path), FmtStr(tracy_env_var_name))); OS_Exit(1); } - StringListAppend(&perm, &compile_args, StringF(&perm, Lit("-DTRACY_INCLUDE_PATH=\"%F\""), FmtStr(tracy_include_path))); - - /* Disable compiler warnings when compiling tracy client */ - compile_warnings = (StringList) { 0 }; - link_warnings = (StringList) { 0 }; - StringListAppend(&perm, &compile_warnings, Lit("-Wno-everything")); - StringListAppend(&perm, &link_warnings, Lit("-Wno-everything")); + StringListAppend(&perm, &compile_args, StringF(&perm, Lit("-DTRACY_CLIENT_HEADER_PATH=\\\"%F\\\""), FmtStr(tracy_client_header_path))); + StringListAppend(&perm, &compile_args, StringF(&perm, Lit("-DTRACY_CLIENT_SRC_PATH=\\\"%F\\\""), FmtStr(tracy_client_src_path))); } if (!arg_msvc) { @@ -829,14 +824,6 @@ void OnBuild(StringList cli_args) D_Tag src_dir = D_TagFromPath(&perm, Lit("src"), D_TagKind_Dir); D_TagList src_files = D_GetDirContents(&perm, src_dir, false); - if (arg_profiling) { - D_Tag tracy_src_dir = D_TagFromPath(&perm, tracy_public_dir_path, D_TagKind_Dir); - D_TagList tracy_src_files = D_GetDirContents(&perm, tracy_src_dir, true); - for (D_TagListNode *n = tracy_src_files.first; n; n = n->next) { - D_TagListAppend(&perm, &src_files, n->tag); - } - } - for (D_TagListNode *n = src_files.first; n; n = n->next) { Bool ignore = true; @@ -857,7 +844,6 @@ void OnBuild(StringList cli_args) if (PlatformWindows) { ignore = !(StringEqual(name, Lit("sys_win32.c")) || StringEqual(name, Lit("sock_win32.c")) || - StringEqual(name, Lit("gp_dx11.c")) || StringEqual(name, Lit("gp_dx12.c")) || StringEqual(name, Lit("playback_wasapi.c")) || StringEqual(name, Lit("mp3_mmf.c")) || diff --git a/src/prof_tracy.cpp b/src/prof_tracy.cpp new file mode 100644 index 00000000..cf4a6a41 --- /dev/null +++ b/src/prof_tracy.cpp @@ -0,0 +1,8 @@ +#if PROFILING + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Weverything" +# include TRACY_CLIENT_SRC_PATH +#pragma clang diagnostic pop + +#endif diff --git a/src/prof_tracy.h b/src/prof_tracy.h index 59f27871..3d7490de 100644 --- a/src/prof_tracy.h +++ b/src/prof_tracy.h @@ -13,22 +13,29 @@ #define PROFILING_D3D 1 #define PROFILING_CMD_WSTR L"tracy-profiler.exe -a 127.0.0.1" -/* Include tracy client */ +/* Tracy defines */ #define TRACY_ENABLE #if !PROFILING_SYSTEM_TRACE # define TRACY_NO_CALLSTACK # define TRACY_NO_SYSTEM_TRACING #endif -#include STRINGIZE(TRACY_INCLUDE_PATH) + +/* Include tracy client */ +#pragma clang diagnostic ignored "-Wshadow" +#pragma clang diagnostic ignored "-Wextra-semi" +#pragma clang diagnostic ignored "-Wextra-semi-stmt" +#pragma clang diagnostic ignored "-Wpointer-sign" +#pragma clang diagnostic ignored "-Wincompatible-pointer-types-discards-qualifiers" +#include TRACY_CLIENT_HEADER_PATH /* Clang/GCC cleanup macros */ -#define __prof static const struct ___tracy_source_location_data CAT(__tracy_source_location,__LINE__) = { NULL, __func__, __FILE__, (uint32_t)__LINE__, 0 }; __attribute((cleanup(__prof_zone_cleanup_func))) TracyCZoneCtx __tracy_zone_ctx = ___tracy_emit_zone_begin( &CAT(__tracy_source_location,__LINE__), true ); -#define __profscope(name) static const struct ___tracy_source_location_data CAT(__tracy_source_location,__LINE__) = { #name, __func__, __FILE__, (uint32_t)__LINE__, 0 }; __attribute((cleanup(__prof_zone_cleanup_func))) TracyCZoneCtx __tracy_zone_ctx = ___tracy_emit_zone_begin( &CAT(__tracy_source_location,__LINE__), true ); -INLINE void __prof_zone_cleanup_func(TracyCZoneCtx *ctx) { TracyCZoneEnd(*ctx); } +#define __prof static const struct ___tracy_source_location_data CAT(__tracy_source_location,__LINE__) = { NULL, __func__, __FILE__, (uint32_t)__LINE__, 0 }; __attribute((cleanup(__prof_zone_cleanup_func))) TracyCZoneCtx __tracy_zone_ctx = ___tracy_emit_zone_begin( &CAT(__tracy_source_location,__LINE__), true ) +#define __profscope(name) static const struct ___tracy_source_location_data CAT(__tracy_source_location,__LINE__) = { #name, __func__, __FILE__, (uint32_t)__LINE__, 0 }; __attribute((cleanup(__prof_zone_cleanup_func))) TracyCZoneCtx __tracy_zone_ctx = ___tracy_emit_zone_begin( &CAT(__tracy_source_location,__LINE__), true ) +INLINE void __prof_zone_cleanup_func(TracyCZoneCtx *ctx) { TracyCZoneEnd(*ctx) } #define __profalloc(ptr, size) TracyCAlloc((ptr), (size)) #define __proffree(ptr) TracyCFree((ptr)) -#define __profmsg(txt, len, col) TracyCMessageC((txt), (len), BGR32(col)); +#define __profmsg(txt, len, col) TracyCMessageC((txt), (len), BGR32(col)) #define __profframe(name) TracyCFrameMarkNamed((name)) #define __profthread(name) TracyCSetThreadName((name)) @@ -95,14 +102,14 @@ enum __prof_plot_type { #if PROFILING_D3D /* Dx11 */ INLINE void __prof_dx11_zone_cleanup_func(TracyCD3D11ZoneCtx *ctx) { ___tracy_d3d11_emit_zone_end(*ctx); } -# define __profscope_dx11(dx11_ctx, name, color) static const struct ___tracy_source_location_data CAT(__tracy_gpu_d3d11_source_location,__LINE__) = { #name, __func__, __FILE__, (uint32_t)__LINE__, BGR32(color) }; __attribute((cleanup(__prof_dx11_zone_cleanup_func))) TracyCD3D11ZoneCtx __tracy_d3d11_zone_ctx; ___tracy_d3d11_emit_zone_begin( dx11_ctx, &__tracy_d3d11_zone_ctx, &CAT(__tracy_gpu_d3d11_source_location,__LINE__), true); +# define __profscope_dx11(dx11_ctx, name, color) static const struct ___tracy_source_location_data CAT(__tracy_gpu_d3d11_source_location,__LINE__) = { #name, __func__, __FILE__, (uint32_t)__LINE__, BGR32(color) }; __attribute((cleanup(__prof_dx11_zone_cleanup_func))) TracyCD3D11ZoneCtx __tracy_d3d11_zone_ctx; ___tracy_d3d11_emit_zone_begin( dx11_ctx, &__tracy_d3d11_zone_ctx, &CAT(__tracy_gpu_d3d11_source_location,__LINE__), true) # define __prof_dx11_ctx(name) struct TracyCD3D11Ctx *name # define __prof_dx11_ctx_alloc(ctx, device, device_ctx, name, name_len) ctx = ___tracy_d3d11_context_announce(device, device_ctx, name, name_len) # define __prof_dx11_ctx_release(ctx) ___tracy_d3d11_context_terminate(ctx) # define __prof_dx11_collect(ctx) ___tracy_d3d11_context_collect(ctx) /* Dx12 */ INLINE void __prof_dx12_zone_cleanup_func(TracyCD3D12ZoneCtx *ctx) { ___tracy_d3d12_emit_zone_end(*ctx); } -# define __profscope_dx12(dx12_ctx, cmd_list, name, color) static const struct ___tracy_source_location_data CAT(__tracy_gpu_d3d12_source_location,__LINE__) = { #name, __func__, __FILE__, (uint32_t)__LINE__, BGR32(color) }; __attribute((cleanup(__prof_dx12_zone_cleanup_func))) TracyCD3D12ZoneCtx __tracy_d3d12_zone_ctx; ___tracy_d3d12_emit_zone_begin( dx12_ctx, cmd_list, &__tracy_d3d12_zone_ctx, &CAT(__tracy_gpu_d3d12_source_location,__LINE__), true); +# define __profscope_dx12(dx12_ctx, cmd_list, name, color) static const struct ___tracy_source_location_data CAT(__tracy_gpu_d3d12_source_location,__LINE__) = { #name, __func__, __FILE__, (uint32_t)__LINE__, BGR32(color) }; __attribute((cleanup(__prof_dx12_zone_cleanup_func))) TracyCD3D12ZoneCtx __tracy_d3d12_zone_ctx; ___tracy_d3d12_emit_zone_begin( dx12_ctx, cmd_list, &__tracy_d3d12_zone_ctx, &CAT(__tracy_gpu_d3d12_source_location,__LINE__), true) # define __prof_dx12_ctx(name) struct TracyCD3D12Ctx *name # define __prof_dx12_ctx_alloc(ctx, device, queue, name, name_len) ctx = ___tracy_d3d12_context_announce(device, queue, name, name_len) # define __prof_dx12_ctx_release(ctx) ___tracy_d3d12_context_terminate(ctx) @@ -121,7 +128,7 @@ INLINE void __prof_dx12_zone_cleanup_func(TracyCD3D12ZoneCtx *ctx) { ___tracy_d3 #endif /* PROFILING_D3D */ #if PROFILING_CAPTURE_FRAME_IMAGE -# define __profframeimage(image, width, height, offset, flipped) TracyCFrameImage((image), (width), (height), (offset), (flipped)); +# define __profframeimage(image, width, height, offset, flipped) TracyCFrameImage((image), (width), (height), (offset), (flipped)) #else # define __profframeimage(image, width, height, offset, flipped) #endif /* PROFILING_CAPTURE_FRAME_IMAGE */ diff --git a/src/sys_win32.c b/src/sys_win32.c index 4bf22dbb..3ed4a506 100644 --- a/src/sys_win32.c +++ b/src/sys_win32.c @@ -2549,7 +2549,8 @@ int CALLBACK wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev_instance, /* Launch profiler */ if (!__prof_is_connected()) { __profscope(Launch profiler); - STARTUPINFO si = { sizeof(si) }; + STARTUPINFO si = ZI; + si.cb = sizeof(si); PROCESS_INFORMATION pi = ZI; wchar_t cmd[sizeof(PROFILING_CMD_WSTR)] = ZI; MEMCPY(cmd, PROFILING_CMD_WSTR, sizeof(PROFILING_CMD_WSTR));