Skip to content

d3d12: a landing pool asks its limit once a batch, and parks no thread without LEONIDA_AB (D3D12-LAND-POOL-LIMIT-ONCE) - #2692

Merged
MoonEyes merged 2 commits into
ProjectLeonida:mainfrom
TheGeogeo:d3d12-land-pool-limit
Nov 30, 2026
Merged

MoonEyes merged 2 commits into
ProjectLeonida:mainfrom
TheGeogeo:d3d12-land-pool-limit

Conversation

@TheGeogeo

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: D3D12-LAND-POOL-LIMIT-ONCE (#2570 (comment))

What and why

Since ff1874c6f ("helper counts by turns"), the two landing pools in land.rs have a limit function. The views pool runs 8 threads with 4 at work, and the records pool runs 10 threads with 6 at work. The records pool's batches are what the submitting thread waits for at the end of a submission. The views pool's batches are the heap pass's "looking at slots".

On main:

  • Pool::help calls the limit function before every number it takes and after every wake, while it holds the pool's state mutex.
  • The function calls wide(), which runs std::env::var for its _WIDE switch on every call.
  • Because the limit is below the thread count, Pool::each uses notify_all. Every batch therefore also wakes the 3 or 4 parked helpers that cannot work. They read the environment under the lock and go back to sleep.

This change:

  • asks for the limit once, when a batch begins, and keeps it in the pool's state (State::limit); helpers compare with that value;
  • builds the pool with exactly the threads that take part when LEONIDA_AB does not name the _WIDE switch, as before ff1874c6f, so no thread is parked;
  • keeps the by-turns behavior under LEONIDA_AB: the wide count is made, and how many take part follows the switch.

LEONIDA_VIEW_THREADS, LEONIDA_VIEW_THREADS_WIDE and LEONIDA_RECORD_THREADS_WIDE mean what they meant before.

Tested

On Windows 11, from d3d12\:

  • New test land::tests::a_pools_limit_is_asked_once_a_batch: a pool with a counting limit runs three batches of 256 items, and the limit must be asked once per batch. On main it fails, with the limit asked 4 times in the first batch; with the change it passes.
  • cargo test -p leonida-gpu --locked: 553 passed, 49 ignored.
  • rustfmt with d3d12/rustfmt.toml reports nothing in the changed lines. git diff --check and check_no_game_data.py are clean.
  • The diag build (build-nvidia.ps1, features diagnostics,dlss,mimalloc) built.
  • It merges cleanly with the open pull requests on land.rs, D3D12-CLIPPY-LEONIDA-GPU: fix all clippy warnings in leonida-gpu #2682 and runtime, d3d12: memory leak fixes from one sweep (RT-LEAK-SWEEP) #2569 (git merge-tree).
  • In game, I alternated four short runs, main then this branch, twice. Each run went from the menus to the world, then 150 s of a scripted cutscene in the Series S preset. Frame times come from PresentMon 2.6, processor time from the process counters, and the waits from the per-second frame lines (means over the cutscene):
run fps p50 ms p99 ms frames over 1 s cores busy waiting for the heaps' records at the end of a submission (ms/frame) looking at slots (ms/frame)
main 1 13.1 47.1 300.9 9 12.6 1.07 4.81
this change 1 19.5 44.9 146.9 0 12.8 0.69 3.98
main 2 21.0 42.4 116.3 0 11.9 0.82 3.72
this change 2 19.7 45.0 121.2 0 12.6 0.65 3.87

How to read it:

  • The first main run was the session's first start and had an 11 s hitch, so I compare against the second one.
  • Across these runs, the submitting thread's wait for the records pool at the end of a submission went from 0.82 to 0.65-0.69 ms a frame, about 20 % less.
  • "Looking at slots" and the frame times stay within the noise between runs. This is a small overhead removed, not a frame-rate change.

GPUs tested: NVIDIA GeForce RTX 3080 10 GB, driver 32.0.16.2140, Windows 11 Pro 10.0.26300.

AI-assisted: yes

Checklist

…d without LEONIDA_AB (D3D12-LAND-POOL-LIMIT-ONCE)

Since the helper counts went by turns, the views pool (8 threads, 4 at
work) and the records pool (10 threads, 6 at work) have a limit function.
Each helper called it under the pool's state lock before every number it
took and after every wake, and the function read the environment
(std::env::var for its _WIDE switch). As the limit was below the thread
count, every batch also woke the parked helpers with notify_all: they read
the environment under the lock and slept again.

The limit is now asked once when a batch begins, kept in the pool's state,
and helpers compare with that. Unless LEONIDA_AB names the _WIDE switch,
the pool is made with exactly the threads that take part, as before the
counts went by turns, so none is parked. By turns, the wide count is made
and how many take part follows the switch, as it did.
@ecox982745

Copy link
Copy Markdown
Contributor

Independent native Windows landing-pool verification. I tested f19b5750f on 1d22590b9 (clean merge tree df8eb2d84), Windows 11 with MSVC and Rust 1.98.1. The exact cargo test --locked -p leonida-gpu --lib land::tests filter passed 8 tests, with the benchmark ignored.

I also ran a local synthetic probe on Pool::with_limit. The first callback in each 257-item batch changes the requested limit for the next batch. Across 12 batches alternating limits of 1, 2, and 4, each batch used exactly its starting limit, read the limit once, and called all 257 items exactly once. This passed in 10 fresh processes (30,840 callbacks). The probe exercises the changing-limit worker path directly, without changing process-level A/B configuration.

CPU scheduling checks only. No game inputs, GPU dispatch or gameplay timing. AI-assisted with OpenAI Codex (GPT-6.2 Sol).

@TheGeogeo

Copy link
Copy Markdown
Contributor Author

A note for reviewers: with LEONIDA_VIEW_THREADS set, nothing changes.

  • The Some(threads) arm of each_view is untouched. It still builds Pool::new(name, threads.clamp(1, 16)).
  • Pool::new gives the pool the limit all_threads, which returns usize::MAX. So State::limit is usize::MAX for every batch, and every helper takes part, as before.
  • Pool::each still wakes helpers one at a time, as before, because limit < self.threads is false.

The only difference on that path: the limit function is called once per batch instead of once per item, and that function is a constant. The existing land pool tests cover this path. a_pools_limit_is_asked_once_a_batch covers the pool with a limit.

@MoonEyes

Copy link
Copy Markdown
Collaborator

Independent check on Windows 11 (Rust toolchain from d3d12/rust-toolchain.toml, CPU only, no game run). Head f19b5750f merged (no commit) into main bbd45f5cc:

  • cargo test -p leonida-gpu --lib --locked: main 559 passed, 50 ignored; with this PR 560 passed, 0 failed.
  • Red: land.rs from main, tests from this PR: land::tests::a_pools_limit_is_asked_once_a_batch fails (559 passed, 1 failed). The new test catches the old behaviour.
  • cargo clippy -p leonida-gpu --locked -- -D warnings: 9 findings on main, the same 9 with this PR.
  • Merges cleanly with main and does not force a rebase of [integration] PageMirror, GPU detile, async queue & RDNA2->SPIR-V performance stack (INTEGRATION-PERF-CPU-GPU-R6) #2566.
  • Not covered: an in-game run. It touches the render path, so it still needs 300 s in game with no device loss before merge.

AI-assisted (Claude Code).

@TheGeogeo

Copy link
Copy Markdown
Contributor Author

The semantic-tests failure here is not from this change, which only touches Rust files under d3d12/. The same test, test_interp_computed_ij_fallback (ComputedIJDerivativeFallbackTests), also fails in CI on main (run 46365003804). The other checks pass.

@merzleckeier

Copy link
Copy Markdown
Contributor

Independent each_view phase and worker-count check. Tested f19b5750f merged onto 454df8e95 (tree 46a8ed4a3). A standalone Rust harness compiled the unchanged pool, each_view and A/B selection code from each tree, with stubs for platform priority and tracing. It counted real OS helper threads through /proc/self/task and used barriers to flip the A/B bits after every wide worker had taken its first job.

Case main With PR
Default, views / records helper threads, excluding caller 7 / 9 3 / 5
Both _WIDE values set, views / records helpers 7 / 9 7 / 9
Wide → narrow mid-batch, active threads including caller views 8 → 4, records 10 → 6 views 8 → 8, records 10 → 10
Next batch after the phase change, active threads including caller 4 / 6 4 / 6

Naming just LEONIDA_VIEW_THREADS_WIDE in LEONIDA_AB kept a wide-capable views pool and only five record helpers with the PR. Naming an unrelated switch kept both pools narrow. LEONIDA_VIEW_THREADS=1 and =3 still took precedence. All 28 process cases passed across both revisions and both diagnostics configurations, with 20 rounds per pool and an exactly-once check for every job. Three extracted stock pool tests passed with the PR. Only the new limit-count assertion failed with main’s implementation.

CachyOS, Rust 1.97.1. Synthetic CPU scheduling check. AI-assisted with OpenAI Codex.

@OreoFR

OreoFR commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

RUN - in-game gate (Verified by OreoFR), PROVISIONAL - RTX 4070 Laptop 8 GB, NVIDIA 621.40, Windows 11.

  • Base: main e1fe82f63; B = main + this PR at f19b5750f (git merge --no-ff), diag build of leonida.exe.
  • Recipe: play-d3d12.ps1 -SeriesS -NoDlss -NoFrameGen, BAR 0, texture budget 1024, standing in the world, warm pipeline cache, 600 s per run. Runs interleaved with main.

Result: PASS - 0 device loss, 0 panics, every run alive at the end (653-668 s of world frames).

Arm runs (well warmed) fps median p5 preparing (ms/frame)
main 6 22.40 (21.9-23.0) 17.90 28.80
main + #2692 2 22.30 (22.5, 22.1) 16.75 28.80
  • No fps regression: -0.4 %, within the ~4 % run-to-run noise on this machine.
  • Warm-up bias: each new exe starts cold here, and the first warm run after the cold one is slow on every build, main included (main 20.7, this PR 19.7). Those runs are excluded on both sides; with them this PR reads -4.3 %.
  • The PR's own counter (the records' wait at the end of a submission): 0.82 ms/frame against main's 0.89. The direction matches, but the difference is within the run-to-run spread on this card. "Looking at slots" is unchanged.

This run was AI-assisted (Claude Code, oreofr-agent).

@MoonEyes

Copy link
Copy Markdown
Collaborator

@TheGeogeo the in-game gate on an RTX 4070 (OreoFR, above) passes on this head, and the only red check is semantic-tests, which comes from the older base (fixed on main by #2566). Could you merge current main into this branch (a merge, no rebase or force-push) so CI runs again? Merging needs a fully green CI.

AI-assisted (Claude Code).

@MoonEyes

Copy link
Copy Markdown
Collaborator

Closing and reopening so that CI runs against current main: the only red check here (semantic-tests) comes from the older base. The head does not change, so the verdicts above still stand. @TheGeogeo no need to update the branch if this is enough.

AI-assisted (Claude Code).

@MoonEyes MoonEyes closed this Nov 30, 2026
@MoonEyes MoonEyes reopened this Nov 30, 2026
@MoonEyes

Copy link
Copy Markdown
Collaborator

Verified by MoonEyes on head ba3ea1e06 (a merge of main on top of f19b5750f; the pull request's own change is the same), on main f9f3ec4c6. Windows 11, Rust toolchain of d3d12/rust-toolchain.toml.

AI-assisted (Claude Code).

@MoonEyes

Copy link
Copy Markdown
Collaborator

Merging. Head ba3ea1e06 merges cleanly with main f9f3ec4c6 and does not force a rebase of #2566. Verdict with red/green and a 600 s in-game run on this head above; OreoFR's gate on an RTX 4070 and merzleckeier's, ecox982745's checks were on the head before main was merged in. Its CI is green. main's Runtime workflow is red for a known reason (macos, ps_exp_f32_denorm_rt); merging green pull requests meanwhile is agreed with aslan2142. Merged by MoonEyes.

AI-assisted (Claude Code).

@MoonEyes
MoonEyes merged commit 3c07d16 into ProjectLeonida:main Nov 30, 2026
5 checks passed
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.

5 participants