GPU: copy-backs compare a block at a time (stacked on #2242) #2280

Open
github-bot wants to merge 2 commits from github-bot/gh-2280 into main AGit
Owner

@⁠wbkepler on GitHub · 2026-11-25 09:32 UTC · original
wbkepler:gpu/copy-back-block-compare → main · +274 −60 · 1 files · 2 commits · open

Stacked on #2242 (based on gpu/copy-back-gpu-bytes-only; the first commit here is #2242's). Only the last commit is new: differing in shadow.rs, the function #2242 added.

Why

In a world frame, the CPU time on the submitting thread goes to preparing (~210 ms) and copying back (~120–150 ms), and the GPU waits for both. I added throwaway timers (diagnostics build, one live run) to break down the copy-back. Almost all of it is the copy-back of pages that shaders mark as written through views, about 2,250 pages per frame:

copy-back of marked pages, ms/frame before
read title page (alloc + kernel read) 12.4
find changed bytes (differing) + take title's others 70
write runs (open guard, kernel writes, ~15k spans) 28
re-guard (taken) / re-read 8.6 / 4.1
total 131

differing compared 8 bytes per step through a slice comparison, which is a call each time: 8,192 calls per 64 KiB page, about 30 µs per page.

The change

Equal 1 KiB blocks are skipped whole. Inside a block that differs, equal 32-byte lines are skipped, and only lines that differ are walked byte by byte. The runs it returns are the same as before. A new test checks it against a byte-by-byte oracle, with runs across line and block edges, a last byte, partial blocks, and a gpu(i) filter.

Measured (Windows 11, NVIDIA RTX 5090, world, steady state, diagnostics build with the timers)

ms/frame before after
differing + take others 67–79 (avg ~71) 56–60 (avg ~58)
copy-back of marked pages 127–152 (avg ~134) 115–122 (avg ~117)
fps 1.2–1.3 1.3–1.4

On its own, differing now costs next to nothing. I measured that offline on a real host copy mapping with 2,048 pages and about 12 changed words per page. What is left in that step is memory traffic: reading the 64 KiB title page and the 64 KiB host copy, each about 8 µs per page on this host and slower in the world. Going further would need finer marks than 64 KiB pages, and that is out of scope here.

Tested

  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo clippy -p victory --features diagnostics --all-targets -- -D warnings: clean.
  • cargo xtask policy: clean.
  • cargo test -p victory-gpu: 143 passed and 2 failed. The same 2 fail on the unmodified base on this host: dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views. Both hit the 1M view-heap cap on NVIDIA.
  • One live world run with the change on top of an integration build, as above. No device removal.

🤖 Generated with Claude Code

**@⁠wbkepler** on GitHub · 2026-11-25 09:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/2280) `wbkepler:gpu/copy-back-block-compare` → `main` · +274 −60 · 1 files · 2 commits · open **Stacked on #2242** (based on `gpu/copy-back-gpu-bytes-only`; the first commit here is #2242's). Only the last commit is new: `differing` in `shadow.rs`, the function #2242 added. ## Why In a world frame, the CPU time on the submitting thread goes to preparing (~210 ms) and copying back (~120–150 ms), and the GPU waits for both. I added throwaway timers (diagnostics build, one live run) to break down the copy-back. Almost all of it is the copy-back of pages that shaders mark as written through views, about 2,250 pages per frame: | copy-back of marked pages, ms/frame | before | |---|---| | read title page (alloc + kernel read) | 12.4 | | **find changed bytes (`differing`) + take title's others** | **70** | | write runs (open guard, kernel writes, ~15k spans) | 28 | | re-guard (`taken`) / re-read | 8.6 / 4.1 | | total | 131 | `differing` compared 8 bytes per step through a slice comparison, which is a call each time: 8,192 calls per 64 KiB page, about 30 µs per page. ## The change Equal 1 KiB blocks are skipped whole. Inside a block that differs, equal 32-byte lines are skipped, and only lines that differ are walked byte by byte. The runs it returns are the same as before. A new test checks it against a byte-by-byte oracle, with runs across line and block edges, a last byte, partial blocks, and a `gpu(i)` filter. ## Measured (Windows 11, NVIDIA RTX 5090, world, steady state, diagnostics build with the timers) | ms/frame | before | after | |---|---|---| | `differing` + take others | 67–79 (avg ~71) | 56–60 (avg ~58) | | copy-back of marked pages | 127–152 (avg ~134) | 115–122 (avg ~117) | | fps | 1.2–1.3 | 1.3–1.4 | On its own, `differing` now costs next to nothing. I measured that offline on a real host copy mapping with 2,048 pages and about 12 changed words per page. What is left in that step is memory traffic: reading the 64 KiB title page and the 64 KiB host copy, each about 8 µs per page on this host and slower in the world. Going further would need finer marks than 64 KiB pages, and that is out of scope here. ## Tested - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo clippy -p victory --features diagnostics --all-targets -- -D warnings`: clean. - `cargo xtask policy`: clean. - `cargo test -p victory-gpu`: 143 passed and 2 failed. The same 2 fail on the unmodified base on this host: `dynamic_slots_are_held_until_released` and `lists_share_a_table_and_copies_keep_their_views`. Both hit the 1M view-heap cap on NVIDIA. - One live world run with the change on top of an integration build, as above. No device removal. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
After a submission, a page shaders wrote goes back into title memory.
For marked pages (views) and pages written at computed addresses that
was the whole page: read title memory, compare, then write the copy's
64 KiB over it. The title's threads write the same pages meanwhile (its
GPU heap holds CPU records next to what shaders write), and a write that
landed after the read was undone by the copy's older bytes. The page was
then taken with those bytes, so the copy kept them for good, and a later
copy-back of the page put them back over the title's again.

Now only the runs of bytes the shaders changed are written (runs less
than 256 bytes apart as one span, with the title's bytes between them
as read: a kernel copy per run cost over 1 ms per page). The page is
armed while it is read, so a title write that lands during the read
saves the bytes from before it and the shaders' bytes are told apart
from the title's. After the copy-back the page is taken first and the
copy reads it again, so a title write before the guard is back is in
the copy and one after it faults. The snapshot path writes only the
bytes the GPU changed as well.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Finding the bytes the GPU changed in a copy-back compared 8 bytes per
step, a call each: ~30 us per 64 KiB page, the largest part of the
copy-back of the pages shaders mark (~2,250 per world frame). Equal
blocks of 1 KiB are skipped whole, then 32-byte lines inside a block that
differs, bytes only in a line that differs; the runs found are the same.

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

@⁠DesertGamer on GitHub · 2026-11-25 09:37 UTC · original

VIctory V2: community PRs, merged and tested

Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch.

Where it stands today: launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1).

⚠️ Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk.

Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help:
https://DesertGamer/VIctory-V2

Unofficial community fork of Marvisak/VIctory, GPL-3.0.

**@⁠DesertGamer** on GitHub · 2026-11-25 09:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/2280#issuecomment-7158579644) ### VIctory V2: community PRs, merged and tested Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch. **Where it stands today:** launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1). :warning: Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk. Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help: https://DesertGamer/VIctory-V2 *Unofficial community fork of Marvisak/VIctory, GPL-3.0.*
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-25 09:44 UTC · original

Verified the stack on Windows 10 19045 with an RX 7800 XT (RDNA3), head 7ef96fa (both commits, so the block comparison runs on top of #2242's byte-only copy-back):

  • cargo test -p victory-gpu --features diagnostics --lib -- shadow:: — 6 passed, 0 failed.
  • Whole diagnostics suite — 147 passed, 1 failed, 2 ignored; the failure is the known draw::tests::a_texture_written_in_one_format_reads_in_another_through_a_placed_view on a Windows 10 runtime without ID3D12Device10 (#1999/#2251), identical on unmodified main here.

No number for the copy-back time itself: I did not run the game with your timers, so the ms/frame table stays yours. If you want a second machine's breakdown, say which timers to keep and I will run one world frame on this GPU.

**@⁠Calvix2k** on GitHub · 2026-11-25 09:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/2280#issuecomment-7158735932) Verified the stack on Windows 10 19045 with an **RX 7800 XT (RDNA3)**, head `7ef96fa` (both commits, so the block comparison runs on top of #2242's byte-only copy-back): - `cargo test -p victory-gpu --features diagnostics --lib -- shadow::` — **6 passed, 0 failed**. - Whole diagnostics suite — **147 passed, 1 failed, 2 ignored**; the failure is the known `draw::tests::a_texture_written_in_one_format_reads_in_another_through_a_placed_view` on a Windows 10 runtime without `ID3D12Device10` (#1999/#2251), identical on unmodified `main` here. No number for the copy-back time itself: I did not run the game with your timers, so the ms/frame table stays yours. If you want a second machine's breakdown, say which timers to keep and I will run one world frame on this GPU.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 13:32 UTC · original · edited 2026-11-25 15:54 UTC

Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-gpu/src/shadow.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (needs-work) was for an older state of main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 13:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/2280#issuecomment-7163933141) · edited 2026-11-25 15:54 UTC <!-- victory-triage v1 head=7ef96fa98681ec4ab4f4f8377fda50c4a8df5eab verdict=needs-rebase at=2026-11-25T15:54:40Z --> Automated triage for the maintainers. This pull request no longer merges cleanly into `main` (conflicts in `crates/victory-gpu/src/shadow.rs`). It will be reviewed once it is rebased onto the current `main`. The earlier verdict (needs-work) was for an older state of `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-25 13:58 UTC · original

The triage is right and the plan is what I intended: this is stacked on #2242 on purpose (the first commit is #2242's rewrite), so it cannot land before it. Once #2242 is merged I will rebase this onto main and push again, which leaves the diff with only the differing block/line skip and its oracle test — then it is a candidate on its own.

On the SPAN_GAP point the triage raises about the base: agreed, and it belongs on #2242 rather than here, since the gap merge is that PR's. A title write landing in a merged gap after the read is undone by the write-back, which is narrower than the race the rewrite removes but not zero; saying so in write_runs' doc comment (or dropping the gap) is the honest fix. I will not touch it here to keep this PR a single change.

**@⁠Calvix2k** on GitHub · 2026-11-25 13:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/2280#issuecomment-7164553836) The triage is right and the plan is what I intended: this is stacked on #2242 on purpose (the first commit is #2242's rewrite), so it cannot land before it. Once #2242 is merged I will rebase this onto `main` and push again, which leaves the diff with only the `differing` block/line skip and its oracle test — then it is a candidate on its own. On the `SPAN_GAP` point the triage raises about the base: agreed, and it belongs on #2242 rather than here, since the gap merge is that PR's. A title write landing in a merged gap after the read is undone by the write-back, which is narrower than the race the rewrite removes but not zero; saying so in `write_runs`' doc comment (or dropping the gap) is the honest fix. I will not touch it here to keep this PR a single change.
Author
Owner

@⁠r4tedx on GitHub · 2026-11-25 14:30 UTC · original

Measurements for this PR, from our play build on main 940d32f. The in-game part uses an RTX 5070 and local title data; only copy-back sizes and timings are reported. These correct my comment on #2242, which blamed the wrong PR.

In game, per MB written back by marked-page copy-backs (6 min per build, same tree and shader cache, one run per build):

Build Per MB
#2242 alone 0.79 ms/MB (75.6 MB/frame in 59.7 ms)
#2242 + this PR 2.22 ms/MB
#2242 + this PR + a commit of ours that tests a differing line 8 bytes at a time 2.13 ms/MB (68.1 MB/frame in 144.8 ms)

Synthetic (WARP, release build, 1,216 marked 64 KiB pages per GPU-write pattern, µs per page, mean of 2 rounds; the title was not used in these tests):

GPU-write pattern #2242 (09595753) this PR (7ef96fa9)
page rewritten whole 124.6 98.4
one word changed every 64 B 55.9 82.7
one word every 512 B (128 runs) 99.0 118.1
one word every 4 KiB (16 runs) 41.9 53.4
3 runs of 1-8 KiB 42.5 52.7
marked, unchanged 22.8 22.7

The block and line skip helps pages rewritten whole, but costs more on pages where shaders changed scattered words. Our in-game copy-backs are probably mostly that kind: our 8-byte compare, which speeds up dense pages a lot in the benchmark, barely moved the game. That last point is an inference; we'll confirm it with a span count in a game run.

Caveats:

  • The in-game runs were in different scenes, so compare per-MB figures, not totals.
  • The synthetic rounds varied 10-25 % between runs.

AI-assisted

**@⁠r4tedx** on GitHub · 2026-11-25 14:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2280#issuecomment-7165386050) Measurements for this PR, from our play build on `main` 940d32f. The in-game part uses an RTX 5070 and local title data; only copy-back sizes and timings are reported. These correct my comment on #2242, which blamed the wrong PR. **In game, per MB written back by marked-page copy-backs** (6 min per build, same tree and shader cache, one run per build): | Build | Per MB | |---|---:| | #2242 alone | 0.79 ms/MB (75.6 MB/frame in 59.7 ms) | | #2242 + this PR | 2.22 ms/MB | | #2242 + this PR + a commit of ours that tests a differing line 8 bytes at a time | 2.13 ms/MB (68.1 MB/frame in 144.8 ms) | **Synthetic** (WARP, release build, 1,216 marked 64 KiB pages per GPU-write pattern, µs per page, mean of 2 rounds; the title was not used in these tests): | GPU-write pattern | #2242 (09595753) | this PR (7ef96fa9) | |---|--:|--:| | page rewritten whole | 124.6 | 98.4 | | one word changed every 64 B | 55.9 | 82.7 | | one word every 512 B (128 runs) | 99.0 | 118.1 | | one word every 4 KiB (16 runs) | 41.9 | 53.4 | | 3 runs of 1-8 KiB | 42.5 | 52.7 | | marked, unchanged | 22.8 | 22.7 | The block and line skip helps pages rewritten whole, but costs more on pages where shaders changed scattered words. Our in-game copy-backs are probably mostly that kind: our 8-byte compare, which speeds up dense pages a lot in the benchmark, barely moved the game. That last point is an inference; we'll confirm it with a span count in a game run. **Caveats:** - The in-game runs were in different scenes, so compare per-MB figures, not totals. - The synthetic rounds varied 10-25 % between runs. AI-assisted
Author
Owner

@⁠r4tedx on GitHub · 2026-11-25 14:31 UTC · original

Correction to my comment above (#2280): the in-game build I labelled "#2242 alone" (0.79 ms/MB) actually had both #2242 and this PR reverted. So the in-game data shows a cost of ~2.5x per MB for #2242 + this PR together, and does not single out this PR. How it splits is unmeasured. A run with #2242 alone is planned.

The synthetic table in that comment is unaffected. It still shows this PR slower than #2242 on pages with scattered changed words, and faster on pages rewritten whole. Sorry for the noise.

AI-assisted

**@⁠r4tedx** on GitHub · 2026-11-25 14:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/2280#issuecomment-7165414263) Correction to my comment above (https://git.gtahub.st/github/Marvisak--VIctory/pulls/2280): the in-game build I labelled "#2242 alone" (0.79 ms/MB) actually had **both** #2242 and this PR reverted. So the in-game data shows a cost of ~2.5x per MB for #2242 + this PR together, and does not single out this PR. How it splits is unmeasured. A run with #2242 alone is planned. The synthetic table in that comment is unaffected. It still shows this PR slower than #2242 on pages with scattered changed words, and faster on pages rewritten whole. Sorry for the noise. AI-assisted
Author
Owner

@⁠r4tedx on GitHub · 2026-11-25 15:10 UTC · original

A synthetic breakdown of differing alone, with a suggested change. WARP, release build, µs per 64 KiB page, best of 7×200 calls, mean of 2 rounds. The title was not used in these tests.

GPU writes #2242 this PR this PR + word scan in differing blocks
whole page 88.8 53.6 55.2
a word per 64 B 14.2 24.5 8.6
a word per 512 B 6.2 8.7 4.1
a word per 4 KiB 5.6 2.7 1.9
3 runs of 1-8 KiB 18.6 11.5 11.3
marked, unchanged 5.0 1.0 1.0

On scattered words every 1 KiB block differs. That makes 2,048 line compares per page, and each differing line has all 32 of its bytes scanned. At one word per 64 B that's 32,768 bytes scanned, against #2242's 8,192 with its inline 8-byte compare.

The suggested change keeps the 1 KiB block skip, and compares a word at a time inside a differing block, as #2242 does. It's faster than both on every scattered pattern and keeps this PR's gain on unchanged pages. It returns the same runs on every pattern, and differing_matches_a_byte_wise_comparison and the other shadow tests pass (6 of 6). The patch is small; happy to post it or open it against your branch if you want it.

AI-assisted

**@⁠r4tedx** on GitHub · 2026-11-25 15:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/2280#issuecomment-7166422776) A synthetic breakdown of `differing` alone, with a suggested change. WARP, release build, µs per 64 KiB page, best of 7×200 calls, mean of 2 rounds. The title was not used in these tests. | GPU writes | #2242 | this PR | this PR + word scan in differing blocks | |---|--:|--:|--:| | whole page | 88.8 | 53.6 | 55.2 | | a word per 64 B | 14.2 | 24.5 | **8.6** | | a word per 512 B | 6.2 | 8.7 | **4.1** | | a word per 4 KiB | 5.6 | 2.7 | **1.9** | | 3 runs of 1-8 KiB | 18.6 | 11.5 | 11.3 | | marked, unchanged | 5.0 | 1.0 | 1.0 | On scattered words every 1 KiB block differs. That makes 2,048 line compares per page, and each differing line has all 32 of its bytes scanned. At one word per 64 B that's 32,768 bytes scanned, against #2242's 8,192 with its inline 8-byte compare. The suggested change keeps the 1 KiB block skip, and compares a word at a time inside a differing block, as #2242 does. It's faster than both on every scattered pattern and keeps this PR's gain on unchanged pages. It returns the same runs on every pattern, and `differing_matches_a_byte_wise_comparison` and the other `shadow` tests pass (6 of 6). The patch is small; happy to post it or open it against your branch if you want it. AI-assisted
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-25 15:16 UTC · original

That is exactly the trade this PR needed measured, and the numbers say the block skip alone is the wrong shape for scattered writes: it wins on unchanged pages and loses where a word per 64 B or 512 B is written, which is the pattern the title's marked pages actually show. Your "word scan inside a differing block" is the right combination — it keeps the 1 KiB skip and does the byte work only where the block differs — and it beats #2242 on every sparse pattern without giving up the gain on whole pages.

Yes please: open it against gpu/copy-back-block-compare (this PR's branch) with the numbers from your table in the description, and keep differing_matches_a_byte_wise_comparison as the check that the runs are unchanged. If it arrives as a commit on your fork I will cherry-pick it with your authorship, as I did with the shader-read fixture; a PR is just as good.

Two small things to keep in the patch so the review does not have to re-derive them: the comparison must stay run-for-run identical to the byte walk (your test already says so, but say it in the comment), and the 1 KiB block skip must not be dropped for the changed-count paths that use it (taken/compared in copy_back_or_not read the same runs).

On the triage's SPAN_GAP point: your data there is what the doc comment needs — a merged gap is undone by the write-back when the title writes it after the read. Once #2242 is in, I will rebase this branch onto main so the diff is only differing, and then this patch is the last piece of it.

**@⁠Calvix2k** on GitHub · 2026-11-25 15:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/2280#issuecomment-7166579030) That is exactly the trade this PR needed measured, and the numbers say the block skip alone is the wrong shape for scattered writes: it wins on unchanged pages and loses where a word per 64 B or 512 B is written, which is the pattern the title's marked pages actually show. Your "word scan inside a differing block" is the right combination — it keeps the 1 KiB skip and does the byte work only where the block differs — and it beats #2242 on every sparse pattern without giving up the gain on whole pages. Yes please: open it against **`gpu/copy-back-block-compare`** (this PR's branch) with the numbers from your table in the description, and keep `differing_matches_a_byte_wise_comparison` as the check that the runs are unchanged. If it arrives as a commit on your fork I will cherry-pick it with your authorship, as I did with the shader-read fixture; a PR is just as good. Two small things to keep in the patch so the review does not have to re-derive them: the comparison must stay run-for-run identical to the byte walk (your test already says so, but say it in the comment), and the 1 KiB block skip must not be dropped for the changed-count paths that use it (`taken`/`compared` in `copy_back_or_not` read the same runs). On the triage's `SPAN_GAP` point: your data there is what the doc comment needs — a merged gap is undone by the write-back when the title writes it after the read. Once #2242 is in, I will rebase this branch onto `main` so the diff is only `differing`, and then this patch is the last piece of it.
Author
Owner

@⁠r4tedx on GitHub · 2026-11-25 15:24 UTC · original

@⁠Calvix2k here it is as one commit on top of this PR's head (7ef96fa9), for you to cherry-pick: r4tedx/VIctory@5de3f541 on branch fix/2280-word-scan.

  • differing: inside a 1 KiB block that differs, it now compares 8 bytes at a time and scans only a differing word's bytes, instead of comparing 32-byte lines and scanning every byte of a differing line.
    • The 1 KiB block skip stays, and both callers keep it: put_back, and copy_back_or_not with its taken/compared paths.
    • The doc comment says the runs are the same, run for run, as a byte walk, and names differing_matches_a_byte_wise_comparison as the check.
  • SPAN_GAP's doc comment now states the trade-off: a title write that lands in a merged gap after the read is undone by the write-back. It also records the cost of exact runs with a kernel copy per run: ~509 µs per page at one word per 64 B (~49 with the gap), ~15.8 ms at every other byte.

differing alone (WARP, release, µs per 64 KiB page):

GPU writes this PR with this commit
a word per 64 B 24.5 8.6
a word per 512 B 8.7 4.1
a word per 4 KiB 2.7 1.9
marked, unchanged 1.0 1.0
whole page 53.6 55.2

Tests on the commit, on WARP:

  • cargo clippy -p victory-gpu --no-deps --all-targets -- -D warnings, with and without --features diagnostics: clean.
  • VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --lib -- --test-threads=1: 148 passed, 0 failed, 2 ignored, including differing_matches_a_byte_wise_comparison.

The title was not used in these tests.

AI-assisted

**@⁠r4tedx** on GitHub · 2026-11-25 15:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2280#issuecomment-7166805569) @⁠Calvix2k here it is as one commit on top of this PR's head (`7ef96fa9`), for you to cherry-pick: [r4tedx/VIctory@5de3f541](https://github.com/r4tedx/VIctory/commit/5de3f541) on branch `fix/2280-word-scan`. - **`differing`:** inside a 1 KiB block that differs, it now compares 8 bytes at a time and scans only a differing word's bytes, instead of comparing 32-byte lines and scanning every byte of a differing line. - The 1 KiB block skip stays, and both callers keep it: `put_back`, and `copy_back_or_not` with its `taken`/`compared` paths. - The doc comment says the runs are the same, run for run, as a byte walk, and names `differing_matches_a_byte_wise_comparison` as the check. - **`SPAN_GAP`'s doc comment** now states the trade-off: a title write that lands in a merged gap after the read is undone by the write-back. It also records the cost of exact runs with a kernel copy per run: ~509 µs per page at one word per 64 B (~49 with the gap), ~15.8 ms at every other byte. `differing` alone (WARP, release, µs per 64 KiB page): | GPU writes | this PR | with this commit | |---|--:|--:| | a word per 64 B | 24.5 | 8.6 | | a word per 512 B | 8.7 | 4.1 | | a word per 4 KiB | 2.7 | 1.9 | | marked, unchanged | 1.0 | 1.0 | | whole page | 53.6 | 55.2 | Tests on the commit, on WARP: - `cargo clippy -p victory-gpu --no-deps --all-targets -- -D warnings`, with and without `--features diagnostics`: clean. - `VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --lib -- --test-threads=1`: 148 passed, 0 failed, 2 ignored, including `differing_matches_a_byte_wise_comparison`. The title was not used in these tests. AI-assisted
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-25 15:29 UTC · original

Correction to my last comment, and an apology for the confusion: this PR is @⁠wbkepler's (wbkepler/VIctory:gpu/copy-back-block-compare), not mine — I answered the triage here as if I owned the branch. That was wrong of me, and it changes what to do with your commit:

  • The commit 5de3f541 belongs on @⁠wbkepler's branch. Could you open it against that branch (or ping wbkepler to cherry-pick it with your authorship)? I can review it, but I should not push to someone else's PR.
  • The two points I raised still stand for whoever carries it: the comparison must stay run-for-run identical to the byte walk (your test says so — say it in the comment), and the 1 KiB block skip must stay for the callers that use it (put_back, and the compared bookkeeping in the copy-back path).

Your measurements are the part this PR was missing: on scattered writes (a word per 64 B) the block skip alone is slower than #2242's inline compare (24.5 vs 14.2 µs), and the word scan inside a differing block is what turns that into 8.6 µs while keeping the gain on unchanged pages. That is exactly the kind of result a stacked PR needs.

**@⁠Calvix2k** on GitHub · 2026-11-25 15:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/2280#issuecomment-7166923777) Correction to my last comment, and an apology for the confusion: this PR is **@⁠wbkepler's** (`wbkepler/VIctory:gpu/copy-back-block-compare`), not mine — I answered the triage here as if I owned the branch. That was wrong of me, and it changes what to do with your commit: - The commit `5de3f541` belongs on **@⁠wbkepler's** branch. Could you open it against that branch (or ping wbkepler to cherry-pick it with your authorship)? I can review it, but I should not push to someone else's PR. - The two points I raised still stand for whoever carries it: the comparison must stay run-for-run identical to the byte walk (your test says so — say it in the comment), and the 1 KiB block skip must stay for the callers that use it (`put_back`, and the `compared` bookkeeping in the copy-back path). Your measurements are the part this PR was missing: on scattered writes (`a word per 64 B`) the block skip alone is slower than #2242's inline compare (24.5 vs 14.2 µs), and the word scan inside a differing block is what turns that into 8.6 µs while keeping the gain on unchanged pages. That is exactly the kind of result a stacked PR needs.
Author
Owner

@⁠r4tedx on GitHub · 2026-11-25 15:30 UTC · original

@⁠Calvix2k thanks, and no harm done.

@⁠wbkepler, this is for your branch: r4tedx/VIctory@5de3f541 (branch fix/2280-word-scan) is one commit whose parent is this PR's current head 7ef96fa9, so it cherry-picks cleanly and keeps its authorship:

git fetch https://github.com/r4tedx/VIctory fix/2280-word-scan
git cherry-pick 5de3f541

If you'd rather have it as a pull request against wbkepler/VIctory:gpu/copy-back-block-compare, say so and I'll open one.

The two points Calvix2k raised are already in the commit. The doc comment on differing says its runs are the same, run for run, as a byte walk, and names differing_matches_a_byte_wise_comparison as the test that checks it. Both callers keep the 1 KiB block skip: put_back, and copy_back_or_not with its taken/compared paths. The measurements and test results are in my comment above.

AI-assisted

**@⁠r4tedx** on GitHub · 2026-11-25 15:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2280#issuecomment-7166960324) @⁠Calvix2k thanks, and no harm done. @⁠wbkepler, this is for your branch: [r4tedx/VIctory@5de3f541](https://github.com/r4tedx/VIctory/commit/5de3f541) (branch `fix/2280-word-scan`) is one commit whose parent is this PR's current head `7ef96fa9`, so it cherry-picks cleanly and keeps its authorship: ``` git fetch https://github.com/r4tedx/VIctory fix/2280-word-scan git cherry-pick 5de3f541 ``` If you'd rather have it as a pull request against `wbkepler/VIctory:gpu/copy-back-block-compare`, say so and I'll open one. The two points Calvix2k raised are already in the commit. The doc comment on `differing` says its runs are the same, run for run, as a byte walk, and names `differing_matches_a_byte_wise_comparison` as the test that checks it. Both callers keep the 1 KiB block skip: `put_back`, and `copy_back_or_not` with its `taken`/`compared` paths. The measurements and test results are in my comment above. AI-assisted
Author
Owner

@⁠r4tedx on GitHub · 2026-11-25 16:02 UTC · original

Follow-up to the in-game numbers above: a build with #2242 alone (no part of this PR; I checked the tree) measured 2.51 ms/MB copied back, against 2.22 for #2242 + this PR and 0.79 for neither. So in game the cost comes with #2242, and this PR adds little or nothing on top. Caveat: the #2242-alone run is a different, later tree and scene, one run.

The word-scan commit for this PR (r4tedx/VIctory@5de3f541) still helps the scattered-word patterns in the synthetic benchmark. It's independent of this result.

AI-assisted

**@⁠r4tedx** on GitHub · 2026-11-25 16:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/2280#issuecomment-7167547359) Follow-up to the in-game numbers above: a build with #2242 alone (no part of this PR; I checked the tree) measured 2.51 ms/MB copied back, against 2.22 for #2242 + this PR and 0.79 for neither. So in game the cost comes with #2242, and this PR adds little or nothing on top. Caveat: the #2242-alone run is a different, later tree and scene, one run. The word-scan commit for this PR (r4tedx/VIctory@5de3f541) still helps the scattered-word patterns in the synthetic benchmark. It's independent of this result. AI-assisted
Author
Owner

@⁠r4tedx on GitHub · 2026-11-25 16:28 UTC · original

Follow-up to the in-game numbers above: a build with #2242 alone (no part of this PR; I checked the tree) measured 2.51 ms/MB copied back, against 2.22 for #2242 + this PR and 0.79 for neither. So in game the cost comes with #2242, and this PR adds little or nothing on top. Caveat: the #2242-alone run is a different, later tree and scene, one run.

The word-scan commit for this PR (r4tedx/VIctory@5de3f541) still helps the scattered-word patterns in the synthetic benchmark. It's independent of this result.

AI-assisted

**@⁠r4tedx** on GitHub · 2026-11-25 16:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/2280#issuecomment-7168047697) Follow-up to the in-game numbers above: a build with #2242 alone (no part of this PR; I checked the tree) measured 2.51 ms/MB copied back, against 2.22 for #2242 + this PR and 0.79 for neither. So in game the cost comes with #2242, and this PR adds little or nothing on top. Caveat: the #2242-alone run is a different, later tree and scene, one run. The word-scan commit for this PR (r4tedx/VIctory@5de3f541) still helps the scattered-word patterns in the synthetic benchmark. It's independent of this result. AI-assisted
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-25 16:39 UTC · original

That is the split that settles it: the in-game cost is #2242's, not this PR's, and the word scan adds nothing on top in game. Thanks for checking the tree of the measured build — that is what makes the number usable.

Since this is @⁠wbkepler's PR, the per-MB numbers are best kept on #2242's side; the synthetic gain of the word scan is still this PR's case, and no one is arguing it does not exist.

**@⁠Calvix2k** on GitHub · 2026-11-25 16:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/2280#issuecomment-7168326360) That is the split that settles it: the in-game cost is #2242's, not this PR's, and the word scan adds nothing on top in game. Thanks for checking the tree of the measured build — that is what makes the number usable. Since this is @⁠wbkepler's PR, the per-MB numbers are best kept on #2242's side; the synthetic gain of the word scan is still this PR's case, and no one is arguing it does not exist.
Author
Owner

@⁠Machad3x on GitHub · 2026-11-25 18:26 UTC · original

Setup: RTX 3080 Ti (driver 621.24), Windows 11, a local stack of open PRs merged with main 67e8ae1.

7ef96fa applies on a stack that already has an earlier #2242, with one conflict
in the tests of shadow.rs (both sides kept). victory-gpu tests pass. In game
(RTX 3080 Ti), with #2409, copy-back was 135 ms against 181 ms in an earlier
run, but those two runs also differ by five other PRs, so this is not a
measurement of this change alone.

Written with Claude Code; tested locally.

**@⁠Machad3x** on GitHub · 2026-11-25 18:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2280#issuecomment-7170915199) Setup: RTX 3080 Ti (driver 621.24), Windows 11, a local stack of open PRs merged with main 67e8ae1. 7ef96fa applies on a stack that already has an earlier #2242, with one conflict in the tests of `shadow.rs` (both sides kept). `victory-gpu` tests pass. In game (RTX 3080 Ti), with #2409, copy-back was 135 ms against 181 ms in an earlier run, but those two runs also differ by five other PRs, so this is not a measurement of this change alone. Written with Claude Code; tested locally.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/shadow.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/2280/head:github-bot/gh-2280'
git switch 'github-bot/gh-2280'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2280'
git switch 'github-bot/gh-2280'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2280'
git switch 'github-bot/gh-2280'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2280'
git switch 'main'
git merge --squash 'github-bot/gh-2280'
git switch 'main'
git merge --ff-only 'github-bot/gh-2280'
git switch 'main'
git merge 'github-bot/gh-2280'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2280
No description provided.