GPU: runs of a copy-back that lie close together go back in one write (240,000 writes a frame under Wine) #857
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!857
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-857"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@UwUCammie on GitHub · 2026-11-25 10:49 UTC · original
UwUCammie:fix/copy-back-joined-runs→main· +70 −2 · 1 files · 1 commits · openProblem
Since only the GPU's bytes are written back (upstream #2009, in
8dd30ab),Shadow::copy_backcallswrite_mappedonce for every run of changed bytes in a piece. A shader that writes records leaves a lot of short runs, because every byte of a record that comes out the same as before ends one.In the world frames of the opening scene I counted 240,000 to 280,000 runs a frame, in about 250 pieces. Each is one
NtWriteVirtualMemorycall. Under Wine a call measured about 4 µs, so "putting them back" in the frame account was 0.8 to 1.2 s of every frame.Change
Runs with fewer than 64 bytes between them are written as one (
join_runs).VICTORY_BACK_RUN_GAPsets the distance;0writes every run on its own, as before.What it gives up
The bytes between two joined runs are written as they were read a moment earlier. A title write that lands on one of them between the read and the write is lost. Before #2009 that was true of the whole stretch from a piece's first changed byte to its last; with this it is true only of bytes less than 64 bytes away from one the shader wrote. The README's
VICTORY_MERGE_RACEcount (none in 138,000 write-backs of whole stretches) is for the other merges, not this one, so I can't put a number on it here.Measurements
RX 7900 XT, RADV (Mesa 26.3.1), Wine 11.22, vkd3d-proton from GE-Proton11-14, diagnostics build, opening scene up to the first room, one run each of about ten minutes.
How the number of writes falls with the distance, counted in one run: under 8 bytes about 15,000 a frame, under 64 about 4,000, under 512 about 1,100.
The picture is the same in both runs (first room with its walls, the character, the "Move around" prompt).
Not measured: Windows. I'd expect the calls to be cheaper there but still a quarter of a million of them a frame.
The tree I ran is this
main(9376fd6) merged into myokex/victory-amd, with two local loader switches and myokex/victory-amd#6 on top;mainalone was not run. Another program used the card during the first minutes of the second run, before the world frames counted above.Related
Tests
runs_closer_than_the_gap_are_joined.cargo test -p victory-gpu --lockedunder Wine: 145 passed.cargo clippy -p victory-gpu -- -D warningsreports two things that are onmainalready (placed_filler_twinsunused withoutdiagnostics,sort_unstable_byindraw.rs), nothing inshadow.rs.No game files, captures or logs are included.
@alexodee on GitHub · 2026-11-25 11:09 UTC · original
Windows numbers for the idea, since the description says they are missing. I have not run this PR and have not tried a gap of 64. These come from an equivalent local join in
back_piece(runsat most N bytes apart become one write, N = 0 is one write per run).Setup: RTX 3070 Ti Laptop 8 GB (driver 596.36), i7-12700H, 15.7 GB RAM, Windows 11 build 26300, diagnostics build, Series X profile.
VICTORY_RELAY=0 VICTORY_LATE_WAIT=3 VICTORY_WIDE_BACK=1 VICTORY_CARD_BUFFERS_MIN_MB=1 VICTORY_CARD_BUFFERS_MB=512, nativeNtWriteVirtualMemory. Medians over the 5 s report lines with at least 3,000 draws a frame and 400 differing pieces (no minimum of pieces for the card-buffers run below). Rows (a) start at the beginning of the game and include the opening cutscene, (b) start from a save near the first gameplay scene.a26859f+ PRs (b)VICTORY_HEAP_SYNC=0(b)VICTORY_TEXTURE_BUDGET_MB=2800(b)VICTORY_TEXTURE_BUDGET_MB=3200(a)9376fd6+ PRs (b)9376fd6+ PRs, same executable and switches (b)VICTORY_CARD_BUFFERS_MB=1024andVICTORY_TEXTURE_BUDGET_MB=2200(against 512 and 2600 in the last two rows, gap 4096), "putting them back" was 4.9 ms (4.8-5.6; 48 lines, 183 pieces) and the frame 469 ms. The log has 97 host copies in the card's memory (941 MB) instead of 46 (511 MB), so most of the buffers took the card's path, whose pieces this counter does not include (1,527 fetched a frame instead of 772). Both switches changed at once, so I cannot say how much of the frame time is the buffers and how much the smaller texture budget.The
a26859frows carry #276 #52 #51 #610, the9376fd6rows also #640 #823 #799 andVICTORY_HEAP_SYNC_TABLES=1. None of them changesshadow.rs. All carry a local switch in the crash handler.Limits: one machine, one launch per row. Apart from the last two rows this is not a strict A/B (the gap 0 row was not repeated on
9376fd6). The relay was not run, so nothing here is about the default path. #786 would add the same per-run writes there.AI-assisted (Claude Code). No game data.
@UwUCammie on GitHub · 2026-11-25 11:59 UTC · original
Thanks, that's the half I couldn't measure. So it isn't a Wine thing: one write per run costs most of the frame on native Windows as well (632 ms against 37 ms here).
Your 256 against 4096 rows fit what I saw with the counts: past a few dozen bytes the number of writes hardly falls any more (about 4,000 at 64 and about 1,100 at 512 here), so a bigger gap only widens the window in which a title write can be lost. I'll leave the default at 64.
The PR still merges cleanly onto
f85101b. That commit'sVICTORY_MERGE_GAPis the other direction (title bytes going up to the card), it doesn't touch the copy-back.@MamaLeVrai on GitHub · 2026-11-25 12:23 UTC · original
Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present. I merged this PR's head
3a0b70bintomainf85101bin a throwaway tree (no conflict).cargo clippy --workspace --all-targets --locked -- -D warningsfails with exactly the errorsmainitself has on this machine (placed_filler_twins,depth_written, a sort; PR #841 fixes them), also with--all-features; this PR adds none.cargo test --workspace --locked: run 1: stopped atindirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields(the one that fails onmainitself most runs here (PR #849 and #847 fix its assertion)) and thevictory-gputest binary died with an access violation (it does that onmainabout 2 runs in 100, issue #850); run 2: stopped atindirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields(the one that fails onmainitself most runs here (PR #849 and #847 fix its assertion)) and thevictory-gputest binary died with an access violation (it does that onmainabout 2 runs in 100, issue #850) (mainalone: 555 passed, 0 failed, 11 ignored). The title was not run, so this says nothing about in-game effect. No game data.AI-assisted (Claude Code); no game data.
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.Merge
Merge the changes and update on Forgejo.