diff --git a/BUILD.md b/BUILD.md index 96ee6a7967..525e2ea822 100644 --- a/BUILD.md +++ b/BUILD.md @@ -170,7 +170,7 @@ Defined in [`source/CMakeLists.txt`](source/CMakeLists.txt). Pass via `-D= | `BUILD_STEAMLIB` | OFF* | Build the Steamworks integration module | | `BUILD_UNIT_TEST` | OFF | Build cmocka/utest-based unit tests | | `GAME_MODULES_ONLY` | OFF | Build only `cgame`/`game`/`ui` modules | -| `USE_GRAPHICS_NRI` | OFF* | Use the NVIDIA NRI renderer (Vulkan/D3D) | +| `USE_GRAPHICS_NRI` | OFF* | Use the RI renderer (Vulkan) | | `USE_CRASHPAD` | OFF* | Enable Crashpad crash reporting | | `USE_GRAPHICS_X11` | ON | (Linux) X11 backend | | `USE_GRAPHICS_WAYLAND`| ON | (Linux) Wayland backend | @@ -181,5 +181,5 @@ Defined in [`source/CMakeLists.txt`](source/CMakeLists.txt). Pass via `-D= | `USE_SYSTEM_FREETYPE` | OFF* | Use system FreeType | | `USE_SYSTEM_OGG` | OFF | Use system Ogg | | `USE_SYSTEM_VORBIS` | OFF | Use system Vorbis | - +| `TRACY_ENABLE` | OFF | Compile in Tracy profiling instrumentation | \* The workflow presets override several of these defaults — check [`source/CMakePresets.json`](source/CMakePresets.json). diff --git a/PROFILING.md b/PROFILING.md new file mode 100644 index 0000000000..3904f7321b --- /dev/null +++ b/PROFILING.md @@ -0,0 +1,107 @@ +# Profiling Warfork with Tracy + +The codebase ships with [Tracy](https://github.com/wolfpld/tracy) zones across the per-frame hot paths. This guide walks through building a profiler-enabled game, building the Tracy GUI client, and connecting them. + +Tracy is vendored at version **0.11.2** in [`source/extern/tracy/`](source/extern/tracy/) — you do not need to install it system-wide. + +## How it works + +- The game runtime links `TracyClient` and emits zone events when `TRACY_ENABLE` is defined at compile time. +- The Tracy profiler (a separate GUI app) connects to the running game over TCP and visualizes the timeline. +- When `TRACY_ENABLE` is **off** (the default), every Tracy macro expands to nothing — there is zero runtime cost, so non-profiled release builds are unaffected. + +## 1. Build the game with Tracy enabled + +Pass `-DTRACY_ENABLE=ON` through the platform wrapper: + +```bash +# Linux +./build-linux.sh release -- -DTRACY_ENABLE=ON + +# macOS +./build-macos.sh release -- -DTRACY_ENABLE=ON + +# Windows (Developer PowerShell for VS 2022) +.\build-windows.ps1 release -- -DTRACY_ENABLE=ON +``` + +> **Tip**: Profile a `RelWithDebInfo` build (the default for the workflow presets) rather than `Debug` — debug builds spend most of their time in unoptimized code, which makes the timeline dominated by overhead rather than the work you care about. + +When the executable starts, it will listen on TCP port **8086** for an incoming Tracy connection. + +## 2. Build the Tracy profiler GUI + +The GUI is a separate application that lives in [`source/extern/tracy/profiler/`](source/extern/tracy/profiler/). Build it once and reuse the binary across captures. + +### Linux + +System packages required (Debian/Ubuntu shown — the names map directly on Fedora/Arch): + +```bash +sudo apt install build-essential cmake git pkg-config \ + libcapstone-dev libtbb-dev libfreetype-dev libdbus-1-dev \ + libwayland-dev libxkbcommon-dev wayland-protocols +``` + +Build: + +```bash +cd source/extern/tracy/profiler +cmake -B build -DCMAKE_BUILD_TYPE=Release +cmake --build build -j"$(nproc)" +``` + +The binary lands at `source/extern/tracy/profiler/build/tracy-profiler`. + +If you're on a system without Wayland (e.g. an older X11-only setup), pass `-DLEGACY=ON` to fall back to the X11 backend: + +```bash +cmake -B build -DCMAKE_BUILD_TYPE=Release -DLEGACY=ON +``` + +### macOS + +```bash +brew install cmake capstone freetype tbb glfw +cd source/extern/tracy/profiler +cmake -B build -DCMAKE_BUILD_TYPE=Release +cmake --build build -j +``` + +The binary lands at `source/extern/tracy/profiler/build/tracy-profiler`. + +### Windows + +From a *Developer PowerShell for VS 2022*: + +```powershell +cd source\extern\tracy\profiler +cmake -B build -G "Visual Studio 17 2022" -A x64 +cmake --build build --config Release +``` + +The binary lands at `source\extern\tracy\profiler\build\Release\tracy-profiler.exe`. Dependencies (capstone, freetype, glfw, etc.) are fetched automatically via CPM during configure — no manual setup needed. + +### Prebuilt option + +If you don't want to build the GUI yourself, the upstream project publishes prebuilt Windows binaries on its [releases page](https://github.com/wolfpld/tracy/releases). Make sure the download matches the vendored version (**0.11.2**) — the wire protocol is not stable across major versions. + +## 3. Connect and capture + +1. Launch the Tracy profiler GUI (`tracy-profiler` / `tracy-profiler.exe`). +2. In the connection dialog, leave the address as `127.0.0.1` (or enter the game's IP if profiling remotely) and click **Connect**. +3. Start the game (`warfork`, `wf_server`, or `wftv_server`). The profiler attaches automatically and the timeline begins streaming. +4. Play through the scenario you want to profile. +5. Disconnect or close the game — the GUI keeps the capture loaded and offers **File → Save** to write a `.tracy` file for later analysis. + +For headless / CI captures, the `tracy-capture` tool in [`source/extern/tracy/capture/`](source/extern/tracy/capture/) records to a file without a GUI: + +```bash +cd source/extern/tracy/capture +cmake -B build -DCMAKE_BUILD_TYPE=Release +cmake --build build -j +./build/tracy-capture -o my-session.tracy +``` + +Run that *before* starting the game; it will wait for an instrumented client to connect, record until you hit Ctrl+C, then write the capture. + diff --git a/source/client/cl_input.c b/source/client/cl_input.c index 239a8f3e19..98989b7334 100644 --- a/source/client/cl_input.c +++ b/source/client/cl_input.c @@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // cl.input.c -- builds an intended movement command to send to the server #include "client.h" +#include "tracy/TracyC.h" cvar_t *cl_ucmdMaxResend; @@ -901,6 +902,7 @@ void CL_ShutdownInput( void ) */ void CL_UserInputFrame( void ) { + TracyCZoneN( ctx, "CL_UserInputFrame", 1 ); // let the mouse activate or deactivate IN_Frame(); @@ -912,6 +914,7 @@ void CL_UserInputFrame( void ) // process console commands Cbuf_Execute(); + TracyCZoneEnd( ctx ); } /* diff --git a/source/client/cl_main.c b/source/client/cl_main.c index 4db71812e0..4b142b2c4f 100644 --- a/source/client/cl_main.c +++ b/source/client/cl_main.c @@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../qcommon/asyncstream.h" #include "../qalgo/hash.h" #include "../steamshim/src/parent/parent.h" +#include "tracy/TracyC.h" #include cvar_t *cl_stereo_separation; @@ -1456,6 +1457,7 @@ void CL_ReadPackets( void ) int socketind, ret; socket_t *socket; netadr_t address; + TracyCZoneN( ctx, "CL_ReadPackets", 1 ); socket_t* sockets [] = { @@ -1540,6 +1542,7 @@ void CL_ReadPackets( void ) } if( cls.demo.playing ) { + TracyCZoneEnd( ctx ); return; } @@ -1556,12 +1559,15 @@ void CL_ReadPackets( void ) { Com_Printf( "\nServer connection timed out.\n" ); CL_Disconnect( "Connection timed out" ); + TracyCZoneEnd( ctx ); return; } } } else cl.timeoutcount = 0; + + TracyCZoneEnd( ctx ); } //============================================================================= @@ -2756,6 +2762,8 @@ static void CL_SendVoiceData() { */ static void CL_NetFrame( int realmsec, int gamemsec ) { + TracyCZoneN( ctx, "CL_NetFrame", 1 ); + // read packets from server if( realmsec > 5000 ) // if in the debugger last frame, don't timeout cls.lastPacketReceivedTime = cls.realtime; @@ -2776,6 +2784,8 @@ static void CL_NetFrame( int realmsec, int gamemsec ) CL_CheckDownloadTimeout(); CL_ServerListFrame(); + + TracyCZoneEnd( ctx ); } /* @@ -2791,6 +2801,8 @@ void CL_Frame( int realmsec, int gamemsec ) if( dedicated->integer ) return; + TracyCZoneN( cl_frame_ctx, "CL_Frame_active", 1 ); + cls.realtime += realmsec; if( cls.demo.playing && cls.demo.play_ignore_next_frametime ) @@ -2841,7 +2853,8 @@ void CL_Frame( int realmsec, int gamemsec ) CL_UpdateSnapshot(); CL_AdjustServerTime( gamemsec ); - CL_UserInputFrame(); + CL_UserInputFrame(); + CL_NetFrame( realmsec, gamemsec ); if (STEAMSHIM_active()) { STEAMSHIM_dispatch(); @@ -2889,7 +2902,7 @@ void CL_Frame( int realmsec, int gamemsec ) if( allRealMsec + extraMsec < minMsec ) { - // let CPU sleep while playing fullscreen video, while minimized + // let CPU sleep while playing fullscreen video, while minimized // or when cl_sleep is enabled bool sleep = cl_sleep->integer != 0; @@ -2898,6 +2911,7 @@ void CL_Frame( int realmsec, int gamemsec ) if( sleep && minMsec - extraMsec > 1 ) Sys_Sleep( 1 ); + TracyCZoneEnd( cl_frame_ctx ); return; } @@ -2967,7 +2981,7 @@ void CL_Frame( int realmsec, int gamemsec ) // update discord CL_UpdatePresence(); - + // advance local effects for next frame SCR_RunCinematic(); SCR_RunConsole( allRealMsec ); @@ -2976,6 +2990,8 @@ void CL_Frame( int realmsec, int gamemsec ) allGameMsec = 0; cls.framecount++; + + TracyCZoneEnd( cl_frame_ctx ); } diff --git a/source/client/cl_parse.c b/source/client/cl_parse.c index 3d3929293b..663fd91134 100644 --- a/source/client/cl_parse.c +++ b/source/client/cl_parse.c @@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // cl_parse.c -- parse a message received from the server #include "client.h" +#include "tracy/TracyC.h" void CL_StopServerDownload( void ); @@ -411,6 +412,7 @@ static void CL_ParseDownload( msg_t *msg ) { size_t size, offset; char *svFilename; + TracyCZoneN( ctx, "CL_ParseDownload", 1 ); // read the data svFilename = MSG_ReadString( msg ); @@ -420,6 +422,7 @@ static void CL_ParseDownload( msg_t *msg ) if( cls.demo.playing ) { // ignore download commands coming from demo files + TracyCZoneEnd( ctx ); return; } @@ -427,6 +430,7 @@ static void CL_ParseDownload( msg_t *msg ) { Com_Printf( "Error: Download message didn't have as much data as it promised\n" ); CL_RetryDownload(); + TracyCZoneEnd( ctx ); return; } @@ -434,6 +438,7 @@ static void CL_ParseDownload( msg_t *msg ) { Com_Printf( "Error: Download message while not dowloading\n" ); msg->readcount += size; + TracyCZoneEnd( ctx ); return; } @@ -441,6 +446,7 @@ static void CL_ParseDownload( msg_t *msg ) { Com_Printf( "Error: Download message for wrong file\n" ); msg->readcount += size; + TracyCZoneEnd( ctx ); return; } @@ -449,6 +455,7 @@ static void CL_ParseDownload( msg_t *msg ) Com_Printf( "Error: Invalid download message\n" ); msg->readcount += size; CL_RetryDownload(); + TracyCZoneEnd( ctx ); return; } @@ -457,6 +464,7 @@ static void CL_ParseDownload( msg_t *msg ) Com_Printf( "Error: Download message for wrong position\n" ); msg->readcount += size; CL_RetryDownload(); + TracyCZoneEnd( ctx ); return; } @@ -486,6 +494,7 @@ static void CL_ParseDownload( msg_t *msg ) CL_DownloadDone(); } + TracyCZoneEnd( ctx ); } /* @@ -505,6 +514,7 @@ static void CL_ParseServerData( msg_t *msg ) int i, sv_bitflags, numpure; int http_portnum; bool old_sv_pure; + TracyCZoneN( ctx, "CL_ParseServerData", 1 ); Com_DPrintf( "Serverdata packet received.\n" ); @@ -646,6 +656,7 @@ static void CL_ParseServerData( msg_t *msg ) Com_Printf( S_COLOR_WHITE "\n" "=====================================\n" ); Com_Printf( S_COLOR_WHITE "%s\n\n", cl.servermessage ); + TracyCZoneEnd( ctx ); } /* @@ -653,7 +664,9 @@ static void CL_ParseServerData( msg_t *msg ) */ static void CL_ParseBaseline( msg_t *msg ) { + TracyCZoneN( ctx, "CL_ParseBaseline", 1 ); SNAP_ParseBaseline( msg, cl_baselines ); + TracyCZoneEnd( ctx ); } /* @@ -663,6 +676,7 @@ static void CL_ParseFrame( msg_t *msg ) { snapshot_t *snap, *oldSnap; int delta; + TracyCZoneN( ctx, "CL_ParseFrame", 1 ); oldSnap = ( cl.receivedSnapNum > 0 ) ? &cl.snapShots[cl.receivedSnapNum & UPDATE_MASK] : NULL; @@ -723,6 +737,7 @@ static void CL_ParseFrame( msg_t *msg ) cl.serverTimeDeltas[cl.receivedSnapNum & MASK_TIMEDELTAS_BACKUP] = delta; } } + TracyCZoneEnd( ctx ); } //========= StringCommands================ @@ -826,9 +841,12 @@ static void CL_ParseConfigstringCommand( void ) { int i, argc, idx; char *s; + TracyCZoneN( ctx, "CL_ParseConfigstringCommand", 1 ); - if( Cmd_Argc() < 3 ) + if( Cmd_Argc() < 3 ) { + TracyCZoneEnd( ctx ); return; + } // ch : configstrings may come batched now, so lets loop through them argc = Cmd_Argc(); @@ -840,6 +858,7 @@ static void CL_ParseConfigstringCommand( void ) CL_UpdateConfigString( idx, s ); } + TracyCZoneEnd( ctx ); } static void CL_RPC_cb_steamAuth( void *self, struct steam_rpc_pkt_s *rec ){ @@ -908,6 +927,7 @@ static void CL_ParseServerCommand( msg_t *msg ) const char *s; char *text; svcmd_t *cmd; + TracyCZoneN( ctx, "CL_ParseServerCommand", 1 ); text = MSG_ReadString( msg ); @@ -923,11 +943,13 @@ static void CL_ParseServerCommand( msg_t *msg ) if( !strcmp( s, cmd->name ) ) { cmd->func(); + TracyCZoneEnd( ctx ); return; } } Com_Printf( "Unknown server command: %s\n", s ); + TracyCZoneEnd( ctx ); } static void CB_RPC_DecompressVoice( void *self, struct steam_rpc_pkt_s *rec ) @@ -938,14 +960,19 @@ static void CB_RPC_DecompressVoice( void *self, struct steam_rpc_pkt_s *rec ) static void CL_ParseVoiceData( msg_t *msg ) { int client = MSG_ReadShort( msg ); + TracyCZoneN( ctx, "CL_ParseVoiceData", 1 ); int size = MSG_ReadShort( msg ); if (cl_enablevoice->integer != 1) { MSG_SkipData(msg, size); + TracyCZoneEnd( ctx ); return; } - if (size > VOICE_BUFFER_MAX) return; + if (size > VOICE_BUFFER_MAX) { + TracyCZoneEnd( ctx ); + return; + } struct decompress_voice_req_s *req = (struct decompress_voice_req_s *)malloc(sizeof(struct decompress_voice_req_s) + size); @@ -955,6 +982,7 @@ static void CL_ParseVoiceData( msg_t *msg ) { // yes this is bad but i'm not making an allocation for a single int STEAMSHIM_sendRPC(req, sizeof(struct decompress_voice_req_s) + size, (int*)client, CB_RPC_DecompressVoice, NULL); + TracyCZoneEnd( ctx ); } /* @@ -971,6 +999,7 @@ ACTION MESSAGES void CL_ParseServerMessage( msg_t *msg ) { int cmd; + TracyCZoneN( ctx, "CL_ParseServerMessage", 1 ); if( cl_shownet->integer == 1 ) { @@ -1054,6 +1083,7 @@ void CL_ParseServerMessage( msg_t *msg ) } else { + TracyCZoneEnd( ctx ); return; // ignore rest of the packet (serverdata is always sent alone) } break; @@ -1148,4 +1178,6 @@ void CL_ParseServerMessage( msg_t *msg ) // if( cls.demo.recording && !cls.demo.waiting ) CL_WriteDemoMessage( msg ); + + TracyCZoneEnd( ctx ); } diff --git a/source/client/cl_screen.c b/source/client/cl_screen.c index d9c8ad5f3c..72e73e8a9d 100644 --- a/source/client/cl_screen.c +++ b/source/client/cl_screen.c @@ -676,7 +676,6 @@ static void SCR_RenderView( float stereo_separation ) */ void SCR_UpdateScreen( void ) { - TracyCFrameMark static dynvar_t *updatescreen = NULL; int numframes; int i; diff --git a/source/extern/CMakeLists.txt b/source/extern/CMakeLists.txt index 97aa3b8df1..1fe8380be7 100644 --- a/source/extern/CMakeLists.txt +++ b/source/extern/CMakeLists.txt @@ -145,7 +145,14 @@ option(TRACY_STATIC "" OFF ) SET(TRACY_ENABLE OFF CACHE BOOL "Enable profiling") add_compile_definitions(TRACY_IMPORTS) add_subdirectory(tracy) -qf_set_output_dir(TracyClient libs) +if(WIN32) + # Windows has no RPATH equivalent; the loader only searches the exe + # directory for statically-imported DLLs. warfork/wf_server/wftv_server + # link Tracy at load time, so the DLL must sit beside them. + qf_set_output_dir(TracyClient "") +else() + qf_set_output_dir(TracyClient libs) +endif() set(STB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/stb PARENT_SCOPE) diff --git a/source/qcommon/common.c b/source/qcommon/common.c index c391a9799a..2162879c01 100644 --- a/source/qcommon/common.c +++ b/source/qcommon/common.c @@ -34,6 +34,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "crashpad.h" +#include "tracy/TracyC.h" + #define MAX_NUM_ARGVS 50 static bool dynvars_initialized = false; @@ -934,6 +936,8 @@ void Qcommon_Frame( unsigned int realmsec ) int time_before = 0, time_between = 0, time_after = 0; static unsigned int gamemsec; + TracyCZoneN( zone_qcommon, "Qcommon_Frame", 1 ); + #ifdef USE_CRASHPAD Crashpad_RefreshUploadState(); #endif @@ -941,8 +945,10 @@ void Qcommon_Frame( unsigned int realmsec ) if( com_quit ) Com_Quit(); - if( setjmp( abortframe ) ) + if( setjmp( abortframe ) ) { + TracyCZoneEnd( zone_qcommon ); return; // an ERR_DROP was thrown + } if( logconsole && logconsole->modified ) { @@ -1029,6 +1035,9 @@ void Qcommon_Frame( unsigned int realmsec ) frametick = Dynvar_Lookup( "frametick" ); Dynvar_CallListeners( frametick, &fc ); ++fc; + + TracyCZoneEnd( zone_qcommon ); + TracyCFrameMark; } /* diff --git a/source/qcommon/net.c b/source/qcommon/net.c index 5a2343332f..bf2f73d8aa 100644 --- a/source/qcommon/net.c +++ b/source/qcommon/net.c @@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "qcommon.h" #include "sys_net.h" +#include "tracy/TracyC.h" #include "../steamshim/src/parent/parent.h" #include "../steamshim/src/mod_steam.h" #ifdef _WIN32 @@ -1067,32 +1068,44 @@ PUBLIC FUNCTIONS */ int NET_GetPacket( const socket_t *socket, netadr_t *address, msg_t *message ) { + int ret; + TracyCZoneN( ctx, "NET_GetPacket", 1 ); assert( socket->open ); - if( !socket->open ) + if( !socket->open ) { + TracyCZoneEnd( ctx ); return -1; + } switch( socket->type ) { case SOCKET_LOOPBACK: - return NET_Loopback_GetPacket( socket, address, message ); + ret = NET_Loopback_GetPacket( socket, address, message ); + break; case SOCKET_UDP: - return NET_UDP_GetPacket( socket, address, message ); + ret = NET_UDP_GetPacket( socket, address, message ); + break; case SOCKET_SDR: - return NET_SDR_GetPacket( socket, address, message ); + ret = NET_SDR_GetPacket( socket, address, message ); + break; #ifdef TCP_SUPPORT case SOCKET_TCP: - return NET_TCP_GetPacket( socket, address, message ); + ret = NET_TCP_GetPacket( socket, address, message ); + break; #endif default: assert( false ); NET_SetErrorString( "Unknown socket type" ); - return -1; + ret = -1; + break; } + + TracyCZoneEnd( ctx ); + return ret; } /* @@ -1908,8 +1921,12 @@ void NET_Sleep( int msec, socket_t *sockets[] ) fd_set fdset; int i; - if( !sockets || !sockets[0] ) + TracyCZoneN( ctx, "NET_Sleep", 1 ); + + if( !sockets || !sockets[0] ) { + TracyCZoneEnd( ctx ); return; + } FD_ZERO( &fdset ); @@ -1938,6 +1955,7 @@ void NET_Sleep( int msec, socket_t *sockets[] ) timeout.tv_sec = msec / 1000; timeout.tv_usec = ( msec % 1000 ) * 1000; select( FD_SETSIZE, &fdset, NULL, NULL, &timeout ); + TracyCZoneEnd( ctx ); } /* diff --git a/source/qcommon/snap_read.c b/source/qcommon/snap_read.c index 42b4b76f69..45d9c24559 100644 --- a/source/qcommon/snap_read.c +++ b/source/qcommon/snap_read.c @@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "qcommon.h" #include "snap_read.h" +#include "tracy/TracyC.h" /* ========================================================================= @@ -325,6 +326,8 @@ static void SNAP_ParsePacketEntities( msg_t *msg, snapshot_t *oldframe, snapshot entity_state_t *oldstate = NULL; int oldindex, oldnum; + TracyCZoneN( ctx, "SNAP_ParsePacketEntities", 1 ); + newframe->numEntities = 0; // delta from the entities present in oldframe @@ -453,6 +456,7 @@ static void SNAP_ParsePacketEntities( msg_t *msg, snapshot_t *oldframe, snapshot oldnum = oldstate->number; } } + TracyCZoneEnd( ctx ); } /* @@ -573,6 +577,8 @@ snapshot_t *SNAP_ParseFrame( msg_t *msg, snapshot_t *lastFrame, int *suppressCou gcommand_t *gcmd; snapshot_t *newframe; + TracyCZoneN( ctx, "SNAP_ParseFrame", 1 ); + // read header newframe = SNAP_ParseFrameHeader( msg, NULL, suppressCount, backup, false ); deltaframe = NULL; @@ -674,5 +680,6 @@ snapshot_t *SNAP_ParseFrame( msg_t *msg, snapshot_t *lastFrame, int *suppressCou Com_Error( ERR_DROP, "SNAP_ParseFrame: not packetentities" ); SNAP_ParsePacketEntities( msg, deltaframe, newframe, baselines, showNet ); + TracyCZoneEnd( ctx ); return newframe; } diff --git a/source/ref_gl/CMakeLists.txt b/source/ref_gl/CMakeLists.txt index 84d3b9c9db..905d92c257 100644 --- a/source/ref_gl/CMakeLists.txt +++ b/source/ref_gl/CMakeLists.txt @@ -59,7 +59,7 @@ else() endif() add_library(ref_gl SHARED ${REF_GL_HEADERS} ${REF_GL_COMMON_SOURCES} ${REF_GL_PLATFORM_SOURCES}) target_include_directories(ref_gl PRIVATE ${STB_INCLUDE_DIR} "../ref_base" "../qcore") -target_link_libraries(ref_gl PRIVATE qcore ${REF_GL_PLATFORM_LIBRARIES}) +target_link_libraries(ref_gl PRIVATE qcore ${REF_GL_PLATFORM_LIBRARIES} Tracy::TracyClient) qf_set_output_dir(ref_gl libs) diff --git a/source/ref_gl/r_backend.c b/source/ref_gl/r_backend.c index e5aaa1ea9a..e707d0f8e9 100644 --- a/source/ref_gl/r_backend.c +++ b/source/ref_gl/r_backend.c @@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "r_local.h" #include "r_backend_local.h" +#include "tracy/TracyC.h" // Smaller buffer for 2D polygons. Also a workaround for some instances of a hardly explainable bug on Adreno // that caused dynamic draws to slow everything down in some cases when normals are used with dynamic VBOs. @@ -37,6 +38,7 @@ static void RB_SelectTextureUnit( int tmu ); */ void RB_Init( void ) { + TracyCZoneN( ctx, "RB_Init", 1 ); memset( &rb, 0, sizeof( rb ) ); rb.mempool = R_AllocPool( NULL, "Rendering Backend" ); @@ -51,8 +53,9 @@ void RB_Init( void ) // create VBO's we're going to use for streamed data RB_RegisterStreamVBOs(); - + RP_PrecachePrograms(); + TracyCZoneEnd( ctx ); } /* @@ -60,9 +63,11 @@ void RB_Init( void ) */ void RB_Shutdown( void ) { + TracyCZoneN( ctx, "RB_Shutdown", 1 ); RP_StorePrecacheList(); R_FreePool( &rb.mempool ); + TracyCZoneEnd( ctx ); } /* @@ -71,6 +76,7 @@ void RB_Shutdown( void ) void RB_BeginRegistration( void ) { int i; + TracyCZoneN( ctx, "RB_BeginRegistration", 1 ); RB_RegisterStreamVBOs(); RB_BindVBO( 0, 0 ); @@ -88,6 +94,7 @@ void RB_BeginRegistration( void ) } RB_FlushTextureCache(); + TracyCZoneEnd( ctx ); } /* @@ -95,7 +102,9 @@ void RB_BeginRegistration( void ) */ void RB_EndRegistration( void ) { + TracyCZoneN( ctx, "RB_EndRegistration", 1 ); RB_BindVBO( 0, 0 ); + TracyCZoneEnd( ctx ); } /* @@ -112,6 +121,7 @@ void RB_SetTime( unsigned int time ) */ void RB_BeginFrame( void ) { + TracyCZoneN( ctx, "RB_BeginFrame", 1 ); Vector4Set( rb.nullEnt.shaderRGBA, 1, 1, 1, 1 ); rb.nullEnt.scale = 1; VectorClear( rb.nullEnt.origin ); @@ -123,6 +133,7 @@ void RB_BeginFrame( void ) RB_SetShaderStateMask( ~0, 0 ); RB_BindVBO( 0, 0 ); RB_FlushTextureCache(); + TracyCZoneEnd( ctx ); } /* @@ -741,6 +752,7 @@ void RB_AddDynamicMesh( const entity_t *entity, const shader_t *shader, vattribmask_t vattribs; int streamId = RB_VBO_NONE; rbDynamicStream_t *stream; + TracyCZoneN( ctx, "RB_AddDynamicMesh", 1 ); int destVertOffset; elem_t *destElems; @@ -753,6 +765,7 @@ void RB_AddDynamicMesh( const entity_t *entity, const shader_t *shader, trifan = true; } if( !numVerts || !numElems || ( numVerts > MAX_STREAM_VBO_VERTS ) || ( numElems > MAX_STREAM_VBO_ELEMENTS ) ) { + TracyCZoneEnd( ctx ); return; } @@ -854,6 +867,7 @@ void RB_AddDynamicMesh( const entity_t *entity, const shader_t *shader, stream->drawElements.numVerts += numVerts; stream->drawElements.numElems += numElems; + TracyCZoneEnd( ctx ); } /* @@ -867,8 +881,10 @@ void RB_FlushDynamicMeshes( void ) int sx, sy, sw, sh; float offsetx = 0.0f, offsety = 0.0f, transx, transy; mat4_t m; + TracyCZoneN( ctx, "RB_FlushDynamicMeshes", 1 ); if( !numDraws ) { + TracyCZoneEnd( ctx ); return; } @@ -937,6 +953,7 @@ void RB_FlushDynamicMeshes( void ) m[13] = transy; RB_LoadObjectMatrix( m ); } + TracyCZoneEnd( ctx ); } /* @@ -1198,6 +1215,7 @@ static void RB_DrawElements_( void ) void RB_DrawElements( int firstVert, int numVerts, int firstElem, int numElems, int firstShadowVert, int numShadowVerts, int firstShadowElem, int numShadowElems ) { + TracyCZoneN( ctx, "RB_DrawElements", 1 ); rb.currentVAttribs &= ~VATTRIB_INSTANCES_BITS; rb.drawElements.numVerts = numVerts; @@ -1213,6 +1231,7 @@ void RB_DrawElements( int firstVert, int numVerts, int firstElem, int numElems, rb.drawShadowElements.numInstances = 0; RB_DrawElements_(); + TracyCZoneEnd( ctx ); } /* @@ -1224,7 +1243,9 @@ void RB_DrawElementsInstanced( int firstVert, int numVerts, int firstElem, int n int firstShadowVert, int numShadowVerts, int firstShadowElem, int numShadowElems, int numInstances, instancePoint_t *instances ) { + TracyCZoneN( ctx, "RB_DrawElementsInstanced", 1 ); if( !numInstances ) { + TracyCZoneEnd( ctx ); return; } @@ -1233,6 +1254,7 @@ void RB_DrawElementsInstanced( int firstVert, int numVerts, int firstElem, int n // (dynamic geometry will need changes to rbDynamicDraw_t) assert( rb.currentVBOId > RB_VBO_NONE ); if( rb.currentVBOId <= RB_VBO_NONE ) { + TracyCZoneEnd( ctx ); return; } @@ -1272,6 +1294,7 @@ void RB_DrawElementsInstanced( int firstVert, int numVerts, int firstElem, int n rb.drawElements.numInstances = numInstances; rb.drawShadowElements.numInstances = numInstances; RB_DrawElements_(); + TracyCZoneEnd( ctx ); } /* diff --git a/source/ref_gl/r_frontend.c b/source/ref_gl/r_frontend.c index 82c967c68b..70293e0d83 100644 --- a/source/ref_gl/r_frontend.c +++ b/source/ref_gl/r_frontend.c @@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "r_cmdque.h" #include "../ref_base/ref_mod.h" +#include "tracy/TracyC.h" static ref_frontend_t rrf; static ref_cmdbuf_t *RF_GetNextAdapterFrame( ref_frontendAdapter_t *adapter ); @@ -353,6 +354,7 @@ static void RF_CheckCvars( void ) void RF_BeginFrame( float cameraSeparation, bool forceClear, bool forceVsync ) { + TracyCZoneN( ctx, "RF_BeginFrame", 1 ); RF_CheckCvars(); // run cinematic passes on shaders @@ -380,121 +382,156 @@ void RF_BeginFrame( float cameraSeparation, bool forceClear, bool forceVsync ) R_DataSync(); rrf.frame->BeginFrame( rrf.frame, cameraSeparation, forceClear, forceVsync ); + TracyCZoneEnd( ctx ); } void RF_EndFrame( void ) { + TracyCZoneN( ctx, "RF_EndFrame", 1 ); R_DataSync(); rrf.frame->EndFrame( rrf.frame ); - + if( glConfig.multithreading ) { ri.Mutex_Lock( rrf.adapter.frameLock ); rrf.lastFrameNum = rrf.frameNum; rrf.frameId++; ri.Mutex_Unlock( rrf.adapter.frameLock ); } + TracyCZoneEnd( ctx ); } void RF_BeginRegistration( void ) { + TracyCZoneN( ctx, "RF_BeginRegistration", 1 ); // sync to the backend thread to ensure it's not using old assets for drawing RF_AdapterWait( &rrf.adapter ); R_BeginRegistration(); rrf.adapter.cmdPipe->BeginRegistration( rrf.adapter.cmdPipe ); RF_AdapterWait( &rrf.adapter ); + TracyCZoneEnd( ctx ); } void RF_EndRegistration( void ) { + TracyCZoneN( ctx, "RF_EndRegistration", 1 ); // sync to the backend thread to ensure it's not using old assets for drawing RF_AdapterWait( &rrf.adapter ); R_EndRegistration(); rrf.adapter.cmdPipe->EndRegistration( rrf.adapter.cmdPipe ); RF_AdapterWait( &rrf.adapter ); - + // reset the cache of custom colors, otherwise RF_SetCustomColor might fail to do anything memset( rrf.customColors, 0, sizeof( rrf.customColors ) ); + TracyCZoneEnd( ctx ); } void RF_RegisterWorldModel( const char *model, const dvis_t *pvsData ) { + TracyCZoneN( ctx, "RF_RegisterWorldModel", 1 ); RF_AdapterWait( &rrf.adapter ); R_RegisterWorldModel( model, pvsData ); + TracyCZoneEnd( ctx ); } void RF_ClearScene( void ) { + TracyCZoneN( ctx, "RF_ClearScene", 1 ); rrf.frame->ClearScene( rrf.frame ); + TracyCZoneEnd( ctx ); } void RF_AddEntityToScene( const entity_t *ent ) { + TracyCZoneN( ctx, "RF_AddEntityToScene", 1 ); rrf.frame->AddEntityToScene( rrf.frame, ent ); + TracyCZoneEnd( ctx ); } void RF_AddLightToScene( const vec3_t org, float intensity, float r, float g, float b ) { + TracyCZoneN( ctx, "RF_AddLightToScene", 1 ); rrf.frame->AddLightToScene( rrf.frame, org, intensity, r, g, b ); + TracyCZoneEnd( ctx ); } void RF_AddPolyToScene( const poly_t *poly ) { + TracyCZoneN( ctx, "RF_AddPolyToScene", 1 ); rrf.frame->AddPolyToScene( rrf.frame, poly ); + TracyCZoneEnd( ctx ); } void RF_AddLightStyleToScene( int style, float r, float g, float b ) { + TracyCZoneN( ctx, "RF_AddLightStyleToScene", 1 ); rrf.frame->AddLightStyleToScene( rrf.frame, style, r, g, b ); + TracyCZoneEnd( ctx ); } void RF_RenderScene( const refdef_t *fd ) { + TracyCZoneN( ctx, "RF_RenderScene", 1 ); rrf.frame->RenderScene( rrf.frame, fd ); + TracyCZoneEnd( ctx ); } -void RF_DrawStretchPic( int x, int y, int w, int h, float s1, float t1, float s2, float t2, +void RF_DrawStretchPic( int x, int y, int w, int h, float s1, float t1, float s2, float t2, const vec4_t color, const shader_t *shader ) { + TracyCZoneN( ctx, "RF_DrawStretchPic", 1 ); rrf.frame->DrawRotatedStretchPic( rrf.frame, x, y, w, h, s1, t1, s2, t2, 0, color, shader ); + TracyCZoneEnd( ctx ); } -void RF_DrawRotatedStretchPic( int x, int y, int w, int h, float s1, float t1, float s2, float t2, float angle, +void RF_DrawRotatedStretchPic( int x, int y, int w, int h, float s1, float t1, float s2, float t2, float angle, const vec4_t color, const shader_t *shader ) { + TracyCZoneN( ctx, "RF_DrawRotatedStretchPic", 1 ); rrf.frame->DrawRotatedStretchPic( rrf.frame, x, y, w, h, s1, t1, s2, t2, angle, color, shader ); + TracyCZoneEnd( ctx ); } -void RF_DrawStretchRaw( int x, int y, int w, int h, int cols, int rows, +void RF_DrawStretchRaw( int x, int y, int w, int h, int cols, int rows, float s1, float t1, float s2, float t2, uint8_t *data ) { - if( !cols || !rows ) + TracyCZoneN( ctx, "RF_DrawStretchRaw", 1 ); + if( !cols || !rows ) { + TracyCZoneEnd( ctx ); return; + } if( data ) R_UploadRawPic( rsh.rawTexture, cols, rows, data ); rrf.frame->DrawStretchRaw( rrf.frame, x, y, w, h, s1, t1, s2, t2 ); + TracyCZoneEnd( ctx ); } -void RF_DrawStretchRawYUV( int x, int y, int w, int h, +void RF_DrawStretchRawYUV( int x, int y, int w, int h, float s1, float t1, float s2, float t2, ref_img_plane_t *yuv ) { + TracyCZoneN( ctx, "RF_DrawStretchRawYUV", 1 ); if( yuv ) R_UploadRawYUVPic( rsh.rawYUVTextures, yuv ); rrf.frame->DrawStretchRawYUV( rrf.frame, x, y, w, h, s1, t1, s2, t2 ); + TracyCZoneEnd( ctx ); } void RF_DrawStretchPoly( const poly_t *poly, float x_offset, float y_offset ) { + TracyCZoneN( ctx, "RF_DrawStretchPoly", 1 ); rrf.frame->DrawStretchPoly( rrf.frame, poly, x_offset, y_offset ); + TracyCZoneEnd( ctx ); } void RF_SetScissor( int x, int y, int w, int h ) { + TracyCZoneN( ctx, "RF_SetScissor", 1 ); rrf.frame->SetScissor( rrf.frame, x, y, w, h ); Vector4Set( rrf.scissor, x, y, w, h ); + TracyCZoneEnd( ctx ); } void RF_GetScissor( int *x, int *y, int *w, int *h ) @@ -511,8 +548,10 @@ void RF_GetScissor( int *x, int *y, int *w, int *h ) void RF_ResetScissor( void ) { + TracyCZoneN( ctx, "RF_ResetScissor", 1 ); rrf.frame->ResetScissor( rrf.frame ); Vector4Set( rrf.scissor, 0, 0, glConfig.width, glConfig.height ); + TracyCZoneEnd( ctx ); } void RF_SetCustomColor( int num, int r, int g, int b ) @@ -614,9 +653,12 @@ void RF_TransformVectorToScreen( const refdef_t *rd, const vec3_t in, vec2_t out { mat4_t p, m; vec4_t temp, temp2; - - if( !rd || !in || !out ) + TracyCZoneN( ctx, "RF_TransformVectorToScreen", 1 ); + + if( !rd || !in || !out ) { + TracyCZoneEnd( ctx ); return; + } temp[0] = in[0]; temp[1] = in[1]; @@ -640,34 +682,50 @@ void RF_TransformVectorToScreen( const refdef_t *rd, const vec3_t in, vec2_t out Matrix4_Multiply_Vector( m, temp, temp2 ); Matrix4_Multiply_Vector( p, temp2, temp ); - - if( !temp[3] ) - return; - + + if( !temp[3] ) { + TracyCZoneEnd( ctx ); + return; + } + out[0] = rd->x + ( temp[0] / temp[3] + 1.0f ) * rd->width * 0.5f; out[1] = glConfig.height - (rd->y + ( temp[1] / temp[3] + 1.0f ) * rd->height * 0.5f); + TracyCZoneEnd( ctx ); } bool RF_LerpTag( orientation_t *orient, const model_t *mod, int oldframe, int frame, float lerpfrac, const char *name ) { - if( !orient ) + bool ret; + TracyCZoneN( ctx, "RF_LerpTag", 1 ); + + if( !orient ) { + TracyCZoneEnd( ctx ); return false; - + } + VectorClear( orient->origin ); Matrix3_Identity( orient->axis ); - - if( !name ) + + if( !name ) { + TracyCZoneEnd( ctx ); return false; - - if( mod->type == mod_alias ) - return R_AliasModelLerpTag( orient, (const maliasmodel_t *)mod->extradata, oldframe, frame, lerpfrac, name ); - + } + + if( mod->type == mod_alias ) { + ret = R_AliasModelLerpTag( orient, (const maliasmodel_t *)mod->extradata, oldframe, frame, lerpfrac, name ); + TracyCZoneEnd( ctx ); + return ret; + } + + TracyCZoneEnd( ctx ); return false; } void RF_LightForOrigin( const vec3_t origin, vec3_t dir, vec4_t ambient, vec4_t diffuse, float radius ) { + TracyCZoneN( ctx, "RF_LightForOrigin", 1 ); R_LightForOrigin( origin, dir, ambient, diffuse, radius, false ); + TracyCZoneEnd( ctx ); } /* diff --git a/source/ref_gl/r_main.c b/source/ref_gl/r_main.c index 1ab866046e..0745105c13 100644 --- a/source/ref_gl/r_main.c +++ b/source/ref_gl/r_main.c @@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // r_main.c #include "r_local.h" +#include "tracy/TracyC.h" r_globals_t rf; @@ -1176,6 +1177,7 @@ void R_RenderView( const refdef_t *fd ) { int msec = 0; bool shadowMap = rn.renderFlags & RF_SHADOWMAPVIEW ? true : false; + TracyCZoneN( ctx, "R_RenderView", 1 ); rn.refdef = *fd; rn.numVisSurfaces = 0; @@ -1212,8 +1214,10 @@ void R_RenderView( const refdef_t *fd ) R_ClearDrawList( rn.portalmasklist ); - if( !rsh.worldModel && !( rn.refdef.rdflags & RDF_NOWORLDMODEL ) ) + if( !rsh.worldModel && !( rn.refdef.rdflags & RDF_NOWORLDMODEL ) ) { + TracyCZoneEnd( ctx ); return; + } R_SetupFrame(); @@ -1234,6 +1238,7 @@ void R_RenderView( const refdef_t *fd ) if( !rn.numVisSurfaces ) { // no world surfaces visible + TracyCZoneEnd( ctx ); return; } @@ -1273,8 +1278,10 @@ void R_RenderView( const refdef_t *fd ) R_DrawPortals(); - if( r_portalonly->integer && !( rn.renderFlags & ( RF_MIRRORVIEW|RF_PORTALVIEW ) ) ) + if( r_portalonly->integer && !( rn.renderFlags & ( RF_MIRRORVIEW|RF_PORTALVIEW ) ) ) { + TracyCZoneEnd( ctx ); return; + } R_Clear( ~0 ); @@ -1296,6 +1303,8 @@ void R_RenderView( const refdef_t *fd ) R_TransformForWorld(); R_EndGL(); + + TracyCZoneEnd( ctx ); } #define REFINST_STACK_SIZE 64 diff --git a/source/ref_gl/r_mesh.c b/source/ref_gl/r_mesh.c index 8fd6327c20..2e2d90f783 100644 --- a/source/ref_gl/r_mesh.c +++ b/source/ref_gl/r_mesh.c @@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // r_mesh.c: transformation and sorting #include "r_local.h" +#include "tracy/TracyC.h" drawList_t r_worldlist; drawList_t r_shadowlist; @@ -406,6 +407,7 @@ static const batchDrawSurf_cb r_batchDrawSurfCb[ST_MAX_TYPES] = */ static void _R_DrawSurfaces( drawList_t *list ) { + TracyCZoneN( ctx, "_R_DrawSurfaces", 1 ); unsigned int i; unsigned int sortKey; unsigned int shaderNum = 0, prevShaderNum = MAX_SHADERS; @@ -431,6 +433,7 @@ static void _R_DrawSurfaces( drawList_t *list ) int riFBO = 0; if( !list->numDrawSurfs ) { + TracyCZoneEnd( ctx ); return; } @@ -584,6 +587,7 @@ static void _R_DrawSurfaces( drawList_t *list ) } RB_BindFrameBufferObject( riFBO ); + TracyCZoneEnd( ctx ); } /* diff --git a/source/ref_gl/r_program.c b/source/ref_gl/r_program.c index d2844432e7..0a78be791e 100644 --- a/source/ref_gl/r_program.c +++ b/source/ref_gl/r_program.c @@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "r_local.h" #include "../qalgo/q_trie.h" +#include "tracy/TracyC.h" #define MAX_GLSL_PROGRAMS 1024 #define GLSL_PROGRAMS_HASH_SIZE 256 @@ -163,8 +164,10 @@ static int RP_RegisterProgramBinary( int type, const char *name, const char *def void RP_Init( void ) { int program; + TracyCZoneN( ctx, "RP_Init", 1 ); if( r_glslprograms_initialized ) { + TracyCZoneEnd( ctx ); return; } @@ -195,6 +198,7 @@ void RP_Init( void ) } r_glslprograms_initialized = true; + TracyCZoneEnd( ctx ); } /* @@ -529,15 +533,18 @@ static void RF_DeleteProgram( glsl_program_t *program ) /* * RF_CompileShader */ -static int RF_CompileShader( int program, const char *programName, const char *shaderName, +static int RF_CompileShader( int program, const char *programName, const char *shaderName, int shaderType, const char **strings, int numStrings ) { GLhandleARB shader; GLint compiled; + TracyCZoneN( ctx, "RF_CompileShader", 1 ); shader = qglCreateShader( (GLenum)shaderType ); - if( !shader ) + if( !shader ) { + TracyCZoneEnd( ctx ); return 0; + } // if lengths is NULL, then each string is assumed to be null-terminated qglShaderSourceARB( shader, numStrings, strings, NULL ); @@ -566,11 +573,13 @@ static int RF_CompileShader( int program, const char *programName, const char *s } qglDeleteShader( shader ); + TracyCZoneEnd( ctx ); return 0; } qglAttachShader( program, shader ); + TracyCZoneEnd( ctx ); return shader; } @@ -1596,13 +1605,14 @@ static int R_Features2HashKey( r_glslfeat_t features ) /* * RP_RegisterProgramBinary */ -static int RP_RegisterProgramBinary( int type, const char *name, const char *deformsKey, - const deformv_t *deforms, int numDeforms, r_glslfeat_t features, +static int RP_RegisterProgramBinary( int type, const char *name, const char *deformsKey, + const deformv_t *deforms, int numDeforms, r_glslfeat_t features, int binaryFormat, unsigned binaryLength, void *binary ) { unsigned int i; int hash; int linked, error = 0; + TracyCZoneN( ctx, "RP_RegisterProgramBinary", 1 ); int shaderTypeIdx, wavefuncsIdx, deformvIdx, dualQuatsIdx, instancedIdx, vTransformsIdx; int enableTextureArrayIdx; #ifndef GL_ES_VERSION_2_0 @@ -1622,8 +1632,10 @@ static int RP_RegisterProgramBinary( int type, const char *name, const char *def const char *deformv; glslParser_t parser; - if( type <= GLSL_PROGRAM_TYPE_NONE || type >= GLSL_PROGRAM_TYPE_MAXTYPE ) + if( type <= GLSL_PROGRAM_TYPE_NONE || type >= GLSL_PROGRAM_TYPE_MAXTYPE ) { + TracyCZoneEnd( ctx ); return 0; + } assert( !deforms || deformsKey ); @@ -1635,6 +1647,7 @@ static int RP_RegisterProgramBinary( int type, const char *name, const char *def for( program = r_glslprograms_hash[type][hash]; program; program = program->hash_next ) { if( ( program->features == features ) && !strcmp( program->deformsKey, deformsKey ) ) { + TracyCZoneEnd( ctx ); return ( (program - r_glslprograms) + 1 ); } } @@ -1642,6 +1655,7 @@ static int RP_RegisterProgramBinary( int type, const char *name, const char *def if( r_numglslprograms == MAX_GLSL_PROGRAMS ) { Com_Printf( S_COLOR_YELLOW "RP_RegisterProgram: GLSL programs limit exceeded\n" ); + TracyCZoneEnd( ctx ); return 0; } @@ -1667,6 +1681,7 @@ static int RP_RegisterProgramBinary( int type, const char *name, const char *def } else { Com_Printf( S_COLOR_YELLOW "RP_RegisterProgram: failed to find parent for program type %i\n", type ); + TracyCZoneEnd( ctx ); return 0; } } @@ -1923,17 +1938,22 @@ static int RP_RegisterProgramBinary( int type, const char *name, const char *def RP_GetUniformLocations( program ); } + TracyCZoneEnd( ctx ); return ( program - r_glslprograms ) + 1; } /* * RP_RegisterProgram */ -int RP_RegisterProgram( int type, const char *name, const char *deformsKey, +int RP_RegisterProgram( int type, const char *name, const char *deformsKey, const deformv_t *deforms, int numDeforms, r_glslfeat_t features ) { - return RP_RegisterProgramBinary( type, name, deformsKey, deforms, numDeforms, + int ret; + TracyCZoneN( ctx, "RP_RegisterProgram", 1 ); + ret = RP_RegisterProgramBinary( type, name, deformsKey, deforms, numDeforms, features, 0, 0, NULL ); + TracyCZoneEnd( ctx ); + return ret; } /* @@ -2018,14 +2038,15 @@ void RP_ProgramList_f( void ) /* * RP_UpdateShaderUniforms */ -void RP_UpdateShaderUniforms( int elem, - float shaderTime, - const vec3_t entOrigin, const vec3_t entDist, const uint8_t *entityColor, +void RP_UpdateShaderUniforms( int elem, + float shaderTime, + const vec3_t entOrigin, const vec3_t entDist, const uint8_t *entityColor, const uint8_t *constColor, const float *rgbGenFuncArgs, const float *alphaGenFuncArgs, const mat4_t texMatrix ) { GLfloat m[9]; glsl_program_t *program = r_glslprograms + elem - 1; + TracyCZoneN( ctx, "RP_UpdateShaderUniforms", 1 ); if( entOrigin ) { if( program->loc.EntityOrigin >= 0 ) @@ -2059,19 +2080,21 @@ void RP_UpdateShaderUniforms( int elem, qglUniform4fvARB( program->loc.TextureMatrix, 2, m ); } + TracyCZoneEnd( ctx ); } /* * RP_UpdateViewUniforms */ -void RP_UpdateViewUniforms( int elem, +void RP_UpdateViewUniforms( int elem, const mat4_t modelviewMatrix, const mat4_t modelviewProjectionMatrix, - const vec3_t viewOrigin, const mat3_t viewAxis, - const float mirrorSide, + const vec3_t viewOrigin, const mat3_t viewAxis, + const float mirrorSide, int viewport[4], float zNear, float zFar ) { glsl_program_t *program = r_glslprograms + elem - 1; + TracyCZoneN( ctx, "RP_UpdateViewUniforms", 1 ); if( program->loc.ModelViewMatrix >= 0 ) { qglUniformMatrix4fvARB( program->loc.ModelViewMatrix, 1, GL_FALSE, modelviewMatrix ); @@ -2104,6 +2127,7 @@ void RP_UpdateViewUniforms( int elem, if( program->loc.builtin.MirrorSide >= 0 ) qglUniform1fARB( program->loc.builtin.MirrorSide, mirrorSide ); + TracyCZoneEnd( ctx ); } /* @@ -2713,16 +2737,18 @@ void RP_Shutdown( void ) { unsigned int i; glsl_program_t *program; + TracyCZoneN( ctx, "RP_Shutdown", 1 ); qglUseProgram( 0 ); for( i = 0, program = r_glslprograms; i < r_numglslprograms; i++, program++ ) { RF_DeleteProgram( program ); } - + Trie_Destroy( glsl_cache_trie ); glsl_cache_trie = NULL; r_numglslprograms = 0; r_glslprograms_initialized = false; + TracyCZoneEnd( ctx ); } diff --git a/source/ref_gl/r_register.c b/source/ref_gl/r_register.c index bfde6a6ad9..4934a283ef 100644 --- a/source/ref_gl/r_register.c +++ b/source/ref_gl/r_register.c @@ -569,9 +569,11 @@ static bool R_RegisterGLExtensions( void ) R_RegisterFatalExt( "gl_ext_blend_func_separate_EXT_funcs" ); } +#ifndef NDEBUG if(qglDebugMessageCallback && R_TryLoadGLProcAddress( gl_ext_debug_message_callback ) ) { qglDebugMessageCallback( __R_GlCallback, NULL ); } +#endif if( R_TryLoadGLProcAddress( gl_ext_GLSL_core_ARB_funcs ) ) { glConfig.ext.GLSL_core = 1; diff --git a/source/ref_gl/r_scene.c b/source/ref_gl/r_scene.c index 0d3ab76dee..6d2ff2f6e7 100644 --- a/source/ref_gl/r_scene.c +++ b/source/ref_gl/r_scene.c @@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "r_local.h" +#include "tracy/TracyC.h" static void R_ClearDebugBounds( void ); static void R_RenderDebugBounds( void ); @@ -307,9 +308,13 @@ void R_RenderScene( const refdef_t *fd ) int fbFlags = 0; int ppFrontBuffer = 0; image_t *ppSource; + TracyCZoneN( ctx, "R_RenderScene", 1 ); - if( r_norefresh->integer ) + if( r_norefresh->integer ) { + TracyCZoneEnd( ctx ); return; + } + R_Set2DMode( false ); @@ -379,9 +384,9 @@ void R_RenderScene( const refdef_t *fd ) R_BindFrameBufferObject( 0 ); - R_BuildShadowGroups(); + R_BuildShadowGroups(); - R_RenderView( fd ); + R_RenderView( fd ); R_RenderDebugSurface( fd ); @@ -441,6 +446,8 @@ void R_RenderScene( const refdef_t *fd ) colorWhite, 0, 1, &( rn.refdef.colorCorrection->passes[0].images[0] ) ); } + + TracyCZoneEnd( ctx ); } /* diff --git a/source/ref_nri/r_backend.c b/source/ref_nri/r_backend.c index f622887d90..da4a5f95c2 100644 --- a/source/ref_nri/r_backend.c +++ b/source/ref_nri/r_backend.c @@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "ri_types.h" #include "stb_ds.h" +#include "tracy/TracyC.h" // Smaller buffer for 2D polygons. Also a workaround for some instances of a hardly explainable bug on Adreno // that caused dynamic draws to slow everything down in some cases when normals are used with dynamic VBOs. #define COMPACT_STREAM_VATTRIBS ( VATTRIB_POSITION_BIT | VATTRIB_COLOR0_BIT | VATTRIB_TEXCOORDS_BIT ) @@ -32,6 +33,7 @@ rbackend_t rb; void RB_Init( void ) { + TracyCZoneN( ctx, "RB_Init", 1 ); memset( &rb, 0, sizeof( rb ) ); rb.mempool = R_AllocPool( NULL, "Rendering Backend" ); @@ -68,6 +70,7 @@ void RB_Init( void ) RB_InitShading(); RP_PrecachePrograms(); + TracyCZoneEnd( ctx ); } /* @@ -75,6 +78,7 @@ void RB_Init( void ) */ void RB_Shutdown( void ) { + TracyCZoneN( ctx, "RB_Shutdown", 1 ); for( size_t i = 0; i < RB_DYN_STREAM_NUM; i++ ) { #if ( DEVICE_IMPL_VULKAN ) if( rb.dynamicStreams[i].vk.vertexBuffer ) { @@ -91,6 +95,7 @@ void RB_Shutdown( void ) memset( rb.dynamicStreams, 0, sizeof( struct dynamic_vertex_stream_s ) * RB_DYN_STREAM_NUM ); RP_StorePrecacheList(); R_FreePool( &rb.mempool ); + TracyCZoneEnd( ctx ); } /* @@ -98,7 +103,9 @@ void RB_Shutdown( void ) */ void RB_BeginRegistration( void ) { + TracyCZoneN( ctx, "RB_BeginRegistration", 1 ); RB_BindVBO( 0, RI_TOPOLOGY_TRIANGLE_LIST ); + TracyCZoneEnd( ctx ); } /* @@ -106,7 +113,9 @@ void RB_BeginRegistration( void ) */ void RB_EndRegistration( void ) { + TracyCZoneN( ctx, "RB_EndRegistration", 1 ); RB_BindVBO( 0, RI_TOPOLOGY_TRIANGLE_LIST ); + TracyCZoneEnd( ctx ); } /* @@ -123,6 +132,7 @@ void RB_SetTime( unsigned int time ) */ void RB_BeginFrame( void ) { + TracyCZoneN( ctx, "RB_BeginFrame", 1 ); Vector4Set( rb.nullEnt.shaderRGBA, 1, 1, 1, 1 ); rb.nullEnt.scale = 1; VectorClear( rb.nullEnt.origin ); @@ -131,6 +141,7 @@ void RB_BeginFrame( void ) // start fresh each frame RB_SetShaderStateMask( ~0, 0 ); RB_BindVBO( 0, RI_TOPOLOGY_TRIANGLE_LIST ); + TracyCZoneEnd( ctx ); } void RB_EndFrame( void ) {} @@ -390,6 +401,7 @@ void RB_AddDynamicMesh( struct FrameState_s *cmd, rbDynamicDraw_t *prev = NULL, *draw; bool merge = false; vattribmask_t vattribs; + TracyCZoneN( ctx, "RB_AddDynamicMesh", 1 ); // can't (and shouldn't because that would break batching) merge strip draw calls // (consider simply disabling merge later in this case if models with tristrips are added in the future, but that's slow) @@ -400,6 +412,7 @@ void RB_AddDynamicMesh( struct FrameState_s *cmd, trifan = true; } if( !numVerts || !numElems || ( numVerts > MAX_STREAM_VBO_VERTS ) || ( numElems > MAX_STREAM_VBO_ELEMENTS ) ) { + TracyCZoneEnd( ctx ); return; } @@ -573,6 +586,7 @@ void RB_AddDynamicMesh( struct FrameState_s *cmd, } // rsh.nri.coreI.UnmapBuffer( vboReq.buffer ); // rsh.nri.coreI.UnmapBuffer( eleReq.buffer ); + TracyCZoneEnd( ctx ); } /* @@ -580,6 +594,7 @@ void RB_AddDynamicMesh( struct FrameState_s *cmd, */ void RB_FlushDynamicMeshes( struct FrameState_s *cmd ) { + TracyCZoneN( ctx, "RB_FlushDynamicMeshes", 1 ); float offsetx = 0.0f; float offsety = 0.0f; float transx; @@ -587,6 +602,8 @@ void RB_FlushDynamicMeshes( struct FrameState_s *cmd ) mat4_t m; if( rb.numDynamicDraws == 0 ) { + + TracyCZoneEnd( ctx ); return; } // if(cmd->stackCmdBeingRendered == 0) { @@ -642,6 +659,7 @@ void RB_FlushDynamicMeshes( struct FrameState_s *cmd ) m[13] = transy; RB_LoadObjectMatrix( m ); } + TracyCZoneEnd( ctx ); } /* @@ -654,6 +672,7 @@ vattribmask_t RB_GetVertexAttribs( void ) void RB_DrawElements( struct FrameState_s *cmd, int firstVert, int numVerts, int firstElem, int numElems, int firstShadowVert, int numShadowVerts, int firstShadowElem, int numShadowElems ) { + TracyCZoneN( ctx, "RB_DrawElements", 1 ); rb.currentVAttribs &= ~VATTRIB_INSTANCES_BITS; rb.drawElements.numVerts = numVerts; @@ -670,6 +689,7 @@ void RB_DrawElements( struct FrameState_s *cmd, int firstVert, int numVerts, int // RB_DrawElements_(); assert( false ); + TracyCZoneEnd( ctx ); } /* diff --git a/source/ref_nri/r_frontend.c b/source/ref_nri/r_frontend.c index e3455442b9..75cfec574f 100644 --- a/source/ref_nri/r_frontend.c +++ b/source/ref_nri/r_frontend.c @@ -224,7 +224,7 @@ rserr_t RF_Init( const char *applicationName, const char *screenshotPrefix, int rserr_t RF_SetMode( int x, int y, int width, int height, int displayFrequency, bool fullScreen, bool stereo ) { WaitRIQueueIdle( &rsh.device, &rsh.device.queues[RI_QUEUE_GRAPHICS] ); - TracyCZone( ctx, 1 ); + TracyCZoneN( ctx, "RF_SetMode", 1 ); if( fullScreen ) { if( !R_WIN_SetFullscreen( displayFrequency, width, height ) ) { @@ -403,7 +403,7 @@ void RF_Shutdown( bool verbose ) static void RF_CheckCvars( void ) { - TracyCZone( ctx, 1 ); + TracyCZoneN( ctx, "RF_CheckCvars", 1 ); // disallow bogus r_maxfps values, reset to default value instead if( r_maxfps->modified ) { if( r_maxfps->integer <= 0 ) { @@ -460,7 +460,7 @@ static void RF_CheckCvars( void ) void RF_BeginFrame( float cameraSeparation, bool forceClear, bool forceVsync ) { - TracyCZone(ctx, 1); + TracyCZoneN( ctx, "RF_BeginFrame", 1 ); RF_CheckCvars(); AdvanceRICommandRingBuffer(&rsh.graphicsCmdRing); @@ -632,7 +632,7 @@ static inline void __R_ApplyBrightnessBlend(struct FrameState_s* frame) { void RF_EndFrame( void ) { - TracyCZone( ctx, 1 ); + TracyCZoneN( ctx, "RF_EndFrame", 1 ); // render previously batched 2D geometry, if any RB_FlushDynamicMeshes( &rsh.frame ); @@ -760,6 +760,7 @@ void RF_EndFrame( void ) void RF_BeginRegistration( void ) { + TracyCZoneN( ctx, "RF_BeginRegistration", 1 ); // sync to the backend thread to ensure it's not using old assets for drawing // RF_AdapterWait( &rrf.adapter ); R_BeginRegistration(); @@ -767,64 +768,89 @@ void RF_BeginRegistration( void ) // rrf.adapter.cmdPipe->BeginRegistration( rrf.adapter.cmdPipe ); // RF_AdapterWait( &rrf.adapter ); + TracyCZoneEnd( ctx ); } void RF_EndRegistration( void ) { + TracyCZoneN( ctx, "RF_EndRegistration", 1 ); R_EndRegistration(); RB_EndRegistration(); // RFB_FreeUnusedObjects(); // todo: redo fbo logic // reset the cache of custom colors, otherwise RF_SetCustomColor might fail to do anything memset( rrf.customColors, 0, sizeof( rrf.customColors ) ); + TracyCZoneEnd( ctx ); } void RF_RegisterWorldModel( const char *model, const dvis_t *pvsData ) { + TracyCZoneN( ctx, "RF_RegisterWorldModel", 1 ); R_RegisterWorldModel( model, pvsData ); + TracyCZoneEnd( ctx ); } void RF_ClearScene( void ) { + TracyCZoneN( ctx, "RF_ClearScene", 1 ); R_ClearScene(); + TracyCZoneEnd( ctx ); } void RF_AddEntityToScene( const entity_t *ent ) { + TracyCZoneN( ctx, "RF_AddEntityToScene", 1 ); R_AddEntityToScene( ent ); + TracyCZoneEnd( ctx ); } void RF_AddLightToScene( const vec3_t org, float intensity, float r, float g, float b ) { + TracyCZoneN( ctx, "RF_AddLightToScene", 1 ); R_AddLightToScene( org, intensity, r, g, b ); + TracyCZoneEnd( ctx ); } void RF_AddPolyToScene( const poly_t *poly ) { + TracyCZoneN( ctx, "RF_AddPolyToScene", 1 ); R_AddPolyToScene( poly ); + TracyCZoneEnd( ctx ); } void RF_AddLightStyleToScene( int style, float r, float g, float b ) { + TracyCZoneN( ctx, "RF_AddLightStyleToScene", 1 ); R_AddLightStyleToScene( style, r, g, b ); + TracyCZoneEnd( ctx ); } void RF_RenderScene( const refdef_t *fd ) { + TracyCZoneN( ctx, "RF_RenderScene", 1 ); R_RenderScene( fd ); + TracyCZoneEnd( ctx ); } void RF_DrawStretchPic( int x, int y, int w, int h, float s1, float t1, float s2, float t2, const vec4_t color, const shader_t *shader ) { - if( !rsh.frameActive ) + TracyCZoneN( ctx, "RF_DrawStretchPic", 1 ); + if( !rsh.frameActive ) { + TracyCZoneEnd( ctx ); return; + } R_DrawRotatedStretchPic( &rsh.frame, x, y, w, h, s1, t1, s2, t2, 0, color, shader ); + TracyCZoneEnd( ctx ); } void RF_DrawRotatedStretchPic( int x, int y, int w, int h, float s1, float t1, float s2, float t2, float angle, const vec4_t color, const shader_t *shader ) { - if( !rsh.frameActive ) + TracyCZoneN( ctx, "RF_DrawRotatedStretchPic", 1 ); + if( !rsh.frameActive ) { + TracyCZoneEnd( ctx ); return; + } R_DrawRotatedStretchPic( &rsh.frame, x, y, w, h, s1, t1, s2, t2, 0, color, shader ); + TracyCZoneEnd( ctx ); } void RF_DrawStretchRaw( int x, int y, int w, int h, int cols, int rows, float s1, float t1, float s2, float t2, uint8_t *data ) @@ -849,20 +875,26 @@ void RF_DrawStretchRawYUV( int x, int y, int w, int h, float s1, float t1, float void RF_DrawStretchPoly( const poly_t *poly, float x_offset, float y_offset ) { - if( !rsh.frameActive ) + TracyCZoneN( ctx, "RF_DrawStretchPoly", 1 ); + if( !rsh.frameActive ) { + TracyCZoneEnd( ctx ); return; + } R_DrawStretchPoly( &rsh.frame, poly, x_offset, y_offset ); + TracyCZoneEnd( ctx ); } void RF_SetScissor( int x, int y, int w, int h ) { struct RIRect_s rect; + TracyCZoneN( ctx, "RF_SetScissor", 1 ); rect.x = max( 0, x ); rect.y = max( 0, y ); rect.width = w; rect.height = h; FR_CmdSetScissor( &rsh.frame, rect ); Vector4Set( rrf.scissor, x, y, w, h ); + TracyCZoneEnd( ctx ); } void R_InitSubpass( struct FrameState_s *parent, struct FrameState_s *child ) @@ -897,12 +929,14 @@ void RF_ResetScissor( void ) { // struct frame_cmd_buffer_s *cmd = R_ActiveFrameCmd(); struct RIRect_s rect; + TracyCZoneN( ctx, "RF_ResetScissor", 1 ); rect.x = 0; rect.y = 0; rect.width = rsh.swapchain.width; rect.height = rsh.swapchain.height; FR_CmdSetScissor( &rsh.frame, rect ); Vector4Set( rrf.scissor, 0, 0, rsh.swapchain.width, rsh.swapchain.height ); + TracyCZoneEnd( ctx ); } void RF_SetCustomColor( int num, int r, int g, int b ) @@ -1111,9 +1145,12 @@ void RF_TransformVectorToScreen( const refdef_t *rd, const vec3_t in, vec2_t out { mat4_t p, m; vec4_t temp, temp2; + TracyCZoneN( ctx, "RF_TransformVectorToScreen", 1 ); - if( !rd || !in || !out ) + if( !rd || !in || !out ) { + TracyCZoneEnd( ctx ); return; + } temp[0] = in[0]; temp[1] = in[1]; @@ -1138,33 +1175,49 @@ void RF_TransformVectorToScreen( const refdef_t *rd, const vec3_t in, vec2_t out Matrix4_Multiply_Vector( m, temp, temp2 ); Matrix4_Multiply_Vector( p, temp2, temp ); - if( !temp[3] ) + if( !temp[3] ) { + TracyCZoneEnd( ctx ); return; + } out[0] = rd->x + ( temp[0] / temp[3] + 1.0f ) * rd->width * 0.5f; out[1] = rsh.swapchain.height - ( rd->y + ( temp[1] / temp[3] + 1.0f ) * rd->height * 0.5f ); + TracyCZoneEnd( ctx ); } bool RF_LerpTag( orientation_t *orient, const model_t *mod, int oldframe, int frame, float lerpfrac, const char *name ) { - if( !orient ) + bool ret; + TracyCZoneN( ctx, "RF_LerpTag", 1 ); + + if( !orient ) { + TracyCZoneEnd( ctx ); return false; + } VectorClear( orient->origin ); Matrix3_Identity( orient->axis ); - if( !name ) + if( !name ) { + TracyCZoneEnd( ctx ); return false; + } - if( mod->type == mod_alias ) - return R_AliasModelLerpTag( orient, (const maliasmodel_t *)mod->extradata, oldframe, frame, lerpfrac, name ); + if( mod->type == mod_alias ) { + ret = R_AliasModelLerpTag( orient, (const maliasmodel_t *)mod->extradata, oldframe, frame, lerpfrac, name ); + TracyCZoneEnd( ctx ); + return ret; + } + TracyCZoneEnd( ctx ); return false; } void RF_LightForOrigin( const vec3_t origin, vec3_t dir, vec4_t ambient, vec4_t diffuse, float radius ) { + TracyCZoneN( ctx, "RF_LightForOrigin", 1 ); R_LightForOrigin( origin, dir, ambient, diffuse, radius, false ); + TracyCZoneEnd( ctx ); } /* diff --git a/source/ref_nri/r_image.c b/source/ref_nri/r_image.c index 6862c636cd..de255cd01e 100644 --- a/source/ref_nri/r_image.c +++ b/source/ref_nri/r_image.c @@ -662,7 +662,7 @@ static bool R_IsKTXFormatValid( int format, int type ) // TODO: move ktx loader to a seperate file static bool __R_LoadKTX( image_t *image, const char *pathname ) { - TracyCZone( ctx, 1 ); + TracyCZoneN( ctx, "__R_LoadKTX", 1 ); const uint_fast16_t numFaces = ( ( image->flags & IT_CUBEMAP ) ? 6 : 1 ); if( image->flags & ( IT_FLIPX | IT_FLIPY | IT_FLIPDIAGONAL ) ) return false; @@ -976,7 +976,7 @@ static uint16_t __R_calculateMipMapLevel( int flags, int width, int height, uint struct image_s *R_LoadImage( const char *name, uint8_t **pic, int width, int height, int flags, int minmipsize, int tags, int samples ) { - TracyCZone( ctx, 1 ); + TracyCZoneN( ctx, "R_LoadImage", 1 ); struct image_s *image = __R_AllocImage( qCToStrRef( name ) ); image->width = width; @@ -1113,7 +1113,7 @@ image_t *R_CreateImage( const char *name, int width, int height, int layers, int static void __FreeImage( struct image_s *image ) { - TracyCZone( ctx, 1 ); + TracyCZoneN( ctx, "__FreeImage", 1 ); { __FreeGPUImageData( image ); // R_ReleaseNriTexture(image); @@ -1148,7 +1148,7 @@ static void __FreeImage( struct image_s *image ) void R_ReplaceImage( image_t *image, uint8_t **pic, int width, int height, int flags, int minmipsize, int samples ) { - TracyCZone( ctx, 1 ); + TracyCZoneN( ctx, "R_ReplaceImage", 1 ); assert( image ); // const NriTextureDesc *textureDesc = rsh.nri.coreI.GetTextureDesc( image->texture ); uint32_t mipNum = __R_calculateMipMapLevel( flags, width, height, minmipsize ); @@ -1232,7 +1232,7 @@ void R_ReplaceImage( image_t *image, uint8_t **pic, int width, int height, int f */ void R_ReplaceSubImage( image_t *image, int layer, int x, int y, uint8_t **pic, int width, int height ) { - TracyCZone( ctx, 1 ); + TracyCZoneN( ctx, "R_ReplaceSubImage", 1 ); assert( image ); const size_t reservedSize = width * height * image->samples; @@ -1279,7 +1279,7 @@ void R_ReplaceSubImage( image_t *image, int layer, int x, int y, uint8_t **pic, */ void R_ReplaceImageLayer( image_t *image, int layer, uint8_t **pic ) { - TracyCZone( ctx, 1 ); + TracyCZoneN( ctx, "R_ReplaceImageLayer", 1 ); assert( image ); // assert( image->texture ); @@ -1330,7 +1330,7 @@ void R_ReplaceImageLayer( image_t *image, int layer, uint8_t **pic ) */ image_t *R_FindImage( const char *name, const char *suffix, int flags, int minmipsize, int tags ) { - TracyCZone( ctx, 1 ); + TracyCZoneN( ctx, "R_FindImage", 1 ); assert( name ); assert( name[0] ); struct UploadImgBuffer { @@ -1905,7 +1905,7 @@ void R_TouchImage( image_t *image, int tags ) */ void R_FreeUnusedImagesByTags( int tags ) { - TracyCZone( ctx, 1 ); + TracyCZoneN( ctx, "R_FreeUnusedImagesByTags", 1 ); int i; image_t *image; int keeptags = ~tags; @@ -1944,7 +1944,7 @@ void R_FreeUnusedImages( void ) */ void R_ShutdownImages( void ) { - TracyCZone( ctx, 1 ); + TracyCZoneN( ctx, "R_ShutdownImages", 1 ); int i; image_t *image; diff --git a/source/ref_nri/r_main.c b/source/ref_nri/r_main.c index 2f8ef802b8..de68bcc789 100644 --- a/source/ref_nri/r_main.c +++ b/source/ref_nri/r_main.c @@ -26,6 +26,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "ri_conversion.h" #include +#include "tracy/TracyC.h" + r_globals_t rf; mapconfig_t mapConfig; @@ -1137,6 +1139,7 @@ void R_RenderView(struct FrameState_s* frame, const refdef_t *fd ) { int msec = 0; bool shadowMap = rn.renderFlags & RF_SHADOWMAPVIEW ? true : false; + TracyCZoneN( ctx, "R_RenderView", 1 ); rn.refdef = *fd; rn.numVisSurfaces = 0; @@ -1173,8 +1176,10 @@ void R_RenderView(struct FrameState_s* frame, const refdef_t *fd ) R_ClearDrawList( rn.portalmasklist ); - if( !rsh.worldModel && !( rn.refdef.rdflags & RDF_NOWORLDMODEL ) ) + if( !rsh.worldModel && !( rn.refdef.rdflags & RDF_NOWORLDMODEL ) ) { + TracyCZoneEnd( ctx ); return; + } R_SetupFrame(); @@ -1186,15 +1191,16 @@ void R_RenderView(struct FrameState_s* frame, const refdef_t *fd ) if( !shadowMap ) { if( r_speeds->integer ) msec = ri.Sys_Milliseconds(); - R_MarkLeaves(); + R_MarkLeaves(); if( r_speeds->integer ) rf.stats.t_mark_leaves += ( ri.Sys_Milliseconds() - msec ); if( ! ( rn.refdef.rdflags & RDF_NOWORLDMODEL ) ) { - R_DrawWorld(); + R_DrawWorld(); if( !rn.numVisSurfaces ) { // no world surfaces visible + TracyCZoneEnd( ctx ); return; } @@ -1205,14 +1211,14 @@ void R_RenderView(struct FrameState_s* frame, const refdef_t *fd ) if( r_speeds->integer ) msec = ri.Sys_Milliseconds(); - R_DrawPolys(); + R_DrawPolys(); if( r_speeds->integer ) rf.stats.t_add_polys += ( ri.Sys_Milliseconds() - msec ); } if( r_speeds->integer ) msec = ri.Sys_Milliseconds(); - R_DrawEntities(); + R_DrawEntities(); if( r_speeds->integer ) rf.stats.t_add_entities += ( ri.Sys_Milliseconds() - msec ); @@ -1224,24 +1230,26 @@ void R_RenderView(struct FrameState_s* frame, const refdef_t *fd ) R_SetupViewMatrices(); // render to depth textures, mark shadowed entities and surfaces - R_DrawShadowmaps(frame); + R_DrawShadowmaps(frame); } - R_SortDrawList( rn.meshlist ); + R_SortDrawList( rn.meshlist ); R_SetupGL(frame); - R_DrawPortals(frame); + R_DrawPortals(frame); - if( r_portalonly->integer && !( rn.renderFlags & ( RF_MIRRORVIEW|RF_PORTALVIEW ) ) ) + if( r_portalonly->integer && !( rn.renderFlags & ( RF_MIRRORVIEW|RF_PORTALVIEW ) ) ) { + TracyCZoneEnd( ctx ); return; + } R_Clear(frame, ~0 ); if( r_speeds->integer ) msec = ri.Sys_Milliseconds(); - - R_DrawSurfaces(frame, rn.meshlist ); + + R_DrawSurfaces(frame, rn.meshlist ); if( r_speeds->integer ) rf.stats.t_draw_meshes += ( ri.Sys_Milliseconds() - msec ); @@ -1258,6 +1266,8 @@ void R_RenderView(struct FrameState_s* frame, const refdef_t *fd ) R_TransformForWorld(); R_EndGL(frame); + + TracyCZoneEnd( ctx ); } #define REFINST_STACK_SIZE 64 diff --git a/source/ref_nri/r_mesh.c b/source/ref_nri/r_mesh.c index 544a76fd24..43479f262a 100644 --- a/source/ref_nri/r_mesh.c +++ b/source/ref_nri/r_mesh.c @@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // r_mesh.c: transformation and sorting #include "r_local.h" +#include "tracy/TracyC.h" drawList_t r_worldlist; drawList_t r_shadowlist; @@ -406,6 +407,7 @@ static const batchDrawSurf_cb r_batchDrawSurfCb[ST_MAX_TYPES] = */ static void _R_DrawSurfaces(struct FrameState_s* frame, drawList_t *list ) { + TracyCZoneN( ctx, "_R_DrawSurfaces", 1 ); unsigned int i; unsigned int sortKey; unsigned int shaderNum = 0, prevShaderNum = MAX_SHADERS; @@ -430,6 +432,7 @@ static void _R_DrawSurfaces(struct FrameState_s* frame, drawList_t *list ) unsigned int shadowBits = 0; if( !list->numDrawSurfs ) { + TracyCZoneEnd( ctx ); return; } @@ -589,6 +592,7 @@ static void _R_DrawSurfaces(struct FrameState_s* frame, drawList_t *list ) if( cullHack ) { RB_FlipFrontFace(frame); } + TracyCZoneEnd( ctx ); } /* diff --git a/source/ref_nri/r_model.c b/source/ref_nri/r_model.c index bd5825af65..50c184cae2 100644 --- a/source/ref_nri/r_model.c +++ b/source/ref_nri/r_model.c @@ -1289,7 +1289,7 @@ static void R_FinishMapConfig( const model_t *mod ) */ void R_RegisterWorldModel( const char *model, const dvis_t *pvsData ) { - TracyCZone( ctx, 1 ); + TracyCZoneN( ctx, "R_RegisterWorldModel", 1 ); r_prevworldmodel = rsh.worldModel; rsh.worldModel = NULL; rsh.worldBrushModel = NULL; diff --git a/source/ref_nri/r_program.c b/source/ref_nri/r_program.c index 0a9d5978e6..2188c7fb35 100644 --- a/source/ref_nri/r_program.c +++ b/source/ref_nri/r_program.c @@ -31,6 +31,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include "r_vattribs.h" +#include "tracy/TracyC.h" #include "ri_conversion.h" #include "ri_renderer.h" @@ -84,6 +85,7 @@ static glslang_stage_t __RP_GLStageToSlang( glsl_program_stage_t stage ) */ void RP_Init( void ) { + TracyCZoneN( ctx, "RP_Init", 1 ); glslang_initialize_process(); memset( r_glslprograms, 0, sizeof( r_glslprograms ) ); memset( r_glslprograms_hash, 0, sizeof( r_glslprograms_hash ) ); @@ -104,6 +106,7 @@ void RP_Init( void ) RP_RegisterProgram( GLSL_PROGRAM_TYPE_COLORCORRECTION, DEFAULT_GLSL_COLORCORRECTION_PROGRAM, NULL, NULL, 0, 0 ); // check whether compilation of the shader with GPU skinning succeeds, if not, disable GPU bone transforms RP_RegisterProgram( GLSL_PROGRAM_TYPE_MATERIAL, DEFAULT_GLSL_MATERIAL_PROGRAM, NULL, NULL, 0, GLSL_SHADER_COMMON_BONE_TRANSFORMS1 ); + TracyCZoneEnd( ctx ); } typedef struct { @@ -219,6 +222,7 @@ void RP_StorePrecacheList( void ) {} static void RF_DeleteProgram( struct glsl_program_s *program ) { struct glsl_program_s *hash_next; + TracyCZoneN( ctx, "RF_DeleteProgram", 1 ); if( program->name ) R_Free( program->name ); @@ -248,6 +252,7 @@ static void RF_DeleteProgram( struct glsl_program_s *program ) hash_next = program->hash_next; memset( program, 0, sizeof( struct glsl_program_s ) ); program->hash_next = hash_next; + TracyCZoneEnd( ctx ); } #define MAX_DEFINES_FEATURES 255 @@ -947,9 +952,11 @@ static int __VK_SortVkVertexInputAttributeDescription( const void *a1, const voi void RP_BindPipeline( struct FrameState_s *cmd, struct pipeline_hash_s *pipeline ) { + TracyCZoneN( ctx, "RP_BindPipeline", 1 ); #if ( DEVICE_IMPL_VULKAN ) vkCmdBindPipeline( cmd->handle.vk.cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->vk.handle ); #endif + TracyCZoneEnd( ctx ); } struct pipeline_hash_s *RP_ResolvePipeline( struct glsl_program_s *program, struct pipeline_desc_s *cmd ) @@ -1175,16 +1182,19 @@ bool RP_ProgramHasUniform( const struct glsl_program_s *program, const struct gl void RP_BindPushConstant( struct RIDevice_s *device, struct FrameState_s *cmd, struct glsl_program_s *program, void *data, size_t len ) { + TracyCZoneN( ctx, "RP_BindPushConstant", 1 ); #if ( DEVICE_IMPL_VULKAN ) { assert( len <= program->vk.pushConstant.size ); vkCmdPushConstants( cmd->handle.vk.cmd, program->vk.pipelineLayout, program->vk.pushConstant.shaderStageFlags, 0, program->vk.pushConstant.size, data ); } #endif + TracyCZoneEnd( ctx ); } void RP_BindDescriptorSets( struct RIDevice_s *device, struct FrameState_s *cmd, struct glsl_program_s *program, struct glsl_descriptor_binding_s *bindings, size_t numDescriptorData ) { + TracyCZoneN( ctx, "RP_BindDescriptorSets", 1 ); #if ( DEVICE_IMPL_VULKAN ) { size_t numWrites = 0; @@ -1252,10 +1262,12 @@ void RP_BindDescriptorSets( struct RIDevice_s *device, struct FrameState_s *cmd, } } #endif + TracyCZoneEnd( ctx ); } struct glsl_program_s *RP_ResolveProgram( int type, const char *name, const char *deformsKey, const deformv_t *deforms, int numDeforms, r_glslfeat_t features ) { + TracyCZoneN( ctx, "RP_ResolveProgram", 1 ); assert( type > GLSL_PROGRAM_TYPE_NONE && type < GLSL_PROGRAM_TYPE_MAXTYPE ); assert( !deforms || deformsKey ); @@ -1265,12 +1277,14 @@ struct glsl_program_s *RP_ResolveProgram( int type, const char *name, const char const uint64_t hashIndex = hash_u64( HASH_INITIAL_VALUE, features ) % GLSL_PROGRAMS_HASH_SIZE; for( struct glsl_program_s *program = r_glslprograms_hash[type][hashIndex]; program; program = program->hash_next ) { if( ( program->features == features ) && strcmp( program->deformsKey, deformsKey ) == 0 ) { + TracyCZoneEnd( ctx ); return program; } } if( r_numglslprograms == MAX_GLSL_PROGRAMS ) { Com_Printf( S_COLOR_YELLOW "RP_RegisterProgram: GLSL programs limit exceeded\n" ); + TracyCZoneEnd( ctx ); return NULL; } @@ -1291,11 +1305,16 @@ struct glsl_program_s *RP_ResolveProgram( int type, const char *name, const char name = parent->name; } else { Com_Printf( S_COLOR_YELLOW "RP_RegisterProgram: failed to find parent for program type %i\n", type ); + TracyCZoneEnd( ctx ); return 0; } } - return RP_RegisterProgram( type, name, deformsKey, deforms, numDeforms, features ); + { + struct glsl_program_s *ret = RP_RegisterProgram( type, name, deformsKey, deforms, numDeforms, features ); + TracyCZoneEnd( ctx ); + return ret; + } } #if ( DEVICE_IMPL_VULKAN ) @@ -1348,6 +1367,7 @@ void _vk__descriptorSetAlloc( struct RIDevice_s *device, struct DescriptorSetAll struct glsl_program_s *RP_RegisterProgram( int type, const char *name, const char *deformsKey, const deformv_t *deforms, int numDeforms, r_glslfeat_t features ) { + TracyCZoneN( ctx, "RP_RegisterProgram", 1 ); const uint64_t hashIndex = hash_u64( HASH_INITIAL_VALUE, features ) % GLSL_PROGRAMS_HASH_SIZE; struct glsl_program_s *program = r_glslprograms + r_numglslprograms++; struct QStr featuresStr = { 0 }; @@ -1771,6 +1791,7 @@ struct glsl_program_s *RP_RegisterProgram( int type, const char *name, const cha r_glslprograms_hash[type][hashIndex] = program; } + TracyCZoneEnd( ctx ); return program; } /* @@ -1780,6 +1801,7 @@ void RP_Shutdown( void ) { unsigned int i; struct glsl_program_s *program; + TracyCZoneN( ctx, "RP_Shutdown", 1 ); for( i = 0, program = r_glslprograms; i < r_numglslprograms; i++, program++ ) { RF_DeleteProgram( program ); @@ -1789,4 +1811,5 @@ void RP_Shutdown( void ) glsl_cache_trie = NULL; r_numglslprograms = 0; + TracyCZoneEnd( ctx ); } diff --git a/source/ref_nri/r_scene.c b/source/ref_nri/r_scene.c index 6fe375a5fa..8460ac94d3 100644 --- a/source/ref_nri/r_scene.c +++ b/source/ref_nri/r_scene.c @@ -29,6 +29,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "ri_vk.h" #include "ri_swapchain.h" +#include "tracy/TracyC.h" + static void R_RenderDebugBounds( struct FrameState_s* frame); /* @@ -297,6 +299,8 @@ void R_RenderScene(const refdef_t *fd ) if( r_norefresh->integer ) return; + TracyCZoneN( ctx, "R_RenderScene", 1 ); + R_Set2DMode(&rsh.frame, false ); RB_SetTime( fd->time ); @@ -397,9 +401,9 @@ void R_RenderScene(const refdef_t *fd ) .height = fd->scissor_height } ); - R_BuildShadowGroups(); + R_BuildShadowGroups(); - R_RenderView(&rsh.frame, fd ); + R_RenderView(&rsh.frame, fd ); R_RenderDebugSurface( &rsh.frame, fd ); @@ -476,6 +480,8 @@ void R_RenderScene(const refdef_t *fd ) FR_CmdSetScissor(&rsh.frame, prevScissor); R_Set2DMode( &rsh.frame, true ); + + TracyCZoneEnd( ctx ); } void R_AddDebugBounds( const vec3_t mins, const vec3_t maxs, const byte_vec4_t color ) diff --git a/source/ref_nri/r_texture_buffer_load.c b/source/ref_nri/r_texture_buffer_load.c index 97a481a630..c48d22f2a0 100644 --- a/source/ref_nri/r_texture_buffer_load.c +++ b/source/ref_nri/r_texture_buffer_load.c @@ -12,7 +12,7 @@ static uint32_t pallet[256]; bool T_LoadImagePCX(char *filename, struct texture_buf_s* buffer, uint8_t** pallet) { - TracyCZone(ctx, 1); + TracyCZoneN( ctx, "T_LoadImagePCX", 1 ); void* const raw; size_t len = R_LoadFile( filename, (void **)&raw ); if(raw == NULL) { @@ -117,7 +117,7 @@ static void __R_stbi_free_image(void* p) { } bool T_LoadImageSTBI(char *filename, struct texture_buf_s* buffer ) { - TracyCZone(ctx, 1); + TracyCZoneN( ctx, "T_LoadImageSTBI", 1 ); uint8_t* data; size_t size = R_LoadFile( filename, ( void ** ) &data ); if(data == NULL) { @@ -172,7 +172,7 @@ uint32_t* T_Pallet() { //https://developer.valvesoftware.com/wiki/WAL bool T_LoadImageWAL(char *filename, struct texture_buf_s* tex) { - TracyCZone(ctx, 1); + TracyCZoneN( ctx, "T_LoadImageWAL", 1 ); // load the file uint8_t* const buf = NULL; const size_t size = R_LoadFile( filename, (void **)&buf); diff --git a/source/server/CMakeLists.txt b/source/server/CMakeLists.txt index 0e1c36b0d9..c20db76589 100644 --- a/source/server/CMakeLists.txt +++ b/source/server/CMakeLists.txt @@ -94,7 +94,7 @@ add_dependencies(${QFUSION_SERVER_NAME} angelwrap game) if (BUILD_STEAMLIB) add_dependencies(${QFUSION_SERVER_NAME} wf_steam) endif() -target_link_libraries(${QFUSION_SERVER_NAME} PRIVATE qcore CURL::libcurl ${SERVER_PLATFORM_LIBRARIES} ${STEAMSHIMPARENT_LIBRARY}) +target_link_libraries(${QFUSION_SERVER_NAME} PRIVATE qcore CURL::libcurl ${SERVER_PLATFORM_LIBRARIES} ${STEAMSHIMPARENT_LIBRARY} Tracy::TracyClient) if (USE_CRASHPAD) target_link_libraries(${QFUSION_SERVER_NAME} PRIVATE crashpad_client) diff --git a/source/server/sv_main.c b/source/server/sv_main.c index c96f5e7f50..0c9fde9148 100644 --- a/source/server/sv_main.c +++ b/source/server/sv_main.c @@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "server.h" #include "../qcommon/steam.h" #include "../steamshim/src/mod_steam.h" +#include "tracy/TracyC.h" static bool sv_initialized = false; mempool_t *sv_mempool; @@ -109,6 +110,7 @@ static void SV_CalcPings( void ) unsigned int i, j; client_t *cl; unsigned int total, count, lat, best; + TracyCZoneN( ctx, "SV_CalcPings", 1 ); for( i = 0; i < (unsigned int)sv_maxclients->integer; i++ ) { @@ -145,6 +147,7 @@ static void SV_CalcPings( void ) // let the game dll know about the ping cl->edict->r.client->r.ping = cl->ping; } + TracyCZoneEnd( ctx ); } /* @@ -279,6 +282,7 @@ static void SV_ReadPackets( void ) { int i, socketind, ret; client_t *cl; + TracyCZoneN( ctx, "SV_ReadPackets", 1 ); #ifdef TCP_ALLOW_CONNECT socket_t newsocket; #endif @@ -486,6 +490,7 @@ static void SV_ReadPackets( void ) } } + TracyCZoneEnd( ctx ); } /* @@ -503,6 +508,7 @@ static void SV_CheckTimeouts( void ) { client_t *cl; int i; + TracyCZoneN( ctx, "SV_CheckTimeouts", 1 ); #ifdef TCP_ALLOW_CONNECT // timeout incoming connections @@ -553,6 +559,7 @@ static void SV_CheckTimeouts( void ) SV_ClientCloseDownload( cl ); } } + TracyCZoneEnd( ctx ); } /* @@ -567,6 +574,7 @@ static void SV_CheckLatchedUserinfoChanges( void ) client_t *cl; int i; unsigned int time = Sys_Milliseconds(); + TracyCZoneN( ctx, "SV_CheckLatchedUserinfoChanges", 1 ); for( i = 0, cl = svs.clients; i < sv_maxclients->integer; i++, cl++ ) { @@ -582,6 +590,7 @@ static void SV_CheckLatchedUserinfoChanges( void ) SV_UserinfoChanged( cl ); } } + TracyCZoneEnd( ctx ); } //#define WORLDFRAMETIME 25 // 40fps @@ -597,6 +606,8 @@ static bool SV_RunGameFrame( int msec ) bool refreshGameModule; bool sentFragments; + TracyCZoneN( ctx, "SV_RunGameFrame", 1 ); + accTime += msec; refreshSnapshot = false; @@ -688,9 +699,11 @@ static bool SV_RunGameFrame( int msec ) sv.nextSnapTime = svs.gametime + ( svc.snapFrameTime - extraSnapTime ); + TracyCZoneEnd( ctx ); return true; } + TracyCZoneEnd( ctx ); return false; } @@ -779,6 +792,8 @@ void SV_Frame( int realmsec, int gamemsec ) return; } + TracyCZoneN( ctx, "SV_Frame_active", 1 ); + svs.realtime += realmsec; svs.gametime += gamemsec; @@ -787,6 +802,7 @@ void SV_Frame( int realmsec, int gamemsec ) { Cbuf_AddText( "wait; vstr nextmap\n" ); SV_ShutdownGame( "Restarting server due to time wrapping", true ); + TracyCZoneEnd( ctx ); return; } @@ -828,6 +844,8 @@ void SV_Frame( int realmsec, int gamemsec ) SV_Web_GameFrame( ge->WebRequest ); SV_CheckPostUpdateRestart(); + + TracyCZoneEnd( ctx ); } //============================================================================ diff --git a/source/server/sv_send.c b/source/server/sv_send.c index e58dacaadd..d50c9e06d7 100644 --- a/source/server/sv_send.c +++ b/source/server/sv_send.c @@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // sv_main.c -- server main program #include "server.h" +#include "tracy/TracyC.h" // shared message buffer to be used for occasional messages msg_t tmpMessage; @@ -429,6 +430,8 @@ void SV_SendClientMessages( void ) int i; client_t *client; + TracyCZoneN( ctx, "SV_SendClientMessages_loop", 1 ); + // send a message to each connected client for( i = 0, client = svs.clients; i < sv_maxclients->integer; i++, client++ ) { @@ -475,4 +478,6 @@ void SV_SendClientMessages( void ) } } } + + TracyCZoneEnd( ctx ); } diff --git a/source/snd_openal/CMakeLists.txt b/source/snd_openal/CMakeLists.txt index 123d9060f4..6e3684d50e 100644 --- a/source/snd_openal/CMakeLists.txt +++ b/source/snd_openal/CMakeLists.txt @@ -25,5 +25,5 @@ else () endif() add_library(snd_openal SHARED ${SND_OPENAL_HEADERS} ${SND_OPENAL_SOURCES}) -target_link_libraries(snd_openal PRIVATE ogg vorbis vorbisfile OpenAL::OpenAL ${SND_OPENAL_PLATFORM_LIBRARIES}) +target_link_libraries(snd_openal PRIVATE ogg vorbis vorbisfile OpenAL::OpenAL ${SND_OPENAL_PLATFORM_LIBRARIES} Tracy::TracyClient) qf_set_output_dir(snd_openal libs) diff --git a/source/snd_openal/snd_al.c b/source/snd_openal/snd_al.c index da202319f2..076844db8e 100644 --- a/source/snd_openal/snd_al.c +++ b/source/snd_openal/snd_al.c @@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "snd_local.h" #include "snd_cmdque.h" +#include "tracy/TracyC.h" ALCdevice *alDevice = NULL; ALCcontext *alContext = NULL; @@ -358,8 +359,9 @@ static void S_SetListener( const vec3_t origin, const vec3_t velocity, const mat */ static void S_Update( void ) { + TracyCZoneN( ctx, "S_Update", 1 ); S_UpdateMusic(); - + S_UpdateStreams(); s_volume->modified = false; // Checked by src and stream @@ -381,6 +383,7 @@ static void S_Update( void ) qalSpeedOfSound( s_sound_velocity->value > 0.0f ? s_sound_velocity->value : 0.0f ); s_sound_velocity->modified = false; } + TracyCZoneEnd( ctx ); } /* diff --git a/source/snd_openal/snd_sources.c b/source/snd_openal/snd_sources.c index f38a37abfc..75c7aec8e4 100644 --- a/source/snd_openal/snd_sources.c +++ b/source/snd_openal/snd_sources.c @@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "snd_local.h" +#include "tracy/TracyC.h" #ifdef __MACOSX__ #define MAX_SRC 64 @@ -298,6 +299,7 @@ void S_UpdateSources( void ) { int i, entNum; ALint state; + TracyCZoneN( ctx, "S_UpdateSources", 1 ); for( i = 0; i < src_count; i++ ) { @@ -338,6 +340,7 @@ void S_UpdateSources( void ) source_spatialize( &srclist[i] ); } + TracyCZoneEnd( ctx ); } /* diff --git a/source/snd_openal/snd_stream.c b/source/snd_openal/snd_stream.c index e617ffc0a5..6fc16d5701 100644 --- a/source/snd_openal/snd_stream.c +++ b/source/snd_openal/snd_stream.c @@ -22,6 +22,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "snd_local.h" +#include "tracy/TracyC.h" typedef struct { @@ -161,6 +162,7 @@ void S_UpdateStreams( void ) { int i; rawsrc_t *rs; + TracyCZoneN( ctx, "S_UpdateStreams", 1 ); for( i = 0; i < MAX_RAW_SOUNDS; i++ ) { @@ -168,13 +170,14 @@ void S_UpdateStreams( void ) if( !rs->src ) { continue; } - + update_rawsound( rs ); if( !rs->src->isActive ) { memset( rs, 0, sizeof( *rs ) ); } } + TracyCZoneEnd( ctx ); } void S_StopStreams( void ) diff --git a/source/steamshim/CMakeLists.txt b/source/steamshim/CMakeLists.txt index 438ab2b9e7..942868e6f3 100644 --- a/source/steamshim/CMakeLists.txt +++ b/source/steamshim/CMakeLists.txt @@ -55,6 +55,7 @@ file(GLOB parent_SRC ) add_library(steamshim_parent STATIC ${parent_SRC}) +target_link_libraries(steamshim_parent PRIVATE Tracy::TracyClient) qf_set_output_dir(steamshim_parent libs) file(GLOB child_SRC diff --git a/source/steamshim/src/parent/parent.cpp b/source/steamshim/src/parent/parent.cpp index 21c0496013..8a47f6b076 100644 --- a/source/steamshim/src/parent/parent.cpp +++ b/source/steamshim/src/parent/parent.cpp @@ -34,6 +34,8 @@ freely, subject to the following restrictions: #include "../mod_steam.h" +#include "tracy/TracyC.h" + int GArgc = 0; char **GArgv = NULL; @@ -63,15 +65,19 @@ std::mutex writeGuard; int STEAMSHIM_dispatch() { + TracyCZoneN( ctx, "STEAMSHIM_dispatch", 1 ); // struct steam_packet_buf packet; uint32_t syncIndex = 0; // size_t cursor = 0; struct steam_rpc_shim_common_s pkt; pkt.cmd = RPC_PUMP; if( STEAMSHIM_sendRPC( &pkt, sizeof( steam_rpc_shim_common_s ), NULL, NULL, &syncIndex ) < 0 ) { + TracyCZoneEnd( ctx ); return -1; } - return STEAMSHIM_waitDispatchSync( syncIndex ); + int result = STEAMSHIM_waitDispatchSync( syncIndex ); + TracyCZoneEnd( ctx ); + return result; } static bool setEnvironmentVars( PipeType pipeChildRead, PipeType pipeChildWrite ) @@ -177,20 +183,26 @@ void STEAMSHIM_deinit( void ) bool STEAMSHIM_active() { - return ( ( GPipeRead != NULLPIPE ) && ( GPipeWrite != NULLPIPE ) ); + TracyCZoneN( ctx, "STEAMSHIM_active", 1 ); + bool result = ( ( GPipeRead != NULLPIPE ) && ( GPipeWrite != NULLPIPE ) ); + TracyCZoneEnd( ctx ); + return result; } int STEAMSHIM_sendEVT( void *packet, uint32_t size ) { + TracyCZoneN( ctx, "STEAMSHIM_sendEVT", 1 ); writeGuard.lock(); writePipe( GPipeWrite, &size, sizeof( uint32_t ) ); writePipe( GPipeWrite, (uint8_t *)packet, size ); writeGuard.unlock(); + TracyCZoneEnd( ctx ); return 0; } int STEAMSHIM_sendRPC( void *packet, uint32_t size, void *self, STEAMSHIM_rpc_handle rpc, uint32_t *sync ) { + TracyCZoneN( ctx, "STEAMSHIM_sendRPC", 1 ); uint32_t syncIndex = ++SyncToken; if( sync ) { ( *sync ) = syncIndex; @@ -207,12 +219,15 @@ int STEAMSHIM_sendRPC( void *packet, uint32_t size, void *self, STEAMSHIM_rpc_ha writePipe( GPipeWrite, &size, sizeof( uint32_t ) ); writePipe( GPipeWrite, (uint8_t *)packet, size ); writeGuard.unlock(); + TracyCZoneEnd( ctx ); return 0; } int STEAMSHIM_waitDispatchSync( uint32_t syncIndex ) { + TracyCZoneN( ctx, "STEAMSHIM_waitDispatchSync", 1 ); if( currentSync == syncIndex ) { + TracyCZoneEnd( ctx ); return 0; // can't wait on dispatch if there is no RPC's staged } static struct steam_packet_buf packet; @@ -223,12 +238,14 @@ int STEAMSHIM_waitDispatchSync( uint32_t syncIndex ) if( bytesRead > 0 ) { cursor += bytesRead; } else { + TracyCZoneEnd( ctx ); return -1; } continue_processing: if( packet.size > STEAM_PACKED_RESERVE_SIZE - sizeof( uint32_t ) ) { // the packet is larger then the reserved size + TracyCZoneEnd( ctx ); return -1; } @@ -263,10 +280,12 @@ int STEAMSHIM_waitDispatchSync( uint32_t syncIndex ) break; } } + TracyCZoneEnd( ctx ); return 0; } void STEAMSHIM_subscribeEvent( uint32_t id, void *self, STEAMSHIM_evt_handle evt ) { + TracyCZoneN( ctx, "STEAMSHIM_subscribeEvent", 1 ); assert( evt ); assert( id >= EVT_BEGIN && id < EVT_END ); struct event_subscriber_s *handle = evt_handles + ( id - EVT_BEGIN ); @@ -274,9 +293,11 @@ void STEAMSHIM_subscribeEvent( uint32_t id, void *self, STEAMSHIM_evt_handle evt size_t subIndex = handle->numSubscribers++; handle->handles[subIndex].self = self; handle->handles[subIndex].cb = evt; + TracyCZoneEnd( ctx ); } void STEAMSHIM_unsubscribeEvent( uint32_t id, STEAMSHIM_evt_handle cb ) { + TracyCZoneN( ctx, "STEAMSHIM_unsubscribeEvent", 1 ); assert( id >= EVT_BEGIN && id < EVT_END ); struct event_subscriber_s *handle = evt_handles + ( id - EVT_BEGIN ); size_t ib = 0; @@ -292,5 +313,6 @@ void STEAMSHIM_unsubscribeEvent( uint32_t id, STEAMSHIM_evt_handle cb ) continue; handle->handles[ib] = handle->handles[ic]; } + TracyCZoneEnd( ctx ); } } diff --git a/source/tv_server/CMakeLists.txt b/source/tv_server/CMakeLists.txt index 3c17bae710..77cc12a536 100644 --- a/source/tv_server/CMakeLists.txt +++ b/source/tv_server/CMakeLists.txt @@ -86,7 +86,7 @@ else() endif() add_executable(${QFUSION_TVSERVER_NAME} ${TV_SERVER_BINARY_TYPE} ${TV_SERVER_HEADERS} ${TV_SERVER_SOURCES} ${TV_SERVER_PLATFORM_SOURCES}) -target_link_libraries(${QFUSION_TVSERVER_NAME} PRIVATE qcore CURL::libcurl ${TV_SERVER_PLATFORM_LIBRARIES} ${STEAMSHIMPARENT_LIBRARY}) +target_link_libraries(${QFUSION_TVSERVER_NAME} PRIVATE qcore CURL::libcurl ${TV_SERVER_PLATFORM_LIBRARIES} ${STEAMSHIMPARENT_LIBRARY} Tracy::TracyClient) if (USE_CRASHPAD) target_link_libraries(${QFUSION_TVSERVER_NAME} PRIVATE crashpad_client) endif()