d3d12: keep pipeline wait budgets from moving backward #2601

Merged
louisdibiasi merged 1 commit from upstream-pr/2601 into main 2026-11-29 18:59:55 +00:00
louisdibiasi commented 2026-11-29 02:25:17 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by louisdibiasi on 2026-11-29T02:25:17Z.


Claimed in the coordination issue as: Keep an older frame request from resetting the Rust D3D12 pipeline wait budget

What and why

A recording thread can sample the frame number and reach the pipeline wait lock after a newer frame has already spent its budget. Resetting the budget on every frame-number change lets a delayed request for frame 41 reopen a spent budget for frame 42. Give stale requests zero wait time and keep the currently tracked frame's accounting intact.

Tested

  • A deterministic CPU regression covers frame 0, a delayed request, a repeat request for the current frame, and the next frame in both shared and non-shared wait modes. With the original logic the delayed request and the repeat request each get 500 ms. With the fix both get zero and the next frame gets its normal allowance.
  • All eight pipeline::make::tests and the frame counter test passed on Windows 11 with Rust 1.98.1. cargo check --locked --offline --profile diag -p leonida --features diagnostics and the changed-file game-data scan passed.
  • Gameplay impact is unmeasured. If a maintainer has a repeatable pipeline-compilation workload, a matched A/B with frame generation off would help check rendered frame times and draw completeness.

GPUs tested: n/a (CPU-only regression and application check).

AI-assisted: Yes, with OpenAI Codex (GPT-6).

Checklist

  • Based on current main and merges cleanly.
  • One topic.
  • No game data, keys, or decryption.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5546796951 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2601). Originally posted by [louisdibiasi](https://github.com/louisdibiasi) on 2026-11-29T02:25:17Z. --- Claimed in the coordination issue as: [Keep an older frame request from resetting the Rust D3D12 pipeline wait budget](https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7249291723) ### What and why A recording thread can sample the frame number and reach the pipeline wait lock after a newer frame has already spent its budget. Resetting the budget on every frame-number change lets a delayed request for frame 41 reopen a spent budget for frame 42. Give stale requests zero wait time and keep the currently tracked frame's accounting intact. ### Tested - A deterministic CPU regression covers frame 0, a delayed request, a repeat request for the current frame, and the next frame in both shared and non-shared wait modes. With the original logic the delayed request and the repeat request each get 500 ms. With the fix both get zero and the next frame gets its normal allowance. - All eight `pipeline::make::tests` and the frame counter test passed on Windows 11 with Rust 1.98.1. `cargo check --locked --offline --profile diag -p leonida --features diagnostics` and the changed-file game-data scan passed. - Gameplay impact is unmeasured. If a maintainer has a repeatable pipeline-compilation workload, a matched A/B with frame generation off would help check rendered frame times and draw completeness. GPUs tested: n/a (CPU-only regression and application check). AI-assisted: Yes, with OpenAI Codex (GPT-6). ### Checklist - [x] Based on current `main` and merges cleanly. - [x] One topic. - [x] No game data, keys, or decryption.
lixonik commented 2026-11-29 02:31:34 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-29T02:31:34Z.


Reviewed head 2336020880, merged with main c8bf0e7b65. All 8 pipeline::make unit tests passed in leonida-gpu (Windows 10, Rust 1.100.1).

I also compared the reservation logic in isolation with a partly spent budget, in both shared and non-shared modes. With 60 ms already charged against a 100 ms limit for frame 42, the old main logic granted frame 41 another 100 ms. The updated logic granted frame 41 0 ms and left frame 42 with 40 ms. The next frame got the full 100 ms. CPU-only, no game files.

AI-assisted. Codex (GPT-6).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7249482453 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2601#issuecomment-7249482453). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-29T02:31:34Z. --- Reviewed head 233602088041c9c2c75f724dbad187474e2cb286, merged with main c8bf0e7b6568f471b42540010e335ca6413d4c58. All 8 pipeline::make unit tests passed in leonida-gpu (Windows 10, Rust 1.100.1). I also compared the reservation logic in isolation with a partly spent budget, in both shared and non-shared modes. With 60 ms already charged against a 100 ms limit for frame 42, the old main logic granted frame 41 another 100 ms. The updated logic granted frame 41 0 ms and left frame 42 with 40 ms. The next frame got the full 100 ms. CPU-only, no game files. AI-assisted. Codex (GPT-6).
zmasi commented 2026-11-29 03:01:00 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-29T03:01:00Z.


#2601 | head 2336020880 (merged cleanly onto origin/main c8bf0e7b65) | Windows 11 (10.0.26200.9974), rustc 1.96.0 (ac68faa20 2026-05-25), MSVC 19.44.35228 (x64) | AI-assisted: yes

Summary — PASS

Verified 233602088041c9c2c75f724dbad187474e2cb286 merged cleanly onto origin/main (c8bf0e7b6568f471b42540010e335ca6413d4c58, git merge-tree --write-tree exit 0) on native Windows 11 (x64).

Verification Details

  1. Root cause (d3d12/crates/leonida-gpu/src/pipeline/make.rs):
    • On origin/main, SPENT initialized to (u64::MAX, Duration::ZERO) and reset whenever spent.0 != frame, so a recording thread that sampled frame = N - 1 before acquiring spent_of after another thread already advanced spent.0 to N reset *spent = (N - 1, Duration::ZERO) (and the next N waiter reset it back to (N, Duration::ZERO)), reopening the full per-frame pipeline wait budget.
  2. Build & Test (CARGO_BUILD_JOBS=4, --test-threads=4):
    • cargo test -p leonida-gpu --lib pipeline::make::tests -- --test-threads=4: test result: ok. 7 passed; 0 failed; 0 ignored; 0 measured; 564 filtered out; finished in 0.51s on origin/main -> test result: ok. 8 passed; 0 failed; 0 ignored; 0 measured; 564 filtered out; finished in 0.51s (13.75s) with #2601, including pipeline::make::tests::older_frames_cannot_reopen_a_pipeline_wait_budget ... ok across both shared = true and shared = false.
    • cargo check -p leonida-gpu --tests -> 0 errors, 0 warnings.
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7249787171 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2601#issuecomment-7249787171). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-29T03:01:00Z. --- #2601 | head 233602088041c9c2c75f724dbad187474e2cb286 (merged cleanly onto origin/main c8bf0e7b65) | Windows 11 (10.0.26200.9974), rustc 1.96.0 (ac68faa20 2026-05-25), MSVC 19.44.35228 (x64) | AI-assisted: yes ### Summary — PASS Verified `233602088041c9c2c75f724dbad187474e2cb286` merged cleanly onto `origin/main` (`c8bf0e7b6568f471b42540010e335ca6413d4c58`, `git merge-tree --write-tree` exit `0`) on native Windows 11 (`x64`). ### Verification Details 1. **Root cause (`d3d12/crates/leonida-gpu/src/pipeline/make.rs`)**: - On `origin/main`, `SPENT` initialized to `(u64::MAX, Duration::ZERO)` and reset whenever `spent.0 != frame`, so a recording thread that sampled `frame = N - 1` before acquiring `spent_of` after another thread already advanced `spent.0` to `N` reset `*spent = (N - 1, Duration::ZERO)` (and the next `N` waiter reset it back to `(N, Duration::ZERO)`), reopening the full per-frame pipeline wait budget. 2. **Build & Test (`CARGO_BUILD_JOBS=4`, `--test-threads=4`)**: - `cargo test -p leonida-gpu --lib pipeline::make::tests -- --test-threads=4`: `test result: ok. 7 passed; 0 failed; 0 ignored; 0 measured; 564 filtered out; finished in 0.51s` on `origin/main` -> **`test result: ok. 8 passed; 0 failed; 0 ignored; 0 measured; 564 filtered out; finished in 0.51s`** (`13.75s`) with `#2601`, including `pipeline::make::tests::older_frames_cannot_reopen_a_pipeline_wait_budget ... ok` across both `shared = true` and `shared = false`. - `cargo check -p leonida-gpu --tests` -> `0` errors, `0` warnings.
timbot103 commented 2026-11-29 04:29:16 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-29T04:29:16Z.

Review: COMMENTED


Reviewed head 233602088. The guard in d3d12/crates/leonida-gpu/src/pipeline/make.rs:443 gives older frame requests zero wait before changing the recorded frame or spend. The mutex serializes comparison, reset, and reservation for each budget. Saturating subtraction and the per-pipeline cap keep shared reservations within the remaining allowance, and completion accounts for the wait only if its frame still owns the budget.

The waiting path samples the process-wide unsigned frame counter in d3d12/crates/leonida-gpu/src/pipeline/make.rs:379. The counter starts at zero and advances independently of the pacing clock in d3d12/crates/leonida-gpu/src/frame.rs:76 and d3d12/crates/leonida-gpu/src/frame.rs:217. The relaxed atomic is sufficient for the frame number because the mutex protects the budget state. The patch reuses the existing Rust types and standard-library operations.

The regression at d3d12/crates/leonida-gpu/src/pipeline/make.rs:757 covers frame zero, a stale request after spending the current frame's budget, a repeat current-frame request, and the next frame in both wait modes.

Static audit only. No builds, tests, or GPU runs performed.

AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6101401584 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2601#pullrequestreview-6101401584). Originally posted by [timbot103](https://github.com/timbot103) on 2026-11-29T04:29:16Z. **Review:** COMMENTED --- Reviewed head `233602088`. The guard in `d3d12/crates/leonida-gpu/src/pipeline/make.rs:443` gives older frame requests zero wait before changing the recorded frame or spend. The mutex serializes comparison, reset, and reservation for each budget. Saturating subtraction and the per-pipeline cap keep shared reservations within the remaining allowance, and completion accounts for the wait only if its frame still owns the budget. The waiting path samples the process-wide unsigned frame counter in `d3d12/crates/leonida-gpu/src/pipeline/make.rs:379`. The counter starts at zero and advances independently of the pacing clock in `d3d12/crates/leonida-gpu/src/frame.rs:76` and `d3d12/crates/leonida-gpu/src/frame.rs:217`. The relaxed atomic is sufficient for the frame number because the mutex protects the budget state. The patch reuses the existing Rust types and standard-library operations. The regression at `d3d12/crates/leonida-gpu/src/pipeline/make.rs:757` covers frame zero, a stale request after spending the current frame's budget, a repeat current-frame request, and the next frame in both wait modes. Static audit only. No builds, tests, or GPU runs performed. AI-assisted.
OreoFR commented 2026-11-29 05:47:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T05:47:24Z.


Verified by OreoFR — READY

  • Base: main c8bf0e7b6 + this PR (head 233602088) merged with --no-ff
  • Red (main + only this PR's tests): main's inline budget logic, extracted unchanged into a reserve_frame_wait so the PR's test can call it: older_frames_cannot_reopen_a_pipeline_wait_budget fails (left: (500ms, 500ms), right: (0ns, 0ns)), so an older frame reopens the budget. The other 7 pipeline::make tests pass.
  • Green (merge): cargo test -p leonida-gpu --lib pipeline::make in d3d12/: 8 passed, 0 failed
  • Diff read: no issue. SPENT has to start at 0 now that frame < spent.0 returns zero, and the end-of-wait accounting is unchanged.
  • Other runs: Confirms lixonik's run (8/8 on the same head and main).
  • Machine: Windows 11, Intel Core Ultra 7 155H, RTX 4070 Laptop 8 GB, NVIDIA 621.40, Python 3.12.10, MSVC 19.44

AI-assisted (Claude Code, Claude Opus 5.5), run for OreoFR.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7251460941 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2601#issuecomment-7251460941). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T05:47:24Z. --- **Verified by OreoFR** — READY - Base: main c8bf0e7b6 + this PR (head 233602088) merged with --no-ff - Red (main + only this PR's tests): main's inline budget logic, extracted unchanged into a `reserve_frame_wait` so the PR's test can call it: `older_frames_cannot_reopen_a_pipeline_wait_budget` fails (`left: (500ms, 500ms)`, `right: (0ns, 0ns)`), so an older frame reopens the budget. The other 7 `pipeline::make` tests pass. - Green (merge): `cargo test -p leonida-gpu --lib pipeline::make` in `d3d12/`: 8 passed, 0 failed - Diff read: no issue. `SPENT` has to start at 0 now that `frame < spent.0` returns zero, and the end-of-wait accounting is unchanged. - Other runs: Confirms lixonik's run (8/8 on the same head and main). - Machine: Windows 11, Intel Core Ultra 7 155H, RTX 4070 Laptop 8 GB, NVIDIA 621.40, Python 3.12.10, MSVC 19.44 AI-assisted (Claude Code, Claude Opus 5.5), run for OreoFR.
merzleckeier commented 2026-11-29 10:38:11 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-29T10:38:11Z.


Linux game-run follow-up for 233602088. I compared 5844b6481 with the same base plus this PR on a desktop RTX 4070 SUPER 12 GiB (NVIDIA 620.73.04, CachyOS, Wine 11.22, VKD3D-Proton 71cae091, DXVK DXGI). Both runs were offline in Series S with frame generation off, the same input, copies of the same warm caches, and 500 ms for ordinary pipelines / 10 s for screen passes.

90–135 s after launch Main PR
Median rendered FPS 1.15 0.8
Median draws/frame 230 158
Highest logged interval mean of pipeline wait/frame 502.7 ms 175.4 ms

The opening-sequence title card was sampled on main only. The sampled images and draw counts differ, so the numbers do not establish a same-scene performance effect. The PR test harness ended early after 163 s and stopped the runtime. A previous cold A/B on 54b2a81e9 with the launcher's 10 s ordinary budget still showed waits around 10 s on both builds.

A separate test on newer main found a Series S presentation fallback in this Wine setup. I verified the compositor portion of #2577 separately and posted that result there. A visible open-world scene is still unverified. AI-assisted with OpenAI Codex (GPT-6).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7254567021 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2601#issuecomment-7254567021). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-11-29T10:38:11Z. --- Linux game-run follow-up for `233602088`. I compared `5844b6481` with the same base plus this PR on a desktop RTX 4070 SUPER 12 GiB (NVIDIA 620.73.04, CachyOS, Wine 11.22, VKD3D-Proton `71cae091`, DXVK DXGI). Both runs were offline in Series S with frame generation off, the same input, copies of the same warm caches, and 500 ms for ordinary pipelines / 10 s for screen passes. | 90–135 s after launch | Main | PR | | --- | ---: | ---: | | Median rendered FPS | 1.15 | 0.8 | | Median draws/frame | 230 | 158 | | Highest logged interval mean of pipeline wait/frame | 502.7 ms | 175.4 ms | The opening-sequence title card was sampled on main only. The sampled images and draw counts differ, so the numbers do not establish a same-scene performance effect. The PR test harness ended early after 163 s and stopped the runtime. A previous cold A/B on `54b2a81e9` with the launcher's 10 s ordinary budget still showed waits around 10 s on both builds. A separate test on newer main found a Series S presentation fallback in this Wine setup. I verified the compositor portion of #2577 separately and posted that result there. A visible open-world scene is still unverified. AI-assisted with OpenAI Codex (GPT-6).
merzleckeier commented 2026-11-29 11:27:49 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-29T11:27:49Z.


Follow-up with a visually matched opening marker on Linux. I tested b589e0fe0 + the existing DXC compiler branch 9075a5e419 against the same build plus #2601 at 233602088. Both used app-local DXC v1.9.2609, the same launcher and input, copies of the same warm caches and the 500 ms ordinary pipeline wait budget. Series S, Wine 11.22, VKD3D-Proton 71cae091, DXVK DXGI, RTX 4070 SUPER, NVIDIA 620.73.04, CachyOS.

40 s from first sampled frame of the same opening title card Base + DXC Base + DXC + #2601
Log intervals 6 7
Median rendered FPS 0.9 1.3
Median draws/frame 1,165 960
Highest logged interval mean of pipeline wait/frame 503.5 ms 572.5 ms

Both runs reached the visible 3D opening sequence and exited normally. The title card was first captured at 125 s and 130 s with a five-second capture cadence. One run per arm and differing draw loads leave the effect on FPS unresolved. This run did not show a reduction in the largest logged pipeline wait interval mean.

The app-local compiler was needed to get comparable visible scenes. In a separate same-binary control on this base, adding only the official DXC DLL pair changed the max logged indirect clamp counter from 0 to 268 per frame and eliminated the two clamp creation failures. Compiler-side reproduction and GPU tests. AI-assisted with OpenAI Codex (GPT-6).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7255128560 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2601#issuecomment-7255128560). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-11-29T11:27:49Z. --- Follow-up with a visually matched opening marker on Linux. I tested `b589e0fe0` + the existing DXC compiler branch `9075a5e419` against the same build plus #2601 at `233602088`. Both used app-local DXC v1.9.2609, the same launcher and input, copies of the same warm caches and the 500 ms ordinary pipeline wait budget. Series S, Wine 11.22, VKD3D-Proton `71cae091`, DXVK DXGI, RTX 4070 SUPER, NVIDIA 620.73.04, CachyOS. | 40 s from first sampled frame of the same opening title card | Base + DXC | Base + DXC + #2601 | | --- | ---: | ---: | | Log intervals | 6 | 7 | | Median rendered FPS | 0.9 | 1.3 | | Median draws/frame | 1,165 | 960 | | Highest logged interval mean of pipeline wait/frame | 503.5 ms | 572.5 ms | Both runs reached the visible 3D opening sequence and exited normally. The title card was first captured at 125 s and 130 s with a five-second capture cadence. One run per arm and differing draw loads leave the effect on FPS unresolved. This run did not show a reduction in the largest logged pipeline wait interval mean. The app-local compiler was needed to get comparable visible scenes. In a separate same-binary control on this base, adding only the official DXC DLL pair changed the max logged indirect clamp counter from 0 to 268 per frame and eliminated the two clamp creation failures. [Compiler-side reproduction and GPU tests](https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7254721395). AI-assisted with OpenAI Codex (GPT-6).
enlight3d commented 2026-11-29 18:35:28 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-11-29T18:35:28Z.


RUN: PR #2601 (pipeline wait budgets cannot move backward)

Heads: PR 233602088, main eedd72e30 (current origin/main at the time; main had moved from 4364a4fa6 during the job). Merged locally with git merge --no-ff (clean, make.rs auto-merged, nothing pushed). No conflict with #2566.

Command (d3d12/, MSVC target, vcvars64): cargo test -j 6 -p leonida-gpu --lib (and older_frames alone for the red), cargo check -j 6 -p leonida-gpu --tests.

  • RED (behavioural, the PR's test kept: reserve_frame_wait put back to the old rule, any frame different from the stored one resets the budget): older_frames_cannot_reopen_a_pipeline_wait_budget FAILED at make.rs:805 (left: (500ms, 500ms), right: (0ns, 0ns)): a delayed older frame got a fresh budget. Restored afterwards. (Reverting only the non-test code is a build failure: the test calls the new function.)
  • GREEN (merged tree): the new test passes; whole --lib suite 545 passed, 0 failed, 47 ignored. Plain main: 544 passed, 0 failed, 47 ignored (the difference is the new test).
  • cargo check -p leonida-gpu --tests on the merged tree: clean.

Machine: RTX 3090 24 GB, NVIDIA 621.40, Windows 11 (native D3D12 target).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7260602900 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2601#issuecomment-7260602900). Originally posted by [enlight3d](https://github.com/enlight3d) on 2026-11-29T18:35:28Z. --- RUN: PR #2601 (pipeline wait budgets cannot move backward) Heads: PR 233602088, main eedd72e30 (current origin/main at the time; main had moved from 4364a4fa6 during the job). Merged locally with `git merge --no-ff` (clean, `make.rs` auto-merged, nothing pushed). No conflict with #2566. Command (d3d12/, MSVC target, vcvars64): `cargo test -j 6 -p leonida-gpu --lib` (and `older_frames` alone for the red), `cargo check -j 6 -p leonida-gpu --tests`. - RED (behavioural, the PR's test kept: `reserve_frame_wait` put back to the old rule, any frame different from the stored one resets the budget): `older_frames_cannot_reopen_a_pipeline_wait_budget` FAILED at `make.rs:805` (left: (500ms, 500ms), right: (0ns, 0ns)): a delayed older frame got a fresh budget. Restored afterwards. (Reverting only the non-test code is a build failure: the test calls the new function.) - GREEN (merged tree): the new test passes; whole `--lib` suite 545 passed, 0 failed, 47 ignored. Plain main: 544 passed, 0 failed, 47 ignored (the difference is the new test). - `cargo check -p leonida-gpu --tests` on the merged tree: clean. Machine: RTX 3090 24 GB, NVIDIA 621.40, Windows 11 (native D3D12 target).
MoonEyes commented 2026-11-29 18:59:52 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T18:59:52Z.


Merging. Head 233602088 has red/green verdicts from reviewers other than the author (above), merges cleanly with main 7c66bc52e, does not force a rebase of #2566, and carries a claim ID. Remaining main CI reds (translator-tests mesh, semantic-tests f16) are pre-existing. Merged by MoonEyes.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7260923413 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2601#issuecomment-7260923413). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T18:59:52Z. --- Merging. Head `233602088` has red/green verdicts from reviewers other than the author (above), merges cleanly with `main` `7c66bc52e`, does not force a rebase of #2566, and carries a claim ID. Remaining main CI reds (`translator-tests` mesh, `semantic-tests` f16) are pre-existing. 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!2601
No description provided.