GPU: a copy that meets an unmapped page retries in 64 KiB kernel calls (2 300-2 500 a world frame); one query per region is 2.3x cheaper #783
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#783
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?
@rocobalt1 on GitHub · 2026-11-24 10:37 UTC · original
A CPU-side cost that #400's table does not separate: copies that meet an unmapped page retry in the kernel 64 KiB at a time, and rediscover the same holes every frame.
Setup: NVIDIA RTX 4060 Ti (driver 32.0.16.1656), Ryzen 9 5900X, 64 GB, Windows 11; Xbox Series 1.0.2.1; diag build (
--profile diag --features diagnostics) of an integration tree at2b1a569(about 50 PRs onmain);VICTORY_NO_WATCHDOG=1;TdrDelay=60set machine-wide on this box. No game data used.What the log says
In the world, one frame:
moves(the timed first attempt) is 29 ms; the copies take 120-275 ms. The difference is the fallback path, and its counter is the only one that scales withfallbacks.The path
copy_mappedreads the range with oneReadProcessMemory. If any page of it is unmapped, it redoes the whole range in 64 KiB pieces (then 4 KiB inside a piece that fails), oneReadProcessMemoryper piece, zeros where nothing can be read.VICTORY_COPY_MODE=plain, which copies the range blindly, ends the run inside a minute on this machine.The change (gist below)
On the fallback, walk the range with
VirtualQueryand copy what the region says is committed and readable, zeros for the rest - same bytes in the destination as today, but one query per region instead of one kernel call per 64 KiB piece. The regions of the big pools are megabytes long, so a 174 MB range is a handful of queries. The same change inwrite_mappedfor the copy-back, over writable regions, leaves the rest alone as before.The comment above
copy_mappednotes thatVirtualQuerycost about 2 ms per copy in these pools; that was querying before every copy. Here it runs only on the fallback and replaces thousands of calls.A/B, one binary, same save
VICTORY_COPY_FALLBACK=pieces(diagnostics builds only) keeps the old path, so both arms are the same binary, written save, 120 s after world entry, 10 frames each:The region arm also had more content (2 823 draws/frame against 2 400). The win is bounded by what copies cost in the scene: 15 % of the frame here, and the earlier opening-cutscene frames on this machine showed
copies 1 799 msof a 4 400 ms frame, where this path is most of it.Not tested: AMD, release builds,
mainitself (the function and its callers are unchanged sinced2a4baeas far as I can tell, but I only built the tree), and the case where the title unmaps a page between the query and thememcpyof its region.Patch: https://gist.github.com/rocobalt1/1edb3c0dad03f54c05f972b95475b14c
If it is useful, a collaborator is welcome to take it as a PR; I do not have write access here.
Same shape as #776: both costs come from asking the kernel about the same pages again every submission. They are independent (copy bytes vs write-watch askings) and should stack.
AI-assisted: an agent working with the tester, which built the change and ran the A/B.
@MartinIndra02 on GitHub · 2026-11-24 10:58 UTC · original
Clean
main-based implementation ready on a fork (since PR creation is currently collaborators-only): https://github.com/MartinIndra02/VIctory/tree/perf/gpu-copy-mapped-region-fallback (based onmainffe310e).Two improvements over the gist in the description
memcpyafterVirtualQuery, each committed region is copied with a singleReadProcessMemory/WriteProcessMemorycall, and only if that call fails (a concurrent unmap/reprotect betweenVirtualQueryand the copy) does it fall back to the existing 64 KiB → 4 KiBfor_piecesloop on that region. Unmapped /PAGE_NOACCESS/PAGE_GUARDregions are still zeroed in onewrite_bytes(0, n)(or skipped inwrite_mapped).done): when the initialReadProcessMemory/WriteProcessMemoryhits the first unmapped page (ERROR_PARTIAL_COPY), Windows already copiedlpNumberOfBytesRead(done) bytes before the hole. Startingfor_regionsatstart + doneavoids re-copying the committed prefix a second time.Verification
Windows 11 Pro 26200, Ryzen 7 5800X3D, NVIDIA GeForce RTX 3080 (
621.24), Rust 1.98.1 (x86_64-pc-windows-msvc):host::batch::copy_mapped_and_write_mapped_handle_holes_across_regions: 2 MiB reserved range with two 512 KiB committed regions and two 512 KiB unmapped holes — verifiescopy_mappedcopies committed regions and zeroes holes, andwrite_mappedwrites committed regions while skipping holes.cargo test --release -p victory-gpu --lib -- --ignored --nocapture copy_mapped_hole_benchmark, 16 runs each):64 MiB (4 KiB hole at 32 MiB):136.35 ms→81.03 ms(1.68×)64 MiB (32 MiB hole at 16 MiB):608.11 ms→49.82 ms(12.21×)cargo test -p victory-gpu --lib -- --test-threads=1: 51 passed, 0 failed, 2 ignoredcargo clippy -p victory-gpu --all-targets -- -D warnings(default and--features diagnostics): 0 warningscargo xtask policy: 154 files okNo game data used. AI-assisted; all builds, tests, and benchmarks executed on my machine.
@rocobalt1 on GitHub · 2026-11-24 11:24 UTC · original
Real-title numbers for the same idea, to put next to your microbenchmark: the naive form I measured (raw
memcpyoverVirtualQueryd regions, which is the race you fixed) took 275 ms -> 120 ms per world frame in one binary with a switch, 233-302 MB copied, i.e. 1.18 -> 0.40 ms/MB. Same save, 120 s after world entry, 10 frames each arm.Your two changes both look right to me:
ReadProcessMemoryinstead ofmemcpyis the version that should ship; the race window in mine is real (the title unmaps pages of these pools while the frame is prepared, which is why the fallback exists at all), and a failed region re-entering the oldfor_piecesloop keeps today's behaviour exactly.start + doneis free: the partial copy already did the prefix, and today's code copies it twice.One caveat on what this buys, from the same machine now that the fix is in a stacked build (tree
2b1a569+ #431 + this): the world still reports copies 1 209 ms / 216 MB (5.6 ms/MB) in the scene where the title rewrites most of its big pools. So the fallback is necessary but not sufficient - in that scene the time is in the volume and in the write-watch askings (#776), not in the hole walk. With the fix the copy line stops being dominated by the pathological case; it does not make copies cheap.If it helps: RTX 4060 Ti, driver 32.0.16.1656,
TdrDelay=60machine-wide, diag build,VICTORY_SHADER_LOOP_LIMIT=32,VICTORY_NO_WATCHDOG=1. I can run your branch on this machine if you want an in-title number for the race-safe form specifically; it is main-based (ffe310e) while mine is a 50-PR tree, so the scenes will not be identical, but the copy line is comparable.@MartinIndra02 on GitHub · 2026-11-24 11:28 UTC · original
@rocobalt1 Thanks for checking the two changes and sharing the real-title numbers (
275 ms -> 120 ms/1.18 -> 0.40 ms/MB)!Yes — if you don't mind running
perf/gpu-copy-mapped-region-fallback(61474f6) on your machine, having an in-title number specifically for the race-safe per-regionReadProcessMemoryform would be very helpful to have alongside the microbenchmark.@Gruzzberry on GitHub · 2026-11-24 11:37 UTC · original
A fork branch with this change, written from the description above (not from the gist): https://github.com/Gruzzberry/VIctory/tree/gpu/copy-fallback-by-region (one commit on
mainffe310e).On the fallback,
copy_mappedandwrite_mappedwalk the range withVirtualQueryinstead of 64 KiB pieces: a region that is not committed or has no access reads as zeros (or is left alone, for the copy-back), any other is read or written in one call, and only a region the kernel then refuses is cut into 64 KiB and 4 KiB pieces as before. The first whole-range read is unchanged, so the query is still not asked on the common path.Tests build 8 MiB of address space with committed, reserved-only and no-access stretches and check the bytes that arrive, the zeros, and that the copy-back leaves the holes alone. An ignored timing test copies 8 MiB with a 4 MiB hole: 3.24 ms a copy with the old pieces, 0.48 ms with regions (debug build, RTX 4070 machine).
cargo test -p victory-gpupasses 52 tests; with diagnostics 55 pass on the RTX 4070 and on WARP, also withVICTORY_D3D12_DEBUG=1. Workspace tests (344), both clippy runs and the asset policy are clean.Not run on the title, so the frame-time effect measured above is not confirmed on my side; the case of a page unmapped between the query and the read goes to the old piece path, as the kernel refuses it.
AI use: written with Claude; tests run on an RTX 4070 and WARP.
@rocobalt1 on GitHub · 2026-11-24 11:39 UTC · original
In-title A/B of your branch, same machine and same save:
mainffe310evsmartin-copy61474f6, diag builds of each,VICTORY_NO_WATCHDOG=1,VICTORY_SHADER_LOOP_LIMIT=32,VICTORY_D3D12_DRED=1, driven into the world withVICTORY_KEYS, 90 s of settling, then the last 8 frames.ffe310emoves(the timed first attempt)So in the title the fix is -29 % on copies and -19 % on the frame, not the 12x the microbenchmark shows, and the reason is visible in the same line: the write-watch askings cost 610-671 ms/frame here, more than the copies themselves. The hole walk was never the largest term in this scene; it was the largest term in the cutscene frames where
copiesreached 1 800 ms of a 4 400 ms frame.That is not an argument against the change - it is the right shape, it removes a pathological case, and it is the version I would ship (race-safe, and the
doneprefix reuse is free). It is an argument that the next win is #776: the same askings over nested buffers, 120-180 ms in that report's runs, 610 ms in mine. With both, this frame would be about 1 196 - 570 = ~630 ms; flags not needed to see which one matters more here.Caveat: one run each, main-based (515 shaders still refuse, world black), so the scene is lighter than the 50-PR tree; the columns are comparable because both arms ran the same save and the same keys.
@DaviTostes on GitHub · 2026-11-24 11:43 UTC · original
A/B on the gap your report lists as not tested: AMD, release build, Linux/Wine, with the actual game.
Setup: AMD RX 9060 XT (RDNA4, RADV 26.3.1), Arch Linux, kernel 6.18.x; Wine 11.22 (system), DXVK 3.1.1
dxgi, vkd3d-proton 3.2.0 (Proton Experimental DLLs),WINEDLLOVERRIDES="d3d12,d3d12core,dxgi=n"; release MSVC build (cargo xwin); package 1.0.2.1,build unknown (b99f876b…b5c35a79d5decd9f716504239e93). Both runs booted withVICTORY_KEYSand reached the world.mainffe310e61474f6First 13 world lines of each (closest to a like-for-like window):
main61474f6And the subset with
copy_MB > 20(removes small-copy noise):main2955 ms / 63.2 MB = 62.6 ms/MB;61474f6559 ms / 118.6 MB = 12.9 ms/MB.On Wine the 64 KiB kernel-call fallback is especially expensive, so the region scan is a large win here: copy time roughly 3x lower and world fps about 2x, even in frames where the branch copied more MB. Caveat: these are two real runs, not the same save/frame window (no controlled save on this machine), so treat it as directional; the scene mix differs.
Both runs hit the #774 SRWLock freeze ~3 minutes into the world, so there is no longer-session number.
Not tested: Windows/NVIDIA, a same-save controlled A/B, and the race where a page is unmapped between query and copy.
@DaviTostes on GitHub · 2026-11-24 12:15 UTC · original
Tried to open this as a PR, but
CreatePullRequestis restricted for non-collaborators right now. So the branch is ready on a fork with the commit unchanged:61474f6(author @MartinIndra02, from @rocobalt1's analysis/gist)A collaborator can open it from there.
Verification I ran on the pushed commit (AMD / Linux / release, actual game):
victory-gpuunder Wine 11.22, Windows MSVC release: 51 passed, 0 failed, 2 ignored.cargo xtask policy: 154 files ok.mainffe310evs61474f6— copies 2627 ms / 56.7 MB → 610 ms / 28.6 MB per world frame; 0.32 → 0.78 fps; subsetcopy_MB > 20: 62.6 → 12.9 ms/MB. Not a same-save comparison (directional); both runs freeze at #774 ~3 min in.Not tested: the unmap-between-query-and-copy race, a controlled same-save A/B, AMD on Windows.
@MartinIndra02 on GitHub · 2026-11-24 14:24 UTC · original
Additional in-title A/B on top of the full
r4tedx/integration/testersstack (mpDom/pr/present-1440p-fallbackd6897fa, Windows 11, RTX 3080621.24, diag build,VICTORY_PRESENT_1440P=1,VICTORY_SHADER_LOOP_LIMIT=32,VICTORY_NO_WATCHDOG=1,VICTORY_D3D12_DRED=1):d6897fa): world settled at0.2 – 0.4 fps(2,733 – 4,100 ms/frame), of whichpreparingwas2,009 – 3,107 ms/frame(0device removals).perf/gpu-copy-mapped-region-fallback(61474f6ported) +#798: world ran at0.7 – 0.9 fps(1,065 – 1,398 ms/frame), withpreparingdown to631 – 837 ms/frame(0device removals,0refused pipelines).Aggregate timings only; no game data posted. AI-assisted; builds and runs executed on my machine.
@jtrudeau1530 on GitHub · 2026-11-24 16:10 UTC · original
Measured on RX 7900 XT / RADV Mesa 26.2.3, Wine 11.18, vkd3d-proton 3.2.0 (cae8353), native Microsoft d3dcompiler_47. Compared official
ffe310ewith exact MartinIndra02 commit61474f6b35, its sole parentffe310e. No other source changes, same diagnostics flags.The new hole-copy regression executed and passed under Wine. In the bounded title run, late copy windows were 187-698 ms instead of roughly 2-4 seconds on the baseline, with approximately 0.7-1.1 fps rather than 0.2-0.4. This is directional evidence, not a matched replay benchmark; work and pipeline warmup differed.
The world remained dark with translation refusals. At about 108 seconds the candidate hit the same TCP read GPUVM signature described in #714 (0x401031, permission fault, followed by device removed 0x887A0005). The earlier baseline observation ended by closing the window, so this does not establish whether the copy change caused a new regression or simply reached an existing faulty submission sooner. Holding any stability claim and reviewing the two public fault fixes in #844 before further title runs.
@0xcheems on GitHub · 2026-11-24 16:20 UTC · original
A/B of
61474f6on a Strix Halo iGPU under Proton, in case another AMD/Linux data point helps.AI use: the runs were driven and the logs summarised with Claude Code (Claude Fable 5.2) on my machine. Own copy of 1.0.2.1.
Setup: Ryzen AI MAX+ 395, Radeon 8060S (RDNA 3.5, unified memory, 32 GB, 20 GB GPU limit); NixOS, kernel 7.1.5, Mesa 26.1.5 RADV; Proton Experimental
experimental-11.0-20261112, vkd3d-proton 3.2.0. Diag builds cross-built with cargo-xwin, Series X profile,VICTORY_NO_WATCHDOG=1, driven into the world withVICTORY_KEYS, 10-minute runs. Base for both arms:ffe310e+ #493 + #454 + #190.Median over the world lines of the per-frame summary (63 to 65 lines per run):
61474f6, run 161474f6, run 2So about -35 % on the frame and roughly half the copy time here, between the Windows NVIDIA and the RX 9060 XT results above. The arms are separate runs, not the same frames.
One thing to flag, without a cause: run 1 with the commit ended at 8 min 58 s with
ring gfx_0.0.0 timeout(threadvkd3d_queue), device removed0x887A0005after a submission of 24 lists, and no GPUVM page-fault line. Run 2, the same executable, ran the full 10 minutes, as did the base run. System memory was nearly exhausted at that point (about 1 GB available), so I would not pin it on this change.@Marvisak on GitHub · 2026-11-25 03:52 UTC · original
Automated triage for the maintainers. Confirmed on
main: when the first whole-range read fails,copy_mappedincrates/victory-gpu/src/host.rsretries the whole range in 64 KiB pieces, then 4 KiB, with one kernel call per piece (for_pieces), andwrite_mappeddoes the same for the copy-back. The cost grows with the size of the range, not with how much of it is unmapped.Open PR #943 carries the region-walk fallback (the race-safe per-region form from the comments, also starting after the bytes already copied). The in-title A/B runs here (Windows NVIDIA, and AMD under Wine) all show shorter copy times. One Wine run hit the #714 page fault, and nothing so far ties that to this change.
Generated by Claude Code