perf(gpu): lift slow-pipeline cap on warm library loads and boost waited-for workers #283

Merged
Mikey970 merged 2 commits from upstream-pr/283 into main 2026-11-29 08:16:59 +00:00
Mikey970 commented 2026-11-27 20:40:36 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Mikey970 on 2026-11-27T20:40:36Z.


Problem

slow-pipelines.txt only grows over time: pipelines that once took >= 1 s to compile on a cold start stay on the slow list permanently. On subsequent warm launches where the D3D12 pipeline library loads those PSOs in milliseconds, slow_limit() still throttles them to workers / 4 at THREAD_PRIORITY_LOWEST. Hundreds of early cached pipelines spill into world entry, where recording threads stall up to VICTORY_PIPELINE_WAIT_MS (500 ms) waiting on starved lowest-priority workers.

Fix

  • Warm library slow-limit lift (VICTORY_PIPELINE_SLOW): Tracks whether the pipeline library opened from an existing saved blob (library::warm()). While a warm library is actively serving the run (at most 1 in 4 pipelines built fresh), the slow-list concurrency cap is lifted so cached PSOs load ahead of world entry. Cold starts, driver updates, and large translator invalidations keep the cold cap. VICTORY_PIPELINE_SLOW=1 forces the cold cap; =0 disables it as before.
  • Draw-wait priority boost (VICTORY_PIPELINE_BOOST, on by default; =0 disables): While a draw/dispatch is actively blocked waiting for a pipeline, temporarily raises the worker thread making it to THREAD_PRIORITY_NORMAL and restores its base priority when the wait ends or at the next pipeline.

Testing

  • Added unit tests the_slow_limit_is_lifted_with_a_warm_library and a_waiting_draw_raises_the_worker_making_its_pipeline; all 9 tests in pipeline::make::tests pass.
  • Verified in release runs: eliminated pipeline-wait stalls (pipeline_wait_ms = 0) on warm launches.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5532821081 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/283). Originally posted by [Mikey970](https://github.com/Mikey970) on 2026-11-27T20:40:36Z. --- ## Problem `slow-pipelines.txt` only grows over time: pipelines that once took >= 1 s to compile on a cold start stay on the slow list permanently. On subsequent warm launches where the D3D12 pipeline library loads those PSOs in milliseconds, `slow_limit()` still throttles them to `workers / 4` at `THREAD_PRIORITY_LOWEST`. Hundreds of early cached pipelines spill into world entry, where recording threads stall up to `VICTORY_PIPELINE_WAIT_MS` (500 ms) waiting on starved lowest-priority workers. ## Fix - **Warm library slow-limit lift (`VICTORY_PIPELINE_SLOW`):** Tracks whether the pipeline library opened from an existing saved blob (`library::warm()`). While a warm library is actively serving the run (at most 1 in 4 pipelines built fresh), the slow-list concurrency cap is lifted so cached PSOs load ahead of world entry. Cold starts, driver updates, and large translator invalidations keep the cold cap. `VICTORY_PIPELINE_SLOW=1` forces the cold cap; `=0` disables it as before. - **Draw-wait priority boost (`VICTORY_PIPELINE_BOOST`, on by default; `=0` disables):** While a draw/dispatch is actively blocked waiting for a pipeline, temporarily raises the worker thread making it to `THREAD_PRIORITY_NORMAL` and restores its base priority when the wait ends or at the next pipeline. ## Testing - Added unit tests `the_slow_limit_is_lifted_with_a_warm_library` and `a_waiting_draw_raises_the_worker_making_its_pipeline`; all 9 tests in `pipeline::make::tests` pass. - Verified in release runs: eliminated pipeline-wait stalls (`pipeline_wait_ms = 0`) on warm launches.
0xkn0wh3r3 commented 2026-11-28 09:12:13 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by 0xkn0wh3r3 on 2026-11-28T09:12:13Z.


I tried the same idea on an RTX 5070 Ti (16 pipeline workers) and ran into one thing worth guarding against: how many workers end up at normal priority at once.

My first version marked a pipeline when a draw first waited for it, and the worker that made it ran at THREAD_PRIORITY_NORMAL until the pipeline was done, not just while the draw waited. In a play run a burst of new pipelines had 46 to 82 being made at once, so all 16 workers could sit at the title's priority beside its own threads. That run also had audio dropouts. The log has no audio warnings, so I can't prove they were connected, but it was the obvious suspect.

The fix I settled on is a small cap on the number of workers raised at once (4 by default, VICTORY_PIPELINE_HURRY=<n>, 0 for none):

static HURRYING: AtomicUsize = AtomicUsize::new(0);

/// A worker takes one of the `hurry_most()` places; whether it got one.
fn take_hurry() -> bool {
    HURRYING
        .fetch_update(Ordering::AcqRel, Ordering::Acquire, |n| (n < hurry_most()).then_some(n + 1))
        .is_ok()
}

// in the worker loop
let p = next(screens_only);
let hurried = p.hurried.load(Ordering::Relaxed) && take_hurry();
if hurried {
    set(THREAD_PRIORITY_NORMAL);
}
p.make();
if hurried {
    set(low);
    HURRYING.fetch_sub(1, Ordering::AcqRel);
}

This PR is less exposed than my first version: it lowers the worker when the wait ends, and with the shared wait budget (VICTORY_PIPELINE_WAIT_SHARED, on by default) usually only one draw waits at a time. Passes over the screen have their own budget and can wait alongside it, though, and with VICTORY_PIPELINE_WAIT_SHARED=0 every recording thread can wait at once. A cap like the one above would bound that for little code. In boost(p, true) it would mean taking a place first and skipping the raise if none is free, and giving the place back in boost(p, false).

I haven't measured the cap in play yet, so take it as a suggestion rather than a measured result.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7237084450 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/283#issuecomment-7237084450). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-28T09:12:13Z. --- I tried the same idea on an RTX 5070 Ti (16 pipeline workers) and ran into one thing worth guarding against: **how many workers end up at normal priority at once**. My first version marked a pipeline when a draw first waited for it, and the worker that made it ran at `THREAD_PRIORITY_NORMAL` until the pipeline was done, not just while the draw waited. In a play run a burst of new pipelines had 46 to 82 being made at once, so all 16 workers could sit at the title's priority beside its own threads. That run also had audio dropouts. The log has no audio warnings, so I can't prove they were connected, but it was the obvious suspect. The fix I settled on is a small cap on the number of workers raised at once (4 by default, `VICTORY_PIPELINE_HURRY=<n>`, `0` for none): ```rust static HURRYING: AtomicUsize = AtomicUsize::new(0); /// A worker takes one of the `hurry_most()` places; whether it got one. fn take_hurry() -> bool { HURRYING .fetch_update(Ordering::AcqRel, Ordering::Acquire, |n| (n < hurry_most()).then_some(n + 1)) .is_ok() } // in the worker loop let p = next(screens_only); let hurried = p.hurried.load(Ordering::Relaxed) && take_hurry(); if hurried { set(THREAD_PRIORITY_NORMAL); } p.make(); if hurried { set(low); HURRYING.fetch_sub(1, Ordering::AcqRel); } ``` This PR is less exposed than my first version: it lowers the worker when the wait ends, and with the shared wait budget (`VICTORY_PIPELINE_WAIT_SHARED`, on by default) usually only one draw waits at a time. Passes over the screen have their own budget and can wait alongside it, though, and with `VICTORY_PIPELINE_WAIT_SHARED=0` every recording thread can wait at once. A cap like the one above would bound that for little code. In `boost(p, true)` it would mean taking a place first and skipping the raise if none is free, and giving the place back in `boost(p, false)`. I haven't measured the cap in play yet, so take it as a suggestion rather than a measured result.
hazben commented 2026-11-28 09:56:34 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by hazben on 2026-11-28T09:56:34Z.


A data point for #283 from the other side of world entry: pipeline makes in the middle of play, felt as "lag after a pause". RTX 4070 SUPER, 32 GB, DLSS Quality, frame generation off, main 64d4931 plus a local patch stack and a diagnostics build, async submit (depth 24). One play run of 3,939 s; a tester reported extreme input lag after the pause that ended at 3,292 s. I read the run to see whether any delay sits between the stick and the picture.

1. The stick-to-view delay is normal. Camera angle read every ~0.28 s against the right stick's onsets (windowed cross-correlation); onsets where the view moved before the stick (follow camera) are left out:

onsets median p25 / p75 max
before the pause 89 132 ms 79 / 200 964 ms
after the pause 35 154 ms 131 / 199 424 ms

By frame time at the onset (all 124): under 45 ms 148 ms (n=29), 45-65 ms 119 (57), 65-90 ms 161 (36), over 90 ms 251 (2). Limits: this reads the game's camera state, not the display after Present; the left stick is no probe (the follow camera answers 1-2.3 s late by itself). The swap chain has 2 buffers, flip-discard; the frame recorder's "begun minus presented" is 0 in all 190,358 frames to 3,333 s.

2. What the 11 lag presses have in common (a key press at each moment the tester felt it; window = press -3 s to +3 s):

  • 10 of the 11 are in heavy scenes: 5,000-13,000 draws, 55-135 ms median frames. The other one is the pause ending.
  • In 7 of 11, pipeline makes came 0.5-3 s before the press (47 in one window; 1 in two of them). In 5 of those 7 a frame of 447-905 ms came with them; four of the five are 447-569 ms, the size of the 500 ms wait budget in this PR's text. Unverified that it is that wait.
  • Heavy 6 s stretches after the pause: any pipeline make in 9 %, a frame over 400 ms in 1 %. The 19 stretches around the presses: 53 % and 32 %.
  • The 4 without a make are the pause end and three presses in steady 93-135 ms frames at 10-13k draws.
  • When the pause ended, the scene went from 117 to 7,214 draws per frame; the longest frame of the next 40 s was 1,294 ms.

3. The cache was warm at the start but not for these places. The line "shaders from the cache and translated so far": hits=3,461 misses=0 at 66 s; misses 12 at 369 s, 42 at 1,437 s, 170 at 2,628 s (hits stay at 3,477 from 1,437 s on). Every shader gets a "shader translated" line, from the cache or not: 3,647 lines to 2,628 s = 3,477 hits + 170 misses. After the pause (3,292-3,800 s) there are 47 more lines; 33 of them fall in the press windows, which are 19 % of that time. Likely mostly misses (hits had stopped growing); unverified, no count line after 2,628 s. So the hitch is the new shaders and pipelines of a new place, not a cold start.

4. No growth with uptime. The raw cost at 8-11.5k draws rose from 68 to 87 ms per frame over the hour. At the same place (within 30 m, draws within 25 %, 106 late/early pairs) the ratio is 1.02 (IQR 0.97-1.11); host copies stay at about 3,660 copies / 2,060 MB. The rise is the scene, not a leak.

Not measured: display latency after Present, the tester's display path, mouse input (13 events in the run, none after the pause).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7237566282 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/283#issuecomment-7237566282). Originally posted by [hazben](https://github.com/hazben) on 2026-11-28T09:56:34Z. --- A data point for #283 from the other side of world entry: pipeline makes in the middle of play, felt as "lag after a pause". RTX 4070 SUPER, 32 GB, DLSS Quality, frame generation off, main 64d4931 plus a local patch stack and a diagnostics build, async submit (depth 24). One play run of 3,939 s; a tester reported extreme input lag after the pause that ended at 3,292 s. I read the run to see whether any delay sits between the stick and the picture. **1. The stick-to-view delay is normal.** Camera angle read every ~0.28 s against the right stick's onsets (windowed cross-correlation); onsets where the view moved before the stick (follow camera) are left out: | | onsets | median | p25 / p75 | max | |---|---|---|---|---| | before the pause | 89 | 132 ms | 79 / 200 | 964 ms | | after the pause | 35 | 154 ms | 131 / 199 | 424 ms | By frame time at the onset (all 124): under 45 ms 148 ms (n=29), 45-65 ms 119 (57), 65-90 ms 161 (36), over 90 ms 251 (2). Limits: this reads the game's camera state, not the display after Present; the left stick is no probe (the follow camera answers 1-2.3 s late by itself). The swap chain has 2 buffers, flip-discard; the frame recorder's "begun minus presented" is 0 in all 190,358 frames to 3,333 s. **2. What the 11 lag presses have in common** (a key press at each moment the tester felt it; window = press -3 s to +3 s): - 10 of the 11 are in heavy scenes: 5,000-13,000 draws, 55-135 ms median frames. The other one is the pause ending. - In 7 of 11, pipeline makes came 0.5-3 s before the press (47 in one window; 1 in two of them). In 5 of those 7 a frame of 447-905 ms came with them; four of the five are 447-569 ms, the size of the 500 ms wait budget in this PR's text. Unverified that it is that wait. - Heavy 6 s stretches after the pause: any pipeline make in 9 %, a frame over 400 ms in 1 %. The 19 stretches around the presses: 53 % and 32 %. - The 4 without a make are the pause end and three presses in steady 93-135 ms frames at 10-13k draws. - When the pause ended, the scene went from 117 to 7,214 draws per frame; the longest frame of the next 40 s was 1,294 ms. **3. The cache was warm at the start but not for these places.** The line "shaders from the cache and translated so far": hits=3,461 misses=0 at 66 s; misses 12 at 369 s, 42 at 1,437 s, 170 at 2,628 s (hits stay at 3,477 from 1,437 s on). Every shader gets a "shader translated" line, from the cache or not: 3,647 lines to 2,628 s = 3,477 hits + 170 misses. After the pause (3,292-3,800 s) there are 47 more lines; 33 of them fall in the press windows, which are 19 % of that time. Likely mostly misses (hits had stopped growing); unverified, no count line after 2,628 s. So the hitch is the new shaders and pipelines of a new place, not a cold start. **4. No growth with uptime.** The raw cost at 8-11.5k draws rose from 68 to 87 ms per frame over the hour. At the same place (within 30 m, draws within 25 %, 106 late/early pairs) the ratio is 1.02 (IQR 0.97-1.11); host copies stay at about 3,660 copies / 2,060 MB. The rise is the scene, not a leak. Not measured: display latency after Present, the tester's display path, mouse input (13 events in the run, none after the pause).
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
trustno1-coder/VIctory-NVIDIA!283
No description provided.