GPU: ask for written pages allocation by allocation when a range spans several #515
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!515
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/515/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?
@desplmfao on GitHub · 2026-11-24 04:22 UTC · original
desplmfao:fix/write-watch-per-allocation→main· +187 −3 · 1 files · 3 commits · closed without mergingStatus (2026-11-24): not needed if #185 lands as it is now. #185 was reworked after this PR was opened (
481fb1a,8bec415,5aca0db;481fb1arefers to "the wholly reserved case examined in #515"): it groups write-watch questions by reservation up front and handles what this PR handles; the two conflict inwatch::writes. Measured (world frames, median): old #185 + this and #436, #462, #600 4.3 s per frame, new #185 alone 2.9 s. Without #185 this still helpsmain's ordinary refreshes. (Correction: the third commit fixes a case this PR's own first commit introduced, not one inmain, whose single question resets nothing when it fails.) Details in the comments below; the rest of this description is as written before.Problem
watch::writesasksGetWriteWatchabout a whole range at once. The kernel refuses a range that spans more than one allocation, and the runtime reserves title memory allocation by allocation, so a buffer over several of them was taken as not write-watched:writesreturnedNoneand its range was copied whole on every refresh, although every part of it is watched.In the world (with #185's direct SRV refreshes), a diagnostic counting the failed questions per buffer showed thousands per frame, on ranges of 133 KB to 3.9 MB on average, starting in allocations that are only partly committed (for example a 64 KiB allocation at
0x756000000with its last 56 KiB reserved). They came to 1.6–5 GB of whole copies per frame.Change
crates/victory-gpu/src/watch.rsonly. When the question for the whole range fails,by_allocationasks it again allocation by allocation (VirtualQueryfor the boundaries). Parts never committed cannot have been written and are not asked about. If a committed part is not write-watched, nothing changes:writesfalls back to guarding orNoneas before. A range inside one allocation is not asked again.Measured
RTX 5080, Linux (proton-cachyos, vkd3d-proton 3.2.0), Series X 1.0.2.1, diagnostics build with #185, #436, #462, #440, #493 (+#336), #259, #177, #151, Enter into story mode at about 35 s. Before: the same stack without this change and without #464; after: with this change and #464 (unmapped guarded view blocks, the same kind of waste for view memory), so the two effects are not separated here:
Frame time does not follow the bytes: what is left of a frame is mostly CPU time per refreshed range (87,000–105,000 direct SRV ranges took 2.7–6.4 s), not bytes copied. Part of that may be this change asking
VirtualQueryfor allocation boundaries again on each refused range; caching them is a possible follow-up.Of the questions still failing at first, 98 % were ranges inside one allocation reserved but not committed at all; the second commit answers those with no writes (nothing can have written there; once committed, the range is asked about normally).
Both commits, measured (same stack, with #514 in place of #464; #514 includes it), 7.5 min, about 6 min in the world, no GPU hang:
What remains of a frame is mostly the number of questions, not bytes: in late frames copies were 36–99 MB and still took 4.5–7.6 s. The whole-range question fails first for almost every refreshed range (they span several allocations), and
by_allocationthen took 0.4–0.9 s per frame (59,000–141,000 calls, 93,000–279,000VirtualQuerycalls). Remembering which ranges span several allocations, and their boundaries, is the next step.Third commit: a fix
by_allocationasks withWRITE_WATCH_FLAG_RESET. When an allocation later in the range is committed but not write-watched, it returnedNoneand dropped the pages the earlier allocations had reported, which the kernel had already cleared. The caller copied its own range whole, so it saw them, but the journal never did, so another host copy over the same pages would not copy those writes. The third commit hands those pages back and records them before falling back;writes_found_before_a_refusal_are_keptfails without it (the write is gone:[]instead of the page) and passes with it.Tests
New
a_range_never_committed_has_no_writes: a reservation not committed has no writes; committed and written afterwards, the write is found. Newa_range_over_several_watched_allocations_is_watched: two adjacent write-watched allocations, written in each, asked about as one range. It fails onmain(writesreturnsNone) and passes with the change. Both test allocations are kept rather than freed, since the journal is shared and a later test given the same addresses would find their pages written. Thewatchtests pass, also merged with #464 (itsunmapped_blocks_are_reported_once_until_mappedincluded).cargo clippyreports nothing new inwatch.rs.Related
VirtualQueryabout every region of the range, so one committed page anywhere in it is enough to ask the kernel normally;a_range_never_committed_has_no_writescommits and writes after the first question and checks the write is found.AI-assisted (Claude Code).
🤖 Generated with Claude Code
@Raxstreams on GitHub · 2026-11-24 05:00 UTC · original
Tested the allocation-by-allocation query on Windows alongside #514. All nine watch tests passed. This included the reserved-then-committed range and the range spanning two write-watched allocations. This was an integrated run; I did not measure a standalone performance delta.
@desplmfao on GitHub · 2026-11-24 05:55 UTC · original
Correction to my comment above: the third commit does not fix a bug in
main. Inmain,writesasks once over the whole range, and a refused question resets nothing, so no writes are lost there. The lost writes could only happen with this PR's own first commit (asking allocation by allocation with reset), which the third commit then fixes. #185's current version avoids the problem by design (it tests the span without resetting first).AI-assisted (Claude Code).
@desplmfao on GitHub · 2026-11-24 05:47 UTC · original · edited 2026-11-24 05:58 UTC
Update: #185 has since been reworked (commits
481fb1a,8bec415,5aca0db, after this PR was opened;481fb1arefers to "the wholly reserved case examined in #515"). It now groups write-watch questions by reservation up front and handles ranges over several reservations, never-committed memory and failed private watches itself, so it covers what this PR does, and the two conflict inwatch::writes.Measured on the same machine and input (RTX 5080, Linux / proton-cachyos, world frames, median over the same window after world entry, with #493 in all three): old #185 6.1 s per frame; old #185 + #436, #462, #515, #600 4.3 s; new #185 alone 2.9 s, with 0.07 GB copied whole per frame against 1.3 GB.
If #185 lands, this PR is not needed. Without #185 it still helps
main's ordinary refreshes of buffers spanning several allocations, and its third commit fixes a case in which writes found before a refused allocation were lost from the journal. Up to you whether that is worth keeping; I'm fine closing it in favour of #185.AI-assisted (Claude Code).
@AgneyaK on GitHub · 2026-11-24 18:24 UTC · original
Test report on a 6 GB / 16 GB laptop. On this machine this PR made write-watch time worse: 475 → 1,605 ms per world frame, alone on the base below.
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.My guess, not verified: the expensive part here is asking inside one huge allocation. #776 measured a 2.2 GB allocation at about 2.2 ms per asking. Splitting a range into per-allocation askings then multiplies the expensive ones. #393 avoids most askings, and with it the time stays low either way (29 ms with all three, 14 ms without this PR). One run per row, spread about ±10%.
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