GPU: ranges shaders may write are armed as runs of pages, not page by page #2147
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!2147
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2147/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?
@r4tedx on GitHub · 2026-11-25 06:09 UTC · original
r4tedx:gpu/arm-page-runs→main· +139 −4 · 1 files · 2 commits · merged 2026-11-25 21:54 UTCSince
cd94d35a range declared as written through views whose writes shaders mark keeps no snapshot:Shadow::writingarms it instead (Tracked::arm), so that the title's first write to one of its pages keeps the page's bytes from before. Arming puts every 64 KiB page of the range into aBTreeSet, once per declaration.A root view declares its copy from its address to the copy's end (
draw.rs,root_view:shadow.left(address)when the copy is marked). On the world's 174 MB heap that is up to 2,784 set entries for each such draw or dispatch, however many declarations before it armed the same pages, andHostList::defer_gpu_writedoes not merge them.The change
watch::Savedkeeps the armed pages as the runs declared, none inside another, and the single pages a copy-back takes out (Tracked::unarm) in a set of their own until the tracker is disarmed. A declaration inside a run already armed costs a scan of the runs; a root view's runs all end at the copy's end, so the heap's collapse into one.Which pages are armed at any moment is the same as before:
armre-arms a page that was taken out, as the set insert did, anddisarmclears both.Numbers (synthetic)
The unit cost printed by the benchmark of #2134, WARP,
diagprofile withdiagnostics, 200 declarations each:mainThat benchmark's frame declares the heap 66 times, so this is about 2 ms of its 168–225 ms preparing: below the run-to-run spread, and I am not claiming a frame time from it. The job that measured this branch ran with the machine busy (
mainalone gave 306 and 722 ms in it), so its frame times compare nothing.How much this is in the title depends on how many ranges a world frame declares through marked root views, which no published log says: the
GPU writesstep of thecopies per frameline (563 ms in the #400 run) holds this together with the refresh batch that step flushes and the snapshots. At thousands of draws a frame it could be tens of milliseconds; a tester's line before and after would say.Not a duplicate of
#435 merges identical declarations (same copy, address and length) at submission, and #2102 changes the hasher of the per-list and per-submission sets. Neither changes what one declaration costs to arm. This merges cleanly with #2136.
Tested
watch::tests::armed_ranges_keep_their_pages_bytes_from_before_the_first_write: pages of overlapping armed ranges keep their bytes from before the first write, a page next to the range and a page taken out keep none, arming again arms it again, and nothing is kept afterdisarm.shadow::tests::marked_pages_go_back_by_the_bytes_the_gpu_changed, which arms a copy and relies on the saved page, passes unchanged.victory-gpusuite on WARP (diagnosticsbuild,VICTORY_D3D12_WARP=1, one thread): 147 passed, 0 failed, 2 ignored.cargo clippy -p victory-gpu --all-targets --locked -- -D warnings, with and without--features diagnostics: clean.Not run: the title; any hardware GPU (the suite and the benchmark ran on the software adapter only);
cargo test --workspace. The title was not used in these tests.AI-assisted
🤖 Generated with Claude Code
@r4tedx on GitHub · 2026-11-25 06:43 UTC · original
@catminou4 on the relation to #1865: the two do not overlap. #1865 changes only
memory.rs(the per-list bitmaps in which shaders mark the title-memory pages they write, and the page table's writes). This PR changes onlywatch.rs: which pages a tracker keeps the old bytes of when the title first writes them, stored as runs instead of one set entry per page. Merged together locally they apply without conflict (a merge check only; nothing was built or run for this comment).AI-assisted
@nathanbzrr on GitHub · 2026-11-25 08:40 UTC · original
Verified head
f869790fe14675920d9aea7ad18117af0fca75a5merged with #2134 (and 3-way merged with #2136) ontomain(940d32f69b) on Windows 11 x64 / AMD Radeon RX 7600:victory-gpulib tests: 144/144 passed (+#2134) and 146/146 passed (+#2134+#2136via 3-waygit merge; note plaingit applyconflicts onwatch.rsnearSaved/impl Changed, whilegit merge/git cherry-pickresolves cleanly).world_frame_preparingunit_costs(RX 7600):declaring the heap from its start to its end as written (marked)dropped from73.0 us(end 9.1 us) on940d32f + #2134to0.0 us(end 0.2-0.3 us). (Median full-framepreparing:263.3 / 250.8 mswith#2134+#2147, and125.5 / 112.1 msRX 7600 /104.2 msWARP when combined with#2136.)Finding (
Saved::armLinear Blowup on Non-Nested Ranges)Saved::armonly prunes strict subsets (a <= first && last <= borfirst <= a && b <= last) and never merges adjacent or partially overlapping runs.adjacent_and_overlapping_armed_runs_coalesce): pushing 200 adjacent[2k, 2k+2)runs leavess.armed.len() == 200instead of[(0, 400)], turningarm()intoO(N^2)andSaved::armed(page)into anO(P)linear scan inside the VEHon_writehandler under the globalGUARDSlock (relevant for descriptor-table UAV sub-ranges indraw.rs:1733, which#2134's single-rangeunit_costssection did not exercise).(Proposed / uncompiled fix sketch using sorted disjoint runs via
partition_point:)AI-assisted; synthetic tests only, no game files, dumps, or captures used.
@r4tedx on GitHub · 2026-11-25 08:58 UTC · original
@nathanbzrr thank you, the finding holds. Pushed as
f2ca0868on top off869790(fast-forward, no rebase).Saved::armedis now a sorted list of separate runs; runs that overlap or touch merge onarm.armed(page)is a binary search, and both ends of the merge are found by binary search (your sketch'stake_whilereplaced by a secondpartition_pointon run starts).first >= last) now returns early, soarm(x, x)no longer inserts an empty run andunarmed.range(first..last)can't panic onfirst > last. Neither is reachable fromTracked::armtoday, which ensuresfrom < to.adjacent_and_overlapping_armed_runs_coalesceis in, extended with nested, disjoint (stays sorted), touching on both sides, one range spanning several runs, the empty range,armed(page)edges, and unarmed pages surviving a merge until armed again.Verified on WARP (
VICTORY_D3D12_WARP=1,--features diagnostics, one test thread): the new test fails onf869790(200 runs left) and passes onf2ca0868. Allvictory-gpulib tests: 148 passed, 0 failed, 2 ignored.cargo clippy -p victory-gpu --features diagnostics --all-targets: no warnings. I did not re-measureworld_frame_preparing, since that bench comes from #2134 and isn't on this branch.AI-assisted; synthetic tests only, no title data used.
@r4tedx on GitHub · 2026-11-25 09:59 UTC · original
In-game counters from one PC: RTX 5070 (driver 616.92), Ryzen 7 7800X3D (max processor state 99 %), Windows 11, diagnostics builds,
VICTORY_LOG=info VICTORY_D3D12_DRED=1. The title was run locally from my own copy. Only counts and timings are given here; no logs or title data are shared.This is not a same-frame A/B:
main940d32f+ #1763.f2ca0868, plus #2136f85763e0and about 25 other PRs.The scenes are different moments of the opening. Here are the preparing steps of the
copies per frame:line, for a late world frame of each run:AI-assisted
@Marvisak on GitHub · 2026-11-25 11:24 UTC · original
Automated triage for the maintainers.
Merge candidate.
watch::Savedincrates/victory-gpu/src/watch.rsnow keeps armed pages as a sorted list of separate runs, plus anunarmedset for pages a copy-back took out, instead of oneBTreeSetentry per page. I checked that the armed pages behave as before.Saved::armclears unarmed pages in the new range, as the old set insert re-armed them. Its twopartition_pointbounds pick up exactly the runs that overlap or touch, and it merges them.armed(page)is a binary search.unarmanddisarmmatch the oldremove/clear. Both new tests cover the cases @nathanbzrr found (adjacent, overlapping, nested and spanning runs, plus pages unarmed inside a merged run). The measured gain is the declaration cost on a large heap, and the in-game run reports no regression. CI: passing (check).Generated by Claude Code