d3d12-gpu: a dedicated short wait for the masked twin, so a cold compile cannot stall the list call (stacked on #3200) #3464

Code

Clone this repository

Checkout

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

git fetch -u  "d3d12/masked-wait-budget:KelboLive-d3d12/masked-wait-budget"
git switch "KelboLive-d3d12/masked-wait-budget"
Open
leonida/mandy
KelboLive wants to merge 9 commits from KelboLive/mandy:d3d12/masked-wait-budget 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/masked-wait-budget:KelboLive-d3d12/masked-wait-budget'
git switch 'KelboLive-d3d12/masked-wait-budget'
First-time contributor

Stacked on #3200 (Depends on: #3200). Please review the last commit only (554bee664); the diff against main includes #3200's four commits.

What/why

#3105: the 300–800 ms list-call freezes are the masked twin built through masked_for. #3200 moves the build to a worker but still waits with the general LEONIDA_PIPELINE_WAIT_MS (1000 in the reporter's runs, 10000 by launcher default), so a cold 782 ms twin is still waited for in full on the list thread. This adds a masked-only budget.

Change

  • LEONIDA_MASKED_WAIT_MS (parsed once, default 50, 0 = no wait).
  • masked_for uses start(REQUESTED) + wait_masked through the existing wait_in/wait_with machinery with a new WaitKind::Masked; the masked wait is charged against the frame's world Waited, so the ordinary budget still bounds the total.
  • On timeout it returns None and the draw uses the unmasked pipeline (the existing fallback); the worker keeps building, no Refused poisoning, no second build.
  • pipeline.rs's "first use completes the build" comment corrected; the wait_with log now distinguishes masked timeouts from dropped ordinary draws.

Behaviour

PIPELINE_WAIT_MS masked result
1000 50 at most 50 ms, 950 left for ordinary waits
10000 50 50 ms, 9950 left
any 0 no wait; fallback until the worker finishes
40 50 40 ms (ordinary budget wins)

Tests

  • 800 ms held build returns in <150 ms at 1000/50 and resolves after release; cached twin returns immediately; MASKED_WAIT_MS=0 returns immediately; ordinary ready still waits the 1000 ms world budget.
  • cargo test -p leonida-gpu --lib make::: 44 passed; full serial: 732 passed, 0 failed, 59 ignored; clippy -D warnings, switch page, no-game-data and diff clean.

Not verified

No game run. A run with the reporter's settings should show the masked-twin list call bounded at ~50 ms (falling back to the unmasked pipeline for that draw) while the twin appears on the next draw; visual check of the first LOD-fade frame is the trade to confirm. If #3200 changes, this rebases onto it.

Item: D3D12-MASKED-TWIN-SHORT-WAIT, claimed in #3312. Depends on: #3200.
AI-assisted: DeepSeek V4.1 Flash (OpenCode).

**Stacked on #3200** (Depends on: #3200). Please review the last commit only (`554bee664`); the diff against `main` includes #3200's four commits. ## What/why #3105: the 300–800 ms list-call freezes are the masked twin built through `masked_for`. #3200 moves the build to a worker but still waits with the **general** `LEONIDA_PIPELINE_WAIT_MS` (1000 in the reporter's runs, 10000 by launcher default), so a cold 782 ms twin is still waited for in full on the list thread. This adds a **masked-only** budget. ## Change - `LEONIDA_MASKED_WAIT_MS` (parsed once, default **50**, `0` = no wait). - `masked_for` uses `start(REQUESTED)` + `wait_masked` through the existing `wait_in`/`wait_with` machinery with a new `WaitKind::Masked`; the masked wait is charged against the frame's world `Waited`, so the ordinary budget still bounds the total. - On timeout it returns `None` and the draw uses the unmasked pipeline (the existing fallback); the worker keeps building, no `Refused` poisoning, no second build. - `pipeline.rs`'s "first use completes the build" comment corrected; the `wait_with` log now distinguishes masked timeouts from dropped ordinary draws. ## Behaviour | `PIPELINE_WAIT_MS` | masked | result | |---|---|---| | 1000 | 50 | at most 50 ms, 950 left for ordinary waits | | 10000 | 50 | 50 ms, 9950 left | | any | 0 | no wait; fallback until the worker finishes | | 40 | 50 | 40 ms (ordinary budget wins) | ## Tests - 800 ms held build returns in **<150 ms** at 1000/50 and resolves after release; cached twin returns immediately; `MASKED_WAIT_MS=0` returns immediately; ordinary `ready` still waits the 1000 ms world budget. - `cargo test -p leonida-gpu --lib make::`: **44 passed**; full serial: **732 passed, 0 failed, 59 ignored**; clippy `-D warnings`, switch page, no-game-data and diff clean. ## Not verified No game run. A run with the reporter's settings should show the masked-twin list call bounded at ~50 ms (falling back to the unmasked pipeline for that draw) while the twin appears on the next draw; visual check of the first LOD-fade frame is the trade to confirm. If #3200 changes, this rebases onto it. Item: D3D12-MASKED-TWIN-SHORT-WAIT, claimed in #3312. Depends on: #3200. AI-assisted: DeepSeek V4.1 Flash (OpenCode).
Give each pending pipeline its own completion gate. Run requested builds at normal priority, including a request that arrives during an early compile, and restore the worker before its next job.
Start eligible slow builds alongside ordinary early work within the configured worker quota. Keep offline slow-only records out of the demand set; a full warm can produce them without a draw.
Claim: D3D12-PIPELINE-WAIT-AND-SLOW-EARLY (#3103).
Keep upstream requested, ordinary-early, then slow-early queue ordering. Bound concurrent slow jobs by the configured general-worker pool, without admitting never-drawn offline slow records.
Raise a worker when an actual waiter joins, including a caller arriving in driver code. Withdraw the boost on the last departure or build unwind. Requests that exhaust their wait budget do not raise the compiler backlog.
Check native priority with overlapping waiters and after timeouts, along with per-pipeline wake isolation and caught refusal. No new switch.
Claim: D3D12-PIPELINE-WAIT-AND-SLOW-EARLY (#3103).
Route `pipeline::make::masked_for` through `ready` instead of running
`Pending::make` synchronously on `leonida-list-*` recording threads.

- Queues first-seen sample-mask twin PSOs onto `leonida-pipelines-*` workers
  (`start(p, REQUESTED)`) with `AWAITED` promotion, live-waiter normal
  priority donation, and `C::PipelineWaitUs` / `WAITING` accounting.
- Fast or cached masked twins still finish within `LEONIDA_PIPELINE_WAIT_MS`
  before the first masked draw is recorded, while multi-second cold driver
  compiles time out cleanly (`p.made` left unset as `Gone::Making`) and fall
  back to the bound unmasked pipeline until a worker publishes the twin.

Refs #3105

AI-assisted.
Masked twins now use LEONIDA_MASKED_WAIT_MS (default 50 ms; 0: no wait) instead of the general pipeline wait budget, so a cold masked compile no longer holds the list thread for the world budget. The wait still counts against the frame's world waits and PipelineWaitUs, and a timeout falls back to the unmasked pipeline while the worker keeps building.

Correct the masked timeout log line and the first-use doc comment.
Cover the two claims of 554bee664 and harden the timing-fragile assertions:

- Masked is capped by the world budget: with PIPELINE_WAIT_MS=40 and
  MASKED_WAIT_MS=2000, a build held for 800 ms still returns in <150 ms.
- A masked wait is charged to the frame's world Waited: after a 50 ms masked
  wait an ordinary wait on the same frame is left ~nothing (local FrameWait
  and Queue, so the global WAITS is untouched).
- The masked_zero arm keeps the 150 ms limit for every mode and additionally
  asserts billed(...).is_zero(), the deterministic no-charge contract, rather
  than relying on a 50 ms margin.
- The ordinary ready test uses a 2000 ms world budget, so the 800 ms hold has
  margin while it still fails if ready used the 50 ms masked budget.
- Correct the first-use, masked_for, and wait_masked comments: the twin is
  waited for on every draw until made, capped by wait-once/the frame, a zero
  world budget disables it, and 50 ms is also its whole-run cap; the wait uses
  the frame's world accounting with a 50 ms sub-budget reduced by all prior
  frame waiting.
- Factor ready_by() for ready/masked_for and WaitKind::from(Class).

Regenerate d3d12/docs/switches.md.
Author
First-time contributor

Review follow-up pushed as 5c767312b (still stacked on #3200; please review only the two commits 554bee664..5c767312b).

The review's point was right: the production logic was sound but the two claims of the commit were not tested. Added:

  • Cap test: LEONIDA_MASKED_WAIT_MS=2000 + LEONIDA_PIPELINE_WAIT_MS=40 with an 800 ms held build returns in <150 ms - without .min(wait_budget()) it would be held ~800 ms.
  • Sharing test: a local FrameWait/Queue (global WAITS untouched) shows a 50 ms masked wait charges >=25 ms to the world Waited, and an ordinary wait on the same frame is then left ~nothing.
  • Zero arm is deterministic: limit = 150 for every mode, and masked_zero additionally asserts billed(...).is_zero() - no wait and no charge, not a 50 ms timing margin.
  • Ordinary-ready headroom: LEONIDA_PIPELINE_WAIT_MS=2000 for the 800 ms hold (still fails if ready used the 50 ms budget).
  • Docs: first-use/masked_for/wait_masked comments corrected (it waits on every draw until made, capped by wait-once and the frame; no world budget means no wait; the sub-budget is reduced by all prior frame waiting). switches.md regenerated with only the masked row changing.
  • Low-risk refactor: ready_by(p, wait) shared by ready/masked_for, and WaitKind::from(Class).

45 make:: tests, 733 full serial, clippy -D warnings, switch page, no-game-data and diff clean.

Still unmentioned-by-design: a screen-class twin is charged to the world sub-budget, so it falls back to the unmasked pipeline after 50 ms rather than waiting the screen budget. That is the intended trade (it is not the pass's only pipeline) and is now stated in the code.

Review follow-up pushed as **`5c767312b`** (still stacked on #3200; please review only the two commits `554bee664..5c767312b`). The review's point was right: the production logic was sound but the two claims of the commit were not tested. Added: - **Cap test:** `LEONIDA_MASKED_WAIT_MS=2000` + `LEONIDA_PIPELINE_WAIT_MS=40` with an 800 ms held build returns in <150 ms - without `.min(wait_budget())` it would be held ~800 ms. - **Sharing test:** a local `FrameWait`/`Queue` (global `WAITS` untouched) shows a 50 ms masked wait charges `>=25 ms` to the **world** `Waited`, and an ordinary wait on the same frame is then left ~nothing. - **Zero arm is deterministic:** `limit = 150` for every mode, and `masked_zero` additionally asserts `billed(...).is_zero()` - no wait and no charge, not a 50 ms timing margin. - **Ordinary-ready headroom:** `LEONIDA_PIPELINE_WAIT_MS=2000` for the 800 ms hold (still fails if `ready` used the 50 ms budget). - **Docs:** first-use/`masked_for`/`wait_masked` comments corrected (it waits on every draw until made, capped by wait-once and the frame; no world budget means no wait; the sub-budget is reduced by all prior frame waiting). `switches.md` regenerated with only the masked row changing. - **Low-risk refactor:** `ready_by(p, wait)` shared by `ready`/`masked_for`, and `WaitKind::from(Class)`. **45 `make::` tests, 733 full serial**, clippy `-D warnings`, switch page, no-game-data and diff clean. Still unmentioned-by-design: a screen-class twin is charged to the world sub-budget, so it falls back to the unmasked pipeline after 50 ms rather than waiting the screen budget. That is the intended trade (it is not the pass's only pipeline) and is now stated in the code.
Author
First-time contributor

Not rebased: still on its #3200 base by design. Hardened tests pushed as 5c767312b (cap, frame sharing, deterministic zero, ordinary-ready headroom, doc precision); 45 make::, 733 full serial.

Not rebased: still on its #3200 base by design. Hardened tests pushed as `5c767312b` (cap, frame sharing, deterministic zero, ordinary-ready headroom, doc precision); 45 `make::`, 733 full serial.
Contributor

A procedural scene could trigger two cold masked variants during a scripted camera cut. Hold the starting PSO cache fixed and compare the per-wait latency, the long-frame distribution, and the first generated LOD-fade frame after the timeout. Check that the fallback renders while the worker is held and that the masked variant becomes available after release.

AI-assisted with OpenAI Codex.

A procedural scene could trigger two cold masked variants during a scripted camera cut. Hold the starting PSO cache fixed and compare the per-wait latency, the long-frame distribution, and the first generated LOD-fade frame after the timeout. Check that the fallback renders while the worker is held and that the masked variant becomes available after release. AI-assisted with OpenAI Codex.
Sign in to join this conversation.
No description provided.