Skip to content

feat(profiling): Integrate Tracy profiler#2202

Merged
xezon merged 9 commits intoTheSuperHackers:mainfrom
stephanmeesters:tracy-profiler
Apr 27, 2026
Merged

feat(profiling): Integrate Tracy profiler#2202
xezon merged 9 commits intoTheSuperHackers:mainfrom
stephanmeesters:tracy-profiler

Conversation

@stephanmeesters
Copy link
Copy Markdown

@stephanmeesters stephanmeesters commented Jan 27, 2026

Merge by rebase

This PR adds Tracy profiler to the CMake preset win32-profile.

Library include

Tracy is added as CMake FetchContent_Declare (version 0.13.1). 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 copying tracy-profiler.exe to the build dir, however we can not do this right now as it requires a 64 bit compile.

What are we tracing?

  • Frame markers (start-end of each frame)
  • Sections ("zones")
  • Logic frame number
  • Pathfinding count of paths and cells
  • Messages ("started game with map Alpine Assault" ..)

A very minimal set of sections are added as part of this PR.

Performance impact

Tracy itself has a negligible impact. The frame capturing does have a minor impact (0.5ms average per capture), but this does not capture on every frame unless configured to do so.

Future work

It should be determined whether this will be sufficient to replace the old profiling code.

Example of a capture. Render bound frame (top), update bound frame (bottom)

Note: image is outdated.

tracy-capture

Todo

  • Replicate to Generals
  • Add pull ID to the commits
  • Check that each commit compiles

stephanmeesters added a commit to stephanmeesters/GeneralsGameCode that referenced this pull request Jan 27, 2026
stephanmeesters added a commit to stephanmeesters/GeneralsGameCode that referenced this pull request Jan 27, 2026
stephanmeesters added a commit to stephanmeesters/GeneralsGameCode that referenced this pull request Jan 27, 2026
stephanmeesters added a commit to stephanmeesters/GeneralsGameCode that referenced this pull request Jan 27, 2026
stephanmeesters added a commit to stephanmeesters/GeneralsGameCode that referenced this pull request Jan 27, 2026
stephanmeesters added a commit to stephanmeesters/GeneralsGameCode that referenced this pull request Jan 27, 2026
@stephanmeesters stephanmeesters marked this pull request as ready for review January 27, 2026 22:29
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Jan 27, 2026

Greptile Summary

This PR integrates the Tracy profiler into the win32-profile CMake preset, replacing the legacy RTS_PROFILE define with RTS_PROFILE_LEGACY and adding a new RTS_PROFILE_TRACY path. It introduces a new W3DProfilerFrameCapture class that performs scaled-down back-buffer captures via a BGRA→RGBA pixel-shader swizzle, along with frame markers, zone sections, and plot instrumentation across GameClient, GameLogic, AIPathfind, and FrameRateLimit.

Confidence Score: 5/5

Safe to merge — no P0/P1 issues found; all previous review findings have been addressed.

All previously reported bugs (uninitialized pointers, missing null checks, incorrect Release() on non-AddRef'd Peek surface) are confirmed fixed. The new capture code handles every D3D failure path, COM refcounts are correct, and the BGRA→RGBA shader math is correct. The RTS_PROFILE → RTS_PROFILE_LEGACY rename is consistently applied across all 37 files.

No files require special attention.

Important Files Changed

Filename Overview
Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DProfilerFrameCapture.cpp New file implementing Tracy frame image capture with BGRA→RGBA pixel shader swizzle; null/error checks throughout, correct COM refcount handling.
Core/GameEngineDevice/Include/W3DDevice/GameClient/W3DProfilerFrameCapture.h New header for W3DProfilerFrameCapture, guarded by PROFILER_ENABLED, uses #pragma once, all members have default initializers.
Core/Libraries/Include/rts/profile.h Adds Tracy macro wrappers and no-op fallbacks; splits RTS_PROFILE_LEGACY and RTS_PROFILE_TRACY paths cleanly.
cmake/tracy.cmake New CMake module that fetches Tracy via FetchContent from TheSuperHackers fork at a pinned commit, validates the TracyClient target, and exposes core_profile_tracy alias.
cmake/config-build.cmake Adds RTS_BUILD_OPTION_PROFILE_TRACY option; renames RTS_PROFILE→RTS_PROFILE_LEGACY compile definition; creates a dummy interface target when Tracy is disabled.
Core/Libraries/Source/debug/debug.h Updates HAS_ASSERTS/HAS_LOGS guard from RTS_PROFILE to RTS_PROFILE_LEGACY; Tracy builds intentionally omit these (confirmed acceptable by team).
GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp Adds W3DProfilerFrameCapture construction/destruction and Capture() call per render frame, guarded by PROFILER_ENABLED.
Core/GameEngine/Source/GameLogic/AI/AIPathfind.cpp Lifts pathsFound counter out of DEBUG_QPF guard to enable Tracy PROFILER_PLOT instrumentation; semantically correct.
Core/Libraries/Source/WWVegas/WWLib/WWCommon.h Adds #include <rts/profile.h> to this fundamental header so that files which removed their direct include still compile; propagates the include broadly.

Sequence Diagram

sequenceDiagram
    participant WinMain
    participant GameClient
    participant GameLogic
    participant W3DDisplay
    participant W3DProfilerFrameCapture
    participant Tracy

    WinMain->>GameClient: update() [PROFILER_FRAME_MARK]
    GameClient->>Tracy: FrameMark (frame boundary)
    GameClient->>Tracy: ZoneScopedC (blue zone)

    GameClient->>GameLogic: update() [PROFILER_SECTION_COLOR green]
    GameLogic->>Tracy: ZoneScopedC (green zone)
    GameLogic->>Tracy: TracyPlot("LogicFrame", frame)
    GameLogic->>Tracy: TracyPlot("PathfindCells/Paths", counts)

    GameClient->>W3DDisplay: draw()
    W3DDisplay->>W3DProfilerFrameCapture: Capture(width, height)
    W3DProfilerFrameCapture->>Tracy: TracyIsConnected?
    alt connected
        W3DProfilerFrameCapture->>W3DProfilerFrameCapture: ShouldReuseLastCapture?
        alt reuse
            W3DProfilerFrameCapture->>Tracy: FrameImage(cached pixels)
        else capture
            W3DProfilerFrameCapture->>W3DProfilerFrameCapture: Compile swizzle shader BGRA to RGBA
            W3DProfilerFrameCapture->>W3DProfilerFrameCapture: Copy backbuffer to intermediate texture
            W3DProfilerFrameCapture->>W3DProfilerFrameCapture: Render scaled-down to render target
            W3DProfilerFrameCapture->>W3DProfilerFrameCapture: GPU to CPU copy via SurfaceClass lock
            W3DProfilerFrameCapture->>Tracy: FrameImage(pixels, width, height)
        end
    end
Loading

Reviews (18): Last reviewed commit: "docs(readme): Add section about profilin..." | Re-trigger Greptile

Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a 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

Edit Code Review Agent Settings | Greptile

Comment thread cmake/tracy.cmake Outdated
Comment thread Core/Libraries/Include/rts/profile.h Outdated
@Caball009
Copy link
Copy Markdown

Would you mind adding a few images or a short video to the first post?

@stephanmeesters
Copy link
Copy Markdown
Author

stephanmeesters commented Jan 29, 2026

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 -win otherwise the frame image capture will use your screen resolution and not the native game resolution so it's much slower... I've tested using 1080p

Nevermind I accidentally had DXVK DLL's in the binary dir and that changed the profile: the Render::VSync block was gone and the TracyFrameImage zone took longer to complete, while overall FPS was way up. I attributed whatever happened in the time after the rendering was complete to VSync but I'm not sure now.

stephanmeesters added a commit to stephanmeesters/GeneralsGameCode that referenced this pull request Feb 4, 2026
stephanmeesters added a commit to stephanmeesters/GeneralsGameCode that referenced this pull request Feb 4, 2026
stephanmeesters added a commit to stephanmeesters/GeneralsGameCode that referenced this pull request Feb 4, 2026
stephanmeesters added a commit to stephanmeesters/GeneralsGameCode that referenced this pull request Feb 4, 2026
stephanmeesters added a commit to stephanmeesters/GeneralsGameCode that referenced this pull request Feb 4, 2026
stephanmeesters added a commit to stephanmeesters/GeneralsGameCode that referenced this pull request Feb 4, 2026
Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

Comment thread GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DDisplay.h Outdated
Comment thread GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp Outdated
Comment thread GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp Outdated
Comment thread GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp Outdated
stephanmeesters added a commit to stephanmeesters/GeneralsGameCode that referenced this pull request Feb 4, 2026
stephanmeesters added a commit to stephanmeesters/GeneralsGameCode that referenced this pull request Feb 4, 2026
stephanmeesters added a commit to stephanmeesters/GeneralsGameCode that referenced this pull request Feb 4, 2026
stephanmeesters added a commit to stephanmeesters/GeneralsGameCode that referenced this pull request Feb 4, 2026
stephanmeesters added a commit to stephanmeesters/GeneralsGameCode that referenced this pull request Feb 4, 2026
stephanmeesters added a commit to stephanmeesters/GeneralsGameCode that referenced this pull request Feb 4, 2026
@xezon xezon added Enhancement Is new feature or request Major Severity: Minor < Major < Critical < Blocker Gen Relates to Generals labels Feb 23, 2026
Comment thread .github/workflows/ci.yml Outdated
Comment thread GeneralsMD/Code/GameEngineDevice/CMakeLists.txt Outdated
Copy link
Copy Markdown

@xezon xezon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this meant to be merged with Rebase? If yes, then the individual commits need polishing and testing that they all compile one after the other.

Comment thread GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp Outdated
@stephanmeesters
Copy link
Copy Markdown
Author

stephanmeesters commented Apr 26, 2026

Is this meant to be merged with Rebase?

Yes preferably, if it's alright with you I can tidy it up after the replicate to Generals? As I was planning to do the replicate per-commit as well.

testing that they all compile one after the other.

Tested that two days ago but will give a final check

Comment thread .github/workflows/ci.yml
Comment thread GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp Outdated
@xezon
Copy link
Copy Markdown

xezon commented Apr 26, 2026

Yes preferably, if it's alright with you I can tidy it up after the replicate to Generals?

Yes it is fine to commit small steps.

Comment thread cmake/tracy.cmake Outdated
stephanmeesters added a commit to stephanmeesters/GeneralsGameCode that referenced this pull request Apr 26, 2026
@stephanmeesters
Copy link
Copy Markdown
Author

stephanmeesters commented Apr 26, 2026

Switched to new fork, replicated to Generals, improved commit titles a bit and added pull ID, checked that each commit compiled, tested Tracy capture on ZH and Generals.

Replicate was done using the git diff, git apply approach. Also did a quick check that there were no dangling "rts_profile" and "core_profile" and "rts/profile.h".

@xezon xezon merged commit 9e8a445 into TheSuperHackers:main Apr 27, 2026
17 checks passed
xezon pushed a commit that referenced this pull request Apr 27, 2026
@stephanmeesters stephanmeesters deleted the tracy-profiler branch April 27, 2026 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Debug Is mostly debug functionality Enhancement Is new feature or request Gen Relates to Generals Major Severity: Minor < Major < Critical < Blocker ZH Relates to Zero Hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants