GPU: refresh a buffer copy's ranges by page; answer clean guarded views from the journal #393
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!393
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/393/head"
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?
@kxiserino on GitHub · 2026-11-24 02:53 UTC · original
kxiserino:gpu/batch-interval-coalescing-and-clean-guard-fastpath→main· +238 −17 · 2 files · 1 commits · closed without mergingSummary
Two costs in the per-submission refresh of host buffer copies.
Batch::addmerged every range of a copy into one bounding range. A submission that reads a few small ranges at the low and high ends of one big shared buffer (a heap of over 100 MB, say) then hadShadow::updateaskwatch::writes(and soGetWriteWatch, or the guard walk) about the whole untouched middle, and copy whatever was stale there, though nothing declared it read.Batchnow keeps aVec<(from, to)>per copy. At the flush,coalesce_ranges(&mut ranges, watch::PAGE)sorts them and merges ranges whose 64 KiB pages overlap or touch (next_from / page <= cur_to.div_ceil(page)). Ranges with a whole untouched page between them stay apart, and each one is updated by itself.address + lensaturates.pending) are skipped byupdateas before.watch::writes(.., guarded = true)on a clean guarded view. Views can't be write-watched, so every asking first calledGetWriteWatch, which fails for them, and thenguard'sVirtualQuery. If every block of the range is already guarded and still clean, nothing has written there since it was guarded: a title write faults into our handler, which removes the block fromclean.writing()andtitle_memory_remapped()remove it too. So the journal already has the answer.guarded && first < lastandguards().clean.range(first..last).count() == last - first, skip both syscalls, bumpaskedand returnwritten.range(first..last)as usual.JOURNALis taken, thenGUARDS, the same orderguard()already uses.install(),guard(),open(),writing(),title_memory_remapped()and the vectored handler only ever takeGUARDS, and none of them takeJOURNAL. Nothing takes the two locks in the opposite order, so this can't deadlock.constassert pinsBLOCK == PAGE, which the fast path relies on (blocks are pages).Related: #119 makes
guard's query cheaper. This change skips the query when every block is clean, so the two complement each other.Testing
All the tests are synthetic: they use their own allocations and pagefile sections, and no title data.
host::batch:empty_ranges_are_dropped,ranges_in_one_page_merge,ranges_in_touching_pages_merge,ranges_pages_apart_stay_apart(low and high ends of a 256 MiB range),ranges_at_the_top_of_the_address_space_do_not_overflow.watch::tests::clean_guarded_views_are_answered_from_the_journalcovers repeatedwrites(.., true)on a clean mapped section. A test-only thread-local counter shows the kernel isn't asked again, and the answer stays the same. A later title write (through the handler),writing()andtitle_memory_remapped()are each still reported, then the range settles back onto the fast path.watch::tests::partly_clean_ranges_ask_the_kernelchecks that a partly guarded range still takes the slow path, and that unguarded askers never take the journal's word.written_pages_are_reported_to_every_askercould see stale entries if its allocation lands at the same address.Results:
cargo test -p victory-gpu: 50 passed. With-- --test-threads=1: 50 passed. With--features diagnostics -- --test-threads=1: 52 passed.cargo clippy -p victory-gpu --features diagnostics -- -D warningsand the same without features: clean.cargo clippy -p victory-gpu --all-targets [--features diagnostics] -- -D warnings: the only error is the existing missingSAFETYcomment athost.rs:267onmain, which #355 fixes. With that line patched locally, both are clean.cargo xtask policy:asset policy: 151 files ok.In-game frame time is not measured here.
🤖 Generated with Claude Code
@jeremygold02 on GitHub · 2026-11-24 04:27 UTC · original
Thanks @kxiserino for this journal-backed range handling. I tested head
6e7186c09b15f25822b05707f0b7ded00f57a747with:Result: 4 passed, 0 failed. The watch tests cover clean guarded reads answered from the journal, partially clean ranges falling back to the kernel, guarded kernel reads, and reporting written pages to all askers. These are synthetic watch/journal unit tests, not a title workload.
@LooperSalty on GitHub · 2026-11-24 09:18 UTC · original
Measured in the world on an RTX 4070 SUPER + i7-13700KF (diag build, same ~20-PR stack before and after, 2 minutes in the world,
VICTORY_SHADER_LOOP_LIMIT=32), per frame fromcopystat:Batchforgot them after eachflush(), so the same ~174 MB range was asked again by every list): 875 watches, 224 ms, 3,350 MB checked.What remains on that path here is ~81,000 guard page faults per frame and ~136 MB of unchanged textures hashed per frame, so the frame time only moved from about 550 to 500 ms; #185's per-reservation write-watch looks like the next step.
🤖 Generated with Claude Code
@AgneyaK on GitHub · 2026-11-24 18:24 UTC · original
Test report on a 6 GB / 16 GB laptop: this PR takes write-watch time from 475 ms to 13 ms per world frame, and frames get 16% shorter.
Setup: RTX 3050 6 GB Laptop (NVIDIA, driver 32.0.16.2124), i7-13700H, 16 GB RAM, Windows 11 26300, diag build. Title 1.0.2.1, Series X profile, the story load. Base tree:
mainffe310e+ the PRs listed in #1232 + #431. Each PR was merged onto that base, and each row is one run of 300 s from launch. "World frame" is the average of thefps, ms/frame (…)lines under 10 fps with 20+ draws. Write-watch numbers are the last 8copystatlines.Not tested: more than one run, a release build, AMD. I didn't check correctness beyond the run not failing (no device removal or title stop in the 300 s window).
AI use: Claude Code (Claude Opus 5.5) built the trees, ran the title on my machine and drafted this report; results are from the runs described.
Pull request closed