GPU: coalesce nearby shadow-buffer refreshes without spanning huge heap gaps #1554
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1555"
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 Texbirds on 2026-11-24T19:07:34Z.
Problem
In
crates/victory-gpu/src/host.rs,Batch::addcollapses all pending refreshes for aShadowbuffer into one[min(from), max(to))bounding range.When draws in a submission read small buffers at distant offsets inside a large shared GPU heap (e.g. a 174 MiB heap),
Batch::flushcallsshadow.updateover the entire span between them—scanning write-watch/guard pages and copying unrelated dirty or unwatched megabytes viaReadProcessMemorysynchronously beforeExecuteCommandLists.Fix
[from, to)intervals inBatchand sort/coalesce overlapping or nearby intervals withinCOALESCE_GAP(64 KiB, one guard block) before flushing, so adjacent buffers still coalesce into a single update while megabyte-wide gaps are never spanned.coalesce_ranges_merges_nearby_but_keeps_distant_ranges_separate.Verification
windows-latestCI (cargo clippydefault +--all-featuresandcargo test --workspace --locked).Imported from Marvisak/VIctory. Originally posted by wwwwwwww3333333 on 2026-11-24T21:51:11Z.
On Windows,
cargo test -p victory-gpu --libdoesn't compile with this PR: headbfffb01on mainffe310e(clean merge), Rust 1.98.1 MSVC.The new test
coalesce_ranges_merges_nearby_but_keeps_distant_ranges_separatesits inmod batch, which imports onlysuper::Batch.coalesce_rangesandCOALESCE_GAPare private items ofhost.rs(lines 1236 and 1240), so the module needs them too:use super::{Batch, COALESCE_GAP, coalesce_ranges};. This probably didn't show up off Windows because host.rs is Windows-only.Unit tests only, no game files. AI-assisted (Claude; I ran it on my machine).
Imported from Marvisak/VIctory. Originally posted by Texbirds on 2026-11-24T21:54:36Z.
Thanks for catching that — fixed in 51a046d by importing COALESCE_GAP and coalesce_ranges in mod batch.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T03:30:06Z.
Automated triage for the maintainers.
Needs work (measurement only). The PR changes
Batchincrates/victory-gpu/src/host.rs. It keeps a list of spans per host copy instead of one bounding range. Inflush,coalesce_rangesmerges spans less than 64 KiB (watch::PAGE) apart, so distant buffers in a large heap no longer pull the whole gap intoshadow.update.currentkeeps the disjoint spans that are up to date.addkeeps main'sshadow.clean()early return. The code reads correctly.coalesce_ranges_merges_nearby_but_keeps_distant_ranges_separateanddisjoint_ranges_skip_dirty_gap_pagescover the merge and the dirty pages in a gap. CI: passing (check).This is a performance change with a trade-off that needs data.
addnow scans every current span of a copy on each call, and pending spans grow untilflush. On a world submission that asks for about 9,000 copies, that could cost more than the gap copies it saves. Please post--features diagnosticsnumbers from the same retail scene onmainand on this branch: thepreparing: copies … ms … MBframe summary and thecopies per frameline. If they show a drop, this can go to the maintainer.On your reply: the build and log instructions for testers are clear. The verdict stays until such numbers are posted.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T04:06:47Z.
Review: COMMENTED
Tested locally merged onto
origin/main(940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC):cargo test -p victory-gpu --lib host::tests::— all 12 baseline passing tests (including the newcoalesce_rangestests) pass on both RTX 5090 and WARP (the 1HEAP_VIEWSfailure reproduces identically on untouchedorigin/main940d32f)cargo xtask policy— ok (183 files ok)cargo clippy -p victory-gpu --all-targetsreports 2 warnings (which will fail-D warningsin CI):Holding off approval until those 2
clippy::type_complexitywarnings are resolved.AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by Texbirds on 2026-11-25T12:16:04Z.
@DenRakEiw Thanks for testing and catching the
clippy::type_complexitywarnings — those are fixed inbf7bd1eusingPendingRefresh/CurrentRefresh, and CIcheckis now passing (along with theBatchdoc comment placement and thedisjoint_ranges_skip_dirty_gap_pagestest).Regarding the remaining triage point on real-submission numbers:
Step::Refresh(viaShadow::refresh) andStep::Heap(bindless::refresh) both submit sub-ranges intoBatch::addfor command lists that don't invokememory::prepare(Step::Memory). I don't have a retail capture setup locally to collect--features diagnostics(PREPARING/copystat) before/after numbers — if a tester with a retail build can comparebf7bd1evsmain(940d32f) with--features diagnosticsand share whetherPREPARINGbytes/time drop (or ifStep::Memorydominates in practice and makes this unnecessary), that would decide whether this is worth merging.Imported from Marvisak/VIctory. Originally posted by Texbirds on 2026-11-25T16:31:58Z.
Rebased onto
main(67e8ae1) in6d5f103. I keptmain's newshadow.clean()early return inBatch::add, nowlen == 0 || shadow.clean(), and dropped the texture parts thatmainremoved. The per-spanPendingRefresh/CurrentRefreshlogic and both tests are unchanged. The open triage point is the same: this still needs before/afterPREPARING/copystatnumbers from a real submission.Imported from Marvisak/VIctory. Originally posted by Texbirds on 2026-11-25T17:13:21Z.
For anyone able to run the diagnostics comparison, the current pair is
67e8ae1(main) and6d5f103(this PR). Build both with:Please run the same world scene with the same settings after warm-up and share a few matching log intervals with:
preparing: copies … ms … MBcopies per frameline, includingrefresh batchesandtitle memoryThose numbers will help show whether the time saved by skipping gap copies outweighs the cost of tracking spans. CI passed on
6d5f103. The retail comparison is still pending.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.