GPU: scan all sub-regions before marking a 64 KiB page unmapped #3125
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!3125
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3125"
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?
@fuzeofficlal on GitHub · 2026-11-26 09:12 UTC · original
fuzeofficlal:fix/gpu-watch-partial-commit-pages→main· +179 −5 · 2 files · 1 commits · openSummary
In
crates/victory-gpu/src/watch.rs,protect_notingchecks whether a 64 KiB page (PAGE) thatVirtualProtect(..., PAGE_READONLY)failed on is unmapped by callingVirtualQueryonce atpage * PAGEand testingn == 0 || info.State != MEM_COMMIT.Because Windows commits memory at 4 KiB granularity while
watch::PAGEis 64 KiB, a 64 KiB block whose leading 4 KiB OS page isMEM_RESERVEand whose remaining 4 KiB sub-pages areMEM_COMMITreturnsinfo.State == MEM_RESERVEwithinfo.RegionSize == 4096.unmapped(page)then returnstrue, which causes:take_splitto classify the entire 64 KiB page asunmappedsoShadow::update_trackedzero-fills all 64 KiB in the host shadow buffer, discarding live committed title data (even thoughhost::copy_mappedalready supports 4 KiB fallback copies for partially committed blocks).protect_notingto include the page intaken, removing it fromchanged(and marking the tracker clean) even though the committed sub-pages could not be guarded, so subsequent CPU writes to those sub-pages are silently missed.guard_aliases,Tracked::taken, andtitle_memory_aliased(which all go throughprotect) to treat partially committed pages as guarded.Changes
crates/victory-gpu/src/watch.rs:unmappedinsideprotect_notingto walk allVirtualQuerysub-regions across[page * PAGE, (page + 1) * PAGE)and returnfalseas soon as any sub-region hasinfo.State == MEM_COMMIT. Fully unmapped/reserved 64 KiB pages (RegionSize >= PAGE) still finish in a singleVirtualQuerycall.watch::tests::partially_committed_pages_are_not_taken_as_unmappedcovering leading-reserved/tail-committed pages,Tracked::taken, and transitioning to guarded/clean once the full 64 KiB page is committed.crates/victory-gpu/src/shadow.rs:shadow::tests::partially_committed_page_copies_committed_tail_and_tracks_updatesverifying end-to-endShadow::updatecopies committed sub-pages and picks up later title writes instead of zeroing the host buffer and marking it clean.Testing
main(63bcca43) before the fix (watchclassifies the partially committed 128 KiB range as zero-fill/unmapped;shadowreads[0]instead of0xDEAD_BEEFfrom the committed tail).cargo test -p victory-gpu --locked --lib -- --skip lists_share_a_table_and_copies_keep_their_views --skip dynamic_slots_are_held_until_released(RTX 5090): 231 passed, 0 failed, 1 ignored.VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --locked --features diagnostics(WARP): 248 passed, 0 failed, 1 ignored.cargo clippy --workspace --all-targets --locked -- -D warningsand--all-features: clean.cargo test -p xtask --locked policy::tests::repository_passes_policy: passed.@Marvisak on GitHub · 2026-11-26 09:20 UTC · original
Automated triage for the maintainers.
Merge candidate. The
unmappedcheck inprotect_noting(crates/victory-gpu/src/watch.rs) made a singleVirtualQueryatpage * PAGE, which reports only the first region. So a 64 KiB page with a reserved head and a committed tail counted as unmapped:take_split/Shadow::update_trackedzero-filled it and dropped it fromchanged. The new loop walks the page's regions, returns false at the firstMEM_COMMIT, and stops if a region fails to advance. It runs only afterVirtualProtecthas already failed. Both new tests build a real partial commit withVirtualAllocand check the copy, the dirty state, and the switch to guarded once the page is fully committed. One cost to know about: a page that stays partly committed is never guarded, so it is copied at every refresh. That is correct, but it will show in the copy statistics.CI:
checkpassing.Generated by Claude Code
@Dukestar69 on GitHub · 2026-11-26 09:26 UTC · original · approved these changes
Verified on RTX 5090 against
origin/main(63bcca4):cargo test -p victory-gpu --lib watch:: -- --test-threads=1: 16/16 passed (includingpartially_committed_pages_are_not_taken_as_unmapped).cargo test -p victory-gpu --lib shadow:: -- --test-threads=1: 11/11 passed (includingpartially_committed_page_copies_committed_tail_and_tracks_updates).cargo test -p victory-gpu --lib host::title_copies:: -- --test-threads=1: 2/2 passed.cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Cleanly scans all sub-regions before treating a partially committed 64 KiB page as unmapped.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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.