d3d12: LEONIDA_AB tells the frame lines' counters by arm (D3D12-AB-COUNTERS) #2779

Merged
TheGeogeo merged 1 commit from upstream-pr/2779 into main 2026-11-30 23:14:28 +00:00
TheGeogeo commented 2026-11-30 18:30:36 +00:00 (Migrated from github.com)

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_AB turns 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_AB for 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) and SPLIT (the submitting thread's preparing) were emptied with swap(0) each time the frame line was written.
  • That line runs on its own thread at its own pace, so a phase could not read them without stealing the frame line's values.

This change:

  • turns those three arrays into running totals, never reset. No writer changes: every tally, fault_count and SPLIT[i].fetch_add stays as it is;

  • makes the frame line take what came since its last take (ab::take), so it prints the same numbers. It uses fetch_max on 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:

    A/B counters phase 12 bits 1: kernel_asks=3.20 blocks_read_only=495.00 guard_wait_ms=10.010 protect_ms=8.204 steps_ms=21.300 ...
    

    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\:

  • New tests (--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 on main, where it fails by assertion ("the take emptied the total"), because asks() 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 --check and check_no_game_data.py are 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 with main as with this branch.
  • Not run in game yet: I will post one LEONIDA_AB run'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

  • Based on current main and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (Not applicable: no translator change.)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5571313988 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2779). Originally posted by [TheGeogeo](https://github.com/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_AB` turns 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_AB` for 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) and `SPLIT` (the submitting thread's preparing) were emptied with `swap(0)` each time the frame line was written. - That line runs on its own thread at its own pace, so a phase could not read them without stealing the frame line's values. This change: - turns those three arrays into **running totals, never reset**. No writer changes: every `tally`, `fault_count` and `SPLIT[i].fetch_add` stays as it is; - makes the frame line take what came since its last take (`ab::take`), so it prints the same numbers. It uses `fetch_max` on 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: ``` A/B counters phase 12 bits 1: kernel_asks=3.20 blocks_read_only=495.00 guard_wait_ms=10.010 protect_ms=8.204 steps_ms=21.300 ... ``` 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\`: - New tests (`--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 on `main`, where it **fails by assertion** ("the take emptied the total"), because `asks()` 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 --check` and `check_no_game_data.py` are 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 with `main` as with this branch. - Not run in game yet: I will post one `LEONIDA_AB` run'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 - [x] Based on current `main` and merges cleanly. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (Not applicable: no translator change.)
KelboLive commented 2026-11-30 18:36:52 +00:00 (Migrated from github.com)

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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7288109367 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2779#issuecomment-7288109367). Originally posted by [KelboLive](https://github.com/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).
enlight3d commented 2026-11-30 23:05:55 +00:00 (Migrated from github.com)

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 main 8f41d7d01 with git merge --no-ff, no conflicts. The head still merges cleanly into main b1f91c2f9. 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 behind diagnostics.
  • 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_take and the three ab::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 in ab.rs, host.rs or watch.rs (6 already there without the feature, 7 with it, the same on the merge).
  • Red, by assertion: on main with only the new watch.rs test added, cargo test -p leonida-gpu --lib --features diagnostics a_running_total_survives fails with "the take emptied the total". Main's asks() swaps the counter to 0. With the change it passes.
  • Red, behavioural, by mutation: with ab::take reading the last take without moving it (taken[i].load instead of fetch_max), 2 of the 3 ab::tests fail. a_take_counts_what_came_since_the_last_one_and_the_totals_stay gets [8, 7] for [3, 7], and takers_at_once_count_everything_once counts 800,070,223 for 40,000.
  • Not covered here: the new A/B counters line in a real LEONIDA_AB run. 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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7294706141 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2779#issuecomment-7294706141). Originally posted by [enlight3d](https://github.com/enlight3d) on 2026-11-30T23:05:55Z. --- RUN (independent run on Windows, #2779 head 4c36dba7c, merged locally into main 8f41d7d01 with `git merge --no-ff`, no conflicts. The head still merges cleanly into main b1f91c2f9. 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 behind `diagnostics`. - `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_take` and the three `ab::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 in `ab.rs`, `host.rs` or `watch.rs` (6 already there without the feature, 7 with it, the same on the merge). - Red, by assertion: on main with only the new `watch.rs` test added, `cargo test -p leonida-gpu --lib --features diagnostics a_running_total_survives` fails with "the take emptied the total". Main's `asks()` swaps the counter to 0. With the change it passes. - Red, behavioural, by mutation: with `ab::take` reading the last take without moving it (`taken[i].load` instead of `fetch_max`), 2 of the 3 `ab::tests` fail. `a_take_counts_what_came_since_the_last_one_and_the_totals_stay` gets [8, 7] for [3, 7], and `takers_at_once_count_everything_once` counts 800,070,223 for 40,000. - Not covered here: the new `A/B counters` line in a real `LEONIDA_AB` run. 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.
MoonEyes commented 2026-11-30 23:13:29 +00:00 (Migrated from github.com)

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 into main 407f71a23 (clean).

  • Machine: RTX 4060 8 GB, Windows 11, diag profile, features diagnostics,mimalloc, Series S, -FrameGen 2 (frame generation files absent, so off), BAR window off, texture budget 1024 MB.
  • In-game, standing in the prologue cell, 480 s asked each: 2 runs, 0 device lost, 0 panics, 0 exceptions, alive at the time limit. About 500 s in the world each. Frame rate median 18.7 (first start: shaders retranslated and pipelines made, 955 s) and 18.6 (warm, 167 s). p5 11.0 and 11.6. The lowest lines are the load and the window's end.
  • Tests on main eec86d0fa + the three (Windows): leonida 47, leonida-hle 223, leonida-gpu 582, leonida-shader 403, 0 failed.
  • Red for #2779, by mutation (leonida-gpu, --features diagnostics, ab::): 4 pass; take without 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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7294861181 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2779#issuecomment-7294861181). Originally posted by [MoonEyes](https://github.com/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 into `main` `407f71a23` (clean). - **Machine:** RTX 4060 8 GB, Windows 11, diag profile, features diagnostics,mimalloc, Series S, `-FrameGen 2` (frame generation files absent, so off), BAR window off, texture budget 1024 MB. - **In-game, standing in the prologue cell, 480 s asked each:** 2 runs, **0 device lost, 0 panics, 0 exceptions**, alive at the time limit. About 500 s in the world each. Frame rate median 18.7 (first start: shaders retranslated and pipelines made, 955 s) and 18.6 (warm, 167 s). p5 11.0 and 11.6. The lowest lines are the load and the window's end. - **Tests on `main` `eec86d0fa` + the three (Windows):** leonida 47, leonida-hle 223, leonida-gpu 582, leonida-shader 403, 0 failed. - **Red for #2779, by mutation** (leonida-gpu, `--features diagnostics`, `ab::`): 4 pass; `take` without 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).
MoonEyes commented 2026-11-30 23:14:25 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T23:14:25Z.


Merging. Head 4c36dba7c merges cleanly with main 29635b202 and 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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7294880331 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2779#issuecomment-7294880331). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-30T23:14:25Z. --- Merging. Head `4c36dba7c` merges cleanly with `main` `29635b202` and 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).
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
ProjectLeonida/mandy!2779
No description provided.