GPU: keep old title bytes out of buffer ranges a compute pass is still writing (VICTORY_MERGE_AFTER_LANDING, #90) #357

Closed
cafeoh wants to merge 672 commits from upstream-pr/357 into main
cafeoh commented 2026-11-27 19:39:30 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by cafeoh on 2026-11-27T19:39:30Z.


What it fixes

The stretched-triangle spikes ("wedges") of #90. On by default: VICTORY_MERGE_AFTER_LANDING=3 when unset; =0 gives the merge as it was.

The cause

Some buffers are written both by the title (CPU) and by the card (compute passes, for example the skinning output the vertices are drawn from). When the title wrote a page of such a buffer while a compute pass writing the same range had not landed yet, our merge (merge_under_writes / stale_under_writes) put the title's bytes into that range. They were older than the card's results, and at the landing a byte both had written was taken from the title. That frame drew from old skinned vertices: a wedge.

It was never the descriptor heaps. Pacing (the first version of this PR) only hid it: the card had always landed before we merged. The same goes for VICTORY_LATE_WAIT=2 and VICTORY_THIN=0 in #90: both make the overlap rarer by timing, not impossible.

What it does

VICTORY_MERGE_AFTER_LANDING What goes into memory a flight not landed writes
0 as before: the title's bytes, merged now
1 nothing until the landing. Simple, but a title write there reaches the card a submission or more late: short screen flashes.
2 only the bytes the title really changed (compared with the copy's reference), at once; bytes the card writes wait for the landing.
3 (default) =2, and also refreshes of a copy outside the ranges the flights declared (shaders that store where they didn't say): again only the title's changed bytes.

No CPU wait anywhere. The frame line counts what was merged, skipped and left for the landing. VICTORY_WEDGE_TRACE=1 (diagnostics builds) logs the paths that can still put old bytes in front of the card.

Numbers (RTX 2080 Ti, Ryzen 7 7800X3D, Win10, Series S, café -> cell, 40 s window)

Off =1 =2 =3
fps café -> cell / cell 19.17 / 20.07 19.14 / 20.30 18.66 / 19.77 19.64 / 19.41
p99 frame time 124 ms 123 ms 100 ms 117 ms
frames over 2x median 16 (1324 ms) 19 (1476 ms) 11 (736 ms) 15 (1019 ms)
Wedges, by eye most frames among the inmates 2-3 in a long watch, plus flashes a dozen or two in a long free run none seen in three free runs to the inmates

=3 covers every path we found that could put old bytes under a card write, and we saw no wedges with it in three free runs (our tree, this branch with the switch set, and unset). That's one PC, though, so confirmations from other setups are welcome. Measured on our tree with the same changes; this branch is the port.

A trap we hit on the way (kept out of =3): holding the title's changes back from card-written dwords in the gaps for longer than one landing made the title crash (6 of 11 runs, 0 of 9 without it). The card kept old pointers and wrote through them into memory the title had freed. =3 puts the title's changes in at once there.

Why on by default

It costs nothing measurable (table above) and never waits for the card, so there's little reason to leave the bug on. If something looks wrong with it, VICTORY_MERGE_AFTER_LANDING=0 brings the old merge back. If you see wedges, we'd be thankful if you could try this branch (no switch needed) and say whether they're gone (card, console profile, a rough count). VICTORY_HEAP_SYNC_PACE=1 stays opt-in; it's no longer needed for the wedges.

Tests

This branch, built and run (RTX 2080 Ti, Series S): with =2 to the cell and 5 min there, no crash; with =3 (set, then unset as the default) free runs to the cell, no wedges seen, no crash. cargo test -p victory-gpu shadow::: new tests for the range subtraction, deferred parts, the byte choice, the undeclared-store put, the dword map and the dword widening.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:issue:5532173744 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/357). Originally posted by [cafeoh](https://github.com/cafeoh) on 2026-11-27T19:39:30Z. --- **What it fixes** The stretched-triangle spikes ("wedges") of #90. On by default: `VICTORY_MERGE_AFTER_LANDING=3` when unset; `=0` gives the merge as it was. **The cause** Some buffers are written both by the title (CPU) and by the card (compute passes, for example the skinning output the vertices are drawn from). When the title wrote a page of such a buffer while a compute pass writing the same range had not landed yet, our merge (`merge_under_writes` / `stale_under_writes`) put the title's bytes into that range. They were older than the card's results, and at the landing a byte both had written was taken from the title. That frame drew from old skinned vertices: a wedge. It was never the descriptor heaps. Pacing (the first version of this PR) only hid it: the card had always landed before we merged. The same goes for `VICTORY_LATE_WAIT=2` and `VICTORY_THIN=0` in #90: both make the overlap rarer by timing, not impossible. **What it does** | `VICTORY_MERGE_AFTER_LANDING` | What goes into memory a flight not landed writes | |---|---| | 0 | as before: the title's bytes, merged now | | 1 | nothing until the landing. Simple, but a title write there reaches the card a submission or more late: short screen flashes. | | 2 | only the bytes the title really changed (compared with the copy's reference), at once; bytes the card writes wait for the landing. | | 3 (default) | `=2`, and also refreshes of a copy outside the ranges the flights declared (shaders that store where they didn't say): again only the title's changed bytes. | No CPU wait anywhere. The frame line counts what was merged, skipped and left for the landing. `VICTORY_WEDGE_TRACE=1` (diagnostics builds) logs the paths that can still put old bytes in front of the card. **Numbers** (RTX 2080 Ti, Ryzen 7 7800X3D, Win10, Series S, café -> cell, 40 s window) | | Off | `=1` | `=2` | `=3` | |---|---|---|---|---| | fps café -> cell / cell | 19.17 / 20.07 | 19.14 / 20.30 | 18.66 / 19.77 | 19.64 / 19.41 | | p99 frame time | 124 ms | 123 ms | 100 ms | 117 ms | | frames over 2x median | 16 (1324 ms) | 19 (1476 ms) | 11 (736 ms) | 15 (1019 ms) | | Wedges, by eye | most frames among the inmates | 2-3 in a long watch, plus flashes | a dozen or two in a long free run | none seen in three free runs to the inmates | `=3` covers every path we found that could put old bytes under a card write, and we saw no wedges with it in three free runs (our tree, this branch with the switch set, and unset). That's one PC, though, so confirmations from other setups are welcome. Measured on our tree with the same changes; this branch is the port. **A trap we hit on the way** (kept out of `=3`): holding the title's changes back from card-written dwords in the gaps for longer than one landing made the title crash (6 of 11 runs, 0 of 9 without it). The card kept old pointers and wrote through them into memory the title had freed. `=3` puts the title's changes in at once there. **Why on by default** It costs nothing measurable (table above) and never waits for the card, so there's little reason to leave the bug on. If something looks wrong with it, `VICTORY_MERGE_AFTER_LANDING=0` brings the old merge back. If you see wedges, we'd be thankful if you could try this branch (no switch needed) and say whether they're gone (card, console profile, a rough count). `VICTORY_HEAP_SYNC_PACE=1` stays opt-in; it's no longer needed for the wedges. **Tests** This branch, built and run (RTX 2080 Ti, Series S): with `=2` to the cell and 5 min there, no crash; with `=3` (set, then unset as the default) free runs to the cell, no wedges seen, no crash. `cargo test -p victory-gpu shadow::`: new tests for the range subtraction, deferred parts, the byte choice, the undeclared-store put, the dword map and the dword widening.
hamdanpor-ctrl commented 2026-11-27 22:42:00 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by hamdanpor-ctrl on 2026-11-27T22:42:00Z.


Build and test check on a laptop, no game run (default settings, so the opt-in pacing itself is not exercised):

  • PC: RTX 3050 Laptop GPU 4 GB (driver 617.42), i7-12700H, 16 GB, Windows 11 Pro; Rust 1.98.1
  • This PR's own diff (6d20a25 against its merge base) applied on main at 0148258
  • Clippy with and without --all-features: clean
  • cargo test -p victory-gpu --locked, parallel: 9 of 10 runs passed (527 tests each). The one failure was host::refresh_tests::raw_title_copy_keeps_write_watch_and_resends_equal_bytes, which also fails now and then on main (#354, addressed in #382), so not from this change.

AI-assisted (Claude Code).

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7229544428 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/357#issuecomment-7229544428). Originally posted by [hamdanpor-ctrl](https://github.com/hamdanpor-ctrl) on 2026-11-27T22:42:00Z. --- Build and test check on a laptop, no game run (default settings, so the opt-in pacing itself is not exercised): - PC: RTX 3050 Laptop GPU 4 GB (driver 617.42), i7-12700H, 16 GB, Windows 11 Pro; Rust 1.98.1 - This PR's own diff (`6d20a25` against its merge base) applied on `main` at `0148258` - Clippy with and without `--all-features`: clean - `cargo test -p victory-gpu --locked`, parallel: 9 of 10 runs passed (527 tests each). The one failure was `host::refresh_tests::raw_title_copy_keeps_write_watch_and_resends_equal_bytes`, which also fails now and then on `main` (#354, addressed in #382), so not from this change. AI-assisted (Claude Code).
cafeoh commented 2026-11-28 12:23:32 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by cafeoh on 2026-11-28T12:23:32Z.


Correction to this PR: further testing with ray tracing on (and longer free play) shows VICTORY_MERGE_AFTER_LANDING=3 does not fix the wedges or the black flashing skin; earlier clean runs were luck in timing. On our RTX 2080 Ti, VICTORY_LATE_WAIT=2 removes both (2 of 2 RT runs, plus earlier raster runs), matching @CristianCiubancan's 0/106 in #90. The cause looks like the title writing the next frame's per-frame data while the current frame is still being prepared.

We're converting this PR to a draft. We're still hunting the exact cause, and a cheaper fix than LATE_WAIT=2 (about 14% slower here).

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7239195249 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/357#issuecomment-7239195249). Originally posted by [cafeoh](https://github.com/cafeoh) on 2026-11-28T12:23:32Z. --- Correction to this PR: further testing with ray tracing on (and longer free play) shows `VICTORY_MERGE_AFTER_LANDING=3` does not fix the wedges or the black flashing skin; earlier clean runs were luck in timing. On our RTX 2080 Ti, `VICTORY_LATE_WAIT=2` removes both (2 of 2 RT runs, plus earlier raster runs), matching @CristianCiubancan's 0/106 in #90. The cause looks like the title writing the next frame's per-frame data while the current frame is still being prepared. We're converting this PR to a draft. We're still hunting the exact cause, and a cheaper fix than `LATE_WAIT=2` (about 14% slower here).
TaynanGT commented 2026-11-29 11:37:52 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-29T11:37:52Z.


Thanks for correcting the earlier conclusion and converting this back to a draft. LATE_WAIT=2 is a useful diagnostic control, but its reported cost and the remaining unknown overlap mean we shouldn't treat it as the final fix. Please keep the wedge count, black-skin artifact and frame-time measurements separate.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7255242870 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/357#issuecomment-7255242870). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-29T11:37:52Z. --- Thanks for correcting the earlier conclusion and converting this back to a draft. LATE_WAIT=2 is a useful diagnostic control, but its reported cost and the remaining unknown overlap mean we shouldn't treat it as the final fix. Please keep the wedge count, black-skin artifact and frame-time measurements separate.
TaynanGT commented 2026-11-30 17:11:21 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-30T17:11:21Z.


main has moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the current main and open a new PR; I'll review it there.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7285858694 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/357#issuecomment-7285858694). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-30T17:11:21Z. --- `main` has moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the current `main` and open a new PR; I'll review it there.

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
TaynanGT/Vice-Tay!357
No description provided.