Upload ahead: a list waits for an upload still being taken (copy-queue race) #536

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

@⁠MamaLeVrai on GitHub · 2026-11-27 10:18 UTC · original
MamaLeVrai:upload-ahead-race → a-publier · +75 −1 · 1 files · 1 commits · open

What

A race between the upload-ahead copy queue (VICTORY_UPLOAD_AHEAD, texture/ahead.rs) and a list that uploads the same texture on the drawing queue.

  • claim() marks a texture as on its way before its job exists. It then builds the staging buffer while holding the staging lock (texture.rs ~1839), and only after that puts the job in the "on their way" list.
  • listed(), which a list calls before it records an upload (texture.rs ~751), waited only while the job was in that list, and gave up after 1 s.

So a list that uploads the same texture inside that window, or more than 1 s later, recorded its copy on the drawing queue while the copy queue wrote the same texture. The copy-queue worker also rewrites the staging buffer the drawing-queue copy reads.

Fix (ahead.rs): listed() now waits for the texture to leave the "on its way" state, not for its job in the list. The wait is capped at 10 s, with a log line if it runs out. A claim() that gives up after marking the texture wakes any list waiting on it.

Test

texture::ahead::tests::a_list_waits_for_an_upload_still_being_taken holds the staging lock to freeze claim() inside the window, then calls listed() from another thread.

  • without the fix: FAILED, listed() returned while the upload was still on its way (left: Ok(1), right: Ok(2));
  • with it: passes, 5 of 5 runs, on an RX 6950 XT (RDNA 2), along with the existing a_placed_texture_is_filled_ahead_of_the_lists. Clippy on victory-gpu: 0 warnings.

Not claimed

This is not relay-only (ahead::take depends on VICTORY_SHOW_AFTER), and RDNA 2 players with VICTORY_RELAY=0 and VICTORY_UPLOAD_AHEAD=1 don't crash. So it is unlikely to be the cause of the RDNA 2 resets (#376); with relay on, the overlap just gets more likely. Not run in the game.

One theoretical case: a thread calling listed() between its own claim() and send() would stand for up to 10 s. No such path was found.

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

🤖 Generated with Claude Code

**@⁠MamaLeVrai** on GitHub · 2026-11-27 10:18 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/536) `MamaLeVrai:upload-ahead-race` → `a-publier` · +75 −1 · 1 files · 1 commits · open ## What A race between the upload-ahead copy queue (`VICTORY_UPLOAD_AHEAD`, `texture/ahead.rs`) and a list that uploads the same texture on the drawing queue. - `claim()` marks a texture as on its way **before** its job exists. It then builds the staging buffer while holding the staging lock (`texture.rs` ~1839), and only after that puts the job in the "on their way" list. - `listed()`, which a list calls before it records an upload (`texture.rs` ~751), waited only while the job was **in that list**, and gave up after 1 s. So a list that uploads the same texture inside that window, or more than 1 s later, recorded its copy on the drawing queue while the copy queue wrote the same texture. The copy-queue worker also rewrites the staging buffer the drawing-queue copy reads. **Fix (`ahead.rs`):** `listed()` now waits for the texture to leave the "on its way" state, not for its job in the list. The wait is capped at 10 s, with a log line if it runs out. A `claim()` that gives up after marking the texture wakes any list waiting on it. ## Test `texture::ahead::tests::a_list_waits_for_an_upload_still_being_taken` holds the staging lock to freeze `claim()` inside the window, then calls `listed()` from another thread. - without the fix: FAILED, `listed()` returned while the upload was still on its way (`left: Ok(1), right: Ok(2)`); - with it: passes, 5 of 5 runs, on an RX 6950 XT (RDNA 2), along with the existing `a_placed_texture_is_filled_ahead_of_the_lists`. Clippy on victory-gpu: 0 warnings. ## Not claimed This is not relay-only (`ahead::take` depends on `VICTORY_SHOW_AFTER`), and RDNA 2 players with `VICTORY_RELAY=0` and `VICTORY_UPLOAD_AHEAD=1` don't crash. So it is unlikely to be the cause of the RDNA 2 resets (#376); with relay on, the overlap just gets more likely. Not run in the game. One theoretical case: a thread calling `listed()` between its own `claim()` and `send()` would stand for up to 10 s. No such path was found. AI-assisted (Claude Code); no game data. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
texture::ahead::claim marks a texture PENDING before its job exists (the
staging buffer is made in between, under the staging table's lock), and
listed() waited only while the job was in ON_THEIR_WAY. A draw's list that
uploaded the same texture in that window went on at once and recorded the
upload on the drawing queue while the copy queue wrote the texture too (and
the worker refreshed the staging buffer that list's copy reads). Past 1 s of
waiting the same happened.

listed() now waits on the state (PENDING), notified by finish() and by a
claim that turns the texture down; the cap is 10 s, logged.

Test a_list_waits_for_an_upload_still_being_taken holds the staging lock to
freeze claim in that window: before, listed() returned with the state still
PENDING (1 of 1); now it returns after the copy ran (5 of 5, RX 6950 XT).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 10:41:13 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-27 10:18 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-27 10:18 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/536#pullrequestreview-6086632318) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Author
Owner

@⁠gw1337x on GitHub · 2026-11-27 11:13 UTC · original · edited 2026-11-27 11:52 UTC

In-game check on RDNA 3, with VICTORY_UPLOAD_AHEAD=1 on (part of the setting I test with). Memory Integrity was off.

PC: Ryzen 7 9800X3D, RX 7800 XT, 32 GB. Test: 270 s hands-off boat scene, RT off, warm caches. #536 on 4eb6cfd vs 4eb6cfd, runs interleaved (PR, base, PR).

#536 run 1 base #536 run 2
steady fps (last minute, layer log) 28.7 28.6 28.4
lists that waited for an upload ahead (whole run) 3,066 3,708 3,004
longest upload ahead, ms 300 156 1,657
"did not run in 10 s" warnings 0 0 0
device loss lines 0 0 0
  • Across the 14 base runs today, the longest upload ranged 46-1,699 ms and list waits 2,901-3,708. The PR's values are inside both ranges.
  • Peak commit: 34.8 / 33.7 GB vs 33.8 GB. The 4 base runs since 10:29 were 33.8-34.2 GB, so run 1's 34.8 is above that range. That's one run; I haven't measured whether it repeats.
  • Picture: run 2 looks normal at 241 s. Run 1 has a dark boat deck in every shot from 220 to 270 s. A base run earlier today (same 4eb6cfd build, 10:52) shows the same dark deck over the same span, so it isn't specific to this PR.

No measurable change and no regression in this scene. This doesn't test whether the race itself shows up here.

**@⁠gw1337x** on GitHub · 2026-11-27 11:13 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/536#issuecomment-7216829407) · edited 2026-11-27 11:52 UTC In-game check on RDNA 3, with `VICTORY_UPLOAD_AHEAD=1` on (part of the setting I test with). Memory Integrity was off. PC: Ryzen 7 9800X3D, RX 7800 XT, 32 GB. Test: 270 s hands-off boat scene, RT off, warm caches. #536 on `4eb6cfd` vs `4eb6cfd`, runs interleaved (PR, base, PR). | | #536 run 1 | base | #536 run 2 | |---|---|---|---| | steady fps (last minute, layer log) | 28.7 | 28.6 | 28.4 | | lists that waited for an upload ahead (whole run) | 3,066 | 3,708 | 3,004 | | longest upload ahead, ms | 300 | 156 | 1,657 | | "did not run in 10 s" warnings | 0 | 0 | 0 | | device loss lines | 0 | 0 | 0 | - Across the 14 base runs today, the longest upload ranged 46-1,699 ms and list waits 2,901-3,708. The PR's values are inside both ranges. - Peak commit: 34.8 / 33.7 GB vs 33.8 GB. The 4 base runs since 10:29 were 33.8-34.2 GB, so run 1's 34.8 is above that range. That's one run; I haven't measured whether it repeats. - Picture: run 2 looks normal at 241 s. Run 1 has a dark boat deck in every shot from 220 to 270 s. A base run earlier today (same `4eb6cfd` build, 10:52) shows the same dark deck over the same span, so it isn't specific to this PR. No measurable change and no regression in this scene. This doesn't test whether the race itself shows up here.
Author
Owner

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

Thanks @⁠gw1337x. That fits what the PR should do: no fps change, list waits and longest uploads within the base range, and no device loss. The race only shows when a list uploads the same texture inside the claim window, which a hands-off boat scene may rarely hit. The unit test is the proof of the fix, and your runs are the check that it costs nothing here. The 34.8 GB peak commit in run 1 is worth watching if it repeats, but nothing in this change allocates more.

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

**@⁠MamaLeVrai** on GitHub · 2026-11-27 11:32 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/536#issuecomment-7217197151) Thanks @⁠gw1337x. That fits what the PR should do: no fps change, list waits and longest uploads within the base range, and no device loss. The race only shows when a list uploads the same texture inside the claim window, which a hands-off boat scene may rarely hit. The unit test is the proof of the fix, and your runs are the check that it costs nothing here. The 34.8 GB peak commit in run 1 is worth watching if it repeats, but nothing in this change allocates more. AI-assisted (Claude Code); no game data.
Author
Owner

@⁠gut0to on GitHub · 2026-11-27 13:28 UTC · original · reviewed

AI-assisted review: I traced the timeout path through listed() and its caller, which continues recording the list upload after this function returns.

**@⁠gut0to** on GitHub · 2026-11-27 13:28 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/536#pullrequestreview-6088882364) · **reviewed** AI-assisted review: I traced the timeout path through `listed()` and its caller, which continues recording the list upload after this function returns.
@ -157,2 +168,3 @@
let started = std::time::Instant::now();
while way.iter().any(|(serial, _)| *serial == copy.serial) && started.elapsed().as_millis() < 1000 {
while copy.ahead.load(Relaxed) == PENDING {
if started.elapsed().as_secs() >= 10 {
Author
Owner

@⁠gut0to on GitHub · 2026-11-27 13:28 UTC · original

After 10 seconds this returns while copy.ahead is still PENDING, so the caller proceeds with its drawing-queue upload even though the copy-queue job may still write the same texture and refresh the staging buffer. That is the original race with a longer timeout. Could the timeout cancel/retire the pending claim or otherwise prevent the duplicate upload before returning? If cancellation is not possible, the caller needs a safe failure path instead of continuing concurrently.

**@⁠gut0to** on GitHub · 2026-11-27 13:28 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/536#discussion_r4719968763) After 10 seconds this returns while `copy.ahead` is still `PENDING`, so the caller proceeds with its drawing-queue upload even though the copy-queue job may still write the same texture and refresh the staging buffer. That is the original race with a longer timeout. Could the timeout cancel/retire the pending claim or otherwise prevent the duplicate upload before returning? If cancellation is not possible, the caller needs a safe failure path instead of continuing concurrently.
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/536/head:github-bot/gh-536'
git switch 'github-bot/gh-536'

Merge

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