victory-gpu: take per-frame allocations, locks and system calls off the frame paths (7 places the profile points at) #2848
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!2848
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2848"
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?
@pes7 on GitHub · 2026-11-25 22:10 UTC · original
pes7:perf/cpu-paths→main· +240 −91 · 5 files · 9 commits · openSeven places in the frame paths that cost allocations, locks or system calls per call site rather than per frame. Each one comes from a number in the diagnostics profile of a world frame (
copystat, 8 137 draws a frame), and each is independent.victory-gpu: read a copy-back's title bytes into a pooled buffer-copy_back_page,copy_back_or_notandcopy_back_markedmade a freshVecof up to 64 KiB for the bytes they read from title memory. The frame report counted ~1 900 page faults per frame in copy-back alone, from committing those buffers from scratch. They come from the pool the snapshots already use and go back to it; the pages a copy-back took are filtered in place instead of being collected into a secondVec.victory-gpu: sync a heap's slots in passes, without a vector of them-HostHeap::sync_slotscollected every slot's record into aVec, then aVec<bool>of which name a current view, then aVecof the differing slots. A world frame asks about 806 912 slots (copystat: "heap slots the title copied"), so that is tens of megabytes of allocation per frame for records read once. 512 slots at a time in stack buffers now;views_currentfills a slice.victory-gpu: let heap readers share the shader heaps' lock-SHADER_HEAPSguards the list of shader-visible heaps. Every title thread that writes a view and every submission's heap sync only ever read it, but they took turns on a mutex, and the frame report put 48 ms per world frame into title threads waiting for it. Readers share anRwLocknow; a heap's release still takes it alone and waits for readers, so a heap cannot be freed under a sync.victory-gpu: ask how many ranges shaders are writing before the lock-Shadow::updateruns for every refreshed range (tens of thousands a frame) and lockedpendingto see whether the range meets a range shaders write. Most meet none, and the set is empty outside the window between a GPU-write step and the copy-back. An atomic count answers that without the lock.victory-gpu: keep a view's generation away from the view-Views::listheld(View, u32), so the per-slot question "does this record still name a current view" touched a wholeView(tens of bytes) for 4 bytes of generation. The generations live in aVec<u32>of their own now: one 4-byte read per slot, and the view itself only for the few hundred slots that get mirrored.victory-watch: give write access back to guarded pages in runs-opengave access back one page at a time, aVirtualProtecteach: the frame report counted 13 624 pages opened and 75.95 ms in the guard handler. Consecutive guarded pages are given back in one call, both where a write of ours opens what it covers and where a released tracker opens what nothing else watches.victory-gpu: keep a shader's user data on the stack- the dwords a stage's user data sets were collected into a freshVecfor every stage of every draw (up to 64 dwords). They live in an array on the stack now; a title that asks for more still gets aVec.What is measured and what is not: the per-item numbers above are from the diagnostics build's own counters (they pointed at these call sites). The frame-time effect of the stack as a whole is not measured yet - this machine's world frames are TDR-prone and other GPU clients share the adapter, so the plan is one A/B run of the whole stack (diagnostics build, same save,
copystatbefore/after) before anything else here is extended. Nothing in the patches changes what a frame does, only how it does it;cargo test --workspacepasses (228 invictory-gpu), clippy is clean.The tier below this one is design-level and is not in this PR:
ReadProcessMemoryof 205 MB a frame (117 ms), per-pageVirtualProtectof the write watch (40 ms) and the 61 MB of snapshots for ranges shaders write (45 ms).What it gives (to decide the merge): seven allocations, locks and system calls off the frame paths: a copy-back's 64 KiB buffer from the pool (~1 900 page faults a frame in copy-back alone), a heap sync that collected 806 912 slots into three
Vecs per call,SHADER_HEAPSreadable by many (48 ms a world frame of title threads waiting on it), apendingcount that answers before the lock (25 000 refreshes a frame), view generations apart from the views (800 000 random reads a frame), guarded pages given back in runs (13 624VirtualProtecta frame), and user data kept on the stack (16 000 allocations a frame).State: MERGEABLE, CI
checkgreen, rebased onto today'smain(f3578e3).Risk: no behaviour change, only how a frame does the same work; each item is independent. The frame-time effect of the stack as a whole is not measured yet - that is the next run.
github-bot referenced this pull request2026-11-26 06:27:40 +00:00
@fuzeofficlal on GitHub · 2026-11-25 22:34 UTC · original
Reviewed all 7 commits of
f9997fb9and verified on Windows 11 (RTX 5090 + WARP) againstmain(f3578e3):Verification
cargo xtask policy(190 ok),cargo clippy --locked -p victory-gpu --all-targets(default &--features diagnostics, 0 warnings).--features diagnostics):descriptor::tests7/7,descriptor::host::tests14/14,shadow::tests9/9,watch::tests15/15,draw::tests20/20 passed.--features diagnostics, full crate): 243 passed, 0 failed, 1 ignored.3dfeb43(pooledBack),7f475db(stack-chunkedsync_slots),1c70f4b(SHADER_HEAPSRwLock— verified noprepare()re-entry),058f995(splitViews::current/list), andf9997fb(stackuser_databuffer) look solid.Two issues found
6319997(Shadow::pending_lenfast path inshadow.rs):writing()drops theself.pendingmutex before callingself.pending_len.fetch_add(1, Ordering::Relaxed), andupdate()readspending_lenwithOrdering::Relaxedoutside the lock. Ifwriting/copy_back/updateever overlap across threads,update()can observe0right after an insert (orcopy_backcanremove+fetch_subbeforefetch_add, underflowingpending_lentousize::MAX), andRelaxedestablishes no happens-before edge withpending. Updatingpending_lenwhile holding thependingmutex withRelease(and reading withAcquireinupdate()) closes both the race and ordering gap at zero extra lock cost.2851648(watch::open_runsinwatch.rs):open_runsremoves[first, last)fromg.protectedand issues a singleVirtualProtect(..., PAGE_READWRITE)ignoring the return value. On Windows,VirtualProtectfails withERROR_INVALID_ADDRESS(487) across adjacentVirtualAllocregions or uncommitted pages (verified locally on Windows 11: 128 KiB across two contiguous 64 KiBVirtualAllocblocks returned0,err=487), leaving the whole runPAGE_READONLYafter dropping it fromg.protected-> unhandled0xc0000005on next write. Checking the return value and falling back to per-pageVirtualProtect(matchingprotect_noting) fixes it. Also conflicts directly with #2849 inwatch.rs.@kotekompotek on GitHub · 2026-11-25 22:52 UTC · original
Heads-up: this SHADER_HEAPS Mutex->RwLock conversion overlaps #2821, which does the same change (plus VIEWS) and includes a benchmark harness measuring list-call cost on the title's threads. Worth coordinating so one lands cleanly; #2821's measured baseline may be the more useful vehicle.
@Therecalloftheonion on GitHub · 2026-11-25 22:53 UTC · original
Review note on item 6 (
open_runs), from the same failure found in #2849 (now closed as a duplicate of this item).Bug:
VirtualProtectcan return 0 withERROR_INVALID_ADDRESS(487) when the run crosses two separateVirtualAllocreservations/allocations, even when the pages are contiguous and all present ing.protected.open_runsremoves each page fromg.protectedbefore the call and ignores theBOOL. On failure the pages are still read-only but are no longer guarded; the next write faults and can end in an access violation.Suggested shape: do not make the batch authoritative without checking its result.
Either keep the pages in
protecteduntil the batch succeeds and only then remove them, or remove them and rely on the per-page fallback. Keep theOpenPagesdiagnostic count for the pages actually opened.Reproduction test: two adjacent 64 KiB
VirtualAlloc(..., PAGE_READONLY)regions, add both pages tog.protected, callopen_runs; without the fallback the 128 KiB batch fails 487 and both pages stay read-only; with it both becomePAGE_READWRITE.writable()inwatch::testscan assert the result. This was reproduced on Windows 11 by @fuzeofficlal; I have not pushed a competing branch.@pes7 on GitHub · 2026-11-26 00:10 UTC · original
Ran the A/B, and it does not show a win - here is exactly what was reachable and why that is the answer, not a hidden one.
Setup:
measure3= today'smain+ #2634 (so the per-slot warning does not own the first frame), against the same branch with these seven commits, both--features diagnostics, ABBA (base, pr, pr, base), 240 s each, same save. The title was driven past the account screen with the repo's ownVICTORY_KEYS=40:Enter,45:Enter,...(gameinput.rs: scripted keys, independent of focus) - without it the runs sit at "choose a player" forever.What the runs reached: the loading phase - 6-16 draws a frame, 18 refreshes and 174 MB of title memory copied a frame, 3 submissions. Per frame, medians over the last part of each run:
That is noise:
base2sits on the PR values, and the first run of the set is the outlier on page faults (cold file cache). No column separates the two builds.That is also what the numbers predict: this phase syncs ~5 000 heap slots a frame and makes 395
VirtualProtectcalls, against the world's 806 912 slots and 13 624 pages opened - the costs these commits remove are ~150 times smaller here than where they were measured.And the world is unreachable on this machine right now: all four runs die about 110 s in, before a single frame with more than 800 draws. On this build the title faults in its own code (Breakpad upload, frames 1 089-1 704, right after first binds of
mesh/vertex/pixel/computepipelines); the oldermain13f91ca+ #2634 + #2683 + #2696 build in the same conditions dies with the device removal instead. Either way the prologue does not survive here.So: no frame-time claim for this PR. What it has is the per-call costs its counters measured (the seven lines in the description) and the fact that none of them changes what a frame does; a before/after needs a run that survives into the world, which is a TDR/machine problem (issues #2310, #2311, #1799 are other people's work on it) rather than something this stack can show.
@liandraraiane on GitHub · 2026-11-26 02:42 UTC · original
Measured on a Ryzen 7 5700G (16 threads) + RTX 3060, Windows 11, release, against their base
f3578e3, with a guard-lock contention benchmark (writer threads faulting on guarded pages while a submission thread arms and takes every tracker in rounds, plus a kernel-writer thread opening 8-page ranges withwritingevery 200 µs;guard_lock_contention_benchon branchliandraraiane/VIctory:perf/guard-lock-contention). Median of 5 rotated runs:writingp50 µsWith writers pausing 50 µs between writes the picture is the same. Under contention the time is waiting for the guard lock, not the open calls, so batching them does not show here. Even with one writer, an 8-page
writingtakes ~270 µs, almost all queued behind takes. Both pass a 12-thread stress test (writes vs takes and copies, no write lost, no stray fault) 20/20. Not tested: the title; ranges longer than 8 pages; #2848's other six changes.AI use: Claude Code ran the builds and benchmarks on this machine and drafted this comment.
@Marvisak on GitHub · 2026-11-26 03:20 UTC · original
Automated triage for the maintainers.
Reviewed at
f9997fb, which merges cleanly. CI: passing. Thanks for running the A/B and reporting the null result plainly.The pooled
Backbuffer, the chunkedsync_slots, the split generations inViewsand the stack user data read correctly. Two of the seven commits have the problems reviewers found, and I confirm both:watch.rsopen_runs: the pages are removed fromg.protectedand then oneVirtualProtectcovers the whole run, with its result ignored.VirtualProtectfails when a range spans two separate allocations (error 487, reproduced above). The pages then stay read-only but are no longer known as guarded, so the next title write faults with nothing to handle it. Check the result and fall back to one page at a time, as the oldopendid.shadow.rs:pending_lenis changed after thependinglock is released, andupdatereads itRelaxed. Update it while holding the lock, then read it withAcquire.Also: the
SHADER_HEAPSRwLockchange overlaps #2821, so please coordinate with that PR. No frame-time gain is measured, so consider splitting off the clearly safe commits (1, 2, 5, 7) so they can land on their own.Verdict: needs work. CI: passing.
Generated by Claude Code
@crashbashash on GitHub · 2026-11-26 10:10 UTC · original
In-game confirmation of the
open_runsproblem the triage describes, from Linux (RX 6800 XT, RADV, Proton): with thisPR on
main219878aplus our Linux commits, both runs crashed entering the world, in VIctory's own write intotitle memory:
Wine refuses a
VirtualProtectwhose range is not inside one view, as Windows does across allocations: #2849'sfallback test, ported to this PR's
open_runs, fails under Wine too (both pages still read-only afterwards).On splitting off the safe commits: with
open_runsreplaced by #2849's version (so nothing crashes), the rest of thisPR ran the same scene with 30.8 submissions a frame instead of 23.3, and frames of 849 and 668 ms instead of 522 and
657 ms (preparing 446 and 388 ms instead of 249 and 292 ms; 2 runs each, interleaved). I haven't found which commit
changes the submission count, but it may help in choosing which ones go first.
AI-assisted (Claude Code). No game data attached.
@Creaa on GitHub · 2026-11-26 13:32 UTC · original
@pes7 a before/after on a machine where the title gets past loading (FIND-34). One finding first: with this PR the title crashes about two minutes in, in 2 of 2 runs; without commit
2851648("victory-watch: give write access back to guarded pages in runs") it runs the full 8 minutes.Setup: RTX 4070 12 GB (32-lane waves, driver 617.14), i7-13700F, 32 GB, Windows 11 26300, diag build. Base:
main63bcca4+ #2176 + #2461 + #2464 + #3115 (the stack that gets this card into the intro's 3D shots),VICTORY_SKIP_PIPELINESwith #1968's three programs, scripted Enter every 10 s, 8 minutes, same warm cache for every run. "With" = the base + this PR atf9997fb(merged cleanly).The crash (both runs with this PR, same place, nothing on the GPU side):
A DirectStorage decompression writes into title memory whose page is still read-only, which looks like a page the run-based
opendoes not give write access back to. With2851648reverted on top of this PR (the other six commits kept), the same run went 8 minutes with no crash and no device removal.Frame time (median ms per frame over the frames above 100 ms, i.e. the intro's 3D part; from the diag build's
fps, ms/frame (… preparing …; … on the GPU)lines):2851648So in this scene the other six items do not show up in the frame time (within the run-to-run spread); this says nothing about the busier world frames your counters came from.
Counts and times only, no game data. AI use: Claude Code (Claude Opus 5.5) ran the runs, symbolised the crash with the build's PDB and drafted this; the runs were done on my machine.
@pes7 on GitHub · 2026-11-26 13:37 UTC · original
Both confirmed bugs are fixed on the branch, each as its own commit.
4a195c94- a guarded page leaves the guard set only once the kernel opened it.watch::open_runsremoved each page fromGuards::protectedbeforeVirtualProtectand ignored the result. A page that only left the set that way stays read-only for good (no tracker holds it any more, so nothing opens it again) and the title's next write there faults with no guard to take it - the Wine removalcrashbashashreproduced. Now:copystat's "pages opened" counts what actually opened.50be8a7c- the pending-range count moves under its lock.Shadow::writinginserted intopendingand then bumpedpending_lenafter the mutex was released, whilecopy_backreads that count to choose the fast path ("nothing pending"). A reader could see 0 with a range already in the set, take the snapshot path without it, and the count could drift below the set's size. The bump is now inside the lock the set moves under; add/sub areRelease, the loadAcquire.Verification:
cargo test --release -p victory-gpu- 228 passed, 1 ignored; clippy-D warningsclean on the crate and its targets. One GPU test failed once in a full run and passed alone and in the next full run (draw::tests::a_texture_is_uploaded_once_per_submission_and_only_when_written), so it is the load-sensitive kind this machine has, not these changes.Still open on this PR, and deliberately not mixed in: the
SHADER_HEAPSRwLockthat duplicates #2821. The triage's advice was to land the safe commits first, and this is that - the two bugs above are the ones that were confirmed in code and in a run.No frame-time claim: these are correctness fixes on paths the profile pointed at, and the per-call numbers in the PR body are unchanged by them.
@Creaa on GitHub · 2026-11-26 13:56 UTC · original
@pes7 confirmed on the same setup as above: with this PR at
50be8a7(merged onto the same base) the title ran the full 8 minutes, no crash, no device removal, and nothing new incrashes.log(the two earlier runs atf9997fbboth died at ~2 min in the DirectStorage decompress).Frame time in the same intro window (median ms/frame over frames above 100 ms): 573 (preparing 132, GPU 389), against 605 and 614 for the base without this PR and 639 for
f9997fbwithout2851648. One run each, so read it as "no regression, maybe slightly faster", not as a measured gain.AI use: Claude Code (Claude Opus 5.5) ran it and drafted this; the run was done on my machine.
@Jackster on GitHub · 2026-11-26 14:56 UTC · original
On the retail title this tree crashes in
miniz_oxide::inflate, writing to a page the guards left read-onlySetup: Windows 10 26300.10075, RX 7900 XTX (
1002:744c), driver 32.0.32029.2010, retail 1.0.2.1, diagnostics build. The branch is this PR merged intoupstream/main(63bcca4) — the merge was automatic (ort, one auto-merged hunk indraw.rs) — run withVICTORY_KEYS, a warm shader cache and a save that the unpatched tree runs for 300 s. Nothing else differs between the two runs.upstream/main63bcca463bcca4+ this PREvery exception is the same and is reproducible:
The address is the same in both runs; only the write target differs. Symbolised against the build's own PDB (matching GUID, same binary):
So the faulting instruction is inflate writing its output, and the page it writes to is read-only. Of the seven changes here, the one that matches that shape is item 6 (
watch::opengiving write access back to guarded pages in runs): a range reopened in a run, then written by a decompressor that is not the title's thread. I cannot prove that from the address alone — the inflate call site is the caller's, not in this symbol — so treat it as the prime suspect, not the conclusion.Caveat that matters: the branch is 78 commits behind
63bcca4, and I merged rather than rebased, so it is possible this is an interaction my merge created rather than something in the PR as written. Building the PR on its own base and running the same 300 s would separate the two, and I can do that (or bisect the seven items into separate builds) if it is useful.What I can say with confidence: on this machine,
63bcca4+ this PR does not reach the world, and the write-to-read-only indecompress_fastis what stops it.Written with an AI assistant.
@Jackster on GitHub · 2026-11-26 15:09 UTC · original
Bisected: reverting the guard-reopen commit makes the tree run
Follow-up to the note above. Same save, same cache, 300 s runs:
63bcca4+ #2848 (merged)+0x51d250 (write <addr>: read-only), symbolised tominiz_oxide::inflate::core::decompress_fast + 0x1e0f3578e3, no merge+0x242aa3 (read 0x30: nothing mapped there)— a different fault63bcca4+ #2848 with2851648revertedSo the write-to-read-only in
decompress_fastcomes from2851648("give write access back to guarded pages in runs"), the item I suspected.The own-base run is a separate question:
f3578e3is three commits behind63bcca4, and one of those three may be what stops theread 0x30fault, so I would not read that row as "the PR also has a null fault" untilf3578e3alone has been run. I can do that if it is useful.With the revert the tree runs at 0.73 fps: preparing 584 ms, copies 305 ms of 496 MB, GPU 163 ms, copy-back 94 ms, 9,202 protect calls for 17,373 pages, 7,074 pages opened. I could not measure the full PR in the same state because it does not survive, so the cost of the reverted item is not yet attributable.
What would settle this quickly: which write paths
2851648is meant to serve — a page reopened in a run for a title write — and whether a decompressor writing into a host copy is one of them. The faulting instruction is inflate writing its destination, which the run logic had left read-only.Written with an AI assistant.
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.