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

Closed
Skyfrye wants to merge 1 commit from upstream-pr/254 into main
Skyfrye commented 2026-11-25 21:57:37 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by Skyfrye on 2026-11-25T21:57:37Z.


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

<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:5499868497 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/254). Originally posted by [Skyfrye](https://github.com/Skyfrye) on 2026-11-25T21:57:37Z. --- **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)
LooperSalty commented 2026-11-26 00:06:52 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-26T00:06:52Z.


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.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7178409514 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/254#issuecomment-7178409514). Originally posted by [LooperSalty](https://github.com/LooperSalty) on 2026-11-26T00:06:52Z. --- 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.
KainanP commented 2026-11-26 10:32:06 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by KainanP on 2026-11-26T10:32:06Z.


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.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7189493970 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/254#issuecomment-7189493970). Originally posted by [KainanP](https://github.com/KainanP) on 2026-11-26T10:32:06Z. --- 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._
LooperSalty commented 2026-11-27 13:02:40 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-27T13:02:40Z.


Closing: this draft conflicts with main and has had no activity from its author for more than 24 hours. Please reopen after a rebase on main if it is still wanted.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7218987734 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/254#issuecomment-7218987734). Originally posted by [LooperSalty](https://github.com/LooperSalty) on 2026-11-27T13:02:40Z. --- Closing: this draft conflicts with main and has had no activity from its author for more than 24 hours. Please reopen after a rebase on main if it is still wanted.

Pull request closed

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
LooperSalty/AnyXboxX!254
No description provided.