Skip to content

xbox_present: one [d3d12-trace] line per PresentX, with its outcome - #9549

Merged
ItsNotRexed merged 2 commits into
ProjectLeonida:mainfrom
Mumogg:trace-presentx
Nov 23, 2026
Merged

ItsNotRexed merged 2 commits into
ProjectLeonida:mainfrom
Mumogg:trace-presentx

Conversation

@Mumogg

@Mumogg Mumogg commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claimed in #9522 (comment)

What

XboxPresentation::PresentX writes one [d3d12-trace] #<seq> XboxPresentation::PresentX <ok|failed> line per call when the D3D12 trace is on (d3d12_trace::result). The body moves unchanged into a private present_x; the public method records its result, so every return path is covered.

Why

The console's PresentX is a queue slot past the PC chain, so nothing records it, and a --trace-d3d12 run of a frame loop cannot say how many frames were presented or whether a present was refused. Several frame-loop reports in #7154 say so ("PresentX writes no trace line on this head, so presents are not counted", "this build has no present counter"). tools/boot_trace.py needs no change: it already groups trace lines by method and outcome.

With the same line carried locally on an integration stack, a retail run counted 90,932 presents against 272,797 DrawInstanced in two minutes, which is how "3 draws per present" was measured.

Tested

Linux (Nobara 44), clang-cl 22.1.8 + xwin SDK 10.0.26100 cross-build, Wine 11.21 staging, RTX 5070 Ti (NVIDIA 615.78.08), real display. No game files.

  • xbox_present_test: all cases pass. The new case captures stderr around a blank present and a refused three-plane call and expects exactly one ok line, one failed line and no other trace line.
  • gta6rt builds.
  • python -I scripts/check_no_game_data.py on the four files: clean.
  • tests/test_docs_links.py and tests/test_docs_cli_flags.py: one failure each, the same on unmodified main (5d74c2723).

Not run: the MSVC build and the Windows CI jobs.

AI-assisted.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HxBQf4pXH8PWpC5oZsM4bt

The queue proxy's PresentX slot is past the PC chain, so nothing recorded
a present: a --trace-d3d12 run of a frame loop could not say how many
frames were presented, or whether one was refused. XboxPresentation::PresentX
now writes one line per call through d3d12_trace::result (ok or failed).

xbox_present_test captures the trace around a blank present and a refused
three-plane call and checks for exactly those two lines.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HxBQf4pXH8PWpC5oZsM4bt
@dragoso

dragoso commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 85441c34f (directly on main 5d74c2723) natively on Windows 11 (build 26300), MSVC 14.51.36231, Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0, NVIDIA GeForce RTX 5060 Ti (driver 32.0.16.1742), real display: pass. This is the MSVC build the description lists as not run.

  • xbox_present_test and gta6rt build. ctest -R ^xbox_present$: pass (5.0 s), xbox_present_test: all cases pass, including 0 planes (blank): ok with the new trace-count checks.
  • The \n in the needles holds on MSVC too: _dup2 gives fd 2 the binary mode of the "wb" file, so the CRT doesn't turn the trace's \n into \r\n there.

Code read, no problems found: the body moves unchanged into present_x, and PresentX only wraps it in d3d12_trace::result, so every return path (E_INVALIDARG, suspended, the blank and plane paths) writes exactly one line. The line is written after present_mutex_ is released, so tracing doesn't lengthen the locked section.

Two notes, neither blocking:

  1. MSVC warns C4996: 'fopen' at xbox_present_test.cpp(49) (the only new warning in the build). The fopen(path.string().c_str(), "wb") behind it also narrows the temp path to the ANSI code page, so with a TEMP holding characters outside it (the non-ASCII folder case runtime tests: a non-ASCII build folder no longer breaks the d3d12 tests (TEST-1982) #9037 fixed for other tests) the open can fail. The capture then silently doesn't redirect, and the test fails with counts of 0. _wfopen_s(&out, path.c_str(), L"wb") avoids both.
  2. The comment above the new block says a call writes "nothing when the trace is off", but the test only runs with the trace on. Either a third PresentX after finish() with an empty capture, or dropping that clause, would line it up.

No game files. AI-assisted (Claude Code).

@OliverMarcusson

Copy link
Copy Markdown

Tested 85441c34 (merged cleanly onto main 5d74c272) on NVIDIA GeForce RTX 5070 Ti (driver 621.01, Vulkan 1.4.357), Windows 11 10.0.26200, MSVC 19.44 (RelWithDebInfo, Windows SDK 10.0.26100.0): pass.

  • ctest -C RelWithDebInfo -R ^xbox_present$: 1/1 PASS (full Vulkan present test + [d3d12-trace] ok/failed PresentX assertions).
  • Minor note: MSVC emits C4996 for fopen at runtime/test/xbox_present_test.cpp(49) (non-fatal).

AI-assisted (Gemini).

…he trace-off case

Review notes on ItsNotRexed#9549: fopen warns C4996 on MSVC and narrows the temp path to
the ANSI code page, so a TEMP outside it left stderr unredirected and the test
failed with counts of 0. The capture now opens the wide path and reports
whether it redirected, which the test expects.

The comment said nothing is written with the trace off; a refused PresentX
under a capture with the trace off now checks it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HxBQf4pXH8PWpC5oZsM4bt
@Mumogg

Mumogg commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks both for the MSVC runs, that was the gap in my description.

0438ee44f takes the two notes from the first review:

  1. The capture opens the file with _wfopen_s(&out, path.c_str(), L"wb"), so no C4996 and no narrowing of the temp path. It also records whether stderr was redirected, and the test expects that, so a capture that could not open its file fails as such instead of as "0 lines".
  2. The trace-off clause is now checked: a refused three-plane PresentX under a second capture with the trace off, expecting no [d3d12-trace] line.

Re-run on the same machine as before (clang-cl 22.1.8 + xwin, Wine 11.21 staging, RTX 5070 Ti 615.78.08): xbox_present_test: all cases pass. Not re-run on MSVC.

AI-assisted.

@nullmarsh

Copy link
Copy Markdown
Contributor

checked: #9549 | head 0438ee4 merged onto main 5d74c27 (clean) | on: native Windows 11 26200, MSVC 14.44 (the build the description didn't run), RX 9060 XT (RDNA4), AMD 26.11.2 | result: pass. It builds with no new warnings in the changed files; xbox_present, xbox_present_readback_size, d3d12_present and dxgi_swapchain pass. Unrelated, the same on main 6312c057 here: xbox_present logs 5 present failed (VkResult -11) on this card and still passes. Diff read: nothing risky.

AI-assisted (Claude Code), no game files.

@Hiiva

Hiiva commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Validated complete current head 0438ee44fdc03b65765e2ef3285e05326691afbd in local integration bd8b17d5 on upstream 5d74c272, retaining complete #7448 (af2059f9), #9419 (014d99f3), and #8019 (e939b667).

xbox_present_test.exe passed on Windows x64 / RTX 4080 in 2.638 s with Vulkan validation enabled, fresh TEMP/TMP, and 0 VUIDs. The current fixture's redirection-success assertions passed. It verified:

  • Tracing enabled: the blank PresentX returned S_OK and emitted exactly one ok line; the refused call returned E_INVALIDARG and emitted exactly one failed line, with two trace lines total.
  • Tracing disabled: the refused call still returned E_INVALIDARG and emitted no D3D12 trace line.

The remaining synthetic presentation/readback cases also passed. Source preservation review found the original PresentX implementation unchanged inside the traced wrapper. These are full-owner-head integration results; the owner head was not run alone. No game data is included.

Built with MSVC / Visual Studio 2022, RelWithDebInfo. Tested source: https://github.com/Hiiva/Leonida/tree/work/exe-reviewed-bd8b17d5

@sgonzalez-glitch

Copy link
Copy Markdown

Tested 0438ee44f (as part of #9516, #9549, #9614, #9653, #9657, #9660, #9678 and #9689 merged together onto main 5d74c2723) on NVIDIA GeForce RTX 2080, driver 621.24 (32.0.16.2124), Windows 11, MSVC 19.44 RelWithDebInfo: pass.

AI-assisted: yes

@RavenLorr

Copy link
Copy Markdown

checked: #95490438ee4 | with: merged onto main 5d74c2723 (clean), MSVC 14.44 RelWithDebInfo, target xbox_present_test, plus two controls the checks above don't include | on: Windows 11 Pro 26300, NVIDIA GeForce RTX 5070 Ti (610.88) | result: pass (5 of 5 runs), and both controls behave as they should

Adding to @nullmarsh's MSVC run, the two controls:

  • Negative control for the trace: with runtime/shims/xbox_present.cpp and xbox_present.h taken from main and the PR's test kept, the test exits 1 at line 512: count_of(trace, " XboxPresentation::PresentX ok\n") == 1. So the new case catches a missing trace line. Restored and rebuilt afterwards: exit 0 again.
  • Control for the C4996 fix: with xbox_present_test.cpp from the previous head 85441c34f, the same build gives xbox_present_test.cpp(49,31): warning C4996: 'fopen'; on 0438ee44f there's no C4996. The target's only warning left is C4189 at runtime/src/vulkan_present.h(669,24), which main has too.

One difference from @Hiiva's run, for whoever tests next: on this card, with LEONIDA_VK_VALIDATION=1, the test exits 77 (skipped) with 4 × VUID-VkSwapchainCreateInfoKHR-imageFormat-01778, identically on main 5d74c2723 built alone and on this PR (3 runs each). So it's not caused by this PR, but here the validation layer gives no verdict on the test; on the RTX 4080 it reported 0 VUIDs.

AI-assisted (Claude Code), run by a person. No game files.

@ItsNotRexed
ItsNotRexed merged commit 2be1e08 into ProjectLeonida:main Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants