Loader: speculative pipeline builds run below normal priority #14

Closed
github-bot wants to merge 1 commit from gh-pr/14/head into gh-pr/14/base
Owner

@⁠marquezinii on GitHub · 2026-11-24 21:33 UTC · original
marquezinii:loader/compile-thread-priority → main · +227 −8 · 11 files · 1 commits · closed without merging

The driver's pipeline compiles run on the build threads, next to the game's own threads. The slow boot frames in d3d12x-shim.md were game threads standing Ready while the driver compiled. With this change, a build thread runs a creation below normal priority unless something is waiting for it:

Creation Priority
a pipeline a command list has set (urgent), or one a game thread still waits for (inside its budget, before the stand-in) normal
the journal's creations, creations after their stand-in was given, deferred creations not set yet below normal
  • A creation promoted while it runs (Promote) has its thread raised to normal priority.
  • A creation a game thread runs itself (RunNow) keeps that thread's priority.
  • --normal-priority-builds keeps every build at normal priority, for A/B runs.

Scope. This first version also lowered the program workers. Rebased onto the compile host, it now covers only the driver's pipeline build threads, as discussed. Program compiles are untouched: lowered in-process dxc threads starved an urgent compile through the heap lock, and the compile host now runs them at the asking thread's priority. It sits on top of the half-the-threads cap for speculative creations: the speculative threads give way to the game, and urgent creations keep normal priority.

What to watch in the A/B. The NVIDIA compiler still allocates from the process heap, which game threads use too. If a lowered build thread holding that lock starves a game thread, it shows as the same WaitOnAddress stalls, and the switch would show it. Also compare:

  • the 600-present mean interval during the boot and the story load;
  • how soon stand-ins are replaced (built since in the sample summary).

I measured only a model (11 in-process DXC compile threads next to an 8-thread frame loop on a 12-thread Ryzen 5 5600X): about 19 fps with the compile threads at normal priority, 52 to 100 fps below normal. That was dxc, not the driver, so the real numbers have to come from the A/B. @⁠danik1222 offered a 4-core run on #13 once a build boots there.

Tests:

  • WorkerPriorityTests covers speculative, urgent and awaited creations, promotion while running, a creation the game thread runs itself, and the switch.
  • Loader tests: 194 passed, 17 skipped. Architecture rules: 29/29.
**@⁠marquezinii** on GitHub · 2026-11-24 21:33 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/14) `marquezinii:loader/compile-thread-priority` → `main` · +227 −8 · 11 files · 1 commits · closed without merging The driver's pipeline compiles run on the build threads, next to the game's own threads. The slow boot frames in d3d12x-shim.md were game threads standing Ready while the driver compiled. With this change, a build thread runs a creation below normal priority unless something is waiting for it: | Creation | Priority | |---|---| | a pipeline a command list has set (urgent), or one a game thread still waits for (inside its budget, before the stand-in) | normal | | the journal's creations, creations after their stand-in was given, deferred creations not set yet | below normal | - A creation promoted while it runs (`Promote`) has its thread raised to normal priority. - A creation a game thread runs itself (`RunNow`) keeps that thread's priority. - `--normal-priority-builds` keeps every build at normal priority, for A/B runs. **Scope.** This first version also lowered the program workers. Rebased onto the compile host, it now covers only the driver's pipeline build threads, as discussed. Program compiles are untouched: lowered in-process dxc threads starved an urgent compile through the heap lock, and the compile host now runs them at the asking thread's priority. It sits on top of the half-the-threads cap for speculative creations: the speculative threads give way to the game, and urgent creations keep normal priority. **What to watch in the A/B.** The NVIDIA compiler still allocates from the process heap, which game threads use too. If a lowered build thread holding that lock starves a game thread, it shows as the same `WaitOnAddress` stalls, and the switch would show it. Also compare: - the 600-present mean interval during the boot and the story load; - how soon stand-ins are replaced (`built since` in the sample summary). I measured only a model (11 in-process DXC compile threads next to an 8-thread frame loop on a 12-thread Ryzen 5 5600X): about 19 fps with the compile threads at normal priority, 52 to 100 fps below normal. That was dxc, not the driver, so the real numbers have to come from the A/B. @⁠danik1222 offered a 4-core run on #13 once a build boots there. Tests: - `WorkerPriorityTests` covers speculative, urgent and awaited creations, promotion while running, a creation the game thread runs itself, and the switch. - Loader tests: 194 passed, 17 skipped. Architecture rules: 29/29.
The driver's compiles run on the build threads beside the game's own, and
the slow boot frames were game threads standing Ready while the driver
compiled. A build thread now runs a creation below normal priority unless
something waits for it: a pipeline a command list has set, or one a game
thread still waits for within its budget, runs at normal priority, and a
creation promoted while it runs has its thread raised. A creation a game
thread runs itself keeps that thread's priority.

Program compiles are left alone: lowered in-process dxc threads starved
an urgent compile through the heap lock, and the compile host now runs
them at the asking thread's priority. --normal-priority-builds keeps
every build at normal priority for A/B runs.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 03:13:39 +00:00
github-bot closed this pull request 2026-11-27 03:13:39 +00:00
Author
Owner

@⁠ThatRecompDev on GitHub · 2026-11-24 21:36 UTC · original

Thanks, this is a nice clean split, and the model numbers are convincing. I'd like to hold it for a bit though, for two reasons.

First, we tried lowering our compile threads ourselves today and it backfired: a small compute program compiled inline on one of the game's Subrender workers went from about 8 s to 17.7 s, and the story transition stalled for 25 s. The waiting thread sat in WaitOnAddress, which looks like heap-lock contention between the in-process dxc threads, so a lowered thread holding that lock starved the urgent one. Your version only lowers speculative work, which is smarter, but in-process dxc threads still share that heap.

Second, we're about to move program compiles into a separate compile host process (its own heap and GC, prefetch capped at half the workers, speculative pipeline builds capped at half the build threads), and it touches the same files as your change.

Once that lands, could you rebase onto it? Lowering the priority of the driver's pipeline build threads, which have no shared dxc heap, still sounds worthwhile, and I'd happily measure it on our side with --normal-priority-builds for the A/B.

**@⁠ThatRecompDev** on GitHub · 2026-11-24 21:36 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/14#issuecomment-7145160701) Thanks, this is a nice clean split, and the model numbers are convincing. I'd like to hold it for a bit though, for two reasons. First, we tried lowering our compile threads ourselves today and it backfired: a small compute program compiled inline on one of the game's Subrender workers went from about 8 s to 17.7 s, and the story transition stalled for 25 s. The waiting thread sat in `WaitOnAddress`, which looks like heap-lock contention between the in-process dxc threads, so a lowered thread holding that lock starved the urgent one. Your version only lowers speculative work, which is smarter, but in-process dxc threads still share that heap. Second, we're about to move program compiles into a separate compile host process (its own heap and GC, prefetch capped at half the workers, speculative pipeline builds capped at half the build threads), and it touches the same files as your change. Once that lands, could you rebase onto it? Lowering the priority of the driver's pipeline build threads, which have no shared dxc heap, still sounds worthwhile, and I'd happily measure it on our side with `--normal-priority-builds` for the A/B.
Author
Owner

@⁠marquezinii on GitHub · 2026-11-24 21:55 UTC · original

Makes sense, holding it. I've marked it as a draft until the compile host lands.

Once it does, I'll rebase and cut this down to the driver's pipeline build threads, with --normal-priority-builds kept for the A/B. One caveat for that measurement: the build threads have no dxc heap, but the NVIDIA compiler still allocates from the process heap, which game threads use too. If the same WaitOnAddress stalls show up with lowered build threads, the cause would be the same, and that would rule out this change as well.

@⁠danik1222 offered on #13 to run the A/B on the 4-core i7-4770 once a build boots there. With your 4090 numbers that gives one machine at each end of the range.

(The Windows check fails here on D3D12XBarrierTests.The_console_texture_copies_move_textures_from_their_home_states_and_back, the same failure as on main since the lane-present merge.)

**@⁠marquezinii** on GitHub · 2026-11-24 21:55 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/14#issuecomment-7145570090) Makes sense, holding it. I've marked it as a draft until the compile host lands. Once it does, I'll rebase and cut this down to the driver's pipeline build threads, with `--normal-priority-builds` kept for the A/B. One caveat for that measurement: the build threads have no dxc heap, but the NVIDIA compiler still allocates from the process heap, which game threads use too. If the same `WaitOnAddress` stalls show up with lowered build threads, the cause would be the same, and that would rule out this change as well. @⁠danik1222 offered on #13 to run the A/B on the 4-core i7-4770 once a build boots there. With your 4090 numbers that gives one machine at each end of the range. (The Windows check fails here on `D3D12XBarrierTests.The_console_texture_copies_move_textures_from_their_home_states_and_back`, the same failure as on main since the lane-present merge.)
Author
Owner

@⁠marquezinii on GitHub · 2026-11-24 22:43 UTC · original

Rebased onto main now that the compile host is in, and cut down to the driver's pipeline build threads. The program workers are no longer touched. It is out of draft for your --normal-priority-builds A/B, and I've updated the description.

Thanks for merging #15 and for the lazy windows.

**@⁠marquezinii** on GitHub · 2026-11-24 22:43 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/14#issuecomment-7146566153) Rebased onto main now that the compile host is in, and cut down to the driver's pipeline build threads. The program workers are no longer touched. It is out of draft for your `--normal-priority-builds` A/B, and I've updated the description. Thanks for merging #15 and for the lazy windows.
Author
Owner

@⁠marquezinii on GitHub · 2026-11-25 01:04 UTC · original

A/B on real boots: RTX 5070 (12 GB), Ryzen 5 5600X (12 threads), 32 GB RAM, commit limit 72 GB, driver cache warm after one cold boot. Build: this branch on 9e8772a. Each run starts from the first-run screens with Space taps; the timeout is 400 s.

Mean present interval per 600 presents:

Run 1-600 601-1200 1201-1800 1801-2400 2401-3000 3001-3600 end
A (default, below normal) 36.9 ms 33.6 47.9 109.4 172.8 191.3 400 s timeout, reached the prologue ([PRÓLOGO], move/camera hints)
A2 (default) 36.6 33.5 37.3 118.9 149.1 GPU hang at ~280 s
B (--normal-priority-builds) 36.8 33.8 60.6 GPU hang at ~165 s
B2 (--normal-priority-builds) 36.5 33.5 51.5 60.2 GPU hang at ~120 s

So the boot and story-load frame times are the same within noise on this machine. Every run is about 33 ms per present for the first 40 s. The 1201-1800 window is 48 and 37 ms default against 61 and 52 ms normal, but with two runs each that is not a result. The hangs hit both settings, so they are not caused by this change.

The hangs:

  • Each one is a TDR: nvlddmkm event 153.
  • After it, Present fails with 0x887a0005 and the game breaks in its device-removed handler at RVA 0x2474606.
  • The queues show lists with no draws stuck behind the hung one. I didn't have DRED on.

One side effect worth knowing about: after a removal, the machine's free commit fell from about 25 GB to under 1 GB within seconds, probably WER collecting the 22 GB process. On a smaller machine that alone can push it to its commit limit.

I can rerun one of these with --d3d12-debug (DRED) if the hang is new to you.

**@⁠marquezinii** on GitHub · 2026-11-25 01:04 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/14#issuecomment-7149171452) A/B on real boots: RTX 5070 (12 GB), Ryzen 5 5600X (12 threads), 32 GB RAM, commit limit 72 GB, driver cache warm after one cold boot. Build: this branch on `9e8772a`. Each run starts from the first-run screens with Space taps; the timeout is 400 s. Mean present interval per 600 presents: | Run | 1-600 | 601-1200 | 1201-1800 | 1801-2400 | 2401-3000 | 3001-3600 | end | |---|---|---|---|---|---|---|---| | A (default, below normal) | 36.9 ms | 33.6 | 47.9 | 109.4 | 172.8 | 191.3 | 400 s timeout, reached the prologue (`[PRÓLOGO]`, move/camera hints) | | A2 (default) | 36.6 | 33.5 | 37.3 | 118.9 | 149.1 | | GPU hang at ~280 s | | B (`--normal-priority-builds`) | 36.8 | 33.8 | 60.6 | | | | GPU hang at ~165 s | | B2 (`--normal-priority-builds`) | 36.5 | 33.5 | 51.5 | 60.2 | | | GPU hang at ~120 s | So the boot and story-load frame times are the same within noise on this machine. Every run is about 33 ms per present for the first 40 s. The 1201-1800 window is 48 and 37 ms default against 61 and 52 ms normal, but with two runs each that is not a result. The hangs hit both settings, so they are not caused by this change. The hangs: - Each one is a TDR: `nvlddmkm` event 153. - After it, `Present` fails with 0x887a0005 and the game breaks in its device-removed handler at RVA 0x2474606. - The queues show lists with no draws stuck behind the hung one. I didn't have DRED on. One side effect worth knowing about: after a removal, the machine's free commit fell from about 25 GB to under 1 GB within seconds, probably WER collecting the 22 GB process. On a smaller machine that alone can push it to its commit limit. I can rerun one of these with `--d3d12-debug` (DRED) if the hang is new to you.
Author
Owner

@⁠marquezinii on GitHub · 2026-11-25 04:30 UTC · original

Closing this one, since the case for it has gone away:

  • On real boots (the A/B above), frame times were the same with and without lowered build threads.
  • Since then your compile-budget changes (a game thread never waits in the budget, whole estimates reserved) took @⁠danik1222's 4-core i7-4770 from 73-200 ms to 35-39 ms per frame (#13). That was the machine this PR was written for.

The branch stays on my fork (loader/compile-thread-priority) if lowering the driver build threads is ever worth measuring again.

**@⁠marquezinii** on GitHub · 2026-11-25 04:30 UTC · [original](https://github.com/ThatRecompDev/five-star-recomp/pull/14#issuecomment-7152902061) Closing this one, since the case for it has gone away: - On real boots (the A/B above), frame times were the same with and without lowered build threads. - Since then your compile-budget changes (a game thread never waits in the budget, whole estimates reserved) took @⁠danik1222's 4-core i7-4770 from 73-200 ms to 35-39 ms per frame (#13). That was the machine this PR was written for. The branch stays on my fork (`loader/compile-thread-priority`) if lowering the driver build threads is ever worth measuring again.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.