GPU: fuse HostHeap::sync_slots with a VIEW_GENS RwLock #3679
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3679"
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 Luislariosss on 2026-11-28T05:46:57Z.
Summary
ecord on append and inside orget on generation bump; free-index reuse keeps its existing generation).
Why
ecords and current) per sync.
Verification
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-28T07:25:41Z.
Independent Software WARP Verification
main):63bcca43c6a00a758510398fa43096ce7e4f7df0#3679head:1f39a2fc151fc8254ec439738c1914777ae38292(clean fast-forward merge; merge tree7518c7caed2763c1d69f68bcb87382eccb4375d0; also merges cleanly with#3688into tree6526713a581880b3eeb40fb931a3d69cd1658847)VICTORY_WARP=1,VICTORY_D3D12_WARP=1,--features diagnosticssovictory-gpuselectswarp_adapter()); DXGI reportsMicrosoft Basic Render Driver (VendorId=0x1414, DeviceId=0x008C, Flags=0x2)d3d10warp.dll10.0.26100.9818,dxil.dll1.8.2502.11Results (base vs merged)
63bcca43:cargo test --locked -p victory-gpu --features diagnostics -j 4: 246 passed, 0 failed, 1 ignored (doc-tests: 0)view_gens_matches_views_across_record_forget_and_reuse: absent (0 tests)#3679(1f39a2fc):cargo test --locked -p victory-gpu --features diagnostics -j 4: 247 passed, 0 failed, 1 ignored (doc-tests: 0)descriptor::tests::view_gens_matches_views_across_record_forget_and_reuse: passedcargo clippy --locked -p victory-gpu --all-targets -- -D warnings: passedcargo clippy --locked -p victory-gpu --all-targets --features diagnostics -- -D warnings: passedcargo xtask policy: passed (191 files ok)Diff Review
self.made -> VIEWS -> VIEW_GENS(record()/forget()acquireVIEWS -> VIEW_GENS;mirror()acquiresself.made -> VIEWS;sync_slots()acquiresself.made -> VIEW_GENS). No cycle.record()pushes1toVIEW_GENSonly onviews.listgrowth;forget()bumpsgeneration.wrapping_add(1).max(1)in bothviews.listandVIEW_GENSunderVIEWSbefore pushing toviews.free; free-slot reuse keeps the bumped generation soVIEW_GENSremains in sync without a write. Minor non-blocking note:forget()takesVIEW_GENS.write()inside thefor i in entriesloop (could hoist one write guard perforget(), though safe as-is).VIEWS,VIEW_GENS, andself.madelocks recover via.unwrap_or_else(|e| e.into_inner());views.listandVIEW_GENSgrow in lockstep and never shrink.descriptor/host.rsPRs#2971,#3139,#3512, and#3522(rebase coordination needed depending on merge order).Verified by Gemini 4 Neon (Antigravity) on software WARP.
Imported from Marvisak/VIctory. Originally posted by reallyvibe on 2026-11-29T00:22:18Z.
Benchmark: this PR's sync is about twice as fast as main on unchanged pages; #3139 and #3055 measured on the same machine
The PR has no timings yet, so I ran KainanP's
sync_slots_bench(f233390e, cherry-picked unchanged) against main63bcca43, this head1f39a2fc, and the two open PRs that rewrite the same function: #313963d630a0and #3055566a27aa. All four ran interleaved. Each frame writes 393,216 slots in 192 pages, then onesync_heaps. Release builds; each cell is the median over 8 processes, in ms:"Wait" is the title threads' time in view writes, in ms per frame. Every run had 0 lost and 0 stale slots. The #3139 and #3055 ratios match KainanP's on those PRs, which serves as a check on the setup. With
SYNC_SLOTS_DIRECT=1(sync_slotsper page, without the write-watch walk), main → this PR is 2.91 → 1.25 ms, and with 5 title threads 6.29 → 1.37 ms (wait 25.2 → 6.4). These results are consistent with less contention onVIEWS, fewer allocations and the fused scan, but they don't isolate what each contributes. With ~9,500 changed records the gain over main is smaller and #3055 is fastest, consistent with view creation taking more of the time there (not isolated either).Merge checks, to add to oni-swr's report. This head merges cleanly with #3068, #3522, #3512, #2971, #3233 and #3456. Each of those merged trees builds the non-test lib and the test binary, and WARP
descriptor::passes on all of them. It conflicts textually with #3139, #3055, #3234, #3409, #3275 and #3745. In #3409's case the resolution needs care: #3409 adds its own generation writer inforget(((generation + 1) & GENERATIONS).max(1)), and that writer has to updateVIEW_GENStoo.Not tested: the title unmapping a heap page during a sync. This head reads the records while holding
self.madeand theVIEW_GENSread lock. I'm not claiming a defect.Windows 11, Ryzen 7 7445HS, RTX 4050 Laptop and Radeon 740M (default D3D12 adapter, not logged), a loaded 16 GB machine, synthetic data only.
AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by reallyvibe on 2026-11-29T01:10:44Z.
Follow-up on merging this with #3409:
host.rsmerges cleanly into a check that never passes #3409's whole-held records@pes7, this is for #3409's tested set, in case this PR goes into it.
My earlier comment flagged only #3409's generation writer in
forget. I built the merge (#3409965d9382+ this head1f39a2fc, base63bcca43) and tested it on WARP.Confirmed defect: host slots not made.
descriptor/host.rsmerges without a conflict and takes this PR'scurrent = tag == VIEW_TAG && gens.get(view) == Some(&generation). #3409 holds constant buffer views and placed views whole in the record, with kind bits 30/31 set ingeneration.VIEW_GENSvalues stay below 2^30, so those records never count as current.heap_syncs_make_the_slots_whose_records_changedandheap_syncs_make_the_slots_whose_records_hold_their_views_whole.mirroragain at every sync.mirrorreturns early, so no view is re-made, but the calls cost time. One release sync of 65,536 unchanged, made slots took 0.084 → 2.06 ms for constant views and 0.125 → 2.85 ms for placed views. That is one thread, uncontended, WARP, the median of 5 interleaved processes.Not tested: rendering consequences. Draw-time mirrors (
draw.rstable entries,make_read) may later make a slot the sync skipped, and I haven't checked whether a shader ever reads one before that. I can't say whether this shows up as wrong data in the title.Two other things the resolution needs:
VIEW_GENSpush has to move into #3409'sViews::entry(). If it goes withrecord()'s old body,VIEW_GENSstays empty andforgetpanics with "index out of bounds: the len is 0".forgetmust keep #3409's& GENERATIONSmask. Withwrapping_addthe generation reaches 2^30, which is the kind bits.Smallest resolution I found (production code +56/-30 on #3409, this PR's own change included):
recordkeeps #3409'swords_for. Withviews_currentas a test wrapper, #3409'sviews_held_whole_are_current_for_heap_syncstests the check the sync uses.On that tree,
cargo build -p victory-gpu --libandcargo clippy -p victory-gpu --all-targets -- -D warnings(default and--all-features) are clean. WARPdescriptor::passes 36/36, also with each test in its own process. That count includes both PRs' tests and two synthetic study tests. The study tests cover table entries, whole constant and placed records, unknown placed shapes, kind 3, foreign tags, unchanged records, byte copies into never-made and made slots, release, entry reuse and generation wrap. The same timing run gives 0 mirrors for all three kinds. For table entries it takes 0.125 ms against 0.090 ms with the merged line; I haven't isolated that difference.Mutation evidence. I changed the resolved tree one thing at a time and ran each test in its own process. Every change fails at least one test:
host.rsas auto-mergedheap_syncs_make_the_slots_whose_records_changedand..._hold_their_views_whole, study test (3 of 3 whole-held made slots re-mirrored per unchanged sync)VIEW_GENSpush inentry()forget)VIEW_GENSwrite inforgetview_gens_matches_views_across_record_forget_and_reuse, #3409'sviews_held_whole_are_current_for_heap_syncs, study test (released slots not re-mirrored: 0, want 2)released_entries_keep_their_generations_below_the_kind_bits, study testviews_held_whole_are_current_for_heap_syncs, both #3409 heap-sync tests, study testviews_held_whole_are_current_for_heap_syncs, study testviews_held_whole_are_current_for_heap_syncs, study testThe full patch, the two study tests and the logs are available on request.
Windows 11, Ryzen 7 7445HS, WARP, synthetic data only.
AI-assisted (Claude Code).
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.