d3d12: LEONIDA_AB tells the frame lines' counters by arm (D3D12-AB-COUNTERS) #2779
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2779"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-30T18:30:36Z.
Claimed in the coordination issue as: D3D12-AB-COUNTERS (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7287775780)
What and why
LEONIDA_ABturns switches on and off by turns inside one run, so that both sides are measured in the same scene. Its phase lines carry only frame times, the card's idle time and the submitting thread's work.Testers asked for more. In #2701, the time spent changing memory protections could not be split by arm. Their wish: "
LEONIDA_ABfor what does not depend on time".The frame lines' counters could not be read per phase:
ASKS(asking about title memory, protections),FAULT_ASKS(the title's faults) andSPLIT(the submitting thread's preparing) were emptied withswap(0)each time the frame line was written.This change:
turns those three arrays into running totals, never reset. No writer changes: every
tally,fault_countandSPLIT[i].fetch_addstays as it is;makes the frame line take what came since its last take (
ab::take), so it prints the same numbers. It usesfetch_maxon a second array (*_TAKEN), so two takers at once never count the same amount twice;has each A/B phase snapshot the totals where it already reads the card's idle time, then log one more line after the existing one, which is unchanged so no parser breaks:
Only counters that moved are listed, per frame over the phase's counted frames, with nanoseconds as ms. Each counter is named in a table next to its array (
ASK_NAMES,FAULT_NAMES,SPLIT_NAMES).As before, all of this is in diagnostics builds only. The hot paths are unchanged: each tally is still one relaxed
fetch_add.Tested
On Windows 11, from
d3d12\:--features diagnostics, the feature these counters live behind):watch::tests::a_running_total_survives_the_frame_lines_take: a total survives the frame line's take. It compiles onmain, where it fails by assertion ("the take emptied the total"), becauseasks()swaps the counter to 0. With the change it passes.ab::tests::a_take_counts_what_came_since_the_last_one_and_the_totals_stay.ab::tests::takers_at_once_count_everything_once: 4 threads × 10,000 adds and takes; the takes sum to the total exactly.ab::tests::a_phase_tells_what_moved_per_frame: the line's format, and one name per counter.cargo test -p leonida-gpu --locked --features diagnostics: 659 passed, 52 ignored. Without diagnostics: 579 passed.cargo clippy -p leonida-gpu --all-targets --locked --features diagnostics: nothing in the changed lines.git diff --checkandcheck_no_game_data.pyare clean.git merge-tree: no new conflict with the open pull requests on these files (#2709, #2703, #2750). #2682 and #2569 have the same conflicts withmainas with this branch.LEONIDA_ABrun's counters line here.GPUs tested: NVIDIA GeForce RTX 3080 10 GB, driver 32.0.16.2140, Windows 11 Pro 10.0.26300 (unit tests).
AI-assisted: yes
Checklist
mainand merges cleanly.docs/design.md, with how it was confirmed. (Not applicable: no translator change.)Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-11-30T18:36:52Z.
Independent check on Windows (not the author), at
4c36dba7c.cargo test --locked -p leonida-gpu --lib(run alone, shared warm target): 579 passed, 0 failed, 52 ignored in 14.3 s.Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711, NVIDIA RTX 4070 Ti SUPER (driver 621.01), Rust 1.98.1 pinned.
AI-assisted: yes (opencode).
Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-11-30T23:05:55Z.
RUN (independent run on Windows, #2779 head
4c36dba7c, merged locally into main8f41d7d01withgit merge --no-ff, no conflicts. The head still merges cleanly into mainb1f91c2f9. CI on the head: change-scope, check, linux-python-and-viewer, no-game-data and semantic-tests all pass.)Commands, in
d3d12/, target x86_64-pc-windows-msvc, toolchain 1.98.1, all with--locked, at low priority:cargo test -p leonida-gpu --no-fail-fast(no features): 580 passed / 0 failed / 52 ignored, on main and on the merge alike. The new code and tests are behinddiagnostics.cargo test -p leonida-gpu --no-fail-fast --features diagnostics: main 657 / 0 / 53; merge 661 / 0 / 53. The 4 new tests pass:a_running_total_survives_the_frame_lines_takeand the threeab::tests. (The PR's 659 was counted on an older main.)cargo clippy -p leonida-gpu --all-targets, without and with--features diagnostics(without-D warnings, which already fails on main in leonida-shader and leonida-lua), on main and on the merge: no new warning inab.rs,host.rsorwatch.rs(6 already there without the feature, 7 with it, the same on the merge).watch.rstest added,cargo test -p leonida-gpu --lib --features diagnostics a_running_total_survivesfails with "the take emptied the total". Main'sasks()swaps the counter to 0. With the change it passes.ab::takereading the last take without moving it (taken[i].loadinstead offetch_max), 2 of the 3ab::testsfail.a_take_counts_what_came_since_the_last_one_and_the_totals_staygets [8, 7] for [3, 7], andtakers_at_once_count_everything_oncecounts 800,070,223 for 40,000.A/B countersline in a realLEONIDA_ABrun. That needs the game.Two of these cargo runs (the main baselines and the mutant) had to be redone: the first try died on a rustc crash (0xC0000005) and a linker PDB error, which had nothing to do with this code.
No runtime/ C++ or Python in this PR, so no link or import check applies.
Machine: Windows 11 Pro 26300, i9-13900K, 64 GB, RTX 3090 24 GB, NVIDIA 621.40.
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T23:13:29Z.
RUN - VERIFY-2779-RTX4060 - by MoonEyes (another person than the author) on head
4c36dba7c, with #2775 (58db554c7), #2777 (aec6998a9) and #2779 (4c36dba7c) merged together intomain407f71a23(clean).-FrameGen 2(frame generation files absent, so off), BAR window off, texture budget 1024 MB.maineec86d0fa+ the three (Windows): leonida 47, leonida-hle 223, leonida-gpu 582, leonida-shader 403, 0 failed.--features diagnostics,ab::): 4 pass;takewithout the subtraction fails 2; the counters line not divided by frames fails 1.Limits: one card, the character standing still, a session that did not reach the open world. Values only, no game data.
AI-assisted (Claude Code).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T23:14:25Z.
Merging. Head
4c36dba7cmerges cleanly withmain29635b202and does not force a rebase of #2566. CI green on this head. Red/green by enlight3d (and KelboLive, OreoFR where they posted) on it; in-game run on the RTX 4060 posted above (2 runs, 0 device lost, about 500 s in the world); leonida, leonida-hle, leonida-gpu and leonida-shader tests pass on main + the three. Merged by MoonEyes.AI-assisted (Claude Code).