perf(gpu): list threads' lookups without shared locks (VICTORY_PLACED_SEEN, VICTORY_VIEWS_SHARDED, VICTORY_SHADOW_SHARDED) #331
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: launcher
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
run report
security: hold
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs gpu test
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Androtim--MiniVI!331
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-331"
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?
@PiloteCode on GitHub · 2026-12-02 12:27 UTC · original
PiloteCode:pr/list-lookups→main· +622 −65 · 5 files · 2 commits · merged 2026-12-02 22:34 UTCSummary
The threads that translate list calls (
VICTORY_THIN) spend much of their time in short lookups that return the same answer draw after draw, behind locks every one of them takes. Even uncontended, taking a sharedRwLockfor reading writes its cache line, which then moves between cores on every read. Three cuts, each with its own switch (on unless0; diagnostics builds can switch each inside a run withVICTORY_AB):VICTORY_PLACED_SEEN:resource::texture_at(aMutexover aBTreeMapof 64-byte keys, taken for every view of placed memory a draw reads) is answered from a small per-thread table first. Safe becausePLACED_TEXTURESis append-only (a texture made for a place and description is kept for the run); a comment on the table now says so.VICTORY_VIEWS_SHARDED: the table of every view (descriptor::VIEWS) is read under one of 16 cache-line-padded locks chosen by the reading thread; a writer takes all of them in order. Same exclusion as oneRwLock; a thread that reads again while reading reuses its first lock (no writer can wedge between).views_read/views_writekeep their try-first-then-count-the-wait shape (ReadMostly::try_writeadded for that).VICTORY_SHADOW_SHARDED: the same for the host copies' tablesshadow::BUFFERSandshadow::LOOSE.The three are in our fork's play defaults since 1 Dec.
Changes
crates/victory-gpu/src/listcpu.rs(new): the switches,ReadMostly<T>(+try_read/try_write),Remembered<K, V, N>,hash_words; tests (concurrent readers under both lock modes while the switch flips, never seeing a half write; try-lock behaviour; memo correctness).crates/victory-gpu/src/resource.rs:texture_at->texture_at_seen/texture_at_table; testa_remembered_placed_texture_is_the_tables(skips without a host device, as the neighbouring test does).crates/victory-gpu/src/descriptor.rs:VIEWSasOnceLock<ReadMostly<Views>>;views_read/views_write.crates/victory-gpu/src/shadow.rs:BUFFERS,LOOSEasReadMostly;.read()/.write()call sites withoutunwrap_or_else(poisoning handled inside).crates/victory-gpu/src/lib.rs:mod listcpu;.host.rsuntouched.Rig Specs Tested On (our fork, not this tree)
Run Settings & Profile
VICTORY_AB(7-8 switches, 10 s phases in a mixed order, 56 phases at the busiest place of a saved game), drift fitted; list threads' processor time per phase from the per-thread CPU countersMeasurements & Verification
PLACED_SEENVIEWS_SHARDEDSHADOW_SHARDEDSHADOW_SHARDEDslowest 1 % +3 +- 4 ms, not resolved). Pictures compared at fixed points: the same.thin_ms(list calls translated by threads of ours per frame) line.main3230974; offline,--locked, toolchain 1.98.1-msvc):cargo clippy --workspace --all-targets --locked -- -D warningscargo clippy --workspace --all-targets --all-features --locked -- -D warningscargo test(not run by us on this tree)cargo xtask policy(not run; files stay far below the 640 KiB limit)Limits
PLACED_SEENrelies onPLACED_TEXTURESnever losing an entry: anyone who later evicts entries from that table must turn this off or bump a generation the memo checks.shadow.rs: it merged without a conflict and passes clippy, but our measurements predate #322.github-bot referenced this pull request2026-12-02 12:52:43 +00:00
@Androtim on GitHub · 2026-12-02 12:49 UTC · original
Read-only security & triage review on
11322318(external authorPiloteCode— awaiting manual owner approval per repository security allowlist policy; not built/executed locally and not auto-merged):crates/victory-gpu/src/{descriptor.rs,lib.rs,listcpu.rs,resource.rs,shadow.rs}(+515/-58); noCargo.toml,build.rs,.github/workflows/, binaries, shell/network calls, or clean-room violations. Note customunsafeshardedRwLockwrapper (listcpu.rs) +VirtualAlloctest — warrants careful soundness review on approval.VICTORY_PLACED_SEEN,VICTORY_VIEWS_SHARDED,VICTORY_SHADOW_SHARDED, default-on with=0kill-switches). Needs manual owner approval to run CI + plain---releaseA/B verification.@Androtim on GitHub · 2026-12-02 13:04 UTC · original · edited 2026-12-02 18:02 UTC
Automated triage for the maintainers (not an approval).
Verdict:
needs-rebase· CI (check):failingThis PR no longer merges cleanly into
main.To change the verdict: Rebase onto current
mainand resolve conflicts; CI and triage will run again automatically.Generated with Antigravity CLI (
agy).@Androtim on GitHub · 2026-12-02 13:18 UTC · original
Allowlist & Architect Deep Review (
PiloteCodeis now on the trusted allowlist; CI46881376625approved and audited):Status:
triage: needs work— CI46881376625Testsstep hung > 5 min (live deadlock), confirming the re-entrantReadMostly::read()self-deadlock bug incrates/victory-gpu/src/listcpu.rs:Blocking — Re-entrant
ReadMostly::read()deadlock (listcpu.rs:245-282, 449-453):UnsafeCell<T>+Send/Syncbounds +!SendReadGuard(_held: RwLockReadGuard<'a, ()>) is sound (every writer takes allSHARDS + 1locks in fixed order0..=SHARDS).std::sync::RwLock(both WindowsSRWLOCKand Linuxfutex) is not recursively re-entrant when a writer is waiting on the same shard. Re-acquiringself.locks[at].0.read()while already holding it deadlocks if a writer queues onself.locks[at]in between. The unit testreaders_never_see_a_write_half_done_whichever_lock_they_takeexercises this directly (PAIR.read()nested insidePAIR.read()under 2 concurrent writers), causing the live CI hang.ReadMostlystrictly non-reentrant (matchingstd::sync::RwLock, removingHELDand the nestedPAIR.read()in the test after verifying noVIEWS/BUFFERS/LOOSEcall site nests reads) or avoid re-acquiring the underlyingRwLockwhiledepth > 0without allowing out-of-order early unlock.Additional architectural findings to fix in the same pass:
LOOSE.write()stalls (crates/victory-gpu/src/shadow.rs):stale_pages(),spans(), and diagnostics helpers (windows,window_use,memory,window_cover) still callLOOSE.write()for read-only iteration. WithReadMostly, eachLOOSE.write()now acquires all 17 shard locks, stalling every recording thread unnecessarily. Switching those read-only sites toLOOSE.read()removes that contention.PLACED_SEEN(crates/victory-gpu/src/resource.rs:texture_at_seen):PLACED_TEXTURESis confirmed append-only, so cachingThisis sound today. However,texture_at_seenhashes and caches the raw*descwithout zeroing filler wordsdesc[1]anddesc[13](unliketexture_at_table), so stack-garbage variations in filler words will cause false misses and duplicate entries in the 1024-slot thread-local cache.Vec::with_capacity(SHARDS + 1)on everyReadMostly::try_write(), and fix thea_remembered_placed_texture_is_the_tableseviction loop (currently callstexture_at_seen(..., &buffer), which returnsNoneand never writes toPLACED_SEEN).Once fixed and CI is green, this will need a plain
--releaseA/B run onmain(b0842d93+) before merge.113223186bto100015c059@PiloteCode on GitHub · 2026-12-02 21:11 UTC · original
Thanks for the deep review. All four points are fixed in
100015c, and the branch is rebased onmain(6bad0e0).1. Re-entrant
read()deadlock (blocking). We took the second option: a thread that already reads aReadMostlytable no longer touches itsRwLockagain. The first read's guard is kept in the thread'sHELDslot, nestedread()/try_read()only count, and the lock is released when that thread's last guard on the table drops, in whatever order, so dropping out of order never unlocks early. Writers still take allSHARDS + 1locks in order.New test
a_thread_reads_again_past_a_writer_waiting_for_it: one thread reads, a writer queues behind it, the same thread reads again (read()andtry_read()), drops its first guard before the second and checks that no write got in. It fails after 20 s instead of hanging. The stress test (readers_never_see_a_write_half_done_whichever_lock_they_take) keeps its nestedPAIR.read().Checked on
listcpu.rsalone (std only), process pinned to 2 logical processors,--test-threads=1, 3 runs each:Err(Timeout)after 20 s)2.
LOOSE:stale_pages,spans,windows,window_use,memoryandwindow_covernow takeLOOSE.read(); only the sites that change the table still write.3.
PLACED_SEEN:texture_at_seennow keys it likePLACED_TEXTURES: both go through a newplaced_key, which zeroes filler words 1 and 13 unlessVICTORY_PLACED_FILLER=1, astexture_at_tablealready did.4. Minor:
try_writekeeps its guards in an array (std::array::from_fn), noVec.a_remembered_placed_texture_is_the_tablesnow fillsPLACED_SEENdirectly with 4096 keys, so the 1024-slot table really gets crowded.cargo clippy --workspace --all-targets --locked -- -D warnings, with and without--all-features: clean on100015c. We did not run the fullcargo testhere; CI will.For the
--releaseA/B onmain: each part keeps its own switch (VICTORY_PLACED_SEEN,VICTORY_VIEWS_SHARDED,VICTORY_SHADOW_SHARDED;0turns it off), so one build can compare them. The figures in the description come from our fork, not from MiniVI'smain.@Androtim on GitHub · 2026-12-02 21:33 UTC · original
Thanks for addressing all four review items cleanly in
100015c0!ReadMostly::read/try_read(&'static self, thread-localHELDholding the singleRwLockReadGuard<'static, ()>with refcount + out-of-order drop +drop(last)outsideRefCellborrow,!SendviaOption<RwLockReadGuard>),LOOSE.read()on all read-only queries,placed_keyfiller masking onPLACED_SEEN, and array-basedtry_write.46971537721: alllistcpustress/re-entrancy tests passed (758/759); the single failure (descriptor::host::tests::views_off_their_elements_get_a_copy_of_their_bytes) is an unrelated pre-existing parallel-test heap flake also seen onmain. Triggeredgh run rerun 46971537721 --failed.triage: needs gpu test— ready for plain---releaseA/B on MiniVImain+--features diagnosticsvisual check once CI turns green!@Androtim on GitHub · 2026-12-02 22:33 UTC · original
Deep Static Audit Pass #4 (
#282comment7359964895) signed off100015c0as VERIFIED CLEAN (Green Light) (Pass #1#12re-entrantSRWLOCKdeadlock cleanly resolved via thread-localHELD+!SendReadGuard,LOOSE.read(),placed_keyfiller masking, and verified append-onlyPLACED_TEXTURES), CI46971537721is GREEN, and zero conflict with merged#341/#343. Merging tomainper Audit Pass #4 routing (#276comment7360813578) —v2026.12.02.12will be tagged oncemainCI turns green!