Repository navigation
Conversation
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
catminou4
left a comment
There was a problem hiding this comment.
Copy-backs compare a block at a time (1 KiB blocks, 32-byte lines inside differing blocks) — stacked on #2242. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Perf follow-up to #2242: ~30 µs/page → the 8-byte scan cost ~70 ms/world frame; the two-level skip looks right. Review together with #2242.
VIctory V2: community PRs, merged and testedOpen 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). 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: Unofficial community fork of Marvisak/VIctory, GPL-3.0. |
DenRakEiw
left a comment
There was a problem hiding this comment.
Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):
cargo test -p victory-gpu --lib shadow::— 6 passed, 0 failedcargo clippy -p victory-gpu --all-targets— 0 warningscargo xtask policy— ok (183 files ok)
Clean block-at-a-time copy-back comparison in shadow.rs. Looks good.
AI-assisted (Gemini 4 Neon).
|
Verified the stack on Windows 10 19045 with an RX 7800 XT (RDNA3), head
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. |
|
Automated triage for the maintainers. This pull request no longer merges cleanly into Generated by Claude Code |
|
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 On the |
|
Measurements for this PR, from our play build on In game, per MB written back by marked-page copy-backs (6 min per build, same tree and shader cache, one run per build):
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):
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:
AI-assisted |
|
Correction to my comment above (#2280 (comment)): 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 |
|
A synthetic breakdown of
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 AI-assisted |
|
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 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 ( On the triage's |
|
@Calvix2k here it is as one commit on top of this PR's head (
Tests on the commit, on WARP:
The title was not used in these tests. AI-assisted |
|
Correction to my last comment, and an apology for the confusion: this PR is @wbkepler's (
Your measurements are the part this PR was missing: on scattered writes ( |
|
@Calvix2k thanks, and no harm done. @wbkepler, this is for your branch: r4tedx/VIctory@5de3f541 (branch If you'd rather have it as a pull request against The two points Calvix2k raised are already in the commit. The doc comment on AI-assisted |
|
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 |
1 similar comment
|
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 |
|
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. |
|
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 Written with Claude Code; tested locally. |
…he ranges asked only, GPU upload heaps said in the log - VICTORY_REFRESH_RANGES=1: a submission's refreshes of a host copy are the ranges its lists asked for, joined only where within 64 KiB (past 256 ranges, their envelope), not one range from the lowest to the highest (upstream Marvisak#2349 dcb4ac3/7cfd3912, Marvisak#2428 3a2279f, read only). Run cpuframe (2026-11-26 00:19): 8.5 GB of refresh ranges asked of the write watch a frame (the 174 MB heap's envelope at every flush), 33 ms, for ~130 MB copied. Tests for the joining. - VICTORY_BACK_BLOCKS=1: what shaders wrote goes back into title memory by 1 KiB block, only the blocks the merge changed, not the span from the first changed byte to the last (upstream Marvisak#2242/Marvisak#2280 without their shader marks); never writes the title's newer bytes over with older ones there. - VICTORY_FAST_TITLE_WRITE=1: those writes by rep movsb (the caller opened our guards), through the kernel only if a fault fails it: hundreds of pieces a frame were each a kernel call. - A log line says whether the card offers GPU upload heaps (resizable BAR); an ignored test asks this PC's card: the RX 7600 does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Stacked on #2242 (based on
gpu/copy-back-gpu-bytes-only; the first commit here is #2242's). Only the last commit is new:differinginshadow.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:
differing) + take title's otherstaken) / re-readdifferingcompared 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)
differing+ take othersOn its own,
differingnow 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_releasedandlists_share_a_table_and_copies_keep_their_views. Both hit the 1M view-heap cap on NVIDIA.🤖 Generated with Claude Code