GPU: VICTORY_SEND_CHANGED without the relay hashes again the pieces a fetch found unchanged #203

Closed
github-bot wants to merge 1 commit from github-bot/gh-203 into main AGit
Owner

@⁠simbaui4life on GitHub · 2026-11-27 19:40 UTC · original
fix/send-changed-rehash → main · +179 −4 · 2 files · 1 commits · closed without merging

One commit on top of main (29d8dbf). It changes behaviour only with VICTORY_SEND_CHANGED=1 and the relay off.

Cause

  • Copies in the card's memory are compared after each submission's lists. Each 64 KiB piece of a declared range is hashed and compared with the hash stored on the card. Only the pieces whose hash differs are fetched and merged into title memory.
  • Without the relay, that compare does not store the hash it makes (mode 1 of CARD_COMPARE). The stored hash is made again only by the pass that follows a send up (Host::card_before). Until something of the piece goes up, every compare that holds the piece flags it again.
  • A title buffer copy done at its place in a list (host/place.rs) changes its pieces on the card. Its bytes are already in the CPU's side (Shadow::placed_copy), so Shadow::card_merge finds nothing new and sends nothing.
    • Without the switch, the next refresh sends the copy's pages up whole, because Placed::prepare wrote them into title memory. Their hash is made with them.
    • With VICTORY_SEND_CHANGED=1, the refresh sends only the dwords that differ from the CPU's side. There are none, so nothing goes up and the hash is never made again.
  • The result: the pieces stay flagged for good. Every piece the copies ever reached is fetched after every submission. In the memory bench at 64 MB that is 64 MB a frame instead of 1.5 MB, and the copy-back takes 8.5 ms instead of 0.56 ms.
  • With the relay this does not happen: its compare stores the hash it makes (mode 2).

What this changes

  • Shadow::card_merge: when a fetched piece holds the same bytes on the card's side as on the CPU's side, and the switch is on, the piece is noted (Shadow::rehash_later, a list in shadow.rs).
    • Only a piece fetched whole: every byte the piece's hash covers must have been fetched and compared. A piece fetched in part keeps its old hash, because a byte that was not compared may be an undeclared shader write that a new hash would hide.
    • Only copies that have hashes on the card.
  • Host::card_before takes the noted pieces (crate::shadow::card_rehash) and hashes them in the same pass that hashes the pieces just sent up. Nothing of them is sent. Their copies are kept alive with the plan, as the sent ones are. card_before runs at every submission, so the list does not grow.
  • With the switch off, card_rehash returns at once and nothing is noted. The relay's merge (card_merge_relay) is not touched.

Numbers (RTX 4070 Ti, driver 621.01, Windows 11 26200, release build, 3 runs each, each run its own process; mean, per frame)

They come from a bench test (memory_bench_cpu_split, on a separate test branch on top of the memory bench #111, not part of this PR), with this commit cherry-picked on top. Default shape: 120 frames after 30 of warm-up, 1 MB of title writes a frame. "Relay on" is VICTORY_RELAY=2 VICTORY_RELAY_COPY=1.

title memory, switch, relay fetched MB before after copy-back ms before after sent up MB before after
64 MB, SEND_CHANGED=1, off 64.0 1.5 8.48 0.56 1.0 1.0
256 MB, SEND_CHANGED=1, off 218.1 1.5 30.75 0.54 1.0 1.0
64 MB, switch off, off 1.5 1.5 0.58 0.57 2.5 2.5
256 MB, switch off, off 1.5 1.5 0.56 0.55 2.5 2.5
64 MB, SEND_CHANGED=1, on 1.5 1.5 0.70 0.66 1.0 1.0
256 MB, SEND_CHANGED=1, on 1.5 1.5 0.73 0.73 1.0 1.0
64 MB, switch off, on 1.5 1.5 0.70 0.65 1.0 1.0
256 MB, switch off, on 1.5 1.5 0.72 0.70 1.0 1.0
  • With the switch and no relay, the fetch and the copy-back return to the level without the switch. The card's hash passes go from 0 to 2 a frame (24 pieces), as without the switch.
  • What goes up stays at 1.0 MB a frame, against 2.5 MB without the switch.
  • With the switch off, or with the relay, the code path is the same as before (one check of the switch). The numbers differ only by what varies between runs and builds: the copy-back with the relay reads 0.65–0.73 ms in both builds.
  • A second, independent re-run (2 runs each, relay off) gave the same: with the switch 1.5 MB fetched and 0.59–0.67 ms copy-back at 64 and 256 MB.

Tests

  • New unit test shadow::rehash_tests::a_piece_fetched_unchanged_is_hashed_again. It runs without a GPU, on a copy with no host buffer behind it (Shadow::unbacked). It checks:
    • which pieces are noted: whole pieces only, not a part of a piece, not the last piece whose hash covers bytes past the copy, nothing without hashes on the card;
    • that noted pieces are joined per copy and taken once;
    • that a merge with no difference sends nothing and notes the piece only with the switch;
    • that a merge with a shader write still goes into title memory and the CPU's side and is sent up as before.
  • cargo test -p victory-gpu: 419 passed, 2 failed, 35 ignored (main: 418 passed, 2 failed, 35 ignored; the one more is the new test). The 2 failures are already on main (indirect::tests::host_list_budget_starts_empty_at_each_submission, indirect::tests::warp_batch_charges_every_execution).
  • The new test and the related ones (refresh_tests::only_what_differs_goes_up, landing_tests, card_tests) also pass with VICTORY_SEND_CHANGED=1.
  • memory_bench_steady_state (debug build, the bench branch with this commit cherry-picked) passes with the relay off and on, each with and without VICTORY_SEND_CHANGED=1.
  • Clippy adds no finding (compared by message and file with main). rustfmt: no new differences in the touched lines.

Not tested

  • In the game (no game data here). The run that turned the switch off (tile1-0: indirect light lost, geometry exploding) is not explained by this fix. This fix only stops the endless re-fetch; it does not make the switch safe to turn on.
  • Pieces that a shader rewrote with the same bytes are handled by the same path, but the bench's frames do not produce them.
  • Copies that take only changed dwords without the switch (keep_stores, by_address) have the same compare and may show the same re-fetch. They are left out on purpose, so that nothing changes with the switch off.
  • AMD and other GPUs.

No game data in the commit.

🤖 Generated with Claude Code

**@⁠simbaui4life** on GitHub · 2026-11-27 19:40 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/203) `fix/send-changed-rehash` → `main` · +179 −4 · 2 files · 1 commits · closed without merging One commit on top of `main` (29d8dbf). It changes behaviour only with `VICTORY_SEND_CHANGED=1` and the relay off. **Cause** - Copies in the card's memory are compared after each submission's lists. Each 64 KiB piece of a declared range is hashed and compared with the hash stored on the card. Only the pieces whose hash differs are fetched and merged into title memory. - Without the relay, that compare does not store the hash it makes (mode 1 of `CARD_COMPARE`). The stored hash is made again only by the pass that follows a send up (`Host::card_before`). Until something of the piece goes up, every compare that holds the piece flags it again. - A title buffer copy done at its place in a list (`host/place.rs`) changes its pieces on the card. Its bytes are already in the CPU's side (`Shadow::placed_copy`), so `Shadow::card_merge` finds nothing new and sends nothing. - Without the switch, the next refresh sends the copy's pages up whole, because `Placed::prepare` wrote them into title memory. Their hash is made with them. - With `VICTORY_SEND_CHANGED=1`, the refresh sends only the dwords that differ from the CPU's side. There are none, so nothing goes up and the hash is never made again. - The result: the pieces stay flagged for good. Every piece the copies ever reached is fetched after every submission. In the memory bench at 64 MB that is 64 MB a frame instead of 1.5 MB, and the copy-back takes 8.5 ms instead of 0.56 ms. - With the relay this does not happen: its compare stores the hash it makes (mode 2). **What this changes** - `Shadow::card_merge`: when a fetched piece holds the same bytes on the card's side as on the CPU's side, and the switch is on, the piece is noted (`Shadow::rehash_later`, a list in `shadow.rs`). - Only a piece fetched whole: every byte the piece's hash covers must have been fetched and compared. A piece fetched in part keeps its old hash, because a byte that was not compared may be an undeclared shader write that a new hash would hide. - Only copies that have hashes on the card. - `Host::card_before` takes the noted pieces (`crate::shadow::card_rehash`) and hashes them in the same pass that hashes the pieces just sent up. Nothing of them is sent. Their copies are kept alive with the plan, as the sent ones are. `card_before` runs at every submission, so the list does not grow. - With the switch off, `card_rehash` returns at once and nothing is noted. The relay's merge (`card_merge_relay`) is not touched. **Numbers** (RTX 4070 Ti, driver 621.01, Windows 11 26200, release build, 3 runs each, each run its own process; mean, per frame) They come from a bench test (`memory_bench_cpu_split`, on a separate test branch on top of the memory bench #111, not part of this PR), with this commit cherry-picked on top. Default shape: 120 frames after 30 of warm-up, 1 MB of title writes a frame. "Relay on" is `VICTORY_RELAY=2 VICTORY_RELAY_COPY=1`. | title memory, switch, relay | fetched MB before | after | copy-back ms before | after | sent up MB before | after | |---|---|---|---|---|---|---| | 64 MB, `SEND_CHANGED=1`, off | 64.0 | **1.5** | 8.48 | **0.56** | 1.0 | 1.0 | | 256 MB, `SEND_CHANGED=1`, off | 218.1 | **1.5** | 30.75 | **0.54** | 1.0 | 1.0 | | 64 MB, switch off, off | 1.5 | 1.5 | 0.58 | 0.57 | 2.5 | 2.5 | | 256 MB, switch off, off | 1.5 | 1.5 | 0.56 | 0.55 | 2.5 | 2.5 | | 64 MB, `SEND_CHANGED=1`, on | 1.5 | 1.5 | 0.70 | 0.66 | 1.0 | 1.0 | | 256 MB, `SEND_CHANGED=1`, on | 1.5 | 1.5 | 0.73 | 0.73 | 1.0 | 1.0 | | 64 MB, switch off, on | 1.5 | 1.5 | 0.70 | 0.65 | 1.0 | 1.0 | | 256 MB, switch off, on | 1.5 | 1.5 | 0.72 | 0.70 | 1.0 | 1.0 | - With the switch and no relay, the fetch and the copy-back return to the level without the switch. The card's hash passes go from 0 to 2 a frame (24 pieces), as without the switch. - What goes up stays at 1.0 MB a frame, against 2.5 MB without the switch. - With the switch off, or with the relay, the code path is the same as before (one check of the switch). The numbers differ only by what varies between runs and builds: the copy-back with the relay reads 0.65–0.73 ms in both builds. - A second, independent re-run (2 runs each, relay off) gave the same: with the switch 1.5 MB fetched and 0.59–0.67 ms copy-back at 64 and 256 MB. **Tests** - New unit test `shadow::rehash_tests::a_piece_fetched_unchanged_is_hashed_again`. It runs without a GPU, on a copy with no host buffer behind it (`Shadow::unbacked`). It checks: - which pieces are noted: whole pieces only, not a part of a piece, not the last piece whose hash covers bytes past the copy, nothing without hashes on the card; - that noted pieces are joined per copy and taken once; - that a merge with no difference sends nothing and notes the piece only with the switch; - that a merge with a shader write still goes into title memory and the CPU's side and is sent up as before. - `cargo test -p victory-gpu`: 419 passed, 2 failed, 35 ignored (`main`: 418 passed, 2 failed, 35 ignored; the one more is the new test). The 2 failures are already on `main` (`indirect::tests::host_list_budget_starts_empty_at_each_submission`, `indirect::tests::warp_batch_charges_every_execution`). - The new test and the related ones (`refresh_tests::only_what_differs_goes_up`, `landing_tests`, `card_tests`) also pass with `VICTORY_SEND_CHANGED=1`. - `memory_bench_steady_state` (debug build, the bench branch with this commit cherry-picked) passes with the relay off and on, each with and without `VICTORY_SEND_CHANGED=1`. - Clippy adds no finding (compared by message and file with `main`). rustfmt: no new differences in the touched lines. **Not tested** - In the game (no game data here). The run that turned the switch off (tile1-0: indirect light lost, geometry exploding) is not explained by this fix. This fix only stops the endless re-fetch; it does not make the switch safe to turn on. - Pieces that a shader rewrote with the same bytes are handled by the same path, but the bench's frames do not produce them. - Copies that take only changed dwords without the switch (`keep_stores`, `by_address`) have the same compare and may show the same re-fetch. They are left out on purpose, so that nothing changes with the switch off. - AMD and other GPUs. No game data in the commit. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Without the relay the compare after the lists leaves the card's hashes as
they are (mode 1): a piece's hash is made again only when something of it
goes up, and until then every compare that holds the piece flags it and has
it fetched. A copy at its place in a list changes its pieces on the card,
but its bytes are in the CPU's side already (Shadow::placed_copy), so the
merge finds nothing new and sends nothing. Without the switch the refresh
then sends the copy's pages up whole (Placed::prepare wrote them into title
memory), and their hash is made with them. With VICTORY_SEND_CHANGED=1 the
refresh sends only dwords that differ from the CPU's side, and there are
none: the pieces stayed flagged for good, and every piece the copies ever
reached was fetched after every submission.

Now card_merge notes such a piece (fetched whole, no byte different from
the CPU's side) and card_before hashes it again in the pass that follows
the sends, with nothing sent. Only with the switch, and only on the path
without the relay (the relay's compare stores its hashes). A piece fetched
in part keeps its old hash: a byte not compared may be an undeclared shader
write that a new hash would hide.

Memory bench CPU split (memory_bench_cpu_split, a test of its own branch,
not in this commit), RTX 4070 Ti, release, 3 runs each, relay off:
- 64 MB, switch on: fetched 64 -> 1.5 MB a frame, copy-back 8.5 -> 0.56 ms
- 256 MB, switch on: fetched 218 -> 1.5 MB, copy-back 30.7 -> 0.54 ms
- sent up 1.0 MB a frame with the switch, 2.5 MB without (as before)
- switch off, or relay on: unchanged (fetched 1.5 MB, copy-back 0.55-0.73 ms)

A unit test covers which pieces are noted and that a merge with a
difference still goes up as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 19:41:09 +00:00
github-bot closed this pull request 2026-11-27 21:47:10 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.