GPU: use VirtualQuery region fallback in copy_mapped and write_mapped #943
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!943
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-943"
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?
@MartinIndra02 on GitHub · 2026-11-24 14:24 UTC · original
MartinIndra02:perf/gpu-copy-mapped-region-fallback→main· +222 −9 · 1 files · 2 commits · openCloses #783
Summary
Replaces the 64 KiB → 4 KiB page-by-page fallback in
copy_mappedandwrite_mapped(crates/victory-gpu/src/host.rs) with a race-safeVirtualQueryregion walk:ReadProcessMemorycall; if a page is concurrently unmapped/reprotected betweenVirtualQueryand the copy, only that region falls back to the existing 64 KiB → 4 KiBfor_piecesloop. Unmapped /PAGE_NOACCESS/PAGE_GUARDregions are zeroed in onewrite_bytes(0, n)(or skipped inwrite_mapped).done): When the initial whole-rangeReadProcessMemorystops at the first unmapped page (ERROR_PARTIAL_COPY), the region walk starts atstart + doneinstead of re-copying the committed prefix.Verification (Windows 11, RTX 3080
621.24, Rust1.98.1)host::batch::copy_mapped_and_write_mapped_handle_holes_across_regions: 2 MiB reserved range with alternating 512 KiB committed regions and 512 KiB unmapped holes.copy_mapped_hole_benchmark, 16 runs each):64 MiB (4 KiB hole):136.35 ms→81.03 ms(1.68×)64 MiB (32 MiB hole):608.11 ms→49.82 ms(12.21×)@rocobalt1on61474f6vsffe310e:-29%copies (792 -> 564 ms),-19%frame time (1,484 -> 1,196 ms).r4tedx/integration/testers(d6897fa, RTX 3080):preparing2.0–3.1 s→0.63–0.84 s, world0.2–0.4 fps→0.7–0.9 fps,0device removals.cargo test -p victory-gpu --lib -- --test-threads=1: 51 passed, 0 failed, 2 ignoredcargo clippy -p victory-gpu --all-targets -- -D warnings(default +--features diagnostics): 0 warningscargo xtask policy: 154 files okNo game data used. AI-assisted; all builds, tests, and benchmarks executed on my machine.
@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
61474f6:cargo test -p victory-gpupasses, 51 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
@TG0000 on GitHub · 2026-11-24 16:26 UTC · original
Thanks, the region walk is worth having: ported into a lab build here (RX 6800, Windows 11), the read side gives the same submission time as a separate implementation of ours (551.0 against 551.2 ms per frame of 36 submissions, 8 paired frames in one launch), so we use this one as our base. That measures submission work only, not frame rate.
One thing to fix on the write side at
61474f6:write_mappedresumes atdst + doneafter a failedWriteProcessMemory. When the destination is what fails,donecan be larger than what was delivered: in 99 of 60,000 attempts here it was up to 16 bytes too high. Example: a write starting 8 bytes before the hole returned a count of 8 and delivered nothing. Those bytes are then never written, so title memory keeps the old ones. (Windows 11 build 26300, not Wine.)Suggestion: on the write side ignore the count and restart the walk at
dst. A write of bytes already delivered repeats the same data, except if the title wrote them in between. (Edit: an earlier version of this comment also suggested stepping back to a page boundary; that would still skip the bytes of the example, please ignore it.)The read side looks fine: when the source fails the count was never too high in about 30,000 failures. It often stops up to 64 KiB short of the hole, which the walk then covers.
AI-assisted (Claude Code); the write count was measured, the rest is from reading the diff.
@MartinIndra02 on GitHub · 2026-11-24 16:34 UTC · original
@TG0000 Great catch — thank you for measuring that on native Windows 11!
Updated in
12cfd38:write_mappednow ignoresdoneon a failedWriteProcessMemoryand restarts theVirtualQueryregion walk fromdst, so no committed prefix bytes right before an unmapped hole can be skipped.doneprefix skip on thecopy_mappedread side.host::batch::copy_mapped_and_write_mapped_handle_holes_across_regionsto testwrite_mappedstarting1, 4, 8, 16, 24, 32bytes before an unmapped hole and assert every prefix byte is written.Re-verified on Windows 11 / RTX 3080 (
621.24):victory-gpu51 passed, 0 failed, 2 ignored, both CI clippy configs (-D warnings) clean,cargo xtask policy154 files ok.@Marvisak on GitHub · 2026-11-25 01:17 UTC · original
Automated triage for the maintainers.
Needs rebase. This pull request conflicts with
main(conflicting:crates/victory-gpu/src/host.rs). It will be reviewed once it is rebased onto the currentmain.Generated by 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.