d3d12/host: record distinct list state preludes across the wide pool (D3D12-WIDE-PRELUDES) #3494

Code

Clone this repository

Checkout

From your project repository, check out a new branch and test the changes.

git fetch -u  "d3d12/wide-preludes:und3rlake-d3d12/wide-preludes"
git switch "und3rlake-d3d12/wide-preludes"
Open
leonida/mandy
und3rlake wants to merge 1 commit from und3rlake/mandy:d3d12/wide-preludes into main

This branch is out-of-date with the base branch

Conversation
Reviewers 0 approvals
  • No reviewers
Details
This pull request is blocked because it's outdated.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'd3d12/wide-preludes:und3rlake-d3d12/wide-preludes'
git switch 'und3rlake-d3d12/wide-preludes'
First-time contributor

What / why

In steady-state world profiling (LEONIDA_PROFILE on leonida-submit, 12,423 samples), HostList::prelude accounted for ~5.8% of submitting-thread time (721 samples: 332 in ID3D12GraphicsCommandList::Reset, 154 in Close, 116 in ID3D12CommandAllocator::Reset, 119 in CopyTextureRegion). Every list in a submission recorded its prelude sequentially on leonida-submit, even though each distinct HostList owns an independent (ID3D12CommandAllocator, ID3D12GraphicsCommandList) pair.

Change

  • Split HostList::prelude into:
    1. HostList::plan_prelude: runs sequentially in submission order inside Host::submit_for, preserving exact copy.state.swap(*last) and u.twin.behind.store(left) mutations and collecting Arc-owned barrier/sync/upload descriptors into PreludePlan (reserving lists[slot] in exact runs order so firsts is unchanged).
    2. PreludePlan::record + record_preludes: records the D3D12 commands (allocator_refresh, allocator.Reset, list.Reset, ResourceBarrier, record_twin_copy, upload.record, list.Close) in parallel across crate::shadow::wide_each when LEONIDA_WIDE_PRELUDES is on (crate::toggled!, on by default, nameable in LEONIDA_AB), plans.len() >= 2, and distinct_preludes confirms no two plans share a HostList pointer (falling back to sequential order otherwise).
  • Time record_preludes wall-clock into SPLIT[16] (preludes_ms) for apples-to-apples A/B accounting.
  • Update d3d12/docs/switches.md (single added row for LEONIDA_WIDE_PRELUDES) and add host::wide_preludes_tests::distinct_preludes_detects_unique_and_duplicate_lists.

Verification (NVIDIA RTX 5070 12 GB, Windows 11)

  • cargo test -p leonida-gpu --lib --locked host::wide_preludes_tests: PASS (1/1)
  • python -I tools/d3d12_switches.py --check d3d12/docs/switches.md & python -I scripts/check_no_game_data.py: PASS
  • In-run LEONIDA_AB=4,LEONIDA_WIDE_PRELUDES (-SeriesS -NoFrameGen -NoPrecompile -AutoMenu, 200 s in world, max_draws = 6,972, 0 ERROR lines, device-lost.txt = false):
    • tools/d3d12_ab_compare.py phases (28 paired blocks):
      • preludes_ms: -0.799 +- 0.097 ms (8.2 sigma)
      • steps_ms: -0.986 +- 0.203 ms (4.9 sigma)
      • median frame time (all 28 pairs): -1.739 +- 1.328 ms
    • Settled world phases (16 consecutive pairs, phase >= 50, draws >= 3,500, frames >= 40):
      • median_ms: 39.50 ms (OFF) -> 38.95 ms (ON), paired -0.613 +- 0.198 ms (3.1 sigma, 13/16 pairs faster)
    • scripts/ab_cpu.py (26 pairs): submit_user_ms median 24.877 ms (OFF) -> 23.488 ms (ON).

AI-assisted.

## What / why In steady-state world profiling (`LEONIDA_PROFILE` on `leonida-submit`, `12,423` samples), `HostList::prelude` accounted for **~5.8% of submitting-thread time** (`721` samples: `332` in `ID3D12GraphicsCommandList::Reset`, `154` in `Close`, `116` in `ID3D12CommandAllocator::Reset`, `119` in `CopyTextureRegion`). Every list in a submission recorded its prelude sequentially on `leonida-submit`, even though each distinct `HostList` owns an independent `(ID3D12CommandAllocator, ID3D12GraphicsCommandList)` pair. ## Change - Split `HostList::prelude` into: 1. `HostList::plan_prelude`: runs sequentially in submission order inside `Host::submit_for`, preserving exact `copy.state.swap(*last)` and `u.twin.behind.store(left)` mutations and collecting `Arc`-owned barrier/sync/upload descriptors into `PreludePlan` (reserving `lists[slot]` in exact `runs` order so `firsts` is unchanged). 2. `PreludePlan::record` + `record_preludes`: records the D3D12 commands (`allocator_refresh`, `allocator.Reset`, `list.Reset`, `ResourceBarrier`, `record_twin_copy`, `upload.record`, `list.Close`) in parallel across `crate::shadow::wide_each` when `LEONIDA_WIDE_PRELUDES` is on (`crate::toggled!`, on by default, nameable in `LEONIDA_AB`), `plans.len() >= 2`, and `distinct_preludes` confirms no two plans share a `HostList` pointer (falling back to sequential order otherwise). - Time `record_preludes` wall-clock into `SPLIT[16]` (`preludes_ms`) for apples-to-apples A/B accounting. - Update `d3d12/docs/switches.md` (single added row for `LEONIDA_WIDE_PRELUDES`) and add `host::wide_preludes_tests::distinct_preludes_detects_unique_and_duplicate_lists`. ## Verification (`NVIDIA RTX 5070 12 GB`, `Windows 11`) - `cargo test -p leonida-gpu --lib --locked host::wide_preludes_tests`: **PASS** (`1/1`) - `python -I tools/d3d12_switches.py --check d3d12/docs/switches.md` & `python -I scripts/check_no_game_data.py`: **PASS** - In-run `LEONIDA_AB=4,LEONIDA_WIDE_PRELUDES` (`-SeriesS -NoFrameGen -NoPrecompile -AutoMenu`, `200 s` in world, `max_draws = 6,972`, `0` `ERROR` lines, `device-lost.txt = false`): - `tools/d3d12_ab_compare.py phases` (`28` paired blocks): - **`preludes_ms`: `-0.799 +- 0.097 ms`** (`8.2 sigma`) - **`steps_ms`: `-0.986 +- 0.203 ms`** (`4.9 sigma`) - `median` frame time (all `28` pairs): `-1.739 +- 1.328 ms` - Settled world phases (`16` consecutive pairs, `phase >= 50`, `draws >= 3,500`, `frames >= 40`): - `median_ms`: `39.50 ms` (OFF) -> `38.95 ms` (ON), paired **`-0.613 +- 0.198 ms`** (`3.1 sigma`, `13/16` pairs faster) - `scripts/ab_cpu.py` (`26` pairs): `submit_user_ms` median `24.877 ms` (OFF) -> `23.488 ms` (ON). AI-assisted.
In steady-state world profiling, HostList::prelude accounted for ~5.8%
of leonida-submit wall-clock time: each list in a submission ran
allocator.Reset(), list.Reset(), ResourceBarrier/CopyTextureRegion, and
list.Close() sequentially on the submitting thread even though every
distinct HostList owns an independent prelude allocator and command
list.

Split HostList::prelude into submission-order planning (plan_prelude,
preserving exact texture state and twin-dirty transitions) and D3D12
recording (PreludePlan::record), and run recording across
crate::shadow::wide_each when two or more distinct HostList targets
need a prelude — behind LEONIDA_WIDE_PRELUDES (on by default, nameable
in LEONIDA_AB). Fall back to sequential recording whenever a submission
repeats a HostList pointer, update d3d12/docs/switches.md, and add unit
tests for distinct_preludes.
First-time contributor

Independent local verification of this change (I changed no code).

  • Head 550b01d2, merge base 6b0498d3. The new test is absent on the base: git grep -F distinct_preludes_detects_unique_and_duplicate_lists 6b0498d3 -- d3d12/crates/leonida-gpu/src/host.rs -> exit 1.
  • On the PR head, with the module-qualified name, -- --exact and a private CARGO_TARGET_DIR: host::wide_preludes_tests::distinct_preludes_detects_unique_and_duplicate_lists -> 1 passed / 850 filtered. No device gate was added.
  • git diff --check 6b0498d3 550b01d2 -> clean. python -I scripts/check_no_game_data.py d3d12/crates/leonida-gpu/src/host.rs d3d12/docs/switches.md -> clean.

GPUs tested: none (synthetic prelude lists; CPU-only unit test). Driver: n/a. No game data, assets or extracted shaders were used or attached.

AI-assisted: yes, Hy4 flash (verification only). No approval implied; this is a local test report.

Independent local verification of this change (I changed no code). - Head `550b01d2`, merge base `6b0498d3`. The new test is absent on the base: `git grep -F distinct_preludes_detects_unique_and_duplicate_lists 6b0498d3 -- d3d12/crates/leonida-gpu/src/host.rs` -> exit 1. - On the PR head, with the module-qualified name, `-- --exact` and a private `CARGO_TARGET_DIR`: `host::wide_preludes_tests::distinct_preludes_detects_unique_and_duplicate_lists` -> 1 passed / 850 filtered. No device gate was added. - `git diff --check 6b0498d3 550b01d2` -> clean. `python -I scripts/check_no_game_data.py d3d12/crates/leonida-gpu/src/host.rs d3d12/docs/switches.md` -> clean. GPUs tested: none (synthetic prelude lists; CPU-only unit test). Driver: n/a. No game data, assets or extracted shaders were used or attached. AI-assisted: yes, Hy4 flash (verification only). No approval implied; this is a local test report.
First-time contributor

Independent in-game A/B of this pull request on a second machine, a processor-bound one on the Series X profile (I changed no code).

RUN 4070tis-3494-ab-1 | 2026-12-05 02:46 UTC | 3mptymud | AI-assisted: Claude Code (Claude Fable 5.2)
BASE:        f4b0404e95 + #3494 (head 550b01d21d, git merge --no-ff) + none | shaders: the runtime's own translation
MACHINE:     NVIDIA GeForce RTX 4070 Ti SUPER, 16 GB, desktop | 621.24 | Windows 11 Pro 26100 | 32 GB RAM, Ryzen 7 5800X, resizable BAR on
RECIPE:      scripts/play-d3d12.ps1 -Game <folder> -Log -NoFrameGen -PrecompileUsed, the script's defaults otherwise (Series X, the title's own upscaler, no DLSS, output 2560x1440) + DEVIATIONS: LEONIDA_AB=4,LEONIDA_WIDE_PRELUDES; menus passed by scripted pad presses; the same save restored before the run, standing where it loads | precompile: yes, 88,875 pipelines made beforehand, 0 bad
OS/DRIVER:   defaults; Developer Mode on (background shader work off by the new default)
TARGET:      preludes_ms and steps_ms, on minus off | PREDICTED: lower with the switch on, as the author measured
MEASURED:    see the table | 330 s in the world (90 s settling, then 240 s) | 23.1 fps, median frame 43.3 ms, about 6,800 draws a frame
END:         time limit (closed by the runner), no device loss, 0 ERROR lines, read from the log
CACHES:      warm (pipelines precompiled, driver cache warm) | RUN 1 of 1
VERDICT:     prediction held for the counters; frame time: no clear difference

python -I tools/d3d12_ab_compare.py phases <log>: 99 phases of 4 s, 43 pairs of blocks, 6 left out for a draw jump. On minus off, mean and standard error:

Counter on - off
preludes_ms -1.006 +- 0.029 ms
steps_ms -1.023 +- 0.113 ms
title_bytes_ms -0.136 +- 0.039 ms
guard_wait_ms +0.819 +- 0.276 ms
kernel_asks +0.588 +- 0.233 a frame
median frame time -0.123 +- 0.168 ms (tool's verdict: no clear difference)

python -I scripts/ab_cpu.py <log>: frame time median 43.70 ms off, 43.65 ms on; p99 54.9 ms off, 53.0 ms on. Its paired means are not usable for this run: one phase at the world's entry holds a 5.8 s frame (an off phase, during loading, before the settled window), which swamps them.

Reading: the saving the pull request claims shows on this machine too, at about 1.0 ms of the submitting thread's work a frame (the author's RTX 5070, Series S: 0.8 ms). It does not show as a shorter frame here within the noise of one 330 s run. One counter moved the other way and may be worth a look: guard_wait_ms is 0.82 +- 0.28 ms higher with the switch on, about as much as the preludes save. Nothing else got worse: no error, no device loss.

Not tested: a cold cache, walking or driving, frame generation, the unit test (already checked by others above), any other GPU.

tested: #3494 on RTX 4070 Ti SUPER (16 GB), same: play / play.

GPUs tested: NVIDIA GeForce RTX 4070 Ti SUPER 16 GB, driver 621.24, Windows 11 Pro 26100.
AI-assisted: yes. Claude Code (Claude Fable 5.2) merged, built, ran and read the run; no approval implied.

Independent in-game A/B of this pull request on a second machine, a processor-bound one on the Series X profile (I changed no code). ```text RUN 4070tis-3494-ab-1 | 2026-12-05 02:46 UTC | 3mptymud | AI-assisted: Claude Code (Claude Fable 5.2) BASE: f4b0404e95 + #3494 (head 550b01d21d, git merge --no-ff) + none | shaders: the runtime's own translation MACHINE: NVIDIA GeForce RTX 4070 Ti SUPER, 16 GB, desktop | 621.24 | Windows 11 Pro 26100 | 32 GB RAM, Ryzen 7 5800X, resizable BAR on RECIPE: scripts/play-d3d12.ps1 -Game <folder> -Log -NoFrameGen -PrecompileUsed, the script's defaults otherwise (Series X, the title's own upscaler, no DLSS, output 2560x1440) + DEVIATIONS: LEONIDA_AB=4,LEONIDA_WIDE_PRELUDES; menus passed by scripted pad presses; the same save restored before the run, standing where it loads | precompile: yes, 88,875 pipelines made beforehand, 0 bad OS/DRIVER: defaults; Developer Mode on (background shader work off by the new default) TARGET: preludes_ms and steps_ms, on minus off | PREDICTED: lower with the switch on, as the author measured MEASURED: see the table | 330 s in the world (90 s settling, then 240 s) | 23.1 fps, median frame 43.3 ms, about 6,800 draws a frame END: time limit (closed by the runner), no device loss, 0 ERROR lines, read from the log CACHES: warm (pipelines precompiled, driver cache warm) | RUN 1 of 1 VERDICT: prediction held for the counters; frame time: no clear difference ``` `python -I tools/d3d12_ab_compare.py phases <log>`: 99 phases of 4 s, 43 pairs of blocks, 6 left out for a draw jump. On minus off, mean and standard error: | Counter | on - off | | --- | --- | | `preludes_ms` | -1.006 +- 0.029 ms | | `steps_ms` | -1.023 +- 0.113 ms | | `title_bytes_ms` | -0.136 +- 0.039 ms | | `guard_wait_ms` | +0.819 +- 0.276 ms | | `kernel_asks` | +0.588 +- 0.233 a frame | | median frame time | -0.123 +- 0.168 ms (tool's verdict: no clear difference) | `python -I scripts/ab_cpu.py <log>`: frame time median 43.70 ms off, 43.65 ms on; p99 54.9 ms off, 53.0 ms on. Its paired means are not usable for this run: one phase at the world's entry holds a 5.8 s frame (an off phase, during loading, before the settled window), which swamps them. Reading: the saving the pull request claims shows on this machine too, at about 1.0 ms of the submitting thread's work a frame (the author's RTX 5070, Series S: 0.8 ms). It does not show as a shorter frame here within the noise of one 330 s run. One counter moved the other way and may be worth a look: `guard_wait_ms` is 0.82 +- 0.28 ms higher with the switch on, about as much as the preludes save. Nothing else got worse: no error, no device loss. Not tested: a cold cache, walking or driving, frame generation, the unit test (already checked by others above), any other GPU. tested: #3494 on RTX 4070 Ti SUPER (16 GB), same: play / play. GPUs tested: NVIDIA GeForce RTX 4070 Ti SUPER 16 GB, driver 621.24, Windows 11 Pro 26100. AI-assisted: yes. Claude Code (Claude Fable 5.2) merged, built, ran and read the run; no approval implied.
Sign in to join this conversation.
No description provided.