perf(gpu): reservation-aware write-watch batching, lock-free view/non-watched bitsets & Wine/Proton compatibility #207
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/207"
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 trustno1-coder/VIctory-NVIDIA. Originally posted by jocost4 on 2026-11-27T19:43:23Z.
Summary
A set of low-risk, zero-regression performance and Wine/Proton compatibility improvements for
victory-gpu(default Windows behavior is preserved everywhere; all tuning knobs are opt-in via environment variables):1. Write-watch & guard optimizations (
crates/victory-gpu/src/watch.rs)ask_once+RESERVATIONScache: CachesVirtualAllocreservation spans (AllocationBase..end) soask_onceonly mergesGetWriteWatchranges within the same reservation — eliminating cross-reservationGetWriteWatchfailures and binary splits.Asking::hold_many: ReplacesAsking::hold_all()(0..usize::MAX) inask_oncewith atomic range holding for only the queried spans, allowing unrelated memory (e.g. shader-visible descriptor heaps insync_heapsand texture refreshes) to proceed concurrently.KNOWN_VIEWandSINGLE_NOT_WATCHEDbitsets:KNOWN_VIEWmarks blocks confirmed asMEM_MAPPEDview memory insideprotect_here(cleared ong.foreignand alltitle_memory_*invalidations).SINGLE_NOT_WATCHEDonly marks isolated single 64 KiB blocks (last - first == 1) whereGetWriteWatchfailed (never poisoning adjacent write-watched blocks).writes(..., false)before acquiringAsking::hold, avoiding redundant lock/condvar churn on known view memory (e.g.texture.rs).placeholder()fallback: Falls back toVirtualQuery(MEM_RESERVE && PAGE_NOACCESS) whenNtQueryVirtualMemory(class = 7)returnsSTATUS_INVALID_INFO_CLASSunder Wine/Proton (zero impact on native Windows, whereNtQueryVirtualMemorysucceeds). Reduces hole queries from ~15,000/frame to ~8–48/frame under Proton.to <= endprogress guards inallocation_end/reservation_ofand callsforget_reservationsoutside theGUARDSlock intitle_memory_unmapping/title_memory_freed.VICTORY_AHEAD_GAP_KB(default8192= 8 MiB, unchanged on Windows; setting e.g.256on Wine/Proton avoids scanning megabytes of unused pages under Wine'svirtual.clock).2. Additional low-overhead improvements
crates/victory-gpu/src/shadow.rs: Short-circuitswide_eachforn == 0andn == 1to avoid worker pool wakeups for trivial work.crates/victory-gpu/src/host.rs: SetshbrBackgroundtoBLACK_BRUSHinmake_windowto avoid a white/blue uninitialized window flash before the firstPresent().crates/victory-gpu/src/draw.rs: Makes buffer-heap rescan cadence configurable viaVICTORY_HEAP_RESCAN_FRAMES(default16, unchanged).crates/victory-gpu/src/texture.rs: Makes guarded texture blind-write hash cadence configurable viaVICTORY_TEXTURE_HASH_EVERY(default8, unchanged).Verification
x86_64-pc-windows-msvc(cargo xwin check --release -p victory --target x86_64-pc-windows-msvc, 0 new warnings).preparingtime from ~200+ ms down to ~50–55 ms/frame (copies~11–12 ms,textures~5–6 ms,ask_once~14–19 ms,heaps_wait~4–5 ms) with GPU utilization reaching 88–92%.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by domx4q on 2026-11-27T21:42:24Z.
Independent confirmation of the Wine/Proton placeholder fallback in this PR, from a separate setup.
Setup: i9-14900KF, RTX 4090 (driver 620.73), Proton with vkd3d-proton, Linux 7.3, headless gamescope, prologue (prison cell), 1080p -> 1440p DLSS Quality. Same save, same scene, 60 s average per run.
I hit the same problem independently. On Wine,
NtQueryVirtualMemory(..., MemoryRegionInformationEx)returnsSTATUS_INVALID_INFO_CLASS, sowatch::placeholder()never learns that a hole is a placeholder. In my profile that meant ~16,000 VirtualQuery calls per frame under the guards' lock (ntdll.so:get_basic_memory_infowas the hottest symbol in thevictory-widethreads).My local fix was slightly different: a small
BTreeMapof the runtime's ownMEM_RESERVE_PLACEHOLDERreservations, filled fromxmem.rsand cleared intitle_memory_freed, used only after the host has once answeredSTATUS_INVALID_INFO_CLASS. Result on top ofVICTORY_PIPELINE_WAIT_MS=0: 18.6 -> 20.5 fps, "preparing" ~45 -> ~31 ms/frame. Your version covers the same case, so I'm not opening a separate PR. I'm happy to post my diff if a second variant is useful for comparison.Not tested on Windows by me (the new path only runs when the host rejects the info class, which Windows doesn't).
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by jocost4 on 2026-11-28T00:34:45Z.
Thanks for the independent numbers, @domx4q — good to see the same ~16k queries/frame bottleneck confirmed on a 4090 setup too.
Your
BTreeMapapproach fromxmem.rsis actually cleaner for distinguishing realMEM_RESERVE_PLACEHOLDERspans from plainPAGE_NOACCESSreservations (and avoids theVirtualQuerycall altogether onceSTATUS_INVALID_INFO_CLASSis seen). Feel free to drop your diff here if you'd like — happy to compare or fold it in if maintainers prefer that variant.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by POMXARK on 2026-11-28T02:11:06Z.
Testing feedback on Windows 11, AMD Ryzen 7 5700X (8C/16T), NVIDIA RTX 5080 16 GB, 32 GB RAM, Series X 1440p + DLSS Quality + DLSS MFG 4× (
4 MiBwindows).Full disclosure: tested on a fork branch based on
v2026.11.27.7(with local GPU patches +x86-64-v3/ThinLTO), porting only thewatch.rschanges (reservation_of,Asking::hold_many,KNOWN_VIEW,SINGLE_NOT_WATCHED, fusedask_oncewith sortedahead_normalizepreserved for PR #469's binary search) pluswide_each(0/1)inshadow.rs(omitting the Wine/Proton knobs).Result
cargo test -p victory-gpu --lib watchtests passed cleanly (0.78 s) after updating theask_resttest call toask_once.t=169 s, early 3D load):14.0 FPS(~71 ms/frame) in the same1k–4kdraw tier; 12-minute run completes with0errors /0DeviceRemoved.watch.rs: 3D immediately degraded to0.2–6.3 FPS(158.9 -> 275.8 -> 1297.7 -> 4072.7 ms/frame,copiesup to67.2 msvs28.1 msbaseline,list::thin: 19464 in 12280.4 ms), followed byDXGI_ERROR_DEVICE_REMOVED(0x887A0005) att=169 s:WARN victory_gpu::streamline: DLSS Frame Generation: a present failed hresult=0x887a0005ERROR victory_gpu::host: a submission sent ahead could not be followed by a signal ... (0x887A0005); device removedwatch.rsandshadow.rsimmediately restored clean 12-minute stability.Possible root causes to double-check on native Windows:
SINGLE_NOT_WATCHED/KNOWN_VIEWbitsets skippingGetWriteWatchif any 64 KiB block transitions state (e.g., uncommitted -> committed) without hitting one of thetitle_memory_*clear hooks, orAsking::hold_many(spans)allowing concurrentsync_heaps/ texture refreshes duringask_once, leading to stale buffer/descriptor reads on the GPU and a TDR (0x887A0005).Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by domx4q on 2026-11-28T10:38:30Z.
@jocost4 thanks — here is the diff, against current main (
a4d05e7). It applies cleanly there; built withcargo xwin build --release -p victoryand run on Proton for several 15–20 min sessions without issues traced to it.How it works:
xmem.rs: everyMEM_RESERVE_PLACEHOLDERreservation the runtime makes for the title is recorded viatitle_placeholder_reserved(at, len).watch::placeholder(): the first time the host answersMemoryRegionInformationExwithSTATUS_INVALID_INFO_CLASS(Wine/Proton), a flag is set and from then on the answer comes from thatBTreeMap(onerange(..=at).next_back()lookup), noVirtualQueryat all. On Windows the class is known, so the new path is never taken.title_memory_freeddrops the recorded reservations a free covers (splits keep every part a placeholder, so no bookkeeping is needed for them).Measured on Proton (14900KF, RTX 4090, prologue, 1080p→1440p DLSS Quality): 18.6 → 20.5 fps at the time, "preparing" ~45 → ~31 ms/frame. Not tested on Windows.
diff (65 lines added)
Unrelated but possibly useful for Linux testers reading this: the "missing heads / dark lighting / missing textures" on Proton experimental 11 came from its vkd3d-proton 3.2.0 hanging on 7 of the title's compute shaders (stack overflow in dxil-spirv; under Wine the worker thread just hangs, the log shows
(7 being made)forever). A current vkd3d-proton master build next tovictory.exefixes it; details in a follow-up on #120.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-11-28T19:23:38Z.
Thanks for this. I'm closing it without merging because it conflicts with the current main in several places (main has moved a lot since it was opened, with about 100 pull requests merged today), and I can't resolve that safely on your behalf. If you'd still like it in, please rebase it on the current main and open a new pull request.
Pull request closed