fix: a texture's staging buffer is not rewritten while a copy from it may be on the card #254

Open
github-bot wants to merge 1 commit from github-bot/gh-254 into main AGit
Owner

@⁠Skyfrye on GitHub · 2026-11-25 21:57 UTC · original
Skyfrye:nep/staging-refresh-guard → main · +113 −13 · 2 files · 1 commits · draft

Draft: the in-game check on this base is pending (the test machine's GPU is in use for a few hours). Everything below the game run is done.

Change

A list that samples a title texture whose staging buffer is newer than the host texture records a copy from that buffer, and the buffer is brought up to date while the list's submission is prepared (Step::Texture → Staging::refresh). A later submission that samples the same texture checks it again while it is prepared and, when the title changed the texture's memory, detiles the new bytes into the same buffer at once. With flights in the air (the relay), the earlier submission's copy can still be waiting on the card, and then reads bytes of two versions of the texture.

The previous base waited for the card at such a point (staging_in_flight → a settle; on an RTX 5080 about 14 settles a frame, most of the ~97 ms the submitting thread stood waiting). The Neptune base no longer waits, and I found nothing else that keeps the buffer from being written (no fence, no double buffer; the pool only reuses a buffer after every list holding it was reset, which is a different case). This may be part of the known issue "objects and clothes can turn black for a moment while their textures are swapped" — not shown.

Now:

  • each Staging notes the last submission whose lists copy from it (copied_by; Step::Texture carries whether the list recorded a copy, Batch carries the submission's number);
  • a check during the preparing of a later submission leaves the buffer alone while that submission has not landed (copied_by > finished and < preparing): nothing waits; the texture's notes (Last) are left untouched so the change is found again at a later check; copies are recorded only after a detiling (a list may still record one from a detiling that came before the guard held off, which is fine: it copies what the buffer holds), so copied_by stops moving, the earlier submission lands and a later check goes ahead. A texture the title rewrites at every submission is then brought up to date about once per flights-in-the-air plus one submissions instead of at every one; it is never starved (an independent review traced this). The texture shows a change that much later;
  • a submission's own copies run after everything it prepares, so its own check still writes the buffer, as before.

VICTORY_STAGING_GUARD=0 restores the previous behaviour. The frame line counts the checks put off ("texture refreshes put off per frame ...").

Linked issue: none.

Verification

Windows 11 26300, Rust 1.98.1 (MSVC), RTX 5080, on upstream main at affaf15, from third_party/victory:

cargo build --locked --release -p victory                              -> Finished, no new warning (the 3 of main)
cargo build --locked --profile diag -p victory --features diagnostics  -> Finished, no new warning
cargo test --locked -p victory-gpu --lib guard_tests                   -> 1 passed (CPU only)
cargo xtask policy                                                     -> asset policy: ok

With copy_in_flight made to return false and the test kept, the test fails.

Pending: a game run (GTA VI 1.0.2.1, my own copy, launcher settings) with the frame line's new counter, against main and with VICTORY_STAGING_GUARD=0, and a picture comparison of the same frames. I will add the numbers here before marking the PR ready.

First game run with the guard on (5 minutes, release build with this and the other open changes of mine, launcher settings, the world of the prologue): the frame line counted 1.3 to 3.7 texture refreshes per frame put off by the guard, that is, that often a staging buffer would have been rewritten while a submission copying from it was still on the card. No exception, no device loss. The A/B against VICTORY_STAGING_GUARD=0 with picture captures is still pending.

Oracle and test data

None involved. Failure case: a_staging_buffer_is_left_alone_while_an_earlier_copy_from_it_may_be_on_the_card (a pure function of the three submission numbers: an earlier copy in the air, landed, none, and the submission's own copy).

Checklist

  • The PR covers a single reviewable behaviour (a staging buffer is not rewritten under an earlier copy from it).
  • A test fails without this change and passes with it.
  • The commands and results of each check are given above (the game run is pending, said above).
  • An unimplemented function returns an error (E_NOTIMPL), never a fake success. (Not concerned.)
  • README: not touched.
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: none beyond the frame-line counts of my own runs.
  • Code taken from another project: none.

AI assistance: written with Claude Code (Claude Opus 5.5): the reading of the base, the change, its test, the checks on my machine and this description.

🤖 Generated with Claude Code

**@⁠Skyfrye** on GitHub · 2026-11-25 21:57 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/254) `Skyfrye:nep/staging-refresh-guard` → `main` · +113 −13 · 2 files · 1 commits · draft **Draft: the in-game check on this base is pending** (the test machine's GPU is in use for a few hours). Everything below the game run is done. ## Change A list that samples a title texture whose staging buffer is newer than the host texture records a copy from that buffer, and the buffer is brought up to date while the list's submission is prepared (`Step::Texture` → `Staging::refresh`). A later submission that samples the same texture checks it again while it is prepared and, when the title changed the texture's memory, detiles the new bytes into **the same buffer** at once. With flights in the air (the relay), the earlier submission's copy can still be waiting on the card, and then reads bytes of two versions of the texture. The previous base waited for the card at such a point (`staging_in_flight` → a settle; on an RTX 5080 about 14 settles a frame, most of the ~97 ms the submitting thread stood waiting). The Neptune base no longer waits, and I found nothing else that keeps the buffer from being written (no fence, no double buffer; the pool only reuses a buffer after every list holding it was reset, which is a different case). This may be part of the known issue "objects and clothes can turn black for a moment while their textures are swapped" — not shown. Now: - each `Staging` notes the last submission whose lists copy from it (`copied_by`; `Step::Texture` carries whether the list recorded a copy, `Batch` carries the submission's number); - a check during the preparing of a later submission leaves the buffer alone while that submission has not landed (`copied_by > finished` and `< preparing`): **nothing waits**; the texture's notes (`Last`) are left untouched so the change is found again at a later check; copies are recorded only after a detiling (a list may still record one from a detiling that came before the guard held off, which is fine: it copies what the buffer holds), so `copied_by` stops moving, the earlier submission lands and a later check goes ahead. A texture the title rewrites at every submission is then brought up to date about once per flights-in-the-air plus one submissions instead of at every one; it is never starved (an independent review traced this). The texture shows a change that much later; - a submission's own copies run after everything it prepares, so its own check still writes the buffer, as before. `VICTORY_STAGING_GUARD=0` restores the previous behaviour. The frame line counts the checks put off ("texture refreshes put off per frame ..."). Linked issue: none. ## Verification Windows 11 26300, Rust 1.98.1 (MSVC), RTX 5080, on upstream `main` at `affaf15`, from `third_party/victory`: ``` cargo build --locked --release -p victory -> Finished, no new warning (the 3 of main) cargo build --locked --profile diag -p victory --features diagnostics -> Finished, no new warning cargo test --locked -p victory-gpu --lib guard_tests -> 1 passed (CPU only) cargo xtask policy -> asset policy: ok ``` With `copy_in_flight` made to return `false` and the test kept, the test fails. Pending: a game run (GTA VI 1.0.2.1, my own copy, launcher settings) with the frame line's new counter, against `main` and with `VICTORY_STAGING_GUARD=0`, and a picture comparison of the same frames. I will add the numbers here before marking the PR ready. First game run with the guard on (5 minutes, release build with this and the other open changes of mine, launcher settings, the world of the prologue): the frame line counted 1.3 to 3.7 texture refreshes per frame put off by the guard, that is, that often a staging buffer would have been rewritten while a submission copying from it was still on the card. No exception, no device loss. The A/B against `VICTORY_STAGING_GUARD=0` with picture captures is still pending. ## Oracle and test data None involved. Failure case: `a_staging_buffer_is_left_alone_while_an_earlier_copy_from_it_may_be_on_the_card` (a pure function of the three submission numbers: an earlier copy in the air, landed, none, and the submission's own copy). ## Checklist - [x] The PR covers a single reviewable behaviour (a staging buffer is not rewritten under an earlier copy from it). - [x] A test fails without this change and passes with it. - [x] The commands and results of each check are given above (the game run is pending, said above). - [x] An unimplemented function returns an error (`E_NOTIMPL`), never a fake success. (Not concerned.) - [x] README: not touched. - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: none beyond the frame-line counts of my own runs. - [x] Code taken from another project: none. AI assistance: written with Claude Code (Claude Opus 5.5): the reading of the base, the change, its test, the checks on my machine and this description. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A list that samples a texture whose staging buffer is newer than the host
texture records a copy from that buffer, and the buffer is brought up to
date while the list's submission is prepared. A later submission that
samples the texture checks it again while it is prepared and, when the
title changed the texture's memory, detiled the new bytes into the same
buffer at once. With flights in the air (the relay) the earlier
submission's copy could still be waiting on the card, and then read bytes
of two versions of the texture. The previous base waited for the card at
such a point (about 14 settles a frame on an RTX 5080); this base no
longer waits, and nothing else kept the buffer from being written.

Now each staging buffer notes the last submission whose lists copy from
it (Step::Texture carries whether the list recorded a copy). A check
during the preparing of a later submission leaves the buffer alone while
that submission has not landed: nothing waits, the texture's notes are
left as they were so the change is found again at a later check, and no
copy is recorded meanwhile (lists record one only after a detiling), so
the earlier submission lands and the next check goes ahead. The texture
shows the change that much later. A submission's own copies run after
everything it prepares, so its own check still writes the buffer.

VICTORY_STAGING_GUARD=0 restores the previous behaviour. The frame line
counts the checks put off.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:40:38 +00:00
Author
Owner

@⁠LooperSalty on GitHub · 2026-11-26 00:06 UTC · original

Thanks — the guard looks right. The only test covers the copy_in_flight helper; could you add one that exercises refresh() itself (a staging buffer still read by an in-flight copy is not rewritten), so the test fails without the change? Since it is on by default, a short in-game note (before/after on brief black textures) would also help. Then please mark it ready for review.

**@⁠LooperSalty** on GitHub · 2026-11-26 00:06 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/254#issuecomment-7178409514) Thanks — the guard looks right. The only test covers the `copy_in_flight` helper; could you add one that exercises `refresh()` itself (a staging buffer still read by an in-flight copy is not rewritten), so the test fails without the change? Since it is on by default, a short in-game note (before/after on brief black textures) would also help. Then please mark it ready for review.
Author
Owner

@⁠KainanP on GitHub · 2026-11-26 10:32 UTC · original

Test report for #254 on three adapters.

Merges cleanly onto current main. Setup: current origin/main (c4c93bd) merged with this PR, Windows 11, cargo test --locked in third_party/victory. Adapters: RTX 4060 Laptop (DXGI 0), Intel UHD 8086:a78b (16-lane waves, no FP64), WARP. The hardware adapter is picked by name through a local, uncommitted test hook and confirmed in its log; WARP for victory-gpu is --features diagnostics + VICTORY_D3D12_WARP=1. victory-gpu runs with --test-threads=1.

victory-gpu --lib main main + #254
RTX 4060 Laptop 183 passed, main's 3 failed 184 passed, main's 3 failed
Intel UHD 183 passed, main's 3 failed 184 passed, main's 3 failed
WARP 196 passed, main's 3 failed 197 passed, main's 3 failed

"main's 3" = descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed, indirect::tests::warp_card_fetch_copies_flagged_pieces_to_their_slots, indirect::tests::warp_card_patch_writes_the_masked_bytes_and_no_others. They fail on all three adapters on main too. The new guard_tests test passes everywhere. No new failure.

Notes from reading the diff:

  • copy_in_flight is only tested as a pure function. Nothing tests refresh + note_copy through run_deferred: that a guarded refresh leaves Last/dirty as they were, so the change is picked up after the landing. That path is where starvation or a lost update would show up. A WARP test with two submissions in the air would cover it.
  • Batch::default() still gives submission: 0. Any refresh outside Host::submit's preparing gets copy_in_flight(_, 0, _) == false, so it is never guarded. I think that is right, but a one-line comment at the Batch default would say so.

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this.

**@⁠KainanP** on GitHub · 2026-11-26 10:32 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/254#issuecomment-7189493970) Test report for #254 on three adapters. Merges cleanly onto current main. Setup: current `origin/main` (c4c93bd) merged with this PR, Windows 11, `cargo test --locked` in `third_party/victory`. Adapters: RTX 4060 Laptop (DXGI 0), Intel UHD 8086:a78b (16-lane waves, no FP64), WARP. The hardware adapter is picked by name through a local, uncommitted test hook and confirmed in its log; WARP for victory-gpu is `--features diagnostics` + `VICTORY_D3D12_WARP=1`. victory-gpu runs with `--test-threads=1`. | `victory-gpu --lib` | main | main + #254 | |---|---|---| | RTX 4060 Laptop | 183 passed, main's 3 failed | 184 passed, main's 3 failed | | Intel UHD | 183 passed, main's 3 failed | 184 passed, main's 3 failed | | WARP | 196 passed, main's 3 failed | 197 passed, main's 3 failed | "main's 3" = `descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed`, `indirect::tests::warp_card_fetch_copies_flagged_pieces_to_their_slots`, `indirect::tests::warp_card_patch_writes_the_masked_bytes_and_no_others`. They fail on all three adapters on main too. The new `guard_tests` test passes everywhere. No new failure. Notes from reading the diff: - `copy_in_flight` is only tested as a pure function. Nothing tests `refresh` + `note_copy` through `run_deferred`: that a guarded refresh leaves `Last`/`dirty` as they were, so the change is picked up after the landing. That path is where starvation or a lost update would show up. A WARP test with two submissions in the air would cover it. - `Batch::default()` still gives `submission: 0`. Any refresh outside `Host::submit`'s preparing gets `copy_in_flight(_, 0, _) == false`, so it is never guarded. I think that is right, but a one-line comment at the `Batch` default would say so. _AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this._
This pull request has changes conflicting with the target branch.
  • third_party/victory/crates/victory-gpu/src/host.rs
  • third_party/victory/crates/victory-gpu/src/texture.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/254/head:github-bot/gh-254'
git switch 'github-bot/gh-254'

Merge

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