WIP: [pr-diagnostics] Count the CPU cost of per-draw descriptor tables, plus DARNER_DIAG_SUBMIT_DELAY_US (diagnostics builds only) #307

Manually merged
TrustNo1 merged 3 commits from Jesper-A/Darner:up-diag-desc-tables into main 2026-12-04 22:17:51 +00:00
Collaborator

Refs #269

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on main: there is no number for how much CPU time the recording threads spend building the per-draw descriptor tables (State::tables in draw.rs), or where inside it the time goes. The descriptor switches in #269 (DARNER_LIST_VIEWS_FRAME, DARNER_FAST_LIST_VIEWS, DARNER_DIRECT_DYNAMIC_CBV, DARNER_SHARED_TABLES, DARNER_SAME_TABLES) cut descriptor work, and on my card that does not show in fps. I could not say how big the work is or whether a CPU-bound PC would see it. Read from the code and measured on one PC; see below.

This adds counters and one test switch. It changes nothing in how the game runs. It exists so that testers on other PCs can send a log that answers the question (see #269), and so the counters are upstream for anyone measuring descriptor work.

Counters (crates/darner-gpu/src/copystat.rs, hooks in draw.rs and descriptor/host.rs; all behind the diagnostics feature):

  • Commit a7e2a32cf. Per frame, the time in State::tables, in building the RecordHash keys and the records hashed, in the fill loop and the slots it filled, fresh_tables hits and misses, views created against slots served by make_listed, and root one-slot tables made. Logged next to the other copy counters as:

    desc tables: per frame N tables() calls X ms (P% of Y ms list calls); hash X ms for N records; dynamic() X ms; fill X ms for N slots; fresh_tables N hits N misses; N views created, N slots from make_listed; N root tables

  • Commit 599bf6f3a. Splits the fill cost: time and calls inside the Create*View/CreateSampler calls, inside CopyDescriptors/CopyDescriptorsSimple (calls and descriptors), in make_listed lookups (and how many made a view), and the rest of the fill. Counted per thread inside the fill and added to the shared counters once per fill, not with an atomic per call. Logged as:

    desc fill split: per frame fill X ms = create X ms in N calls + copy X ms in N calls (N descriptors) + make_listed X ms in N calls (N made a view) + rest X ms

New switch DARNER_DIAG_SUBMIT_DELAY_US (microseconds, default 0 = off; only in diagnostics builds):

  • Commit c03ed4e4c. Read in copystat::submit_delay_us (copystat.rs): first crate::hot::over, so a DARNER_HOT_AB file can change it while the title runs; otherwise once from the environment into a OnceLock. From the environment, a value that is not a whole number counts as 0 (a non-numeric DARNER_HOT_AB value falls through to the environment). When above 0 it logs diag: submit delay N us per frame once (environment path).
  • copystat::submit_delay() is called once per shown frame at the start of queue::show_planes, just before present_placed, and spins on the clock for that long.
  • It is a test aid: it asks whether extra CPU time on the submit thread moves the frame rate.
  • README: one row in the diagnostics switch table, next to DARNER_D3D12_WARP.

Does a release build change? By the diff, no behaviour change, and the counters are compiled out. I did not build or time a release exe, so this is read from the code, not measured.

  • copystat is only compiled with all(windows, feature = "diagnostics") (lib.rs). Without it, lib.rs has a stub module with four #[inline(always)] functions: create, copied and listed run the closure they are given, submit_delay is empty.
  • The call sites in descriptor/host.rs now wrap the existing Create*View/CreateSampler/CopyDescriptors* calls in those closures. Same calls in the same order.
  • The counter calls in draw.rs are each behind #[cfg(feature = "diagnostics")].
  • State::tables is split in two: tables (the same signature) calls the new tables_inner, which holds the old body. With diagnostics off tables only calls tables_inner. The compiler may inline it or not, so the machine code of that function can differ; the behaviour does not.
  • Counters are in the diag build only, and the diag build counts every allocation, so it runs a little slower than release.

How it was tested

  • Tested revision: 599bf6f3a (two commits on main f3840d73d) for the runs; c03ed4e4c (a third commit, how the switch is read) for the gates.
  • Commands and results:
    • cargo build --locked --profile diag -p darner --features diagnostics on 599bf6f3a: built; this is the exe all six runs below used.

    • Game runs, 2026-12-04, diag exe, one run per arm, 6 runs in a row (one unscored settle run first). Series S, DLSS Performance, frame generation off, my usual play set of switches, free roaming. Numbers are the last 180 one-second lines of each run. The "fill" column is the desc tables: fill time per frame, summed over the recording threads (mean of the last 40 counter lines).

      arm avg fps p95 frame time fill ms per frame
      settle (not scored) 15.44 72.2 103.3
      no switches, no delay 13.92 77.8 110.4
      no switches, +5 ms submit delay 14.67 75.5 103.6
      no switches, +10 ms 15.77 71.0 102.0
      no switches, +20 ms 15.53 72.9 99.3
      the five switches above, no delay 15.66 71.3 100.2
    • Split of the fill with no switches and no delay (mean of the last 40 counter lines, ms per frame summed over threads): create 16.9, copy 2.5, make_listed 51.2, rest 39.8. Last line: 53k create calls, 23k copy calls (73k descriptors), 72k make_listed calls of which 22k made a view.

  • Changes a default: no. The counters need the diagnostics feature, and the new switch is off unless set.
  • A/B result: not a change of a default and not a speed claim, so no A/B. What the runs show, for what it is worth: adding 5, 10 and 20 ms of spin on the submit thread did not lower fps on this PC, so the frame is not limited by the submit thread here; and the table-building work is a large share of the recording threads' time (about 100 ms per frame summed over the threads). n = 1 per arm, and two launches of the same setup differ by about 1 fps for me, so the differences between arms are not detectable here. No confidence intervals: one run each.
  • Gates run on c03ed4e4c (599bf6f3a plus the switch-reading commit; the runs below used 599bf6f3a, whose code differs only in how the switch is read): cargo clippy --workspace --all-targets --locked -- -D warnings passed, and the same with --all-features passed. cargo test -p darner-gpu --lib copystat --all-features --locked: 11 passed. cargo test --workspace --locked failed in darner-shader --lib on four GPU/DXIL-validation tests (emit::barycentric_tests::first_half_values_render_on_hardware_and_warp, emit::rect::tests::rectangles_are_drawn_whole, emit::rect::tests::the_rectangle_stage_is_a_geometry_shader, emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders). This PR does not touch darner-shader. The same four failed on this PC for other branches that do not touch it either (one rebased on main f899d8cff); I did not rerun them on main f3840d73d itself. The run stopped at that crate, so the crates after it were not run.
  • Gameplay, when relevant: RTX 2070 SUPER 8 GB (Turing), driver 621.40, ReBAR off, Ryzen 7 5800X, 32 GB, Windows 11 Pro Insider 26320, GPU clocks unlocked, Series S profile, DLSS Performance, frame generation off.
  • Shader wave sizes tested, when relevant: not relevant (no shader change).
  • Hardware dependence: likely general (see Spec dependence).
  • Coverage gaps: no release build compiled or timed; no other GPU, CPU, console profile or scene; no frame generation; no second run per arm; the workspace tests after darner-shader; memory not recorded. The runs were not taken to prove the counters are exact: the sum of the split parts equals the fill time by construction (rest = fill minus the other three), so only the three timed parts are independent measurements.

Spec dependence

Likely general: the counters time ordinary code paths and the switch spins on the clock. The numbers above, and what they say about where the frame is limited, depend on my specs (RTX 2070 SUPER, Turing, 8 GB, ReBAR off, Ryzen 7 5800X, Series S + DLSS Performance). On a fast card the CPU may be the limit instead; that is the question the counters are for, and it is untested on any other PC.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only). Ran in the game as a diag build, six runs on one PC (above); not run as a release build.
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md. No game data; text only.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: none found that add descriptor-table counters or a submit delay (searched open and closed issues and PRs for "copystat", "descriptor tables", "desc tables", "SUBMIT_DELAY", "diagnostics counters"). Open PRs that touch the same files, checked on 2026-12-04 through the API, none in the same code:
    • descriptor/host.rs: #231 (skip cached raw descriptor writes when disabled) and #245 (retry temporary stand-in texture allocation failures). Different functions; #231's hunks sit at lines 6177-6325 of the base, near my wrapped calls at 6082-6730, so a textual conflict is possible there.
    • draw.rs: #187, #143, #57, #48, #17, #15, #14. Their hunks are in other functions; the nearest is #48 (a hunk at about line 6943, just after my fill loop at 6446-6913).
    • #273 (README, measurements for two switches on #269) edits README.md; mine adds one row in another table.
    • Refs #269 (open report): no pull request of its own beyond #273.
  • Replaces or overlaps: none found.

This pull request was written with AI assistance (Claude Code).

Refs #269 ## Contributor role (optional) - Fluxer ID: ## What it changes - The problem on main: there is no number for how much CPU time the recording threads spend building the per-draw descriptor tables (`State::tables` in `draw.rs`), or where inside it the time goes. The descriptor switches in #269 (`DARNER_LIST_VIEWS_FRAME`, `DARNER_FAST_LIST_VIEWS`, `DARNER_DIRECT_DYNAMIC_CBV`, `DARNER_SHARED_TABLES`, `DARNER_SAME_TABLES`) cut descriptor work, and on my card that does not show in fps. I could not say how big the work is or whether a CPU-bound PC would see it. Read from the code and measured on one PC; see below. This adds counters and one test switch. **It changes nothing in how the game runs.** It exists so that testers on other PCs can send a log that answers the question (see #269), and so the counters are upstream for anyone measuring descriptor work. **Counters** (`crates/darner-gpu/src/copystat.rs`, hooks in `draw.rs` and `descriptor/host.rs`; all behind the `diagnostics` feature): - Commit a7e2a32cf. Per frame, the time in `State::tables`, in building the `RecordHash` keys and the records hashed, in the fill loop and the slots it filled, `fresh_tables` hits and misses, views created against slots served by `make_listed`, and root one-slot tables made. Logged next to the other copy counters as: `desc tables: per frame N tables() calls X ms (P% of Y ms list calls); hash X ms for N records; dynamic() X ms; fill X ms for N slots; fresh_tables N hits N misses; N views created, N slots from make_listed; N root tables` - Commit 599bf6f3a. Splits the fill cost: time and calls inside the `Create*View`/`CreateSampler` calls, inside `CopyDescriptors`/`CopyDescriptorsSimple` (calls and descriptors), in `make_listed` lookups (and how many made a view), and the rest of the fill. Counted per thread inside the fill and added to the shared counters once per fill, not with an atomic per call. Logged as: `desc fill split: per frame fill X ms = create X ms in N calls + copy X ms in N calls (N descriptors) + make_listed X ms in N calls (N made a view) + rest X ms` **New switch** `DARNER_DIAG_SUBMIT_DELAY_US` (microseconds, default 0 = off; only in diagnostics builds): - Commit c03ed4e4c. Read in `copystat::submit_delay_us` (`copystat.rs`): first `crate::hot::over`, so a `DARNER_HOT_AB` file can change it while the title runs; otherwise once from the environment into a `OnceLock`. From the environment, a value that is not a whole number counts as 0 (a non-numeric `DARNER_HOT_AB` value falls through to the environment). When above 0 it logs `diag: submit delay N us per frame` once (environment path). - `copystat::submit_delay()` is called once per shown frame at the start of `queue::show_planes`, just before `present_placed`, and spins on the clock for that long. - It is a test aid: it asks whether extra CPU time on the submit thread moves the frame rate. - README: one row in the diagnostics switch table, next to `DARNER_D3D12_WARP`. **Does a release build change?** By the diff, no behaviour change, and the counters are compiled out. I did not build or time a release exe, so this is read from the code, not measured. - `copystat` is only compiled with `all(windows, feature = "diagnostics")` (`lib.rs`). Without it, `lib.rs` has a stub module with four `#[inline(always)]` functions: `create`, `copied` and `listed` run the closure they are given, `submit_delay` is empty. - The call sites in `descriptor/host.rs` now wrap the existing `Create*View`/`CreateSampler`/`CopyDescriptors*` calls in those closures. Same calls in the same order. - The counter calls in `draw.rs` are each behind `#[cfg(feature = "diagnostics")]`. - `State::tables` is split in two: `tables` (the same signature) calls the new `tables_inner`, which holds the old body. With diagnostics off `tables` only calls `tables_inner`. The compiler may inline it or not, so the machine code of that function can differ; the behaviour does not. - Counters are in the diag build only, and the diag build counts every allocation, so it runs a little slower than release. ## How it was tested - Tested revision: 599bf6f3a (two commits on main f3840d73d) for the runs; c03ed4e4c (a third commit, how the switch is read) for the gates. - Commands and results: - `cargo build --locked --profile diag -p darner --features diagnostics` on 599bf6f3a: built; this is the exe all six runs below used. - Game runs, 2026-12-04, diag exe, one run per arm, 6 runs in a row (one unscored settle run first). Series S, DLSS Performance, frame generation off, my usual play set of switches, free roaming. Numbers are the last 180 one-second lines of each run. The "fill" column is the `desc tables:` fill time per frame, summed over the recording threads (mean of the last 40 counter lines). | arm | avg fps | p95 frame time | fill ms per frame | |---|---:|---:|---:| | settle (not scored) | 15.44 | 72.2 | 103.3 | | no switches, no delay | 13.92 | 77.8 | 110.4 | | no switches, +5 ms submit delay | 14.67 | 75.5 | 103.6 | | no switches, +10 ms | 15.77 | 71.0 | 102.0 | | no switches, +20 ms | 15.53 | 72.9 | 99.3 | | the five switches above, no delay | 15.66 | 71.3 | 100.2 | - Split of the fill with no switches and no delay (mean of the last 40 counter lines, ms per frame summed over threads): create 16.9, copy 2.5, `make_listed` 51.2, rest 39.8. Last line: 53k create calls, 23k copy calls (73k descriptors), 72k `make_listed` calls of which 22k made a view. - Changes a default: no. The counters need the `diagnostics` feature, and the new switch is off unless set. - A/B result: not a change of a default and not a speed claim, so no A/B. What the runs show, for what it is worth: adding 5, 10 and 20 ms of spin on the submit thread did not lower fps on this PC, so the frame is not limited by the submit thread here; and the table-building work is a large share of the recording threads' time (about 100 ms per frame summed over the threads). n = 1 per arm, and two launches of the same setup differ by about 1 fps for me, so the differences between arms are not detectable here. No confidence intervals: one run each. - Gates run on c03ed4e4c (599bf6f3a plus the switch-reading commit; the runs below used 599bf6f3a, whose code differs only in how the switch is read): `cargo clippy --workspace --all-targets --locked -- -D warnings` passed, and the same with `--all-features` passed. `cargo test -p darner-gpu --lib copystat --all-features --locked`: 11 passed. `cargo test --workspace --locked` failed in `darner-shader --lib` on four GPU/DXIL-validation tests (`emit::barycentric_tests::first_half_values_render_on_hardware_and_warp`, `emit::rect::tests::rectangles_are_drawn_whole`, `emit::rect::tests::the_rectangle_stage_is_a_geometry_shader`, `emit::waterfall_tests::sampled_marks_restore_early_depth_only_when_safe_in_pixel_shaders`). This PR does not touch `darner-shader`. The same four failed on this PC for other branches that do not touch it either (one rebased on main f899d8cff); I did not rerun them on main f3840d73d itself. The run stopped at that crate, so the crates after it were not run. - Gameplay, when relevant: RTX 2070 SUPER 8 GB (Turing), driver 621.40, ReBAR off, Ryzen 7 5800X, 32 GB, Windows 11 Pro Insider 26320, GPU clocks unlocked, Series S profile, DLSS Performance, frame generation off. - Shader wave sizes tested, when relevant: not relevant (no shader change). - Hardware dependence: likely general (see Spec dependence). - Coverage gaps: no release build compiled or timed; no other GPU, CPU, console profile or scene; no frame generation; no second run per arm; the workspace tests after `darner-shader`; memory not recorded. The runs were not taken to prove the counters are exact: the sum of the split parts equals the fill time by construction (rest = fill minus the other three), so only the three timed parts are independent measurements. ## Spec dependence Likely general: the counters time ordinary code paths and the switch spins on the clock. The numbers above, and what they say about where the frame is limited, depend on my specs (RTX 2070 SUPER, Turing, 8 GB, ReBAR off, Ryzen 7 5800X, Series S + DLSS Performance). On a fast card the CPU may be the limit instead; that is the question the counters are for, and it is untested on any other PC. ## Checklist - [ ] I ran this change in the game, or say below why it can't be (docs, tests only). Ran in the game as a diag build, six runs on one PC (above); not run as a release build. - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. No game data; text only. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: none found that add descriptor-table counters or a submit delay (searched open and closed issues and PRs for "copystat", "descriptor tables", "desc tables", "SUBMIT_DELAY", "diagnostics counters"). Open PRs that touch the same files, checked on 2026-12-04 through the API, none in the same code: - `descriptor/host.rs`: #231 (skip cached raw descriptor writes when disabled) and #245 (retry temporary stand-in texture allocation failures). Different functions; #231's hunks sit at lines 6177-6325 of the base, near my wrapped calls at 6082-6730, so a textual conflict is possible there. - `draw.rs`: #187, #143, #57, #48, #17, #15, #14. Their hunks are in other functions; the nearest is #48 (a hunk at about line 6943, just after my fill loop at 6446-6913). - #273 (README, measurements for two switches on #269) edits `README.md`; mine adds one row in another table. - Refs #269 (open report): no pull request of its own beyond #273. - Replaces or overlaps: none found. This pull request was written with AI assistance (Claude Code).
Diagnostics builds only: time in State::tables, RecordHash building, the
fill loop, fresh_tables hits/misses, views created against make_listed
hits and root one-slot tables, logged as a "desc tables:" line with the
share of list-call time. No behaviour change.

This change was made with AI assistance (Claude Code).
Diagnostics builds only. A "desc fill split:" line next to "desc tables:":
time and calls inside the Create*View/CreateSampler calls, inside
CopyDescriptors/CopyDescriptorsSimple (calls and descriptors), in make_listed
lookups (and how many made a view), and the rest of the fill. Counted per
thread inside the fill and added to the counters once per fill.

DARNER_DIAG_SUBMIT_DELAY_US: spins that many microseconds once per shown
frame in queue::show_planes before present_placed; logs "diag: submit delay
N us per frame". Unset or 0: no effect.

This change was made with AI assistance (Claude Code).
There is no toggled!/asked_for! form for a numeric switch; hot.rs is the
project's reader for values (the DARNER_HOT_AB file, else the environment,
cached once). The default stays 0 = off. README row updated.

This change was made with AI assistance (Claude Code).
TrustNo1 manually merged commit 7679c3d803 into main 2026-12-04 22:17:03 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
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.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!307
No description provided.