Skip to content

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

Open
TheGeogeo wants to merge 1 commit into
ProjectLeonida:mainfrom
TheGeogeo:d3d12-ab-counters
Open

TheGeogeo wants to merge 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).

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.

2 participants