perf(gpu,hle): optimize view-memory guards, xmem alias mapping, texture waits, and relay card copy-back #824
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!824
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-824"
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?
@powplusplus on GitHub · 2026-11-25 09:19 UTC · original
powplusplus:perf/fast-watch-guards→main· +1282 −312 · 6 files · 1 commits · openSummary
Cuts CPU-side frame preparation, lock contention, and copy-back overhead in the 3D world from
0.1-0.2 fps(4,244-6,146 ms/frame, GPU 5-18% busy) to1.9-2.0 fps(498.7-536.7 ms/frame, GPU 71% busy) on RTX 3080 under GE-Proton11-14.Root Causes & Fixes
View-memory guards (
crates/victory-gpu/src/watch.rs,inplace.rs):BTreeSet<usize>tracking inGuards(protected,clean,absent,aliased) with a coalescing half-open intervalRangeSet(BTreeMap<usize, usize>), reducing 174 MiB heap checks to a single O(log intervals) lookup.Guards::holes) from reserved section views (MEM_MAPPED | MEM_RESERVE), adding placeholder holes tocleanuntiltitle_memory_remappedremoves them. Eliminates thousands ofVirtualQuerysyscalls per frame on sparse view buffers while preservingVirtualAlloc(MEM_COMMIT)detection on reserved section views.GUARDSfromMutextoRwLockwith read-first fast paths inwrites_since_kind,guard,ask_once,writing,title_memory_written, andtitle_memory_remapped.VirtualProtectcalls inprotect_hereandopen_here.GUARD_GENandJournal::ahead_guardedto cache guarded view-memory checks across a submission inask_once, plusJournal::last_writeandwrites_since_kindsotexture.rsavoids duplicatewatch::writescalls.inplace::pages_ofcalls insidewatch::protectwith single-lockinplace::aliased_pages_inthat checks view count bounds before allocating, eliminating thousands of temporaryVeccopies of filler-page view lists. Stored single-view mappings inline inPageSet(One(usize)/Many(BTreeSet<usize>)).Shadow refresh fast path (
crates/victory-gpu/src/shadow.rs,texture.rs):Shadow::all_copiedand zero-page tracking inShadow::copied, plusShadow::copy_stale_sparse, so unchanged refreshes skip per-page scans in O(1).VICTORY_TEXTURE_NO_WAITby default (VICTORY_TEXTURE_NO_WAIT=0to wait onMAPPING.read()), eliminating multi-second texture stalls whilexmemremaps streaming pages.Physical page alias mapping (
crates/victory-hle/src/modules/xmem.rs):Physical::shownwith inline single-viewShownPages(One(usize)/Many(HashSet<usize>)), replacing O(N)Vec::retainscans on the filler page while holdingMAPPING.write().map_aliasinto a single view mapping (withMEM_COALESCE_PLACEHOLDERSand page-by-page fallback across split placeholder boundaries).Card copy-back relay (
crates/victory-gpu/src/host.rs,shadow.rs):relay_card_backbeforeCopyBufferRegionandcard_merge_relay, with 64 KiB chunk fallback incard_merge_relaywhen a coalesced span crosses unmapped memory.VICTORY_WIDE_MERGEby default (VICTORY_WIDE_MERGE=0for single-threaded) and parallelizedrelay_card_backmerges across up to 8 workers grouped by shadow to avoidShadow::beforelock contention.Benchmarks (RTX 3080, GE-Proton11-14, live 3D world)
Measured against baseline (
8dd30ab+#737latch fix) on the same binary path and vkd3d-proton shader cache:0.1-0.2 fps(4,244-6,146 ms)1.9-2.0 fps(498.7-536.7 ms)5-18%(2,789-5,817 msidle)71%(47.1 msidle)copies1,324.7-2,545.7 ms37.6-63.6 mstextures(MAPPING.read()wait)1,382-4,566.9 ms(2,104-4,175.7 mswait)5.0-8.0 ms(0.0 mswait)411/frame, 1,170.4 ms(max127.9 ms)3.0/frame, 4.6 ms(max2.2 ms)534-846 ms(pre-coalesce relay3,280 ms)60.3 ms(61.0 MB, 956 pieces)Verification
origin/main(9376fd6), preservingVICTORY_VIEW_ASK,WatchKnownView/WatchFailed,Tracked, andVICTORY_CARD_FETCH_INFLIGHT.cargo clippy --target x86_64-pc-windows-gnu -p victory-gpu -p victory-hle --all-targets(default and--features diagnostics): zero warnings in touched files.watch::*:14/14passed (including newrange_set_merges_splits_and_queries_gapsandplaceholder_holes_join_clean_until_remapped)shadow::*:28/28passedinplace::*:6/6passedhost::*/descriptor::host::*/pipeline::host::*:34/34passed (1 ignored benchmark)xmem::*:13/13passed (including newmap_alias_coalesces_consecutive_pages_and_split_placeholders)@chatgpt-codex-connector[bot] on GitHub · 2026-11-25 09:20 UTC · original · edited 2026-11-25 09:29 UTC
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
9dae0a7ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
@MamaLeVrai on GitHub · 2026-11-25 09:54 UTC · original
Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present. I merged this PR's head
9dae0a7intomain9376fd6in a throwaway tree (no conflict).cargo clippy --workspace --all-targets --locked -- -D warningsfails, with the same two errors asmainitself on this machine (function placed_filler_twins is never used,field depth_written is never read,victory-gpu): this PR adds none and removes none.cargo test --workspace --locked: first run 543 passed, 0 failed, 10 ignored (mainalone: 540 passed). In the second run thevictory-gputest binary died withSTATUS_ACCESS_VIOLATION(0xc0000005) after 40 tests, so the run stopped there. I did not find which test it was, and I have not reproduced it since;mainalone did not crash in its two runs. The title was not run, so this says nothing about in-game effect. No game data.AI-assisted (Claude Code); no game data.
@npanu420 on GitHub · 2026-11-25 10:07 UTC · original
Fixes for the three review findings above, as three commits on top of this PR's head
9dae0a7: https://github.com/npanu420/victory-fork/commits/fix-824-review (cherry-pick or merge as you like).17c0505,shadow.rs): a failed coalesced read is retried in slices cut at absolute 64 KiB title-page boundaries, whatever the trimmed span's size. Testa_relay_merge_writes_the_mapped_side_of_a_page_boundary(changes atPAGE-1andPAGE, the second page uncommitted) fails before the fix: the mapped byte stayed 0.4732b8c,host.rs,shadow.rs):relay_merge_groupssweeps the shadows' title ranges, so transitively overlapping or nested ones share one serialized group, in their original merge order. Disjoint ones still go to separate workers. Testoverlapping_shadows_merge_in_the_same_group.3c649db,watch.rs,xmem.rs): only reservations thatQueryVirtualMemoryInformationconfirms as placeholders are cached as clean. Ordinary and free ones stay inabsent.XMemVirtualAlloccommits go throughcommit_title_memory, which opens guards first and clears the cached state afterwards. Testa_private_reservation_beside_a_view_is_checked_after_commitfails before the fix.Results on Windows 11, RTX 3070:
cargo test -p victory-gpu --features diagnostics --lib -- shadow host watch relay: 86 passed (83 at9dae0a7), 1 ignored benchmark.victory-hlexmem tests: 13 passed.draw.rsunnecessary_sort_byanddepth_writtenwarnings remain.Not yet run in game on its own. Our in-game runs have this PR merged into a larger stack.
(AI-assisted: drafted with Codex and reviewed with Claude Code. No game data.)
@MamaLeVrai on GitHub · 2026-11-25 10:09 UTC · original
Follow-up to my test report above: the
STATUS_ACCESS_VIOLATIONin the second full run did not come back. On this PR's tree (head9dae0a7merged intomain9376fd6), 4 further runs ofcargo test -p victory-gpu --liball passed (146 passed, 3 ignored each). I still do not know which test died the first time, so I cannot say it was not this PR; I can only say I could not reproduce it.AI-assisted (Claude Code); no game data.
@sagouindupm on GitHub · 2026-11-25 11:33 UTC · original
Tested #824 (
9dae0a7) combined with #827 (f681125) on Windows 11 Pro (Intel i5-12400F, 32 GB RAM, NVIDIA GeForce RTX 3050 8 GB) under--console series-s, A/B against the same local base (9376fd6+ #188 + #518 + #610 +VICTORY_LITE=1280x5120, 20 samples from 100 s to ~290 s):bench_k0): entered 3D draws at sample 10/20, max spike 2,357.9 ms/frame, ended at 234.3 ms/frame (2711 draws), walls intact.bench_k1): entered 3D draws at sample 2/20, peak spike across all 20 samples 628.3 ms/frame (no multi-second spikes), last 5 samples 211.9–225.8 ms/frame (mean 218.5 ms/frame, ~4.6 FPS; log peak 4.9 fps / 205.2 ms/frame), walls intact, zero crash during the run.(Note: #824 and #827 were tested together on the same branch.) Next up on our side is testing @npanu420's 3 review-fix commits (
npanu420:fix-824-review).AI-assisted: benchmark analysis and write-up prepared with AI assistance.
@NotADonky43 on GitHub · 2026-11-25 21:06 UTC · original
Related native Windows reproduction, independent of the performance stack: map three adjacent 64 KiB pages separately, return them to placeholders, then remap the range to three consecutive pages of the same committed section. The larger replacement can fail because it spans three separate placeholders, even though the addresses and section offsets are contiguous. This is consistent with
MapViewOfFile3requiring the replacement to match one placeholder exactly.A candidate that respects the returned boundaries instead of coalescing them passed both a targeted Windows test and full GPU texture readbacks. It tries the whole view first and only partitions a proven split on a replacement failure; it does not retry a commit failure or suppress invalidation. Tested on Windows with an RTX 5070 Ti, no game files required. This confirms the failure mode #824 deals with, not its end-to-end performance numbers. Keeping GPU/CPU copy-back ordered relative to the remap is a separate issue.
The standalone patch below applies to
085ee7c(not to this PR's head). All 14 XMem tests passed on that base, including two new Windows regression cases. The GPU check was run on the combined local candidate; the diff below contains only the placeholder fix and its Windows tests.Source-only diff: respect existing placeholder boundaries (12 KB)
@UwUCammie on GitHub · 2026-11-25 22:46 UTC · original
I tried the readback-command coalescing idea on the RX 7900 XT with 16 KiB pieces. My local variant only joins consecutive CopyBufferRegion calls when the source resource, source offsets and destination offsets all continue. It keeps the CPU merge pieces and their original order. This tests one part of the proposal, on a different integration build.
In the first room it removed 4,152 copy commands per frame. Median readback was 75.1 MB/frame at 16.5 ms on the copy queue. A preceding run with ordinary commands measured 77.2 MB/frame at 4.8 ms. The two sessions averaged 5.25 and 8.87 successful presents/s with 4,931 and 4,854 draws/frame respectively. The joined run also had substantially longer CPU preparation and GPU waits. One run each under shared system load; I can verify the command reduction, but can’t attribute the frame-time difference to coalescing. RADV 26.3.1, Wine 11.22, vkd3d-proton v3.1-83.
@ -3300,0 +3417,4 @@let mut written = 0;let mut off = 0;while off < n {let chunk = (n - off).min(crate::watch::PAGE);@chatgpt-codex-connector[bot] on GitHub · 2026-11-25 09:29 UTC · original
When adjacent flagged pieces straddle mapped and unmapped title memory, trimming to the first and last differing bytes can leave
n <= PAGEeven though the span crosses the mapping boundary. For example, changes at offsets 65535 and 65536 produce a two-byte read that fails, bypassing this fallback. The subsequent merge advancesheldwithout writing the changed byte in the mapped page, permanently losing that GPU result; merging the pieces separately preserves it. Split failed coalesced reads at actual title-page boundaries even when the trimmed span is smaller thanPAGE. Fixed-size chunks starting at the trimmed offset can also straddle those boundaries.Useful? React with 👍 / 👎.
@ -4536,0 +4550,4 @@for item in pieces {match groups.last_mut() {Some(g) if std::sync::Arc::ptr_eq(&g[0].0, &item.0) => g.push(item),_ => groups.push(vec![item]),@chatgpt-codex-connector[bot] on GitHub · 2026-11-25 09:29 UTC · original
When at least four dirty runs trigger parallel merging, different shadows backed by overlapping title memory can enter separate workers. Such shadows are supported:
shadow::registerandlookupretain separate copies for overlapping or nested buffers. Grouping only byArcleaves theirbeforemutexes independent, so both workers can read the same title snapshot, merge different GPU changes, and then overwrite each other's results whencard_merge_relaywrites its entire first-to-last-difference span. The previous relay loop serialized these read-modify-write operations. Keep overlapping destinations in the same serialized group rather than treating distinct shadows as necessarily disjoint.Useful? React with 👍 / 👎.
@ -708,0 +1073,4 @@if block < until {if info.State == MEM_FREE || info.Type != MEM_MAPPED {g.holes.insert_range(block, until);g.clean.insert_range(block, until);@chatgpt-codex-connector[bot] on GitHub · 2026-11-25 09:29 UTC · original
When a guarded window spans a mapped view and an ordinary private reservation,
Type != MEM_MAPPEDputs the reservation intocleanas though it were an immutable placeholder.XMemVirtualAlloccan subsequently commit those private pages without callingtitle_memory_remapped, so the clean-range fast paths continue reporting no changes and leave the GPU copy holding the previous zeros. The previous implementation kept these blocks inabsentand detected the commit throughuncommitted_end. Keep ordinary reservations subject to rechecking, or add commit notifications before caching them as clean holes.Useful? React with 👍 / 👎.
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.