GPU: copy-back writes only the GPU's bytes and marks only unchanged pages current #1024
No reviewers
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!1024
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1024"
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?
@Dufftwt on GitHub · 2026-11-24 15:09 UTC · original
Dufftwt:fix/copy-back-only-gpu-bytes→main· +238 −21 · 3 files · 2 commits · openFixes #721, fixes #722.
What's wrong
After a submission,
Shadow::copy_back(crates/victory-gpu/src/shadow.rs) brings what shaders wrote back into title memory. It has two problems, both while the title's own threads keep writing the same memory:What the fix does
VirtualQueryper piece (the newhost::writable) checks that the runs lie in committed read-write memory. Where they don't, each run still goes throughwrite_mapped, which skips pages it can't write. Onewatch::writingper piece opens our guarded view blocks first. A block another thread guards again before the stores faults into our handler, which opens it.writable(at)check inwatch.rsnow callshost::writable(at, 1), the same query.How it behaves after the fix
Title writes made while copy-back runs are kept, and they reach the host copy at the next refresh. When the title doesn't write meanwhile, the result is the same as before. Copy-back takes about as long as writing whole pieces did, however scattered the GPU's writes are (timings below). The added cost is one 64 KiB read per page the GPU wrote, and one memory query per piece. The copy-back figure in the frame log now counts only the bytes actually written, so it drops.
shortcut:a title thread that unmaps or protects memory between the query and the stores would crash us. The GPU's bytes go back before the title is told the submission is done, so only a title that frees memory the GPU is still writing could do that.Tests
Three new tests in
shadow.rs(copy_back_tests), on write-watched memory and a host copy fromhost().shared_buffer. They skip without a host GPU. A test-onlywatch::forgetclears the journal for their memory when they free it, so a later test's allocation at the same address starts clean.copy_back_does_not_undo_title_writes_made_while_it_runs: a title thread keeps bumping a word in each of 64 pages whilecopy_backwrites a shader byte back into each. No write may go back to an older value.a_title_write_during_copy_back_reaches_the_copy: once copy-back has finished page 0, the title writes it while 62 pages are still to go. The next refresh must bring that write into the copy.a_read_only_title_page_is_left_alone: the title made one page read-only. Copy-back must not crash on it, and must leave it alone, aswrite_mappedalways did (the kernel's write fails there). The other 63 pages still get the shader's byte.I ran
cargo test -p victory-gpu -- --test-threads=1on GitHub'swindows-latestwith Rust 1.98.1 fromrust-toolchain.toml(the runner has a hardware D3D12 device as well as WARP):victory-gpu: 53 passed, 1 ignored).main(ffe310e): both fail.copy_back_does_not_undo_title_writes_made_while_it_runs:title writes undone by the copy-back,left: 64, right: 0, so every one of the 64 pages lost its title write.a_title_write_during_copy_back_reaches_the_copy:in the copy,left: 0, right: 7. The write reached title memory but never reached the copy.cargo clippy -p victory-gpu --all-targets -- -D warningsis clean, with and without--all-features.Timings. A scratch test (not in this PR) timed one
copy_backof 64 pages in which the shaders changed every Nth byte. It ran as a release build on the same runner, 3 rounds each, against this PR without its second commit (onewrite_mappedper run):write_mappedper runNot tested: a title run with this branch. Vaximous (RTX 4070 Ti, Windows) and xstraok (Wine) saw a crash and a freeze in the world go away with run-only write-back on #721.
Related: #124, #401 and #693 restructure
copy_backbut keep the whole-piece write; #261 fixes other cases where older bytes went back; #943 changeswrite_mapped's fallback and #991 merges overlapping write-back ranges, on the same lines. Whichever merges second needs a rebase. Fixes for this were also posted on #721 and #722 as branches, since PRs were closed to non-collaborators: xstraok (plain stores, without a check of the memory), Vaximous, Hiiva (with #722), and Machad3x (with #722; pieces with more than 64 runs are still written whole, which keeps the race in them). Their in-game runs are the evidence that this race matters.@MichaelSmithAI on GitHub · 2026-11-24 15:11 UTC · original
The three copyback tests passed at
67125b3on an RTX 4090 under Wine/vkd3d-proton 3.2. They covered preserving a concurrent title write, seeing it in the host copy after refresh, and leaving a read-only title page untouched.We also combined #1024 with #1019 and #322. The existing guest compute test wrote two 56-byte records through an off-element placed UAV. After submission, both GPU-written fields were present in guest memory and all surrounding bytes matched on both ordinary and write-watched allocations. The combined GPU suite had 64 passes, one ignored test and the known Wine empty-library failure.
These runs used stable mappings. They did not measure title copyback time or same-submission visibility through another backing copy.
@Aniseto on GitHub · 2026-11-24 15:22 UTC · original
Ran the three copy-back tests at
67125b3on native Windows:Environment: Windows 11 Pro build 26200 x64, Intel Core i5-12400F, 64 GB RAM, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only) driver 32.0.16.2124, Rust 1.98.1 (pinned by
rust-toolchain.toml), MSVC 14.44.35207, DXC 1.9.2609.5, debug build.copy_back_does_not_undo_title_writes_made_while_it_runs,a_title_write_during_copy_back_reaches_the_copyanda_read_only_title_page_is_left_alonepass. The earlier report was on an RTX 4090 under Wine/vkd3d-proton 3.2; this run is native Windows D3D12, so it also covers the native path on a Blackwell part.Not tested: the title itself (no game data here, and its world can hang the adapter per the README), RDNA2/RDNA4 and Intel GPUs.
AI-assisted (OpenCode), model: DeepSeek V4.1 Flash 1017 - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; no game data was used.
@Zipettte on GitHub · 2026-11-24 15:40 UTC · original
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at
67125b3:cargo test -p victory-gpupasses, 53 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
@AgneyaK on GitHub · 2026-11-24 16:37 UTC · original
Test report on an RTX 3050 6 GB Laptop (i7-13700H, 16 GB RAM, Windows 11 26300), diag build, title 1.0.2.1, Series X profile. Base tree:
mainffe310e+ #208 + #223 #233 #320 #439 + #452 + #579 (VICTORY_SKIP_WAVE64=mesh), from #1232. #472, #322 and #1024 merge cleanly onto it.So about 12% shorter frames, mostly copies (−36%) and copy-back (−18%). One run each, and the three were
not separated.
On this 16 GB machine much of the rest looks like paging: private bytes reach 22.9 GB and the working set is trimmed to 2-5 GB (numbers in #1232).
AI use: Claude Code (Claude Opus 5.5) merged and built the trees, ran the title on my machine and drafted this note; results are from the runs described.
@TG0000 on GitHub · 2026-11-24 16:57 UTC · original
A measured hint on speed, from my own port of this idea (not your build; head
67125b3), RX 6800, Windows 11, one launch, 8 looped world frames of 36 submissions: the write-back withwrite_runstook about the same time asmain's (302 against 292 ms per frame in copy back), because each piece still does aVirtualQuery(about 2 ms in the title's big pools here). With the runs written through a fault-tolerant user-mode copy (the one of #1010, also open) instead, copy back fell to about 79 ms and only the GPU's bytes are written. That also closes the window between the query and the plain stores (host.rs:1400-1410), where a title thread can unmap or protect the memory; that window I only read, I have not reproduced it.QueryWorkingSetExper page (1 to 2 us here) is another way to avoid the slow query.The correctness part, writing only what the GPU changed, looks right to me.
AI-assisted (Claude Code).
@Dufftwt on GitHub · 2026-11-24 16:59 UTC · original
@TG0000 thanks for measuring. 302 against 292 ms is what this PR aims for: only the GPU's bytes are written, at
main's speed. Thewrite_mappedper run it replaces took seconds there (1.3–1.9 s per frame in Vaximous's runs on #721).I agree a fault-tolerant store is the better end state: there's no query, and no window between the query and the stores. It needs the store direction of #1010's copy, though, and #1010 only reads title memory. If #1010 merges first, I'll switch
write_runsto its copy in this PR. Otherwise it's a small follow-up on top of both. Did your port add a store routine next to #1010's load, under the same handler?@TG0000 on GitHub · 2026-11-24 17:31 UTC · original
No new routine: the port called #1010's
copywith the title memory as the destination for each run, and fell back towrite_mappedfor a run that failed. That copy recovers by instruction address, so a fault of the load or of the store fails the call, whichever side it is on. Two things I have not checked for the store direction, so please do not take it as proven: #1010's tests cover the source side only, and after a failed run part of it may already be stored (the fallback then writes it again). A small follow-up on top of both, with tests for a destination that is unmapped, read-only and guarded, sounds right to me.(302 against 292 ms is the port on this PC; I did not measure the per-run
write_mappedit replaces.)AI-assisted (Claude Code).
@465d6a0eac on GitHub · 2026-11-24 17:49 UTC · original
Thank you for this, @Dufftwt! Many pull requests here are still waiting to be merged, so I've ported this one to 465d6a0eac/AgentRecompVI, a VIctory fork where AI agents review and merge each other's work: https://github.com/465d6a0eac/AgentRecompVI/pull/36. You're credited as the author there. This stays the original.
Test results
cargo clippy(both variants) andcargo test --workspacepass (429 passed, 0 failed).copy_back_testsmodule sits next to thetestsmodule #1019 added toshadow.rs.@aycow on GitHub · 2026-11-24 18:18 UTC · original
I retained Duff's authored
3b2181abyte-run copyback in a #387 test branch. Both concurrent title-write controls passed on native Windows with the GPU crate optimized. In a CPU-only 4 MiB snapshot/copyback fixture, changing one byte per 32 bytes generated 131,072 guarded writes and raised median copyback from 1.37 ms to 718.99 ms. The dense and sparse controls are in the reproduction.I kept this candidate separate from #387. The later direct-store shortcut needs the mapping to remain the same generation from VirtualQuery through the stores. An address protection snapshot alone does not provide that lifetime across unmap and reuse. The byte-ownership regressions remain useful for checking a guarded fast path.
@Dufftwt on GitHub · 2026-11-24 18:19 UTC · original
@aycow thanks for the controls and the fixture. Your numbers are for
3b2181a, the first commit, which writes onewrite_mappedper run. This PR's head67125b3replaces that with direct stores after one memory query per piece, for exactly this cost. Onwindows-latest(release build), changing every 2nd byte of 64 pages took 15.6 s with3b2181aand 14–17 ms at the head. Writing whole pages took 10–11 ms either way.On the lifetime point, agreed: a query doesn't pin the mapping, and the PR marks the window as a
shortcut:. Unmap-and-reuse isn't specific to the direct stores, though.write_mapped,main's whole-piece write included, also writes into whatever is mapped at the address when it runs. What keeps all of them safe is the order: the GPU's bytes go back before the title is told the submission is done, so only a title freeing memory the GPU is still writing could hit it. Unmapped or read-only memory at store time would fault here rather than be skipped. TG0000's fault-tolerant copy (#1010) closes that window, and switching to it is the planned follow-up once both land. Your byte-ownership regressions would be good tests for it.@ThomasHFWright on GitHub · 2026-11-24 18:41 UTC · original
Linux/Wine integration test of head
67125b3a891afcb70417ca222a21d768fe0e05ff: the copy-back regressions pass after accounting for the submission boundary in Slaktarn700'sproton-fixeswrite-watch cache.Setup: RTX 5090, NVIDIA 620.73.04, CachyOS7.3.6, Wine11.22, vkd3d-proton3.2.0
30b0eb9bc12dc9f, pinned Rust1.98.1 Windows MSVC cross-build. Integration base is proton-fixes993dff8 + #852 + #454 + #206, with local fence/descriptor probes. This is not an isolated-main or Steam Proton test.The production delta merged into
host.rsandshadow.rscleanly.watch.rshad an insertion conflict: I retained the Wine-specific functions and added your test-onlyforgethelper.The first diagnostic GPU suite was 60 passed / 1 failed / 1 ignored. The failing test was
a_title_write_during_copy_back_reaches_the_copy, expected7, read0. This branch intentionally reuses write-watch answers within a submission; the next title submission callswatch::new_submission()before refreshing. Adding that same boundary at the start ofsubmitted()and immediately before the test's nexts.update(base, PAGE)makes the suite 61 passed / 0 failed / 1 ignored. No assertions weakened and no production change beyond your patch. This is an integration-specific fixture adaptation, not evidence that your main-based test is wrong.Full Windows workspace on the adapted integration: 350 passed / 2 failed / 7 ignored, 14 test executables. Default-feature GPU58/0/1, shader122/0/2. The two unchanged Wine harness failures are the load probe's nested Linux cargo invocation and xtask's Linux git invocation. All-target/all-feature Clippy with warnings denied and native asset policy pass. Four shader differential tests still early-return without console/compiler tools; the local opt-in buffer-view diagnostic is the extra ignored test.
Native Microsoft d3dcompiler_47 used; GPU tests ran on the RTX5090, serially, offline. No concurrent title GPU workload. No title run with this patch yet, so this establishes regression-test compatibility only, not a fix for world rendering, #698, or the GPU execution fault.
AI-assisted with Codex. No game data or derived artifacts attached.
@ThomasHFWright on GitHub · 2026-11-24 19:07 UTC · original
Title follow-up to my synthetic Linux report: #1024 was tested for world loading, but it did not get past the later #698 pool exhaustion.
Same RTX5090 / NVIDIA620.73.04 / Wine11.22 / vkd3d-proton3.2.0 setup and diagnostics as above. The direct control was the #747-style capped split (737856 mirrored / 262144 dynamic) on proton-fixes993dff8 + #852/#454/#206. The candidate adds only this PR's production delta at67125b3; its test fixtures retain the two submission-boundary adaptations described above. Both runs disabled VK_NV_raw_access_chains, used default loop limit, no shader skips, debug pixel shader and intermediate-target display.
Local captures show partial roads, signs and character geometry in debug colours; normal shaded rendering and controllable movement remain unverified. The #774 spin did not recur in this one candidate run, but that failure is intermittent, so this does not establish that #1024 fixes it. #698 is still reproduced. These runs are not a performance benchmark.
Combined candidate checks: full Windows workspace350passed/2unchanged Wine harness failures/7ignored across14executables, diagnostic GPU61/0/1, all-target/all-feature Clippy-Dwarnings and native policy pass. Binary SHA256
00abe81ba6f0c46188427ff2dde9bc8937bb09ac4e8b770351f5a00e622e5462.AI-assisted with Codex; offline/app-muted, read-only title input. All runs stopped. No game-derived files attached.
@Dufftwt on GitHub · 2026-11-24 19:08 UTC · original
@ThomasHFWright thanks for running it in the title with a direct control. Agreed: one run doesn't establish a fix for the #774 spin. But it's the second time that freeze has gone with run-only write-back. On #721, xstraok saw the title freeze after about 4 minutes in the world, with two threads spinning in a hash-table probe at
+0x50eb81a..+0x50eb83d, on RX 9060 XT / RADV / Proton. With run-only write-back they had about 10 minutes and no freeze, and they also called the link a guess from one run each. Your control's spin at+0x50eb81f/+0x50eb826is in that same range.A probe that never ends fits #721's race: copy-back writes a whole 64 KiB piece back and puts older bytes over a table entry a title thread just wrote. Two runs on different GPUs and drivers point the same way. A few more control/candidate pairs would turn that into evidence. #698's
INSTANCE_LISTlimit is the next wall either way.@Marvisak on GitHub · 2026-11-25 00:33 UTC · original
Automated triage for the maintainers.
Needs rebase. This PR does not merge cleanly into current
main(ac2525d). Conflicting files:crates/victory-gpu/src/shadow.rs,crates/victory-gpu/src/watch.rs.The content has not been reviewed yet; it will be once the branch is rebased onto
main.Generated by Claude Code
@anoyarou on GitHub · 2026-11-25 23:14 UTC · original
Another control/candidate pair for the
+0x50eb826freeze, AMD/RADV under Proton Experimental: the candidate differs from the control by the run-only write-back alone.Setup: Fedora 44 (kernel 7.3.4), RX 9070 XT (RADV), Proton Experimental
experimental-11.0-20261112with its vkd3d-proton,VKD3D_CONFIG=ignore_shared_fence,descriptor_heap. Diag builds of Belobug/VIctory-Belobug-AMD (01aadd1+ its PRs #53, #69, #124, #96, #123, #139, and the watchdog patched out). Series X, started from boot into the intro, the same settings in every run.Control:
838a88a, 2 of 2 runs froze. World frames stopped at about 315 s and 280 s from launch. One title thread stayed at 100% CPU, the rest waited. WithVICTORY_STACKSat 300 s and 420 s, the spinning thread was at+0x50eb826 ← +0x31962 ← +0x317fd ← +0x25d801b ← +0x221c29c ← +0x2215ecain both dumps of the second run. That is Ceereals' stack on #1118 and the same range as xstraok's and ThomasHFWright's control above.
Candidate:
838a88a+ one commit, the run-only write-back.Shadow::copy_backwrites back only the runs of bytes the GPU changed. Each run still goes throughwrite_mapped, which on this tree tries a user-mode copy beforeWriteProcessMemory. Same settings, from boot: no freeze. World frames kept coming past 280-315 s, and the dumps at 300 s and 420 s showed no thread spinning in title code (the busiest title thread was at ~5% CPU). The run went on until the title's ownINSTANCE_LISTbreakpoint (#698) at 643 s.After that: 22 more runs with the fix, and none froze. The fix was carried along while other changes were added. Two runs from boot again reached #698's breakpoint (639 s; and past it with #2644's
VICTORY_STEP_OVER, 30 minutes into gameplay). Twenty runs started from a save, most of them 4 to 23 minutes in the world (two were stopped after 1-3 minutes). Copy-back under the fix cost 87-147 ms a frame standing still.So, on a second GPU vendor's driver stack and with the control and candidate one commit apart, the freeze went away with the run-only write-back, and has not come back in 23 runs. The fix is not the whole of #1024: this tree takes only the run-only write-back part, not the #722 epoch part.
AI-assisted (Claude Code)
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.