Keep independent loose-window and exact-view D3D12 allocations outside table locks #238
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/TaynanGT--Vice-Tay!238
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-238"
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?
@Vladimir-Human on GitHub · 2026-11-27 11:36 UTC · original
Vladimir-Human:perf/loose-and-exact-allocations-outside-locks→main· +852 −120 · 2 files · 1 commits · merged 2026-11-27 12:09 UTCFollow-up to #196 (which handles the registered title-buffer table
BUFFERSin #199), applying the same outside-lock allocation pattern to the loose-window table (LOOSE) and exact-view table (EXACT) incrates/victory-gpu/src/shadow.rs. This PR is disjoint from #199 and does not change rendering output.Why
shadow::loose()on every draw/view outside registered title buffers (andshadow::exact()for views starting off their copy's element alignment;descriptor/host.rsnotes heavy contention underEXACT's mutex when many view copies are created).LOOSEwalks (stale_pages,windows,window_use,memory,spans,window_cover) tookLOOSE.write()instead ofLOOSE.read().loose()skippedLOOSE.read()on hits whenever tail mode (VICTORY_WINDOW_TAILS=1) or fine-grid holder lookups (VICTORY_WINDOW_KB+find_any) were active.loose()heldLOOSE.write()across D3D12CreateCommittedResource,MakeResident, residency fence confirmation, andMap(window_mapped_for,shared_buffer,window_card_for), stalling unrelated reads, independent allocations, and idle sweeps.exact()held a globalMutexacrossshared_buffercreation and idle-entry eviction drops.Changes
crates/victory-gpu/src/shadow.rs:LOOSEcallers toLOOSE.read().loose()hits throughLOOSE.read()vialoose_key_with, including tail and fine-grid holder lookups.LOOSE.write()behind per-key constructor tickets (LOOSE_BUILDING,BTreeMap<(u64, u64), Weak<Mutex<()>>>), re-selecting the live key underLOOSE.write()before publishing and dropping any obsolete candidate outside all locks soDrop for Shadowcleanly restoresWINDOW_CARD_BYTES/WINDOW_MAPPED_BYTES/LIVE. Preserves the existing transaction unchanged when optional imported/in-place modes (port::on()/inplace::level() >= 1) are enabled.EXACTtoRwLock+EXACT_TICK: AtomicU64+EXACT_BUILDINGper-key constructor tickets, allocating and dropping evicted copies outsideEXACT.write()and stamping newly published entries with the publish-time tick (published_now).crates/victory-gpu/src/shadow/loose_allocation_tests.rs:spans(), parallel allocations of independent keys, same-key deduplication, concurrent wider tail/holder re-selection with card-budget discard release and byte-exact GPUCopyBufferRegionreadback, allocation failure retry, andEXACTeviction + publish-time tick freshness.Verification
All commands ran on Windows (
rustc 1.98.1,VICTORY_D3D12_DEBUG=1,--test-threads=1), with synthetic memory and real D3D12 buffers (no runtime FPS claim):cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: 0 warningscargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings: 0 warningscargo test -p victory-gpu --locked --lib shadow:: -- --test-threads=1: 59 passed; 0 failed; 4 ignoredcargo test -p victory-gpu --locked --lib port::tests -- --test-threads=1: 2 passed; 0 failedcargo test -p victory-gpu --all-features --locked --lib shadow:: -- --test-threads=1: 59 passed; 0 failed; 4 ignoredVICTORY_D3D12_GBV=1 cargo test -p victory-gpu --all-features --locked --lib shadow::loose_allocation_tests -- --test-threads=1: 5 passed; 0 failedVICTORY_D3D12_WARP=1 cargo test -p victory-gpu --locked --lib shadow::loose_allocation_tests -- --test-threads=1: 5 passed; 0 failedcargo run -p xtask --locked -- policy(311 files ok) andcargo test -p xtask --locked(11 passed; 0 failed)@TaynanGT on GitHub · 2026-11-27 11:50 UTC · original
@Vladimir-Human The separate constructor tickets for
LOOSEandEXACTare the useful part of this follow-up. I’ll check the wider-holder readback and retry cases against current main, especially that discarded candidates return their budget and that the imported and in-place paths keep their existing transaction.@Vladimir-Human on GitHub · 2026-11-27 12:06 UTC · original
Thanks @TaynanGT — checked against current
main(6b3a266, cleangit merge-treewith no conflicts, and all CI checks are green). Quick pointers to the three invariants inff16635:Wider-holder / tail re-selection, readback, and retry:
crates/victory-gpu/src/shadow.rs:6615-6652(loose_with): acquires per-keyLOOSE_BUILDINGticket, re-checksLOOSE.read()vialoose_key_with, allocates outsideLOOSE(make(key.1)?drops_onlycleanly on failure so retries proceed immediately), then re-runsloose_key_withunderLOOSE.write(). If a wider tail/holder or the same key published meanwhile, it adoptsexistingand dropscandidateafter releasingmapand_only; ifselected != key, it dropscandidateand loops.crates/victory-gpu/src/shadow.rs:6732-6784(exact_with_limits): same per-keyEXACT_BUILDINGticket,?-based retry on allocation failure, publish-timepublished_nowtick stamping, and out-of-lockevicteddrops.crates/victory-gpu/src/shadow/loose_allocation_tests.rs:loose_reselects_concurrent_wider_tail_or_holder_and_gpu_readback_sees_live_bytes(L273-370, bothuse_tailsanduse_holderwithShadow::refresh+CopyBufferRegionreadback +host.log_messages().is_none()),loose_allocation_failure_leaves_window_open_to_retry(L373-382),exact_lookups_and_parallel_allocations_proceed_while_pending_with_gpu_readback(L385-471), andexact_eviction_keeps_held_entries_and_uses_publish_time_tick(L474-533).Discarded candidate budget release outside locks:
make_loose_backing(L6457-6467) hands every budget-counted buffer directly intobuild_loose_shadow(L6469-6511) without pushing toCARDEDuntil publish (L6647-6649).L6636-6638,L6642-6644, andL6753-6755),mapand_onlyare dropped beforedrop(candidate), whereDrop for Shadow(L3449-3476) subtractsLIVE,WINDOW_MAPPED_BYTES(shadow.mapped), andWINDOW_CARD_BYTES(shadow.window && shadow.card.is_some()).loose_reselects_concurrent_wider_tail_or_holder_and_gpu_readback_sees_live_bytes(L292,L300,L347-351) uses a card-backed candidate (shared_with_card) and assertsWINDOW_CARD_BYTESreturns to its exact baseline after both tail and holder discards.Imported / in-place transaction preserved:
loose_with(L6589-6611) bypassesLOOSE_BUILDINGwhenevercrate::port::on() || crate::inplace::level() >= 1and keeps the originalLOOSE.write()transaction (loose_key_with->port::place_for/inplace::place_for-> fallback allocation +CARDED+ insert all underLOOSE.write()). Cache hits underLOOSE.read()(L6578-6586) remain mutually excluded fromin_place_let_go(L6035) andlet_go_idle(L3868), which both takeLOOSE.write().Happy to rebase or add a mapped-window discard check as well if helpful.
@TaynanGT on GitHub · 2026-11-27 12:09 UTC · original
@Vladimir-Human I checked the re-selection and out-of-lock discard paths, including the original transaction for imported and in-place memory. The Windows checks passed and the merge onto current main retained the same allocation patch alongside the existing helper priority change. It’s now in main at
1f69d67. The next gameplay comparison can measure table wait and rendered frame time on the same route.@hamdanpor-ctrl on GitHub · 2026-11-27 16:06 UTC · original
Test report, NVIDIA laptop on Windows: one new test fails now and then.
mainat6b3a266, and the same commit withff16635merged (git merge --no-ff, clean)cargo test --workspace --locked, tests in parallel (the default)--all-featuresshadow::loose_allocation_tests::exact_eviction_keeps_held_entries_and_uses_publish_time_tickfailed in 2 of the 5 runs, both times atloose_allocation_tests.rs:526:Likely cause: the test counts ticks of the global
EXACT_TICK(lately = 2, then one more miss), but other tests running beside it also allocate exact entries and advance the same tick, soslow_addrcan already look stale at the trigger. Running the loose-allocation tests that touchEXACTone at a time (a test-only lock, likewatch::one_asking_test) should make it deterministic.The third failing run was
watch::tests::what_the_kernel_writes_through_is_not_guarded_for_another_view, which also fails now and then onmainhere and is addressed separately in #246.Single batch. AI-assisted (Claude Code).
@TaynanGT on GitHub · 2026-11-27 16:17 UTC · original
@hamdanpor-ctrl You found the same shared-clock problem we saw in CI. #300 is on main and checks the published timestamp directly while holding the allocation. Parallel lookups can advance the clock without invalidating that assertion. The current Windows checks pass. Thanks for confirming it under the default parallel test run on your laptop.
github-bot referenced this pull request2026-11-27 16:44:35 +00:00