Repository navigation
Conversation
copy_back_page, copy_back_or_not and copy_back_marked each made a fresh Vec for the bytes they read from title memory, up to 64 KiB a call, and a world frame copies dozens of ranges back. A fresh buffer is committed and touched from scratch, which is one page fault per 4 KiB: the frame report counted about 1 900 page faults per frame in copy-back alone, and the allocator traffic on top. The buffers now come from the same pool the snapshots use and go back to it (the pool keeps what fits, so nothing is dropped in practice), and the pages a copy-back took are filtered where they are instead of being collected into a second Vec. (cherry picked from commit b0bb0dcdbaf3c503640adc839167bc38a61f6001)
`HostHeap::sync_slots` collected the record of every slot it was asked about into a Vec, then a Vec<bool> of which name a current view, then a Vec of the slots that differ. A world frame asks about ~800 000 slots (`copystat`: "heap slots the title copied"), so that is tens of megabytes of allocation and copying per frame, for records that are read once. 512 slots at a time now, in buffers on the stack: read, checked against the records the slots hold, and the differing ones mirrored, which is a few hundred a frame. `views_current` fills a slice instead of building a Vec, and takes one lock of the view list per pass as it did per call. (cherry picked from commit 341a051e9d2a02f35e627b216deed1ba29ae93fa)
`SHADER_HEAPS` guards the list of shader-visible heaps: which heap a handle is in. Two kinds of caller read it and never change it - every title thread that writes a view into a heap (`mirror`) and each submission's heap sync, which walks every slot of the pages the title wrote (`sync_heaps`, ~800 000 slots a frame). With one mutex they took turns, and the frame report put 48 ms per world frame into title threads waiting for it (`copystat`: "title threads waiting to write views"). Readers share an `RwLock` now; only a heap's registration and its release (`Heap::drop`) take it alone, and a drop still waits for readers, so a heap cannot be freed while `mirror` or a sync holds its address. The slot work itself was never serialized by this lock: each host heap has its own `made`/`kept` locks, and `mirror` already re-checks a slot after dropping `made` because another thread may have made it meanwhile. (cherry picked from commit 9fe32dd749df24d987bf9f0c1fb460418c6d5480)
`Shadow::update` is called for every range a submission's lists refresh (thousands to tens of thousands a frame) and locked `pending` - the set of ranges shaders of the submission may be writing - to see whether the range meets any. Most refresh ranges meet none, and outside the window between a GPU-write step and the submission's copy-back the set is empty. An atomic count beside the set now answers that without the lock; the lock is taken only when there is something to look at. The count moves where the set moves (`writing` inserts, the copy-back removes). (cherry picked from commit 98a7a935478282daedb7d69b26ea1b61401fca55)
A heap sync asks, for every slot of every page the title wrote, whether the record there still names a current view: ~800 000 slots a world frame (`copystat`: "heap slots the title copied"), one `Vec` lookup each into `Views::list`, whose entries are a whole `View` (tens of bytes) and a generation. The generation now lives in a `Vec<u32>` of its own, so the answer is one 4-byte read instead of a cache line of view data; only the slots that do name a current view need the view itself, and those are the few hundred that get mirrored. (cherry picked from commit 20db67d0d19e5df272dcce613a86d2e0133e2a8a)
`open` gave access back one page at a time: a `VirtualProtect` per page, plus a set removal. World frames open tens of thousands of pages (`copystat`: "pages opened", 13 624, and 75.95 ms in the guard handler), and the pages a write or a copy covers are consecutive - the title writes runs of them, and so does our own copy-back. Consecutive guarded pages are given back in one call now, both where a write of ours opens what it covers (`changed_here`) and where a released tracker opens what nothing else watches. (cherry picked from commit 1ce5a606f1e9676359f92e07ccd7ca1f243fc798)
The dwords a stage's user data sets were collected into a fresh `vec!` for every stage of every draw (a few dwords at most, thousands of draws a frame). Up to 64 of them now live in an array on the stack; a title that asks for more still gets a Vec. (cherry picked from commit 65f9815f639efbad912d8b33d04f1910244d49c0)
|
Reviewed all 7 commits of Verification
Two issues found
|
|
Review note on item 6 ( Bug: Suggested shape: do not make the batch authoritative without checking its result. let mut old = 0;
let batch = unsafe {
VirtualProtect((first * PAGE) as *const _, (last - first) * PAGE, PAGE_READWRITE, &mut old)
} != 0;
if !batch {
// Separate allocations: one page at a time, as the old `open` did.
for page in first..last {
let mut old = 0;
unsafe { VirtualProtect((page * PAGE) as *const _, PAGE, PAGE_READWRITE, &mut old) };
}
}Either keep the pages in Reproduction test: two adjacent 64 KiB |
|
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: 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: That is also what the numbers predict: this phase syncs ~5 000 heap slots a frame and makes 395 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 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. |
|
Measured on a Ryzen 7 5700G (16 threads) + RTX 3060, Windows 11, release, against their base
With 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 AI use: Claude Code ran the builds and benchmarks on this machine and drafted this comment. |
|
Automated triage for the maintainers. Reviewed at The pooled
Also: the Verdict: needs work. CI: passing. Generated by Claude Code |
protect_here and protect_alias made PAGE_READONLY over a whole 64 KiB block,
or over a whole range, after looking at the first page's old protection
only. A PAGE_GUARD page the title set further on in that block lost its guard
with no fault and no write seen. Now a change of protection covers only
blocks that Windows says are alike (committed, one region, read-only or
read-write throughout). A block that is not gets no call and stays as it is,
with VICTORY_GUARD_RUNS on or off.
Runs (VICTORY_GUARD_RUNS, on; =0 keeps one call per block where a range is
not one alike region):
- unguard: blocks that follow one another in one view are opened with one
call.
- protect_here: one call per run of alike blocks within each view the runtime
told of. A call across two views is refused, so runs are cut there.
- cover: the other views of a run of guarded pages are made read-only with
one call per run (protect_alias_runs); protect_alias takes what is left.
With =0 a range is asked for whole only when it is one alike region, so the
call across views that was refused is no longer made.
Counter on victory_gpu::host (diagnostics builds), on the 5 s lines: calls and
blocks per frame for giving write access back and for making read-only, and
the refused ones ("the guards' changes of protection per frame").
Tests (watch::tests): a_write_over_guarded_blocks_opens_them_with_one_call,
a_write_inside_guarded_blocks_opens_its_own_and_no_others,
runs_of_guarded_blocks_are_cut_where_views_meet,
other_memory_inside_a_run_keeps_its_protection,
the_other_views_of_a_guarded_run_are_guarded_with_one_call,
a_page_the_title_guards_inside_a_range_keeps_its_guard,
a_page_the_title_guards_in_another_view_keeps_its_guard.
Credits: Marvisak/VIctory PR Marvisak#2849 (Therecalloftheonion) for the idea of one
change of protection per run of guarded pages; PR Marvisak#2848 item 6 (pes7) for
giving guarded pages back in runs. As we read them, their runs ignore view
boundaries and the call's result, so their code does not fit this tree; this
is a new implementation for it.
(cherry picked from commit 8b8da9b06fe3a252184876d6e84f7f3d8238a93f)
|
In-game confirmation of the Wine refuses a On splitting off the safe commits: with AI-assisted (Claude Code). No game data attached. |
Seven 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.