Skip to content

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

Merged
MoonEyes merged 1 commit into
ProjectLeonida:mainfrom
TheGeogeo:d3d12-ab-counters
Nov 30, 2026
Merged

MoonEyes merged 1 commit into
ProjectLeonida:mainfrom
TheGeogeo:d3d12-ab-counters

Conversation

@TheGeogeo

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: D3D12-AB-COUNTERS (#2570 (comment))

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

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

…UNTERS)

LEONIDA_AB compares switch settings by turns in one run, but its phase
lines carried only frame times, the card's idle time and the submitting
thread's work: an A/B could not split by arm the time spent changing memory
protections, refreshing, or waiting. The frame lines' counters (watch's
ASKS and FAULT_ASKS, host's SPLIT) were emptied with swap(0) by the frame
line, which runs on its own thread at its own pace, so a phase could not
read them.

They are now running totals, never reset; no writer changes. The frame
line takes what came since its last take (ab::take, a fetch_max on a
second array, so two takers never count the same amount twice) and prints
the same numbers. Each A/B phase snapshots the totals where it reads the
card's idle time and logs one more line, "A/B counters phase N bits b:",
with each counter that moved, per frame, named next to its array
(nanoseconds as ms). Diagnostics builds only, as before.
@KelboLive

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Contributor

RUN (independent run on Windows, #2779 head 4c36dba, merged locally into main 8f41d7d with git merge --no-ff, no conflicts. The head still merges cleanly into main b1f91c2. 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

Copy link
Copy Markdown
Collaborator

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 d3d12: LEONIDA_AB tells the frame lines' counters by arm (D3D12-AB-COUNTERS) #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

Copy link
Copy Markdown
Collaborator

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

@MoonEyes
MoonEyes merged commit d4fabd3 into ProjectLeonida:main Nov 30, 2026
5 checks passed
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.

4 participants