startup: optional Tracy zones for the stand-ins (off by default) #2363

Merged
NiiRoZz merged 1 commit from upstream-pr/2371 into main 2026-11-25 15:02:10 +00:00
NiiRoZz commented 2026-11-25 14:02:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T14:02:03Z.


Change

An optional -DX2W_TRACY=ON CMake option links d3d12_xs.dll, XCRDAPI.dll and xmem.dll against the Tracy client and turns on named zones and a frame mark in a few hot places of the stand-in runtime. It is a developer measurement build for finding where a run spends time, not a behavior change.

  • Off by default. No preset or workflow enables it. With the option off, nothing is fetched, defined or linked, and the X2W_ZONE/X2W_FRAME_MARK macros in src/startup_stubs/profile_zone.h expand to nothing.
  • Dependency policy. Tracy v0.15.0 (3-clause BSD) is fetched with FetchContent only when the option is on, pinned to commit f2a4f2529e7e71844c9e434b877770a21ecf7587. -DFETCHCONTENT_SOURCE_DIR_TRACY=<checkout> reuses an existing checkout and -DFETCHCONTENT_FULLY_DISCONNECTED=ON forbids any download. No Tracy source or binary is committed; the license note is in docs/startup-runtime.md.
  • Client settings. On-demand, TRACY_ONLY_LOCALHOST, TRACY_NO_BROADCAST, no call stacks, no system tracing, no crash handler.
  • Socket note. An instrumented process opens a TCP listener (port 8086 and up) on 127.0.0.1 only (checked by loading the ON TracyClient.dll and listing the process's listening sockets). This build must not be used where a run is meant to stay offline; the docs say so.
  • Zones (whole PR: 9 files, 69 lines added): ExecuteCommandLists, Present with a frame mark, the frame-wait sleep, window present, desktop pipeline creation, device_memory_srv and its four resource scans, each DirectStorage request, and the xmem page map and physical write.

AI-assisted (Claude Code); the commands below were run locally.

Verification

Base 43608f2e (origin/main), head dfa0195b. Windows 11 build 26300, MSVC 14.44, CMake 3.28, Ninja.

  • Default build: cmake --preset dev -DINTAKE_PYTHON=<venv python>, cmake --build --preset dev: X2W_TRACY:BOOL=OFF, no _deps directory (nothing fetched).
  • Selection ctest --preset dev --no-tests=error -R "desktop_root_signature|era_heap_allocation|offscreen_warp|startup_memory_srv|startup_placement|startup_indirect_draw_warp|xmem_mapped_pages|startup_present": 28 passed, 0 skipped, 0 failed with the default build, and 28 passed, 0 skipped, 0 failed with the X2W_TRACY=ON build (ctest --test-dir out/build/tracy-on).
  • A full default-preset run was not completed. An earlier full run in a tree where the Python-driven tests were not registered (541 tests) gave 525 passed, 16 capability skips, 0 failed; the run with the Python-driven tests was stopped after 11 minutes on a loaded machine.
  • Off evidence: cl /EP on a unit that uses the macros prints int f(){ ; ; return 1; }; dumpbin /imports on d3d12_xs.dll, xmem.dll and XCRDAPI.dll of the default build lists no Tracy import.
  • On build: cmake --preset dev -B out/build/tracy-on -DX2W_TRACY=ON -DFETCHCONTENT_SOURCE_DIR_TRACY=<checkout at the pinned commit> -DFETCHCONTENT_FULLY_DISCONNECTED=ON, then cmake --build: 2904/2904 steps. The three DLLs import TracyClient.dll. TracyClient compiles with -DTRACY_ENABLE -DTRACY_ON_DEMAND -DTRACY_ONLY_LOCALHOST -DTRACY_NO_BROADCAST -DTRACY_NO_CALLSTACK -DTRACY_NO_SYSTEM_TRACING -DTRACY_NO_CRASH_HANDLER.
  • Load and unload with the ON build: a small local program loads xmem.dll, d3d12_xs.dll and XCRDAPI.dll, stays up 9 s while Tracy's capture -a 127.0.0.1 -s 3 connects (3 frames of connection, trace saved), frees the three DLLs (TracyClient.dll unloads with them) and returns from main normally. The same program without a capture attached also exits normally. The client starts in its DLL's static initializer (no TRACY_DELAYED_INIT).
  • Neither exception handler in src/xmem_mapped_pages.cpp (lazy_commit_fault, retry_remapped_page) calls a zoned function, so no zone runs on a faulting thread inside a handler (by reading).
  • python -B tests/docs_links_check.py (19 files, 459 links), python -B tests/bidi_controls_check.py: pass. git diff --check origin/main...HEAD: clean.

The selection includes startup_present_view_hardware, which uses a physical adapter; adapter, driver and debug-layer status were not recorded, so no result here is a GPU report. The fetch path itself (a download of the pinned commit) was not exercised in this run; the ON build used a local checkout at the same commit.

Evidence and follow-up

Local observation, one instrumented local run that is not reproducible from the repository: a capture located a by-address lookup that walked a never-pruned resource table on every call (fixed separately in #2343) and showed that the apparent cost of the list threads was waiting, not work. This PR adds only the means to take such a capture.

How to capture without a GUI is in the new docs section (Tracy's capture tool, -a 127.0.0.1).

Follow-ups, each its own PR:

  • a debugger-launcher opt-in that enables the profiler sockets for launched processes;
  • more zones: command-list slot zones, compute and texture-upload paths, stream-cache and inflate paths in DirectStorage, finer xmem zones;
  • GPU zones.

Left out on purpose: the command-list slot zones and counter plots, because they sit in a template on the per-call hot path and need an #if block there; they belong in a follow-up with an overhead measurement. Not covered: no overhead measurement of the ON build, and no claim about full-title startup.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture. (No new fixture; off-state is shown by preprocessing and import inspection.)
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6606242890 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2371). Originally posted by [NiiRoZz](https://github.com/NiiRoZz) on 2026-11-25T14:02:03Z. --- ## Change An optional `-DX2W_TRACY=ON` CMake option links `d3d12_xs.dll`, `XCRDAPI.dll` and `xmem.dll` against the Tracy client and turns on named zones and a frame mark in a few hot places of the stand-in runtime. It is a developer measurement build for finding where a run spends time, not a behavior change. - **Off by default.** No preset or workflow enables it. With the option off, nothing is fetched, defined or linked, and the `X2W_ZONE`/`X2W_FRAME_MARK` macros in `src/startup_stubs/profile_zone.h` expand to nothing. - **Dependency policy.** Tracy v0.15.0 (3-clause BSD) is fetched with `FetchContent` only when the option is on, pinned to commit `f2a4f2529e7e71844c9e434b877770a21ecf7587`. `-DFETCHCONTENT_SOURCE_DIR_TRACY=<checkout>` reuses an existing checkout and `-DFETCHCONTENT_FULLY_DISCONNECTED=ON` forbids any download. No Tracy source or binary is committed; the license note is in `docs/startup-runtime.md`. - **Client settings.** On-demand, `TRACY_ONLY_LOCALHOST`, `TRACY_NO_BROADCAST`, no call stacks, no system tracing, no crash handler. - **Socket note.** An instrumented process opens a TCP listener (port 8086 and up) on 127.0.0.1 only (checked by loading the ON `TracyClient.dll` and listing the process's listening sockets). This build must not be used where a run is meant to stay offline; the docs say so. - **Zones** (whole PR: 9 files, 69 lines added): `ExecuteCommandLists`, `Present` with a frame mark, the frame-wait sleep, window present, desktop pipeline creation, `device_memory_srv` and its four resource scans, each DirectStorage request, and the xmem page map and physical write. AI-assisted (Claude Code); the commands below were run locally. ## Verification Base `43608f2e` (origin/main), head `dfa0195b`. Windows 11 build 26300, MSVC 14.44, CMake 3.28, Ninja. - Default build: `cmake --preset dev -DINTAKE_PYTHON=<venv python>`, `cmake --build --preset dev`: `X2W_TRACY:BOOL=OFF`, no `_deps` directory (nothing fetched). - Selection `ctest --preset dev --no-tests=error -R "desktop_root_signature|era_heap_allocation|offscreen_warp|startup_memory_srv|startup_placement|startup_indirect_draw_warp|xmem_mapped_pages|startup_present"`: 28 passed, 0 skipped, 0 failed with the default build, and 28 passed, 0 skipped, 0 failed with the `X2W_TRACY=ON` build (`ctest --test-dir out/build/tracy-on`). - A full default-preset run was not completed. An earlier full run in a tree where the Python-driven tests were not registered (541 tests) gave 525 passed, 16 capability skips, 0 failed; the run with the Python-driven tests was stopped after 11 minutes on a loaded machine. - Off evidence: `cl /EP` on a unit that uses the macros prints `int f(){ ; ; return 1; }`; `dumpbin /imports` on `d3d12_xs.dll`, `xmem.dll` and `XCRDAPI.dll` of the default build lists no Tracy import. - On build: `cmake --preset dev -B out/build/tracy-on -DX2W_TRACY=ON -DFETCHCONTENT_SOURCE_DIR_TRACY=<checkout at the pinned commit> -DFETCHCONTENT_FULLY_DISCONNECTED=ON`, then `cmake --build`: 2904/2904 steps. The three DLLs import `TracyClient.dll`. `TracyClient` compiles with `-DTRACY_ENABLE -DTRACY_ON_DEMAND -DTRACY_ONLY_LOCALHOST -DTRACY_NO_BROADCAST -DTRACY_NO_CALLSTACK -DTRACY_NO_SYSTEM_TRACING -DTRACY_NO_CRASH_HANDLER`. - Load and unload with the ON build: a small local program loads `xmem.dll`, `d3d12_xs.dll` and `XCRDAPI.dll`, stays up 9 s while Tracy's `capture -a 127.0.0.1 -s 3` connects (3 frames of connection, trace saved), frees the three DLLs (`TracyClient.dll` unloads with them) and returns from `main` normally. The same program without a capture attached also exits normally. The client starts in its DLL's static initializer (no `TRACY_DELAYED_INIT`). - Neither exception handler in `src/xmem_mapped_pages.cpp` (`lazy_commit_fault`, `retry_remapped_page`) calls a zoned function, so no zone runs on a faulting thread inside a handler (by reading). - `python -B tests/docs_links_check.py` (19 files, 459 links), `python -B tests/bidi_controls_check.py`: pass. `git diff --check origin/main...HEAD`: clean. The selection includes `startup_present_view_hardware`, which uses a physical adapter; adapter, driver and debug-layer status were not recorded, so no result here is a GPU report. The fetch path itself (a download of the pinned commit) was not exercised in this run; the ON build used a local checkout at the same commit. ## Evidence and follow-up Local observation, one instrumented local run that is not reproducible from the repository: a capture located a by-address lookup that walked a never-pruned resource table on every call (fixed separately in #2343) and showed that the apparent cost of the list threads was waiting, not work. This PR adds only the means to take such a capture. How to capture without a GUI is in the new docs section (Tracy's `capture` tool, `-a 127.0.0.1`). Follow-ups, each its own PR: - a debugger-launcher opt-in that enables the profiler sockets for launched processes; - more zones: command-list slot zones, compute and texture-upload paths, stream-cache and inflate paths in DirectStorage, finer xmem zones; - GPU zones. Left out on purpose: the command-list slot zones and counter plots, because they sit in a template on the per-call hot path and need an `#if` block there; they belong in a follow-up with an overhead measurement. Not covered: no overhead measurement of the ON build, and no claim about full-title startup. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. (No new fixture; off-state is shown by preprocessing and import inspection.) - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-25 16:05:10 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2363
No description provided.