GPU: the dropped passes a presented image reads go first in the pipeline queue #3378

Open
github-bot wants to merge 3 commits from github-bot/gh-3378 into main AGit
Owner

@⁠neonbyte1 on GitHub · 2026-11-26 20:58 UTC · original
neonbyte1:fix/hurry-feeders → main · +1003 −23 · 9 files · 3 commits · open

Stacked on #3353 (fix/hold-unwritten-frames, df15a809); only the last commit (dba19ba2) is new here.

What is wrong

#3353 fixes the flicker while pipelines are still being made: a dropped draw into the presented image holds the frame and its pipeline goes to the head of the workers' queue. A dropped pass further back still leaves the image wrong, because the image is then written from stale inputs.

Grand Theft Auto VI's world on a cold driver cache (__GL_SHADER_DISK_CACHE=0 VKD3D_SHADER_CACHE_PATH=0, RTX 5090, Wine + vkd3d-proton) first binds ~1,900 pipelines in one frame. With #3353, the final upscale is made at once. But the world then stays black (brightest probed pixel 0–1 of 255) until the compute pass that resolves the lighting (structure_lod_wetness:CS_RaytracingResolve) is made. That pass waited 47–54 s in the queue in three runs, and then took 5.8–6.1 s to build. The image turns bright on the first frame after both pipelines exist, while ~1,000–1,700 others are still queued.

What changes

While pipelines are queued, each frame notes:

  • for passes that run: what each reads and writes (the views its code uses through tables, its render targets and depth);
  • for passes that are dropped: what each would have written:
    • its targets;
    • the unordered views its code names through tables. These come from the container's own resource records, so no translation is needed.

At the present, a walk goes back from the presented images through passes that ran. It finds the dropped passes whose writes those passes read, and the nearest ones go to the head of the workers' queue (crate::feeds). Once a hurried pass runs, a later frame's walk goes on behind it.

The walk must not take the world's content. A first version did: one round put 666 mesh pipelines first and pushed back 103 pipelines the queue would have made within 15 s (a TAA resolve, a tiled-lighting clear, decal and particle compute). The world went dark again for about a minute. Hence three limits:

  • Reads are kept per pass, not per pipeline. A pipeline many passes share (a blit) would otherwise join every one of their inputs.
  • A resource with more than 4 dropped writers is not followed to them (FAN_IN_MAX). One or a few passes (a resolve, lighting) leave a resource stale; hundreds of draws into depth or a geometry buffer leave objects missing. The walk still goes through such targets' passes that ran.
  • At most 8 pipelines per present (HURRY_MAX), nearest first. Only pipelines that can still be hurried count toward the 8: queued, not taken by a worker, not hurried before.

The first 64 pipelines a run hurries (FIRST_MAX) are listed in first-pipelines.txt, beside early-pipelines.txt. The next run starts them ahead of the other early starts, during loading.

The code names no shader.

Measured

All runs below use the same cold-cache setup, one 480 s run each, and the same diag build family. "+s" is the time since the scene's first frame.

blk-cold-hold (#3353 only) hurry3 (this PR, no list) hurry4 (this PR, list from hurry3)
made first rounds — at most 8 pipelines per round —
TAA temporal resolve made +11.8 s +11.7 s —
tiled-lighting clear made +6.3 s +6.5 s —
final upscale hurried at its first draw hurried at its first draw made in advance, never waited for
lighting resolve made 53 s after its first bind made ~6 s after its first bind made ~6 s after its first bind
frames 1300/1303 0.2 (black) 93 / 137 (the "NINE MONTHS AGO" intertitle visible) —
black-frame warnings 3 4 (1, 983, 1291, 1301) 4
held frames 1 1 2 (boot image, frames 6/8)
first-pipelines.txt — 63 entries 64 loaded
  • Same queue order as without the walk. hurry3 makes the TAA resolve and the lighting clear at the same times as blk-cold-hold, so the narrowed walk no longer starves the queue.
  • The lighting resolve still takes its build time. In hurry3 the title bound it only at +53 s (it reached that scene late). It was hurried at once and made 6 s later. hurry4 shows the same, because hurry3 never hurried it, so it is not in the list.
  • Not a full A/B. The title's own timing differs between runs, so frame numbers of scene changes are not comparable one to one.
  • Black-frame counts. The diagnostics detector only sees frames that are shown; held frames are never counted.

Limits

  • Buffers and views a shader indexes in the heap itself are not followed; only descriptor-table views and targets are.
  • A pipeline first bound only after the backlog (the lighting resolve in hurry3/4) is hurried at once but still takes its build time. The list only helps pipelines a run actually hurried.
  • With the list loaded, a boot-screen pipeline was held for 2 frames: it was hurried early and the hold waited for it. The hold limit (10 s, #3353) bounds this.
  • Passes are taken per frame in the order they were recorded on any thread. A pass may be counted as feeding the image even though it runs after the read; that only moves a pipeline ahead in the queue.

Cost

When nothing is queued (a warm run, or once the queue drains):

  • Per bind: one relaxed atomic load and a thread-local flag.
  • Per view and per pass that runs: a flag test. No lock, no map.
  • Per dropped pass: one OnceLock::get. Refused pipelines stop there. A container's resource records are parsed only for pipelines being made, once per container.
  • Per present: one uncontended lock and mem::take of an empty graph, which allocates nothing.

While pipelines are queued:

  • Recording: one mutex per pass that runs, and set inserts per view and target.
  • The walk: once per present, only if a dropped pass was noted.
  • Memory: everything is per frame. The graph is dropped at each present and capped at 2^20 notes per frame (NOTES_MAX). first-pipelines.txt is capped at 64 keys.

Tests

CPU only, under Wine; they create no D3D12 device.

  • feeds::tests:
    • the_dropped_passes_a_presented_image_reads_are_found_nearest_first (including the second round once the resolve runs)
    • nearer_feeders_come_first
    • the_image_s_own_writer_and_writeless_passes
    • a_cycle_ends
    • a_target_many_dropped_draws_write_is_not_followed
    • a_shared_pipeline_s_passes_are_followed_apart
    • notes_are_capped
  • pipeline::library::tests:
    • the_first_list_keeps_this_run_first_under_its_cap
    • a_run_lists_its_first_hurries_only
  • Together with the existing shown, pipeline::make and early-list tests: 20 passed.
  • cargo clippy -p victory-gpu --all-targets --target x86_64-pc-windows-msvc -- -D warnings, with and without --all-features: clean.
  • Not run on Windows; CI runs the Windows tests.
  • #2223 (@⁠andrewpozdnakov7-jpg) fixes a race in make.rs: a pipeline is marked queued before it is counted as waiting, so a promotion in between can let a worker make it before the count. make::hurry (from #3353, used here too) is another promotion through the same window. @⁠andrewpozdnakov7-jpg's combined commit 335eb7b (#2223 + #3353 + #3025) waits for completed registration on both paths; whichever lands second needs a small rebase in make.rs.
  • #3025, #3296, #2582 also reorder the pipeline queue (graphics before compute, slow early pipelines bounded, screen passes on their own workers). They touch the same queue code but not this rule.

AI-assisted (Claude); measured on my machine, no game data shared.

**@⁠neonbyte1** on GitHub · 2026-11-26 20:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/3378) `neonbyte1:fix/hurry-feeders` → `main` · +1003 −23 · 9 files · 3 commits · open **Stacked on #3353** (`fix/hold-unwritten-frames`, `df15a809`); only the last commit (`dba19ba2`) is new here. ## What is wrong #3353 fixes the flicker while pipelines are still being made: a dropped draw into the presented image holds the frame and its pipeline goes to the head of the workers' queue. A dropped pass *further back* still leaves the image wrong, because the image is then written from stale inputs. Grand Theft Auto VI's world on a cold driver cache (`__GL_SHADER_DISK_CACHE=0 VKD3D_SHADER_CACHE_PATH=0`, RTX 5090, Wine + vkd3d-proton) first binds ~1,900 pipelines in one frame. With #3353, the final upscale is made at once. But the world then stays black (brightest probed pixel 0–1 of 255) until the compute pass that resolves the lighting (`structure_lod_wetness:CS_RaytracingResolve`) is made. That pass waited **47–54 s** in the queue in three runs, and then took **5.8–6.1 s** to build. The image turns bright on the first frame after both pipelines exist, while ~1,000–1,700 others are still queued. ## What changes While pipelines are queued, each frame notes: - **for passes that run:** what each reads and writes (the views its code uses through tables, its render targets and depth); - **for passes that are dropped:** what each would have written: - its targets; - the unordered views its code names through tables. These come from the container's own resource records, so no translation is needed. At the present, a walk goes back from the presented images through passes that ran. It finds the dropped passes whose writes those passes read, and the nearest ones go to the head of the workers' queue (`crate::feeds`). Once a hurried pass runs, a later frame's walk goes on behind it. The walk must not take the world's content. A first version did: one round put **666** mesh pipelines first and pushed back 103 pipelines the queue would have made within 15 s (a TAA resolve, a tiled-lighting clear, decal and particle compute). The world went dark again for about a minute. Hence three limits: - **Reads are kept per pass, not per pipeline.** A pipeline many passes share (a blit) would otherwise join every one of their inputs. - **A resource with more than 4 dropped writers is not followed to them** (`FAN_IN_MAX`). One or a few passes (a resolve, lighting) leave a resource stale; hundreds of draws into depth or a geometry buffer leave objects missing. The walk still goes *through* such targets' passes that ran. - **At most 8 pipelines per present** (`HURRY_MAX`), nearest first. Only pipelines that can still be hurried count toward the 8: queued, not taken by a worker, not hurried before. The first 64 pipelines a run hurries (`FIRST_MAX`) are listed in `first-pipelines.txt`, beside `early-pipelines.txt`. The next run starts them ahead of the other early starts, during loading. The code names no shader. ## Measured All runs below use the same cold-cache setup, one 480 s run each, and the same diag build family. "+s" is the time since the scene's first frame. | | blk-cold-hold (#3353 only) | hurry3 (this PR, no list) | hurry4 (this PR, list from hurry3) | |---|---|---|---| | `made first` rounds | — | at most 8 pipelines per round | — | | TAA temporal resolve made | +11.8 s | +11.7 s | — | | tiled-lighting clear made | +6.3 s | +6.5 s | — | | final upscale | hurried at its first draw | hurried at its first draw | made in advance, never waited for | | lighting resolve | made 53 s after its first bind | made ~6 s after its first bind | made ~6 s after its first bind | | frames 1300/1303 | 0.2 (black) | 93 / 137 (the "NINE MONTHS AGO" intertitle visible) | — | | black-frame warnings | 3 | 4 (1, 983, 1291, 1301) | 4 | | held frames | 1 | 1 | 2 (boot image, frames 6/8) | | `first-pipelines.txt` | — | 63 entries | 64 loaded | - **Same queue order as without the walk.** hurry3 makes the TAA resolve and the lighting clear at the same times as blk-cold-hold, so the narrowed walk no longer starves the queue. - **The lighting resolve still takes its build time.** In hurry3 the title bound it only at +53 s (it reached that scene late). It was hurried at once and made 6 s later. hurry4 shows the same, because hurry3 never hurried it, so it is not in the list. - **Not a full A/B.** The title's own timing differs between runs, so frame numbers of scene changes are not comparable one to one. - **Black-frame counts.** The diagnostics detector only sees frames that are shown; held frames are never counted. ## Limits - Buffers and views a shader indexes in the heap itself are not followed; only descriptor-table views and targets are. - A pipeline first bound only after the backlog (the lighting resolve in hurry3/4) is hurried at once but still takes its build time. The list only helps pipelines a run actually hurried. - With the list loaded, a boot-screen pipeline was held for 2 frames: it was hurried early and the hold waited for it. The hold limit (10 s, #3353) bounds this. - Passes are taken per frame in the order they were recorded on any thread. A pass may be counted as feeding the image even though it runs after the read; that only moves a pipeline ahead in the queue. ## Cost When nothing is queued (a warm run, or once the queue drains): - **Per bind:** one relaxed atomic load and a thread-local flag. - **Per view and per pass that runs:** a flag test. No lock, no map. - **Per dropped pass:** one `OnceLock::get`. Refused pipelines stop there. A container's resource records are parsed only for pipelines being made, once per container. - **Per present:** one uncontended lock and `mem::take` of an empty graph, which allocates nothing. While pipelines are queued: - **Recording:** one mutex per pass that runs, and set inserts per view and target. - **The walk:** once per present, only if a dropped pass was noted. - **Memory:** everything is per frame. The graph is dropped at each present and capped at 2^20 notes per frame (`NOTES_MAX`). `first-pipelines.txt` is capped at 64 keys. ## Tests CPU only, under Wine; they create no D3D12 device. - `feeds::tests`: - `the_dropped_passes_a_presented_image_reads_are_found_nearest_first` (including the second round once the resolve runs) - `nearer_feeders_come_first` - `the_image_s_own_writer_and_writeless_passes` - `a_cycle_ends` - `a_target_many_dropped_draws_write_is_not_followed` - `a_shared_pipeline_s_passes_are_followed_apart` - `notes_are_capped` - `pipeline::library::tests`: - `the_first_list_keeps_this_run_first_under_its_cap` - `a_run_lists_its_first_hurries_only` - Together with the existing `shown`, `pipeline::make` and early-list tests: 20 passed. - `cargo clippy -p victory-gpu --all-targets --target x86_64-pc-windows-msvc -- -D warnings`, with and without `--all-features`: clean. - Not run on Windows; CI runs the Windows tests. ## Related - **#2223** (@⁠andrewpozdnakov7-jpg) fixes a race in `make.rs`: a pipeline is marked queued before it is counted as waiting, so a promotion in between can let a worker make it before the count. `make::hurry` (from #3353, used here too) is another promotion through the same window. @⁠andrewpozdnakov7-jpg's combined commit `335eb7b` (#2223 + #3353 + #3025) waits for completed registration on both paths; whichever lands second needs a small rebase in `make.rs`. - **#3025, #3296, #2582** also reorder the pipeline queue (graphics before compute, slow early pipelines bounded, screen passes on their own workers). They touch the same queue code but not this rule. _AI-assisted (Claude); measured on my machine, no game data shared._
A draw whose pipeline is still being made is dropped and leaves its
targets as they were. When it is the draw that writes a presented image
(Grand Theft Auto VI's final upscale, PS_TAA2_SpatialUpscaleWithDithering),
that back buffer still holds the frame drawn into it two presents ago, and
the window alternates between two old frames. On a cold driver cache the
world's first frame wants ~1,900 new pipelines; the upscale's was made 41 s
after its first use, and frames 1300-1346 alternated black and dim.

Such a draw now puts its pipeline at the head of the workers' queue
(make::hurry), and a present of an image it left unwritten is not shown:
the window keeps the last frame shown (crate::shown), for at most 10 s
(HOLD_LIMIT). Past that the frames are shown as they come, and the log
names the pipelines waited for, so a pipeline that never arrives (a dead
worker, a hung driver compile) cannot freeze the window. Refused pipelines
do not count at all. VICTORY_SHOW_UNWRITTEN=1 shows those frames as before.
With #3353 a dropped draw into the presented image holds the frame and
puts its pipeline first. A dropped pass further back still leaves the
image wrong: in Grand Theft Auto VI's world on a cold driver cache the
final upscale was made at once, but the world stayed black for ~50 s
until the compute pass resolving the lighting (CS_RaytracingResolve) was
made: it waited 47 s in the queue behind ~1,900 pipelines first used in
the same frame, and took 6 s once a worker had it.

While pipelines are queued, each frame now notes what each pass that runs
reads and writes (the views its code uses through tables, its targets)
and what the dropped ones would have written: their targets, and the
unordered views their code names through tables, read from the
container's own resource records (no translation needed). At the
present, a walk back from the presented images through the passes that
ran finds the dropped passes whose writes they read, and the nearest
eight go to the head of the workers' queue (crate::feeds). Once a
hurried pass runs, a later frame's walk goes on behind it.

The walk must not take the world's content: reads are kept per pass, not
per pipeline (a blit used by many passes would join all their inputs),
and a resource with more than four dropped writers (depth, a geometry
buffer, filled by hundreds of draws) is not followed to them. Without
these a round put 666 mesh pipelines first, pushed back 103 that the
queue would have made within 15 s, and the world went dark again.

The first 64 pipelines a run hurries are listed in first-pipelines.txt
beside the early list; the next run starts them ahead of the other early
starts, during loading.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:00:56 +00:00
Author
Owner

@⁠neonbyte1 on GitHub · 2026-11-26 21:04 UTC · original

CI note: the one failing test, frame::tests::waits_end_on_ticks_and_count_frames (frame.rs:231, a zero-time-out wait got S_OK instead of TIMEOUT), is the known flaky frame-clock test. #2861 and #2877 describe exactly this line: 2 ms ticks on a loaded runner, plus the test sharing the global clock with waits_begun_together_take_different_ticks. This PR doesn't touch frame.rs, and the other 246 victory-gpu tests passed, including the new feeds::, shown:: and pipeline::library:: ones. #3353, with most of the same code, passed CI twice. I can't re-run the job from a fork; a maintainer re-run should clear it.

AI-assisted (Claude); no game data shared.

**@⁠neonbyte1** on GitHub · 2026-11-26 21:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/3378#issuecomment-7203361119) CI note: the one failing test, `frame::tests::waits_end_on_ticks_and_count_frames` (`frame.rs:231`, a zero-time-out wait got `S_OK` instead of `TIMEOUT`), is the known flaky frame-clock test. #2861 and #2877 describe exactly this line: 2 ms ticks on a loaded runner, plus the test sharing the global clock with `waits_begun_together_take_different_ticks`. This PR doesn't touch `frame.rs`, and the other 246 `victory-gpu` tests passed, including the new `feeds::`, `shown::` and `pipeline::library::` ones. #3353, with most of the same code, passed CI twice. I can't re-run the job from a fork; a maintainer re-run should clear it. _AI-assisted (Claude); no game data shared._
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 21:08 UTC · original · approved these changes

LGTM — verified on RTX 5090 (Windows / D3D12) against origin/main (63bcca4).

  • Prioritizing dropped feeder passes whose outputs feed the presented image (nearest-first, cycle-safe, and capped) works cleanly alongside shown and the pipeline worker queue.
  • cargo test -p victory-gpu --lib feeds:: -- --test-threads=1: 7 passed, 0 failed.
  • cargo test -p victory-gpu --lib shown:: -- --test-threads=1: all passed.
  • cargo test -p victory-gpu --lib pipeline:: -- --test-threads=1: all passed.
  • cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 20 passed, 0 failed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 193 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 21:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/3378#pullrequestreview-6080495468) · **approved these changes** LGTM — verified on RTX 5090 (Windows / D3D12) against `origin/main` (`63bcca4`). - Prioritizing dropped feeder passes whose outputs feed the presented image (nearest-first, cycle-safe, and capped) works cleanly alongside `shown` and the pipeline worker queue. - `cargo test -p victory-gpu --lib feeds:: -- --test-threads=1`: 7 passed, 0 failed. - `cargo test -p victory-gpu --lib shown:: -- --test-threads=1`: all passed. - `cargo test -p victory-gpu --lib pipeline:: -- --test-threads=1`: all passed. - `cargo test -p victory-gpu --lib draw:: -- --test-threads=1`: 20 passed, 0 failed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 193 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request can be merged automatically.
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 origin '+refs/pull/3378/head:github-bot/gh-3378'
git switch 'github-bot/gh-3378'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3378'
git switch 'github-bot/gh-3378'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3378'
git switch 'github-bot/gh-3378'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3378'
git switch 'main'
git merge --squash 'github-bot/gh-3378'
git switch 'main'
git merge --ff-only 'github-bot/gh-3378'
git switch 'main'
git merge 'github-bot/gh-3378'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3378
No description provided.