-
Notifications
You must be signed in to change notification settings - Fork 151
feat(profiling): Integrate Tracy profiler #2202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(profiling): Integrate Tracy profiler #2202
Conversation
12b8fbf to
8ede749
Compare
Greptile Overview
|
| Filename | Overview |
|---|---|
| cmake/tracy.cmake | added FetchContent configuration for Tracy v0.13.1, missing required header prologue |
| cmake/config-build.cmake | added RTS_BUILD_OPTION_PROFILE_TRACY option and conditional Tracy setup logic |
| Core/Libraries/Include/rts/profile.h | added Tracy header includes and macro stubs, TRACY_FRAMEIMAGE_SIZE defined in header instead of CMake |
| GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp | implemented Tracy frame capture with GPU downscaling and BGRA-to-RGBA pixel shader, added profiling zones |
| GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp | added Tracy zones to major game logic subsystems and plot for logic frame number |
| GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPathfind.cpp | added Tracy zones to pathfinding and plots for pathfinding cells/paths, removed DEBUG_QPF guards |
Sequence Diagram
sequenceDiagram
participant GC as GameClient
participant GL as GameLogic
participant D as Display
participant W3DD as W3DDisplay
participant W3DV as W3DView
participant W3DS as W3DScene
participant DX8 as DX8Wrapper
participant Tracy as Tracy Profiler
Note over GC: Game Loop Start
GC->>Tracy: FrameMark
GC->>Tracy: ZoneScopedNC("Render")
Note over GL: Logic Update
GL->>Tracy: ZoneScopedNC("GameLogic::update")
GL->>Tracy: TracyPlot("LogicFrame", frame)
GL->>GL: Update ScriptEngine, TerrainLogic, AI, etc
GL->>Tracy: Multiple ZoneScopedN for subsystems
Note over GC: Render Phase
GC->>D: DRAW()
D->>W3DD: draw()
W3DD->>Tracy: ZoneScopedN("Render::W3DDisplay::...")
W3DD->>W3DV: draw()
W3DV->>Tracy: ZoneScopedN("Render::DisplayDraw::W3DView")
W3DV->>W3DS: Render()
W3DS->>Tracy: ZoneScopedN("Render::W3DScene::...")
W3DS->>W3DS: Render scene passes
W3DD->>DX8: End_Render()
DX8->>Tracy: ZoneScopedN("Render::VSync")
DX8->>DX8: Present()
W3DD->>W3DD: TracyCaptureImage()
W3DD->>Tracy: ZoneScopedN("Render::W3DDisplay::TracyFrameImage")
W3DD->>DX8: Copy backbuffer to intermediate texture
W3DD->>DX8: Downscale with pixel shader (BGRA→RGBA)
W3DD->>Tracy: FrameImage(pixels, width, height)
Note over GC: Frame Complete
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 files reviewed, 2 comments
|
Would you mind adding a few images or a short video to the first post? |
Done. Added examples. I've noticed that it's important to use |
Merge by rebase
This PR adds Tracy profiler to the CMake presets
win32-profileandwin32-vcpkg-profile.A variable
RTS_BUILD_OPTION_PROFILE_TRACYis added to enable Tracy. Enabling this will disable the old profiler.It is not added to the
vc6-profilebecause Tracy library can't compile against it. The presetmingw-w64-i686-profileis also skipped as this preset does not build yet (see #2163).Library include
Tracy is added as a package to VCPKG (version 0.11.1) and as a CMake
FetchContent_Declare(version 0.13.1). These are the latest available versions at the time. Unfortunately the VCPKG is old, but the VCPKG Github has PR's going to update Tracy to the latest version. The version 0.13.1 improves coloring immensely, which is important for at a glance seeing if we are render-bound of update-bound.Tracy themselves recommend adding the library as a CMake include because the version of the library that is included in the game must match exactly with the version of their main executable
tracy-profiler.exe. This can be guaranteed by building and copyingtracy-profiler.exeto the build dir, however we can not do this right now as it requires a 64 bit compile.What are we tracing?
A number of zones were picked that capture the majority of processing time, and will hopefully be useful for profiling sessions.
Performance impact
Tracy itself has a negligible impact, however the frame capturing does have a minor impact (0.5ms average per frame). I have done my best to optimize the frame capturing by downscaling the backbuffer on the GPU side before copying to the CPU. It will be possible to simplify some of this code by moving from DX8 to DX9 and perhaps increase performance too.
Future work
It should be determined whether this will be sufficient to replace the old profiling code. At that point, and when all other profiles build, we can activate Tracy using only
RTS_BUILD_OPTION_PROFILE. Other interesting things to trace would be a plot of the memory usage.Todo
Example of a capture. Render bound frame (top), update bound frame (bottom)
