Shadows: put a run of GPU-written pieces back with one kernel call (fix on a fork) #918
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory#918
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@cybx on GitHub · 2026-11-24 14:09 UTC · original
Problem
After a submission runs,
copy_backcompares the host copy of every GPU-written range with the snapshot taken before it, piece by piece (64 KiB), and puts each differing piece back into title memory with its ownReadProcessMemory/WriteProcessMemorycall. In a busy world frame of the retail title this was thousands of kernel calls a frame: copy-back took ~350–555 ms of a ~830–1030 ms frame on a Ryzen 7 9800X3D / RTX 5070 Ti.Change
crates/victory-gpu/src/shadow.rs:merge(title, host, old, first)(pure) does the byte merge that was done per piece: the GPU's bytes (where the host copy differs from the snapshot) go into a local copy of title memory where it lacks them, title memory goes into the host copy, and it returns the joined runs of pieces where title memory lacked a GPU byte.put_backwrites each of those runs back with one kernel call. If part of a run is not mapped, it falls back to piece by piece for that run.submittedlock) are unchanged.Verification
put_back_writes_joined_runs_of_pieces_the_gpu_changed: synthetic buffers of three pieces plus a short first one. The GPU wrote a byte in each; the title already has one of them and wrote its own bytes in two pieces while the GPU ran. It checks the joined runs returned and that title memory and the host copy both end with the GPU's bytes and the title's.cargo clippy -p victory-gpu --all-targets [--all-features] -- -D warningsclean,cargo xtask policyok,cargo test -p victory-gpu: all pass exceptframe::tests::waits_end_on_ticks_and_count_frames, which also fails onmainhere under load (timing).Branch: https://github.com/cybx/VIctory/tree/shadow-batched-copy-back (one commit on
ffe310e). Compare: https://github.com/Marvisak/VIctory/compare/main...cybx:VIctory:shadow-batched-copy-backNo game files were used in the tests or the change. Written with the help of an AI assistant (Claude); I reviewed and tested it.
@DrDarkDK on GitHub · 2026-11-24 14:15 UTC · original
I found a fallback regression on
4c0d57dwith a synthetic native Windows copy-back test. The range is 8 bytes: the last four bytes of one 64 KiB piece and the first four of the next. I marked one sidePAGE_NOACCESSand repeated with the other side protected.On
ffe310e, both cases wrote the four readable bytes back. On4c0d57d, both wrote zero bytes and the readable word stayed at its original value. The control with both sides readable wrote all eight bytes on both revisions.In
put_back,to - from <= PIECEcan be true even when the range spans two pieces. Computing the first piece’s length before the read and returning early only whenfirst == to - fromrestores the piece-by-piece fallback. With that change, all four shadow tests passed on WARP and RTX 4070 Ti. Diagnostics Clippy passed with warnings denied.AI-assisted. Synthetic buffers only, with no gameplay or performance measurements.
@MamaLeVrai on GitHub · 2026-11-24 19:45 UTC · original
@cybx your fix for this issue is now in a pull request, #1610, with seven other fixes from contributors' forks: the branch is merged as it is, with your commit(s) and your name unchanged, onto
mainffe310e. Clippy (both runs) andcargo test --workspacepass on the result. If you would rather open your own pull request for this one, say so and I will take it out of #1610. AI-assisted (Claude Code); no game data.@Marvisak on GitHub · 2026-11-25 06:54 UTC · original
Automated triage for the maintainers.
mainchanged the copy-back after this branch was written: sincecd94d35and940d32f, translated shaders mark the 64 KiB title pages they write through views, and after a submission only marked pages are compared and written back, one page at a time (copy_back_markedincrates/victory-gpu/src/shadow.rs). The branch (put_back, onffe310e) would need rebasing onto that, and the cross-piece fallback regression found above (to - from <= PIECEfor a range spanning two pieces) needs the fix described. The bundle that carried it, #1610, was closed without being merged; pull requests are open to everyone, so a rebased pull request of your own is the way forward. A measurement of copy-back time on currentmain(see #400, where world frame time is tracked) would show what is left to gain.Generated by Claude Code