perf(gpu): reuse closed command lists’ wide refresh summaries #308
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/lobomfz--VIctory-xmem!308
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-308"
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?
@tommiehansen on GitHub · 2026-12-03 10:21 UTC · original
tommiehansen:perf/t07-record-refresh-front→main· +810 −68 · 5 files · 9 commits · openWhy
Wide submissions repeatedly walk closed deferred streams and schedule planner worker jobs even for reused command lists. The earlier 3–6 ms trace covers the entire refresh-front operation, not just this work.
What changes
With VICTORY_RECORD_REFRESH_FRONT=1, build ListFront at close after async splicing, retain mutation-generation keyed summaries, invalidate on every mutation/reset, and fold/deduplicate in submission order. Narrow, changed and unprepared lists use original fallback; off uses original algorithm.
Benchmark results
Reproducible CI result · head
8904c820e8b8· Linux hosted CPU-only, Standard, four ABBA blocks (8 runs per arm).Same head;
VICTORY_RECORD_REFRESH_FRONT=0→1. Other CPU controls show no significant change; hardware workloads unsupported.Negative values indicate reduced CPU time. Synthetic workloads, not gameplay FPS.
Earlier 16-list ×512-step fixture, one recording and four submissions with partial miss: 100.416→31.250 µs (−69.00%, 95% CI −69.15 to −68.85%), scans 64→18 including close. A repeat at
b88c697measured 101.188→31.625 µs (−68.84%).Why this should be merged
Strong scoped planner savings include recording and repeat submission cost. No frame-time promise; reuse frequency and metadata cost matter.
Validation
Two portable production folding/reuse/mutation tests, Windows all-targets with/without diagnostics on earlier revisions; current-head pinned audit. Report actual recording plus submission and exact rendering on a matched route.
Compatibility and dependencies
Independent opt-in; preserve alias/write/texture coverage, barriers and queue ordering. #528 is a separate repository-policy issue.
Previous detailed description, historical measurements and checklist.
github-bot referenced this pull request2026-12-03 16:15:26 +00:00
@tommiehansen on GitHub · 2026-12-03 19:25 UTC · original
Updated PR #308 (merged current
main45591b0including #220/#330/#332 + commitcb9fd4d):Improvements in
cb9fd4dcrates/victory-gpu/src/host/front_plan.rs):list_frontand three-hash-tablejoin_frontswith single-passbuild_list_frontandjoin_list_fronts(oneByKeymap per stage,Arcstored directly with its bounding span, zero-length refreshes skipped early without hashing/cloning, and a zero-hash-map fast path for single non-empty list joins). This also speeds up uncached wide submissions (VICTORY_RECORD_REFRESH_FRONT=0).seen_textures+ last-key shortcut) beforerefresh_fronts.VICTORY_RECORD_REFRESH_FRONT=1):resolve_fronts): If 15/16 lists have valid summaries and 1 is appended/spliced, only the missing list is rebuilt (inline whenmissing.len() == 1, or viawide_eachovermissing.len()when>= 2) instead of falling back to recomputing all lists.OnceLock<Arc<ListFront>>sentinel instead of allocating a newArc<ListFront>on every close.No duplication of #220 (by-address prefix caching), #330 (
VICTORY_PARTS_ONE_CALL), or #332 (VICTORY_KEEP_HOST_BUFFERS).CPU Benchmark Results (Apple M5 macOS ARM64,
rustc -O, A/B/B/A 8 blocks, exact parity verified)Both Combined (close + submit) and Submit-Only CPU times were measured directly against the production
front_plancode:vs
origin/main(No-cache baseline → Improved PR #308)vs Previous PR #308 (
3ab6d57→ Improved PR #308)EMPTY_FRONT)Verification & Limitations
crates/victory-gpu/src/host/front_plan.rs(rustc --edition 2024 --test crates/victory-gpu/src/host/front_plan.rs): 2 passed, 0 failed.cargo check -p victory-gpu --all-targets --target x86_64-pc-windows-msvc(using check-onlylibmimalloc-sysshim +blake3/pure), both standard and--features diagnostics: passed with 0 errors and 0 warnings.cargo --offline xtask policy --staged: asset policy: 2 files ok.host.rssubmission execution, GPU copy refreshes, RADV/Wine execution, and gameplay frame times require external Windows/Linux AMD GPU hardware).@Kal0s-design on GitHub · 2026-12-03 19:37 UTC · original
Tested
cb9fd4dnatively on Windows 11 with MSVC and toolchain 1.98.1, building only victory-gpu. The D3D12 host tests in the suite ran on one NVIDIA desktop card.One real problem first.
host::front_spans_tests::a_changed_or_reused_list_cannot_share_its_previous_frontfails every time on this head (0/20 in debug and in release, switch on or off). It panics at host.rs:6913 on!Arc::ptr_eq(&first, ...). The list in that test only hasCopy/Fillsteps, so its front is empty, and sincecb9fd4devery empty front is the sharedempty_list_front()Arc, so both summaries are the same pointer. The production code is fine here, it's the test that needs aRefreshstep (or a check that doesn't rely on pointer identity). The standalone rustc run of front_plan.rs wouldn't have caught it because this test lives in host.rs.On staleness, the per-list check is the same as before. Each list is either served from a summary whose step count still matches or rebuilt from its current steps (
resolve_fronts), and narrow submissions only take the summary path when every list has a valid one, otherwise they use the inline loop as on main. Across the crate, steps are only written while recording, by thetake_comingsplice (whichclose()runs beforeprepare_refresh_front()), or by the in-placeCopymerge, which the planner ignores. Submission only reads them andreset()replaces the wholeDeferred. So partial and narrow reuse don't add a new way to get a stale front, as long as nothing starts rewritingRefreshorTexturesteps in place after close.I also compared the new single-pass planner against main's
list_front+join_fronts+front_spanswith a local randomized test (not pushed, up to 16 lists of 200 steps, 20,000 rounds). Without zero-length refreshes the spans and their order come out identical, and textures match once you account fortexture_duealready deduping per submission. With zero-length refreshes they differ, because main still widened a copy's span to include a zero-length point and the new code skips it. For example(c, 50, 0), (c, 10, 20)gives(10, 50)on main and(10, 30)here, and a copy touched only by zero-length refreshes at different addresses is dropped entirely. Every non-empty requested range is still covered, so this only refreshes less, but it means the wide path with the switch off isn't strictly the same as main. Nothing indefer_refreshrules out a zero-length refresh, though I didn't confirm one actually occurs in practice.Results otherwise. Both front_plan tests passed 20/20 in debug and release with the switch off and on. The full lib suite with
--test-threads=4, skippingdescriptor::tests::views_die_with_their_resource, gave 331 passed, 6 failed and 23 ignored with the switch off and the same with it on. main at00aa4d3gave 338 passed, 5 failed and 23 ignored. The extra failure is the test above, and the other five also fail on main (watch::tests::the_rest_of_the_one_asking_has_a_number_of_its_ownis intermittent there too). Clippy with--all-targetsshows the same warnings as main. No existing test drives a real wide submission end to end, and nothing was run with game data.AI-assisted: yes
@tommiehansen on GitHub · 2026-12-03 20:03 UTC · original
Thanks for the native Windows 11 test report and 20,000-round differential check, @Kal0s-design! Both findings are fixed in
ad0d01a:host::front_spans_tests::a_changed_or_reused_list_cannot_share_its_previous_front:host.rstest afterspliceto verify invalidation (is_none()) followed by empty-front pointer sharing (second.is_empty() && Arc::ptr_eq(&first, &second)).front_plan::tests::non_empty_changed_list_allocates_distinct_front_arcto verify that changing a non-empty list invalidates its cache and allocates a distinctArc<ListFront>(!Arc::ptr_eq).VICTORY_RECORD_REFRESH_FRONT=0and=1):len == 0skip inbuild_list_frontso zero-length points participate in per-copymin(from)/max(to)merging within and across lists identically toorigin/main'slist_front+front_spans, while filteringfrom < toinjoin_list_fronts(single-list fast path and multi-listretain).reference_planand addedfront_plan::tests::zero_length_refreshes_match_main_front_spans_semantics+ 256-round randomized differential testing covering both single-list and multi-list zero-length refreshes.Verification:
rustc --edition 2024 --test crates/victory-gpu/src/host/front_plan.rs: 4 passed, 0 failed (0 warnings).cargo check -p victory-gpu --liband--all-targets --features diagnostics(x86_64-pc-windows-msvc): 0 errors, 0 warnings;cargo --offline xtask policy --stagedpassed (2 files ok).host::front_spans_testscould not run on macOS ARM64; only cross-target compilation and nativefront_plan.rstests ran here.@Kal0s-design on GitHub · 2026-12-03 20:32 UTC · original
Reran on
ad0d01a.The cache test passes 20/20 in debug and release, with
VICTORY_RECORD_REFRESH_FRONTunset and set to 1. It isn't passing trivially. I tried a local mutation whereCachedFront::getignores the step count, and it then fails at theis_none()after the splice (so doesnon_empty_changed_list_allocates_distinct_front_arc). The name reads a little odd now that it asserts the two empty fronts do share, but that's cosmetic.The two single-list cases from my last comment are fixed.
(c,50,0),(c,10,20)now gives(10,50), and a copy touched only by zero-length refreshes at 100 and 300 comes out as(100,300)instead of disappearing. I ran a throwaway local differential (not pushed) with 1 to 16 lists of up to 200 steps, around 12% of steps zero-length, plus duplicates, touching ranges, textures and partly cached lists going throughresolve_fronts. Over 20,000 rounds the new planner matches main's inline path (front_spansover all touches) exactly on spans, order and textures. A 200,000 round run also showed no differences.Against main's wide path (
list_frontthenjoin_fronts) it still differs in 8830 of 20,000 rounds, and only in rounds that have zero-length refreshes. Main's per-listfront_spansdrops zero-length points before the join, so it loses them when they sit in a different list from the real refresh. Your ownmulticase inzero_length_refreshes_match_main_front_spans_semanticsshows it. On main's wide path that input gives[(1,10,30)], not[(1,10,50),(3,10,50)], so the "mirrors origin/main's list_front" comment only holds for one list. With the switch unset the new planner only runs for wide submissions, which is exactly where main usedlist_front/join_fronts, so this is a behaviour change by default. In every differing round I checked, the new spans contain main's wide spans (about 477k spans checked, none narrower). Main's inline path already behaves this way, so it might be fine. I just think it's worth saying in the description or having a maintainer decide which one is intended.Full
cargo test -p victory-gpu --lib(skippingviews_die_with_their_resource) gives 334 passed, 5 failed, 23 ignored with the switch unset and set to 1, and the 5 failures are the same ones main has. Main shows 338 passed only because the branch adds 5 tests and is missing 9 newer ones from main. It merges cleanly. Clippy on-p victory-gpu --all-targetsshows the same warnings as main, none new.AI-assisted: yes
@Kal0s-design on GitHub · 2026-12-03 21:20 UTC · original
Reran everything on
6959e16.The wide/narrow split fixes the gap I reported. I ran the same differential harness locally with the new planner on each path separately, comparing it to main's code for that path. It is not part of the PR. Each run used 200k random submissions. They had 1 to 16 lists, zero-length refreshes in both the same list and a different list from the real refresh, repeated steps, touching ranges, and textures.
The single cases match main too. (c,50,0),(c,10,20) in one list gives (10,50) on both paths. Your
multicase gives [(1,10,30)] wide and [(1,10,50),(3,10,50)] narrow, same as main for each. A copy touched only by zero-length refreshes at 100 and 300 keeps (100,300) when they are in the same list as other refreshes. When they sit in separate lists it is dropped on the wide path, as on main.The front_plan and front_spans tests passed 20/20 in debug and release, with the switch both unset and =1. The full victory-gpu lib suite (one known descriptor test skipped) has the same failing tests as main in both switch states. Nothing new. Clippy for victory-gpu shows no new warnings compared to main.
On caching, the cached fronts still keep the zero-length points, and they are only dropped when the lists are joined. So one cached entry works for either join, and the staleness reasoning from last time still holds.
AI-assisted: yes
@tommiehansen on GitHub · 2026-12-04 00:03 UTC · original
Thanks @Kal0s-design for testing
6959e16natively and verifying both the wide and narrow paths across the 200k random differential checks and 20/20 tests.@Luxuride on GitHub · 2026-12-04 12:09 UTC · original
The extraction into
front_plan.rswith a randomized differential oracle against the old planner is exactly how this should be done. Three things keep it from being a yes today.crates/victory-gpu/src/host/front_plan.rs:94is(*recorded_steps == steps).then(...), so correctness rests on an unwritten invariant: a list'scopiesmay only grow between reset and submission. Worse, the test atcrates/victory-gpu/src/host.rs:6906documents the opposite — it mutatesdeferred.copies[0]in place and asserts the stale front is still returned. It is safe only because that slot happens to hold aCopyand not aRefresh; the next person who splices aRefreshin place gets a wrong span and a wrong upload. Key the cache on a generation counter bumped on mutation, not on a count.crates/victory-gpu/src/host.rs:6838gates the cache onVICTORY_RECORD_REFRESH_FRONT=1, yet with it unset you still replace the hot path with the newresolve_fronts/join_frontssplit. So the default path is unchanged-but-different for no measured gain. Say that in the body, or keep the old path when the switch is off.Also:
VICTORY_RECORD_REFRESH_FRONTis indocs/SETTINGS.md:33but not inrun.conf.default, whereVICTORY_LATE_FENCEandVICTORY_BAKE_SOURCES_ONLYlive.The empty-span parity fix (
6959e16) shows you did catch the trap that matters. Generation counter, onerun.conf.defaultrow, one number — then I would take it.@tommiehansen on GitHub · 2026-12-04 15:12 UTC · original
@Luxuride, the fixes are in
1f9ca51(current headb88c697). Deferred step mutations now invalidate by generation, including same-length replacements. The switch-off path uses the original wide and narrow folds, and the switch is inrun.conf.default. Five portable planner tests and the Windows-target check passed. The Standard production-planner fixture measured 101.188 → 31.625 µs (−68.84%, identical output), including one recording, four submissions and a partial miss. That is CPU-only; the PR now documents the reproduction and requests combined recording/submission timings in game.gpu: reuse closed command lists’ wide refresh summariesto perf(gpu): reuse closed command lists’ wide refresh summariesView 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.