GPU: a refresh takes the whole pages it touches #3287
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3289"
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?
Imported from Marvisak/VIctory. Originally posted by QalityDev on 2026-11-26T16:02:41Z.
A refresh of a range that cuts a 64 KiB page copied that part and left the page changed (
Tracked::take), so every later refresh reaching it copied it again, whether or not the title had written it since. GTA VI refreshes small ranges inside its 174 MB GPU-heap buffer dozens of times per frame: on an RTX 4060 Ti, 410-550 MB of the 550-690 MB copied per frame came from such partial pages.Shadow::updatenow widens the range to the whole pages it touches (cut to the copy). Taken whole, a page is guarded and copied again only once the title writes it. Ranges whose shaders' writes stay in the copy (keep_writes) are remembered and the widening stops short of them; ranges shaders are writing still go through the busy split. This generalises what #2172 does for marked UAV refreshes to every refresh.Measured in the intro cutscene (diagnostics build):
New test
a_partial_refresh_takes_the_whole_page; the copy-stats line reports bytes taken from whole and partial pages. On main63bcca4: victory-gpu lib tests 230 passed (dynamic_slots_are_held_until_releasedandlists_share_a_table_and_copies_keep_their_viewsfail on main as well on this RTX 4060 Ti); clippy clean with and withoutdiagnostics.Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T16:08:18Z.
Review: APPROVED
Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090):
Shadow::widento 64 KiB page boundaries (clamped to the buffer and stopping short ofShadow::keptranges, withbusyranges still subtracted afterward) cleanly lets touched pages be taken whole and guarded instead of repeatedly re-copying partial pages, withTakenWholeBytes/TakenPartBytesdiagnostics counters matching.cargo test -p victory-gpu --lib shadow:: -- --test-threads=1(RTX 5090): 11 passed, 0 failed (includinga_partial_refresh_takes_the_whole_page).cargo test -p victory-gpu --lib draw:: -- --test-threads=1(RTX 5090): 20 passed, 0 failed.cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo clippy -p victory-gpu --features diagnostics --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T16:42:32Z.
WARP verification report (test report only, no code changes)
d99e868f63bcca43(control); WARP software adapter forced withVICTORY_WARP=1 VICTORY_D3D12_WARP=1,--features diagnostics, d3d10warp.dll 10.0.26100.9818; dxil.dll 1.8.2502.11 (Windows Kit 10.0.26100.0, viaVICTORY_DXIL). No physical GPU. Synthetic tests only, no game data.cargo test -p victory-gpu --lib --features diagnostics --no-run -j 4, then the test binary with--exact <name> --test-threads 1per test, then the whole lib suite.shadow::tests::a_partial_refresh_takes_the_whole_page: passes on the PR (1 passed, 0.22 s).the written page, whole(left 16, right 65536): the refresh copies the 16 bytes asked for, not the page.victory-gpulib suite: PR 246 passed, 1 failed, 1 ignored; main plus the test 245 passed, 2 failed, 1 ignored (the new test and the failure below).frame::tests::waits_end_on_ticks_and_count_frames(left: 0, right: 1at frame.rs:231). It also fails alone in its own process on the PR and on main, so it is not caused by this PR.AI use: Claude Code (Claude Sonnet 5.5)
Imported from Marvisak/VIctory. Originally posted by Venom2054 on 2026-11-26T17:17:00Z.
I tested a port of
d99e868on an RTX 5070 Ti with a tuned Series S profile. Two fresh launches used the same executable, save and warmed pipeline library. Only whole-page refresh changed. The port avoids widening across ranges previously written by a GPU shader because this fork can retain those writes.At the stationary prison window, median copy volume fell from 75.0 to 55.4 MB per frame. The partial-page counter fell from 26.72 to 0.03 MB per frame. Write-watch time fell from 27.51 to 23.28 ms with 2,251 and 2,271 queries per frame, respectively. The runs issued 4,424 and 4,488 draws per frame.
Seven complete presentation batches per run covered 35.3 and 35.4 seconds. Presentation rate rose from 9.88 to 11.35 FPS (349 and 402 presents). Median frame time went from 101 to 85 ms and p90 from 142 to 120 ms. This is one pair of launches. A separate in-process toggle reproduced the reduction in copy volume. Disabling the change did not immediately restore the original volume because already refreshed pages stayed current.
Codex assisted with the port and measurements.
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T17:21:39Z.
I checked a scaling case for the kept-write lookup on
d99e868. Repeated overlapping declarations kept 131 entries for two disjoint regions, andwidenwalked the full set for each refresh. Follow-up6d3e953keeps the union of overlapping and adjacent ranges. Each lookup uses the nearest kept ranges to find the same boundaries.The new regression gets two records, preserves both clipping boundaries, and keeps a request that overlaps a GPU write narrow. The original WARP kept-texel and whole-page tests pass. Full diagnostics on verified app-local Agility 1.620.2/WARP 1.0.22 had 249 passed, 0 failed, 1 ignored, including runtime identity. Strict Clippy in both configurations and asset policy passed.
I also built an optimized isolated benchmark from the two exact
widenimplementations. It first checked 2,500 mixed overlap insertions/lookups and 16,384 matching lookup results per disjoint-set size, then alternated nine timed runs. Median lookup time stayed at 19 ns with zero kept regions, went from 215 to 101 ns with 64 disjoint regions, and from 12.8 to 0.163 microseconds with 4,096. These are CPU lookup timings on synthetic ranges; a title trace would show how often a real buffer reaches those counts.@QalityDev this is one commit directly on your head if the follow-up fits. Please retain its Git author on cherry-pick or rebase, or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if folding it into another commit. AI-assisted with Codex.Imported from Marvisak/VIctory. Originally posted by QalityDev on 2026-11-26T18:14:34Z.
Thanks @andrewpozdnakov7-jpg — reviewed and added as-is:
6d3e953is now on the branch with your authorship. Checked here on an RTX 4060 Ti:shadow::/watch::tests 27 passed (includingoverlapping_kept_writes_remember_their_union), strict Clippy clean with and withoutdiagnostics.Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-26T19:03:37Z.
Independent local verification on Windows 11 x64, Intel Arc B580 12 GB (12 cores), at this PR's head
6d3e953:Result: victory-gpu lib: 2 known baseline failures only; the new a_partial_refresh_takes_the_whole_page test passed.
Both clippy runs exit 0 (-D warnings, both feature sets). The B580 baseline failures pristine main also hits are: victory-gpu descriptor::host::tests::dynamic_slots_are_held_until_released + memory::tests::lists_share_a_table_and_copies_keep_their_views (#1744/#1829); victory-shader emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros + emit::valu_tests::fspx_programs_run_with_the_hardwares_dot_products. No PR regressions.
Synthetic tests only; no game data used. Full log kept locally. — borosf
Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-27T07:05:51Z.
Measured in game on an RTX 5090 (driver 620.73.04), Linux, GE-Proton11-14 Wine with its vkd3d-proton, GTA VI's opening prison yard, warm cache; base is
mainplus the unmerged PRs this setup needs (#3312, #3318, #2472 and others, listed in #3425). This PR merged on top, 600 s runs, medians of the last 30 frame-rate lines, against a control run of the same base taken next to it (frame times drift by up to ~25 ms between runs hours apart).Around 2-3 ms off preparing, inside the spread of the controls. Its two new
shadow::tests pass under Wine.AI-assisted (Claude); measured on my machine, no game data shared.
Imported from Marvisak/VIctory. Originally posted by AndyLatimer on 2026-11-27T08:47:59Z.
Review: CHANGES_REQUESTED
Reviewed commit
6d3e953(crates/victory-gpu/src/shadow.rs, rebased/merged cleanly onto63bcca4). The core idea of guarding whole 64 KiB pages on partial refreshes makes sense, but two issues need addressing before merge:1. Partial widening on pages with
keptwrites amplifies repeated refreshes, andself.keptis never prunedwatch::Tracked::take_split(from, to)only marks a 64 KiB pagepas guarded (whole) when(p * PAGE).max(self.start) >= from && ((p + 1) * PAGE).min(self.end) <= to.When
self.keptcontains e.g.[p + PAGE - 16, p + PAGE),Shadow::widen(p + 64, p + 80)clamps to(p, p + PAGE - 16)(65,520bytes). Because that page is not covered whole,take_splitleaves it unguarded/dirty, so every subsequent 16-byte refresh on that page re-copies65,520bytes instead of16bytes onmain(up to ~4,095x amplification).In addition,
self.keptis never cleared once title memory and the host copy resync (update_tracked,copy_back_or_notwithback == true,copy_back_marked), so a singlekeep_writespermanently prevents whole-page guarding on that page for the rest of the run.Reproduced on
6d3e953(RED):shadow::tests::repeated_small_refreshes_beside_kept_writes_do_not_amplify_copiesfailed:(Expected
<= 64bytes.)2. Withheld
copy_back_markspages are not recorded inself.keptIn
copy_back_marks, pages withheld inheldcallcrate::memory::drop_withheld(page, PAGE)without recording[page, page + PAGE)viacopy.remember_kept(page, page + PAGE). A later small refresh at another offset on that same page widens across the whole 64 KiB page and overwrites the withheld GPU writes with stale title memory.Reproduced on
6d3e953(RED):shadow::tests::widened_refresh_preserves_withheld_marked_write_on_same_pagefailed:(
0xddwritten atp + 4096overwritten by a small refresh atp + 64..p + 80.)Suggested fix & verification
Shadow::widen, checkhas_keptper boundary page (first_start..first_end,last_start..last_end) so pages containing kept writes stay narrow while clean neighbor pages on multi-page refreshes still widen.Shadow::forget_kept(from, to)and prune synced spans incopy_back_or_not(whenback == true),copy_back_marked, andupdate_tracked(for each copied/zeroed(a, b)span).copy_back_marks, collect(Arc<Shadow>, usize)pairs forheldpages while holdingmarks(), dropMARKS, and callcopy.remember_kept(page, page + PAGE)beforecrate::memory::drop_withheld(page, PAGE).Tested patch + regression tests (applies cleanly on
6d3e953)Verified locally (Windows 11, NVIDIA GeForce RTX 3060 Ti, Rust 1.98.1 MSVC):
cargo test -p victory-gpu --lib --locked -- shadow:: watch:: --test-threads=1-> 29 passed, 0 failedcargo clippy -p victory-gpu --all-targets --locked -- -D warnings-> 0 warningscargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings-> 0 warningscargo xtask policy-> 191 files okSynthetic tests only; AI-assisted review.
Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-27T22:43:56Z.
A local benchmark at
6d3e9539againstmain63bcca4(same base), Windows 11, RTX 3070 PC, release. It is an ignored test inshadow::tests, not proposed: one 32 MiB copy overpool(512)memory,copy.updatecalled directly, and the same random sequence on both trees, 30 frames, 3 runs each (identical every time).mainB is the pattern the description measures in the title: a page cut by a refresh stays changed on
mainand is copied again at every later refresh. Here the PR copies 22× fewer bytes and is about 14× faster. That reproduces the effect away from the title.A shows the other side of the widening. When the refreshes are tiny and land on pages the title writes,
maincopies only the asked bytes, while this PR copies the whole 64 KiB page once after each write. That is about 50× the bytes at no measurable cost here (both under 0.2 ms, the bytes still under 1 MB a frame). For a title that writes many pages each frame and refreshes only a few bytes of each, the cost would grow with the pages written. That is worth keeping in mind against the 410-550 MB the widening removes in the title. Not a reason to hold it, as far as these numbers go.cargo test -p victory-gpu --lib shadow::tests::at the PR head: 11 passed, 0 failed in each of 3 runs,a_partial_refresh_takes_the_whole_pageandoverlapping_kept_writes_remember_their_unionincluded.AI-assisted (Claude Code, Claude Opus 5.5 wrote and ran the local benchmark).
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.