Skip to content

D3D12.X: with XCL_LOOK_STATS=2 split a present's time on the submitter - #2955

Merged
Prime1997 merged 1 commit into
xcl-dev:mainfrom
thisguyStan:d3d12x/presentx-timers
Nov 30, 2026
Merged

Prime1997 merged 1 commit into
xcl-dev:mainfrom
thisguyStan:d3d12x/presentx-timers

Conversation

@thisguyStan

@thisguyStan thisguyStan commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Part of #2688 (workstream 8). Targets main (b38197ae).

In the world, presents take most of the submitting thread's time on NVIDIA (93 % on an RTX 4080 in #2729), but calls of the submitting thread (2 s) shows a present as one presents entry, with only its wait for frame N−2's copy apart. With XCL_LOOK_STATS=2, like that wait, this adds four entries:

  • the wait for the present before it (PRESENTX_LOCK, PRESENTER),
  • the copy (or composite) recorded and submitted, from the allocator's reset to its Signal,
  • the swap chain's Present (a GPU-bound frame waits there),
  • the wait for a frame dump's copy (XCL_FRAME_DUMP, XCL_DUMP_TARGETS).

The rest of presents is the plane checks, the frame-rate line and the device-removal check. When the fallback presents on a submission (no PresentX), the parts run inside ExecuteCommandLists, as the copy wait does. Like it, they are sub-calls (is_sub_call, #2729), so completed counts each present once. XCL_STALL_TRACE times only the swap chain's Present. Diagnostics only: no change with the switch off.

What is in it

  • crates/xcl/src/hle/api_cost.rs: the four entries, their names in CALLS and in is_sub_call, and a test that a present is counted once.
  • crates/xcl/src/hle/d3d12x/present.rs: the timers around the two lock waits, the recording and submit, Present and the frame-dump wait.

Tested

  • RTX 4070 Ti 12 GB (driver 32.0.16.1088, 32-lane waves), Ryzen 9 5900X, 64 GB RAM, Windows 11 Pro build 26200, rustc 1.100.0, DXC 1.9.2602.17; tests in debug, smokes in release.
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on 80e2ee45 (this PR on main 7db2f391): 2595 passed, 0 failed, 49 ignored. The head 2aeec61c is the same patch rebased onto b38197ae (git range-diff: unchanged); the suite was not rerun on it.
  • SKIPPED: 29 (21 no wave64, 3 per-lane forms refused, 2 no heap windows, 3 no D3D12 debug layer).
  • The runs with the timers on below are from before the rebase, when this PR was based on nvidia-dev (merged into main since). The timers are the same. On main, the present's copy is submitted without XCL's look at the title's memory, so the recording part should be smaller there.
  • The timers on: scripts/smoke.ps1 on 1a6ddc2c (release; the same code as dd85383e) with XCL_LOOK_STATS=2, XCL_PREPARE=0, 60 s in the intro and menus (1354 frames, no device removal, no crash). Every calls of the submitting thread (2 s) line (from 12 s on) has the new entries. From 14 s on, the parts add up to the presents entry within 0–4 ms per 2 s (the rest of a present); the first present (12 s) took 51 ms, of them 1 ms in the parts. From 26 s on, every 2 s:
    • 60 presents in 37–58 ms,
    • 120 waits for the present before (two per present) in 0 ms, 60 waits for the last frame's copy in 0 ms,
    • 60 copies recorded and submitted in 16–30 ms,
    • 60 swap chain Presents in 17–24 ms.
    • The slowest 2 s (at 18 s): 54 presents in 225 ms, of them 124 ms recording and submitting and 98 ms in the swap chain's Present.
    • No frame-dump waits (no XCL_FRAME_DUMP): that entry is not printed.
  • Into the world: two runs of dd85383e with XCL_LOOK_STATS=2, XCL_ACTIVITY=1, XCL_PREPARE=0, played past the intro, were stopped as the world loads by a device removal (0x887a0005, no DRED breadcrumbs) and then the title's breakpoint at the same address (at 228 s and 114 s). its base then, ecc0bb57 (nvidia-dev, now part of main), with the timers off stops the same way (223 s), so the world itself was not reached. In the first run, while the world loaded (178–226 s, 9–13 fps), every 2 s:
    • 1–61 presents in 3–190 ms, of them 1–117 ms recording and submitting and 2–102 ms in the swap chain's Present; the parts add up to presents within 0–4 ms,
    • the waits for the present before and for the last frame's copy stay at 0 ms,
    • ExecuteCommandLists takes 57–1005 ms.

Regression run
60 s runs of scripts/smoke.ps1 (JIT path: the script sets XCL_PREPARE=0) on the same title, with no pipeline cap. Each ran on its own copy of one main shader cache. main is this PR's base (b38197ae). XCL_LOOK_STATS was unset, so these runs show the switched-off path.

main (b38197ae):

xcl-smoke v1
commit: b38197ae60974cf5f280e8dfffc4ce554e815590
gpu: NVIDIA GeForce RTX 4070 Ti
title: 83ce7bf6
seconds: 60
exit: 0x0
frames shown: 1575 (PresentX 1575)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 19171 MB

This PR (2aeec61c):

xcl-smoke v1
commit: 2aeec61c045fe315ae3f0ed6e6d4f1e03b05417b
gpu: NVIDIA GeForce RTX 4070 Ti
title: 83ce7bf6
seconds: 60
exit: 0x0
frames shown: 1554 (PresentX 1554)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 18715 MB

Not tested

  • A run in the world: on this machine the old base (ecc0bb57, on nvidia-dev before its merge) stopped with a device removal as the world loads (above), so the split in the world is not measured here. The timers-on runs were not repeated on main.
  • The frame-dump wait (XCL_FRAME_DUMP, XCL_DUMP_TARGETS) and the composite path of a present.
  • AMD and Intel GPUs, 64-lane wave GPUs, Linux / Wine.

AI use

  • Claude Code (Claude Opus 5.5): wrote the change and this description, ran the tests and the smoke runs on the machine above.

@ettehn

ettehn commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

One accounting detail for the #2729 integration, checked at 1a6ddc2c. The submission-driven fallback calls present_now directly, so it emits PresentRecord and PresentSwap without an enclosing Call::Present sample. It runs inside the enclosing ExecuteCommandLists timer. Those samples belong to Submit on that route and to Present on the boundary route. In both cases, #2729’s non-overlapping total should treat them as sub-calls.

A standalone Windows x64 fixture compiled this head’s api_cost.rs and fed it the fallback sequence. It reported Present=0, PresentRecord=12 ms, PresentSwap=20 ms, Submit=40 ms. The durations are fixture inputs. This checks the counters and the source call sites. If the new metrics are meant to break down presents, a route guard or separate fallback labels would keep that interpretation accurate.

OpenAI Codex assisted with verification.

@thisguyStan
thisguyStan force-pushed the d3d12x/presentx-timers branch from 1a6ddc2 to dd85383 Compare November 27, 2026 05:00
@thisguyStan

Copy link
Copy Markdown
Contributor Author

Thanks, that's right: on the submission-driven fallback present_now runs inside ExecuteCommandLists, so its parts land in Submit, not in Present. The copy wait already did the same. I kept the timing as it is. A Present timer around the fallback would count the same time in both entries, and Call::Present deliberately covers only PresentX and the console-method fallback. Instead, dd85383e says it in the doc comment on the entries, the commit message and the description. For #2729's non-overlapping total, all four new entries belong in is_sub_call along with PresentCopyWait, on both routes. That's in the description too, for whichever PR lands second. (Claude Code with Claude Opus 5.5 checked the call sites.)

@thisguyStan
thisguyStan marked this pull request as ready for review November 27, 2026 06:07
@LocranKing

Copy link
Copy Markdown

Tested PR #2955 (dd85383e) on Windows 11 in a 180 s open-world run with XCL_LOOK_STATS=2 to cover the open-world PresentX breakdown noted under Not tested.

Environment

  • GPU: NVIDIA GeForce RTX 3060 Ti (8024 MiB VRAM, driver 32.0.16.2140)
  • CPU / RAM: AMD Ryzen 5 5500 (6C/12T), 32 GB DDR4, Windows 11 Build 26300
  • Shader cache & runtime: Frozen nvidia-dev DXIL cache (XCL_DIRECT_DXIL=1, XCL_HEAP_WINDOWS=1, XCL_TEXTURE_LEVEL_PAGES=1, XCL_PREPARE_GRAPHICS=0, XCL_DRED=1, XCL_LOOK_STATS=2), Series S (lockhart) profile.

180 s Open-World Run (XCL_LOOK_STATS=2)

  • Outcome: exit: 0x0, 0 crashes, 0 device removals, 1760 frames (PresentX 1760), heavy world draws began at 108.55 s, peak commit 29509 MB, peak local VRAM 10279 MB, peak non-local 4982 MB.
  • Aggregated calls of the submitting thread (2 s) breakdown:
Scope Intervals ExecuteCommandLists waits for pipelines being built presents total waits of a present for the one before waits of a present for the last frame's copy copies of a present recorded and submitted swap chain Presents
Full 180 s run 87 4686 (76,902 ms) 64 (3,226 ms) 1760 (32,086 ms) 3520 (0 ms) 1760 (0 ms) 27,148 ms (84.6%) 4,818 ms (15.0%)
In world (t >= 100 s) 47 1382 (50,349 ms) 64 (3,226 ms) 108 (25,543 ms) 216 (0 ms) 108 (0 ms) 22,895 ms (89.6%) 2,624 ms (10.3%)

World observations

  • Once in the world (t >= 100 s), presents (25,543 ms) accounted for ~33.6% of {ExecuteCommandLists + presents} submitter call time (75,892 ms), and copies of a present recorded and submitted dominated presents at 89.6% (22,895 ms across 108 presents), with swap chain Presents at 10.3% (2,624 ms) and lock/copy waits at 0 ms (residual remainder 24 ms / 0.1%).
  • Single 2 s world spikes reached up to 2172 ms for 2 presents (2167 ms in copies of a present recorded and submitted, 4 ms in swap chain Presents, at 144.993 s) and 1654 ms for 1 present (1653 ms in copies of a present recorded and submitted, at 187.661 s).

@thehollowedone

Copy link
Copy Markdown
Contributor

I rebased #2955 head dd85383e locally onto current nvidia-dev ba9d1f94. The only textual conflict is the CALLS array size in api_cost.rs: the base has 20 calls after #2729, and this PR adds four, so the combined array needs 24 entries.

There is one accompanying accounting step, as you anticipated: add all four new present timers to is_sub_call. They run inside Present or the submission fallback's Submit; leaving them top-level makes #2729's non-overlapping completed duration count their time twice. I extended the existing submitter-summary test with all four nonzero timers and kept its completed total at 400 ms.

On the resolved, uncommitted merge: cargo build --offline --locked -j 4 --workspace passed; cargo test --offline --locked -j 4 -p xcl --lib hle::api_cost::tests -- --test-threads=1 passed 8/0/0, with no skips. Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35), Rust 1.99.1. I did not run the full suite or clean-commit smoke on this local rebase; those remain for the updated PR head.

Minimal rebase resolution and accounting test
--- a/crates/xcl/src/hle/api_cost.rs
+++ b/crates/xcl/src/hle/api_cost.rs
@@
-pub const CALLS: [(Call, &str); 16] = [
+pub const CALLS: [(Call, &str); 24] = [
@@
-    matches!(call, Call::PresentCopyWait | Call::PipelineWait | Call::ViewWant)
+    matches!(call, Call::PresentCopyWait | Call::PresentLockWait | Call::PresentRecord
+        | Call::PresentSwap | Call::PresentDumpWait | Call::PipelineWait | Call::ViewWant)
@@ submitter_summary_excludes_sub_calls_and_reports_completed_window
     now[Call::PresentCopyWait as usize] = (2, 30_000);
+    now[Call::PresentLockWait as usize] = (1, 20_000);
+    now[Call::PresentRecord as usize] = (1, 30_000);
+    now[Call::PresentSwap as usize] = (1, 40_000);
+    now[Call::PresentDumpWait as usize] = (1, 50_000);
     // The summary still ends with completed 400 ms (window 2000 ms).

AI use: Codex (GPT-6.2 Sol) resolved the local merge, reviewed the timer nesting, ran the build and test, and drafted this reply.

@Prime1997
Prime1997 changed the base branch from nvidia-dev to main November 28, 2026 20:14
@thisguyStan
thisguyStan force-pushed the d3d12x/presentx-timers branch from dd85383 to c726229 Compare November 28, 2026 21:32
@thisguyStan
thisguyStan marked this pull request as draft November 28, 2026 21:32
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test) labels Nov 28, 2026
@thisguyStan
thisguyStan force-pushed the d3d12x/presentx-timers branch from c726229 to 80e2ee4 Compare November 28, 2026 21:37
@thisguyStan
thisguyStan marked this pull request as ready for review November 28, 2026 22:49
On a 16 GB NVIDIA card in the world, presents took 93 % of the
submitting thread's time (xcl-dev#2688), but a present was one entry with only
its wait for the copy of the frame before apart, so where that time
goes could not be told.

Four more entries, timed with XCL_LOOK_STATS=2 only, as that wait is:
- the wait for the present before it (PresentX's lock, the presenter's),
- the copy (or composite) of the frame recorded and submitted, from the
  allocator's reset to its Signal,
- the swap chain's Present, which DXGI holds while the frames before it
  are queued (a GPU-bound frame waits there),
- the wait for a frame dump's copy (XCL_FRAME_DUMP, XCL_DUMP_TARGETS),
  up to 2 s each.

With XCL_ACTIVITY they appear in "calls of the submitting thread (2 s)"
next to "presents"; what a present spends besides them is the rest
(the plane checks, the frame-rate line, the device-removal check). No
change with the switch off.

When the fallback presents on a submission (a title that does not call
PresentX), its parts are timed inside ExecuteCommandLists rather than
inside presents, as the copy wait already was.

They are sub-calls (is_sub_call, xcl-dev#2729), as the copy wait is, so the
line's "completed" total counts each present once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thisguyStan
thisguyStan force-pushed the d3d12x/presentx-timers branch from 80e2ee4 to 2aeec61 Compare November 29, 2026 22:23
@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Nov 29, 2026
@tiagonleal

tiagonleal commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: cb80246
head: 2aeec61
merge: clean
build: cargo build --workspace -> ok (also cargo build --release -p xcl)
tests: cargo test --workspace --no-fail-fast -j 8 -- --test-threads=4 -> 2810 passed, 1 failed, 51 ignored; SKIPPED: 27 lines (22 no wave64, 3 f16/f32 per-lane cases refused, 2 no heap windows), the same as on the base; failing: hle::d3d12x::standin::tests::concurrent_shell_miss_reuses_winner_and_releases_loser_pipeline, which fails the same way on the base (it came in with #2369; #3474 fixes it). Base alone on this PC: 2809 passed, 1 failed, 51 ignored.
review: whole diff read (+55/-5, api_cost.rs, present.rs). Diagnostic only. The four new timers (PresentLockWait, PresentRecord, PresentSwap, PresentDumpWait) are each created through look_stats::deep().then(...), so with XCL_LOOK_STATS unset or at 1 a present takes no clock read and writes no counter. All four are in is_sub_call, so they are not counted twice in completed, and the new test checks that. The parts do not add up to presents exactly; the comment in present.rs says so. Checked on NVIDIA as the label asks: a 60 s run of the merged tree with XCL_LOOK_STATS=2 prints, in the existing 2 s line of the submitting thread, 60 presents in 21 ms, ... 120 waits of a present for the one before in 0 ms, 60 copies of a present recorded and submitted in 7 ms, 60 swap chain Presents in 12 ms, so 19 of the 21 ms are attributed. At level 2 the line gains entries, which matters only to a script that expects a fixed number of them.
performance: default path: a few level checks per present, no clock and no atomics. Measured with scripts/smoke.ps1, 60 s of a retail title, release: 1683 frames and 15318 MB peak commit with the switch unset, 1678 frames and 15738 MB with XCL_LOOK_STATS=2, against 1662 and 1684 frames, 16196 and 15752 MB on the base. No device removal, no crash.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB (617.42, wave32), Ryzen 7 9800X3D, 32 GB, Windows 11 26300, rustc 1.100.0 / Claude Code (Claude Fable 5.2 ran the build, suite and smoke and wrote this; Claude Opus 5.5 read the diff first, and I checked its main points in the merged source)

  • Tiago

@github-actions github-actions Bot added needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Nov 30, 2026
@jsalzy

jsalzy commented Nov 30, 2026

Copy link
Copy Markdown

merge-check claim
head: 2aeec61

@jsalzy

jsalzy commented Nov 30, 2026

Copy link
Copy Markdown

merge-check
base: 7c01208
head: 2aeec61
merge: clean (also clean on main bfbb4db)
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2851 passed, 0 failed, 51 ignored; SKIPPED: 25 (22 no wave64 on this GPU; 2 no heap windows (opt-in XCL_HEAP_WINDOWS=1); 1 driver cache cannot be disabled without Windows Developer Mode); failing: none
review: whole diff read (+55/-5, api_cost.rs and present.rs). Diagnostic only: each of the four new timers (PresentLockWait, PresentRecord, PresentSwap, PresentDumpWait) is created through look_stats::deep().then(...), so without XCL_LOOK_STATS=2 a present gets no clock read and no counter write. All four are in is_sub_call, so completed counts a present once; the new test the_parts_of_a_present_are_not_counted_twice passes, and a_call_is_counted_with_its_time still confirms CALLS is in enum order. Minor, not blocking: the PresentRecord timer starts before the allocator Reset and is dropped on the early returns before the Signal (Reset, cast or Signal failure), so a present that fails there still counts as a copy recorded and submitted. The timer placement in present.rs has no test (it needs a real present); the unit test covers the accounting only. No duplicate found: #2729 (merged) is what this extends; #3192 and #3104 touch api_cost but not the present timers; no #1607 group.
performance: not measured. Default path: one cached level check per timer site, no clock read, no atomics.
verdict: safe to merge
hardware / tool and model: RTX 4070 SUPER 12 GB (621.24 / 32.0.16.2124), Ryzen 7 7800X3D, 32 GB, Windows 11 Pro 25H2 26200.9974, Rust 1.100.0, debug / Claude app (Claude Opus 5.5): merge, build and suite run on this PC with git and cargo only; diff review by Claude Opus 5.5.

@github-actions github-actions Bot added ready-to-merge Has 2 independent safe merge-checks on current head (#3041) and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) labels Nov 30, 2026
@Prime1997 Prime1997 added the test-only A maintainer reviewed the diff: tests only, no smoke run needed for this revision (CONTRIBUTING.md) label Nov 30, 2026
@Prime1997
Prime1997 merged commit bc4503d into xcl-dev:main Nov 30, 2026
8 of 10 checks passed
@thisguyStan
thisguyStan deleted the d3d12x/presentx-timers branch November 30, 2026 09:07
dudenudem pushed a commit to dudenudem/xcl that referenced this pull request Nov 30, 2026
Upstream since d52ff48:
- 34035fc kernelx: unmark lazy away mappings in FreeTitlePhysicalPages (xcl-dev#1221, b3IKK)
- e5c2bc6 VFS: ReadFileEx, WriteFile and scatter/gather commit lazy pages first (xcl-dev#1355, emirduran707)
- a8683ef Recompiler: track SMEM register offsets as scalar reads (xcl-dev#1540, oni-swr)
- 2aeec61 D3D12.X: with XCL_LOOK_STATS=2 split a present's time on the submitter (xcl-dev#2955, thisguyStan)

Resolved into this fork's port, no upstream change dropped:
- kernelx.rs: lazy::unmark in FreeTitlePhysicalPages; both regression tests inserted before the away-mapping test (context identical).
- vfs_hooks.rs: ReadFileEx / WriteFile / WriteFileEx / scatter / gather hooks and ensure_segments next to this fork's ReadFile hook, with their atomics and install entries.
- present.rs: PresentLockWait at PresentX's lock and at present_now's presenter lock; PresentRecord from the allocator reset to the Signal, dropped before the swap; PresentSwap around sc.Present; PresentDumpWait around the dump fence wait. This port has note_present() and no dumping_targets block, so those hunks were placed by hand; every timer line is upstream's verbatim.
- rdna2.rs: OPR_SMEM_OFFSET is a scalar read in sgpr_uses, with its test.
- kernelx/lazy.rs: mark is public for tests/lazy_file_io.rs.
- api_cost.rs: four new Call variants, labels and is_sub_call, with the sub-call test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH gpu:nvidia Code is specific to NVIDIA / wave32 GPUs (scope tag; see needs:nvidia-test) ready-to-merge Has 2 independent safe merge-checks on current head (#3041) test-only A maintainer reviewed the diff: tests only, no smoke run needed for this revision (CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants