GPU: index withheld ranges during copy-back #3216
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!3216
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3216"
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?
@yumaste on GitHub · 2026-11-26 13:24 UTC · original
yumaste:perf/index-withheld-copyback→main· +134 −32 · 2 files · 3 commits · openProblem
When a GPU submission withholds writes after a memory miss, the host scans all initially withheld ranges for each declared write. It then scans the final withheld ranges again for each marked page. Both scans include ranges owned by other shadows.
Change
Index larger sets by shadow identity and start address, with the maximum end seen so far for each shadow. Each write or page then needs one binary search. Sets of 32 ranges or fewer still use a linear scan. Declared writes are checked against the original withheld set, and marked pages see the final set after that pass. This preserves the existing overlap and whole-page rules.
Synthetic benchmark
Medians of 20 interleaved runs on Windows, Core Ultra 9 275HX, Rust 1.98.1 with
-C opt-level=3. Each case distributes ranges and pages over 128 shadows. It measures building the range sets and checking declared writes and marked pages. Both implementations produced identical decisions. The benchmark excludes bitmap readback, waiting for the GPU and writing bytes to guest memory.Validation
victory-gpulibrary suite with diagnostics: 247 passed, 1 ignored. Strict Clippy and the asset policy check passed.Integration notes
A trial merge with #3211 succeeds. Trial merges with #3099 and #1998 conflict in
host.rsandshadow.rsbecause they change the input and meaning of withheld ranges. Keep their original range data for the behavior change and use an index for overlap queries. #3145 and #3165 conflict inshadow.rsaround mark processing. Their mark-owner lifetime fix must remain outside the marks lock when combining it with the indexed query.Coordination claim. No game files used. AI-assisted (Codex).
@Dukestar69 on GitHub · 2026-11-26 13:27 UTC · original · approved these changes
Verified on RTX 5090 against
origin/main(63bcca4):cargo test -p victory-gpu --lib shadow:: -- --test-threads=1: 11/11 passed (includingwithheld_index_matches_overlap_scan).cargo test -p victory-gpu --lib host::withholding -- --test-threads=1: passed.cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Cleanly indexes withheld ranges during copy-back to avoid repeated linear overlap scans.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@AurumCarlos on GitHub · 2026-11-26 14:07 UTC · original · reviewed
The index is correct. Sorted by
(shadow, start)with a running max end per shadow, the last entry with(copy, start) < (shadow, to)is the latest range of that shadow starting beforeto, and the overlap test reduces tofrom < max_end. That matches the old predicate, including empty ranges (start == end), whichwithheld_index_matches_overlap_scancovers. The host side also keeps the old two-pass behaviour: declared writes are checked against the initial set, marked pages against the final one, with no further propagation. Keeping identities asusizeis fine becausebackholds theArcs until aftercopy_back_marks, as your comment says.Two remarks:
1. The edited test lost a case. In
marked_pages_go_back_by_the_bytes_the_gpu_changed, page 2 used to be unmarked ("page 2 not marked"): it checked that a page nobody marked keeps the title's bytes and that the copy's byte there isn't put back. Now page 2 is marked and withheld, and the assertions are the same, so the test passes either way and the unmarked path is no longer exercised. Using a fourth page for the withheld case (the pool would need 4 pages) would keep both.2. Other open PRs use the old signature.
copy_back_marksnow takes&Withheldinstead of&[(Arc<Shadow>, usize, usize)]. #3099 ("drop only marked pages for withheld marked ranges") and #1998 ("keep valid marked writes beside withheld ranges") both change what a withheld range does in this same function, and both build and pass the slice. #3145 and #3165 rewrite the top ofcopy_back_marks. You've trial-merged with #3211. A note in the description about the ones that would conflict (or a quickgit merge-treeagainst #3099/#1998) would help whoever merges them in sequence.@yumaste on GitHub · 2026-11-26 14:22 UTC · original
The test now uses a fourth page for the withheld case (
e4994f8, with the merge cleanup in2a3b636). Page 2 stays unmarked and page 3 is marked and withheld. Both preserve the title's bytes. All 10 shadow tests passed under WARP. I also documented the four trial-merge conflicts in the description and rechecked that #3211 merges cleanly.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.