fix(gpu): close upload-ahead races and defer new pool flips #454

Open
github-bot wants to merge 1 commit from github-bot/gh-454 into a-publier AGit
Owner

@⁠matheusfrta on GitHub · 2026-11-27 02:45 UTC · original
matheusfrta:patch-1795747540 → a-publier · +187 −47 · 2 files · 1 commits · open

Fixes three stability issues in the upload-ahead path: reserves the in-flight entry before staging so direct lists cannot race the copy queue, avoids marking textures uploaded or firing callbacks when a copy fails, and passes pool::begun_before into ahead flips so VICTORY_SHOW_NEW_LATER is respected.

**@⁠matheusfrta** on GitHub · 2026-11-27 02:45 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/454) `matheusfrta:patch-1795747540` → `a-publier` · +187 −47 · 2 files · 1 commits · open Fixes three stability issues in the upload-ahead path: reserves the in-flight entry before staging so direct lists cannot race the copy queue, avoids marking textures uploaded or firing callbacks when a copy fails, and passes pool::begun_before into ahead flips so VICTORY_SHOW_NEW_LATER is respected.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 02:51:06 +00:00
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-27 03:55 UTC · original

Tested on an RX 6950 XT (RDNA 2), driver 32.0.21045.29003, Windows 11 build 26300, Rust 1.98.1, release. At a18f4a9: cargo test --release -p victory-gpu --lib 398 passed, 0 failed, 34 ignored.

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

**@⁠MamaLeVrai** on GitHub · 2026-11-27 03:55 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/454#issuecomment-7209381981) Tested on an RX 6950 XT (RDNA 2), driver 32.0.21045.29003, Windows 11 build 26300, Rust 1.98.1, release. At `a18f4a9`: `cargo test --release -p victory-gpu --lib` 398 passed, 0 failed, 34 ignored. AI-assisted (Claude Code); no game data.
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-27 06:49 UTC · original

Tested on an RX 7900 XT (RDNA 3), driver 32.0.32029.2010, Windows 11 build 26300, Rust 1.98.1, release. Head a18f4a9 against base a-publier 4eb6cfd.

  • cargo clippy --release -p victory-gpu --all-targets -- -D warnings: no warnings.
  • victory-gpu --lib, base and head interleaved, 3 runs each: base 396 passed, head 398 passed, 0 failed, 34 ignored on both.
  • Same suite with VICTORY_UPLOAD_AHEAD=1 VICTORY_SHOW_AFTER=1, 2 runs each: one head run failed watch::tests::a_write_opens_the_view_it_goes_through. With the same env it passed 3/3 alone on base and 3/3 alone on head. That test is one of the flaky watch tests listed in #446.
  • listed_waits_while_claim_is_starting and failed_copy_leaves_texture_unuploaded_and_skips_callbacks, alone with 1 thread: 10/10 each. a_placed_texture_is_filled_ahead_of_the_lists alone: 10/10 on head and 10/10 on base. The three texture::ahead tests together: 10/10.
  • Fail without the fix: on base I added one test that does what the base claim() does first (CAS NONE -> PENDING, with no entry in ON_THEIR_WAY yet). It then checks that listed() does not return within 50 ms. It failed 5/5 on base, because listed() returns at once. The existing ahead test passed 5/5 on the same binary.

From reading the code:

  • The CAS and the (serial, None) push now run under one ON_THEIR_WAY lock. Starting::drop and a failed finish() store LISTED before they remove the entry. A good finish() stores DONE. I found no window where listed() returns early, and no lost wakeup.
  • Failed copy for a slot shown ahead: when the old view is not kept, texture_slot_show_ahead() -> show_later() has already put the neutral texture in the slot. With State::Failed, the job's callbacks are dropped, and that callback was the slot's only flip. draw.rs still treats the upload as handled. It calls texture_slot_done, or a recheck that ends there while the fingerprint is the same. So the slot keeps the neutral texture until the title rewrites the record or its bytes change. Base flipped to an unfilled texture instead. Impact is low, because Worker::copy only fails on queue or allocator errors.
  • Late failure in Worker::copy: if Signal or SetEventOnCompletion fails after ExecuteCommandLists, finish(ok = false) sets LISTED and removes the entry. The copy may still be running on the copy queue at that point. A direct list can then record an upload into the same texture with nothing ordering it after that copy.
  • wait_known() waits on LANDED with no timeout while the entry is None. A second texture-pass thread asking for the same texture blocks for as long as the first thread's staging() takes. listed() still stops waiting after 1 s, as on base, so the race comes back if staging() is that slow. The only change there is a warning in the log.

Not tested: VICTORY_SHOW_NEW_LATER=1 (the begun_before change), the title, and RDNA 4.

**@⁠adrianmjim** on GitHub · 2026-11-27 06:49 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/454#issuecomment-7211887874) Tested on an RX 7900 XT (RDNA 3), driver 32.0.32029.2010, Windows 11 build 26300, Rust 1.98.1, release. Head `a18f4a9` against base `a-publier` `4eb6cfd`. - `cargo clippy --release -p victory-gpu --all-targets -- -D warnings`: no warnings. - `victory-gpu --lib`, base and head interleaved, 3 runs each: base 396 passed, head 398 passed, 0 failed, 34 ignored on both. - Same suite with `VICTORY_UPLOAD_AHEAD=1 VICTORY_SHOW_AFTER=1`, 2 runs each: one head run failed `watch::tests::a_write_opens_the_view_it_goes_through`. With the same env it passed 3/3 alone on base and 3/3 alone on head. That test is one of the flaky watch tests listed in #446. - `listed_waits_while_claim_is_starting` and `failed_copy_leaves_texture_unuploaded_and_skips_callbacks`, alone with 1 thread: 10/10 each. `a_placed_texture_is_filled_ahead_of_the_lists` alone: 10/10 on head and 10/10 on base. The three `texture::ahead` tests together: 10/10. - Fail without the fix: on base I added one test that does what the base `claim()` does first (CAS `NONE -> PENDING`, with no entry in `ON_THEIR_WAY` yet). It then checks that `listed()` does not return within 50 ms. It failed 5/5 on base, because `listed()` returns at once. The existing ahead test passed 5/5 on the same binary. From reading the code: - The CAS and the `(serial, None)` push now run under one `ON_THEIR_WAY` lock. `Starting::drop` and a failed `finish()` store `LISTED` before they remove the entry. A good `finish()` stores `DONE`. I found no window where `listed()` returns early, and no lost wakeup. - Failed copy for a slot shown ahead: when the old view is not kept, `texture_slot_show_ahead()` -> `show_later()` has already put the neutral texture in the slot. With `State::Failed`, the job's callbacks are dropped, and that callback was the slot's only flip. draw.rs still treats the upload as handled. It calls `texture_slot_done`, or a recheck that ends there while the fingerprint is the same. So the slot keeps the neutral texture until the title rewrites the record or its bytes change. Base flipped to an unfilled texture instead. Impact is low, because `Worker::copy` only fails on queue or allocator errors. - Late failure in `Worker::copy`: if `Signal` or `SetEventOnCompletion` fails after `ExecuteCommandLists`, `finish(ok = false)` sets `LISTED` and removes the entry. The copy may still be running on the copy queue at that point. A direct list can then record an upload into the same texture with nothing ordering it after that copy. - `wait_known()` waits on `LANDED` with no timeout while the entry is `None`. A second texture-pass thread asking for the same texture blocks for as long as the first thread's `staging()` takes. `listed()` still stops waiting after 1 s, as on base, so the race comes back if `staging()` is that slow. The only change there is a warning in the log. Not tested: `VICTORY_SHOW_NEW_LATER=1` (the `begun_before` change), the title, and RDNA 4.
Author
Owner

@⁠gut0to on GitHub · 2026-11-27 15:06 UTC · original · reviewed

AI-assisted static review; I inspected the new wait protocol and its race tests. I did not run the test suite.

**@⁠gut0to** on GitHub · 2026-11-27 15:06 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/454#pullrequestreview-6090102277) · **reviewed** AI-assisted static review; I inspected the new wait protocol and its race tests. I did not run the test suite.
@ -140,0 +198,4 @@
{
let mut way = ON_THEIR_WAY.lock().unwrap_or_else(|e| e.into_inner());
if let Some(entry) = way.iter_mut().find(|(serial, _)| *serial == job.copy.serial) {
entry.1 = Some(job.clone());
Author
Owner

@⁠gut0to on GitHub · 2026-11-27 15:06 UTC · original

AI-assisted review: the new race test covers Starting::drop, but not the successful None -> Some(job) -> completion removes the serial transition. Could a deterministic test block a listed waiter on (serial, None), publish Some(job), then call finish and remove the entry? It should verify that publishing the job alone does not let the drawing list proceed before the copy completes.

**@⁠gut0to** on GitHub · 2026-11-27 15:06 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/454#discussion_r4720951759) AI-assisted review: the new race test covers `Starting::drop`, but not the successful `None -> Some(job) -> completion removes the serial` transition. Could a deterministic test block a `listed` waiter on `(serial, None)`, publish `Some(job)`, then call `finish` and remove the entry? It should verify that publishing the job alone does not let the drawing list proceed before the copy completes.
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/454/head:github-bot/gh-454'
git switch 'github-bot/gh-454'

Merge

Merge the changes and update on Forgejo.
git switch 'a-publier'
git merge --no-ff 'github-bot/gh-454'
git switch 'github-bot/gh-454'
git rebase 'a-publier'
git switch 'a-publier'
git merge --ff-only 'github-bot/gh-454'
git switch 'github-bot/gh-454'
git rebase 'a-publier'
git switch 'a-publier'
git merge --no-ff 'github-bot/gh-454'
git switch 'a-publier'
git merge --squash 'github-bot/gh-454'
git switch 'a-publier'
git merge --ff-only 'github-bot/gh-454'
git switch 'a-publier'
git merge 'github-bot/gh-454'
git push origin 'a-publier'
This discussion has been locked. Commenting is limited to contributors.
No description provided.