fix(gpu): stop copy_mapped on non-writable title destinations instead of faulting #3358
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3358"
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?
Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-26T20:25:35Z.
Summary
copy_mapped(dst, src, len, title_dst = true)fails its initialReadProcessMemorycall because the destination contains committedPAGE_READONLY(or execute-only) pages,crate::texture::committed(dst, len)previously returnedtrue(sincecommittedonly rejectsPAGE_NOACCESS | PAGE_GUARDfor readable sources).read()on each 4 KiB piece and executedunsafe { to.write_bytes(0, n) }, causing an immediate access violation on the read-only title destination.writable(dst, len)check (requiringMEM_COMMIT, noPAGE_NOACCESS | PAGE_GUARD, and a writable base protection) before entering the fallback fortitle_dst, and routestitle_dstzero-fills throughread(ZERO_4K.as_ptr(), to, n)so concurrent protection changes cannot fault either.title_copies::title_copies_do_not_fault_on_read_only_destinationsusingVirtualProtect(..., PAGE_READONLY).Verification
cargo clippy -p victory-gpu --all-targets --target x86_64-pc-windows-msvc --locked -- -D warningscargo test -p xtask --lockedImported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T20:29:00Z.
Review: APPROVED
LGTM — verified on Windows against
origin/main(63bcca4).writable(dst, len)(instead of onlycommitted) and usingread(ZERO_4K.as_ptr(), to, n)ontitle_dstpreventscopy_mappedfrom faulting on read-only title destination pages during the fallback path.cargo test -p victory-gpu --lib host::title_copies:: -- --test-threads=1: 3 passed, 0 failed (includingtitle_copies_do_not_fault_on_read_only_destinations).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T22:29:12Z.
Windows 11,
63bcca4+ this PR, Radeon RX 7900 XTX:host::title_copies::title_copies_do_not_fault_on_read_only_destinationsby name: 1 passed (the test lives inhost::title_copies, not inhost::tests).cargo test -p victory-gpu --lib: 232 passed / 0 failed / 1 ignored (unpatched63bcca4here: 231).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.Synthetic only. AI-assisted.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T23:15:15Z.
Review: APPROVED
Reviewed
ec8343cbmerged ontomain(63bcca43) — solid fix eliminating faults on non-writable title destinations with zero fast-path overhead.Verification
cargo xtask policy: 191 files ok;cargo clippy --locked -p victory-gpu --all-targets -- -D warnings(both default and--features diagnostics): 0 warnings.host::title_copies::(3/3, including the newtitle_copies_do_not_fault_on_read_only_destinationstest) passed on both RTX 5090 and WARP with--features diagnosticsandVICTORY_D3D12_DEBUG=1.writable(crates/victory-gpu/src/host.rs:2542-2575), theZERO_4Kfallback (host.rs:2516, 2528, bounded byfor_pieces's 4 KiB step), and allcopy_mappedcallers (host.rs,texture.rs) — early returns leave no mismatched mappings or leaks, and normal writable copies never incurVirtualQuery.writableandcopy_mapped(..., title_dst = true)reject and stop cleanly without faulting onPAGE_NOACCESS,PAGE_EXECUTE_READ,PAGE_READWRITE | PAGE_GUARD, cross-regionRW + MEM_DECOMMIT + RW, andusize::MAXaddress overflow, while allowing and copying cleanly toPAGE_READWRITE | PAGE_NOCACHEandPAGE_EXECUTE_READWRITE(pluslen == 0).copy_mapped(triggering the 4 KiBZERO_4Kfallback) while a concurrent thread continuously flipped the middle destination block betweenPAGE_READWRITEandPAGE_READONLY(116,111–124,113concurrentVirtualProtectflips): 0 faults.LGTM.
Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-27T11:35:51Z.
A measurement and one dead end, both from
copy_mappedon Intel Arc B580 with the game (origin/main63bcca43+ #2958, diag build, world frame):The fallback path is worth this PR's attention. In the world the diagnostics report
167.8 fallbacks (77.6 ms), i.e. ~0.46 ms each — about 6 % of a 1,200 ms frame spent entirely on copies that met an unmapped page. Anything that keeps a copy out of the fallback is measurable, so yourcommitted()check is on the right track.One shortcut that does not work, so nobody spends a day on it: resuming the piecewise walk where the kernel stopped, instead of starting it again at the beginning.
ReadProcessMemory'slpNumberOfBytesReadis 0 when the call fails partway, not the count it transferred, so the fault offset is not available that way. I checked it with a test rather than by reading the docs: a 3 × 64 KiB source whose middle block is unmapped copies through this path, and a counter on the bytes the fallback re-reads came back at196608— all three blocks, the full range, withdone == 0. So the leading bytes are copied twice on every fallback, and there is no cheap way to know where the hole was; the win has to come from not entering the fallback (as you are doing, and as #3125 argues for the 64 KiB page bookkeeping).The existing doc comment on
copy_mappedexplains whyVirtualQueryis not asked before each copy, but not this; worth one line if you touch that comment, since the resume-looking fix is the natural one to try.Nothing here argues against your change — I have not run it. Synthetic tests only in the tree; the numbers are my own dump. Machine: Windows 11 x64, Ryzen 5 5600, 32 GB, Arc B580 12 GB.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.