GPU: draws find the views their tables hold without the view registry's lock #3273
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3275"
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 KainanP on 2026-11-26T15:26:40Z.
Part of #2586 (the cost of list methods on the title's threads). Local change, same behaviour. Second of two lock fixes for draws recorded on several threads at once. The first is #3274, which removes the most contended lock. This one is smaller and pays off mostly together with #2821.
The problem
Every slot a draw binds looks up its view in the view registry
descriptor::VIEWS:HostHeap::mirror→view_atfor the slots a table names, anddescriptor::viewon the table paths. Each lookup takes the registry's lock. On main that's a mutex. With #2821 it becomes anRwLockread, but readers still write the lock word's shared count, so the five recording threads bounce that cache line between cores. With main + #1978 + #2821 + #3258, a per-call-site lock counter put it second, afterTEXTURES_AT(#3274): six takes per draw, 157 ns on one thread and 439 ns each on five (ranking table in #3274).The change
A registry entry keeps its view for as long as its generation is current. An entry gets another view only after
forgethas freed it under a new generation. So:AtomicU32. The chunks are made as the list grows and never freed. They are written only under the registry's exclusive lock: when an entry gets a view inrecord, and whenforgetfrees it;Same answers as the locked lookup. A view released right after the check is the same race as a view released right after the locked lookup returns. Entries past 4,096 × 1,024 are never kept, so they are always looked up under the lock.
Tests
New:
descriptor::tests::threads_that_looked_views_up_see_them_rewritten_and_released. A second thread looks views up (and keeps them) while the main thread:I checked that the test catches the bug it's meant for: without the
set_live(i, 0)inforget, it fails at "released".That test passes on main too, as oni-swr found. It guards behaviour, not the change.
descriptor::tests::a_view_looked_up_before_does_not_wait_for_the_view_registry(commit9e07df21) shows the change itself. A thread looks a view up once, then looks it up again while another thread holdsVIEWSexclusively. With this PR the second lookup returns within 1 s. On main it blocks until the lock is dropped, so the test fails on main (RTX and WARP) and passes here.--features diagnostics,VICTORY_D3D12_WARP=1)63bcca4The failures are main's (see #3274). Clippy passes with
-D warningsfor the workspace, all targets, with and without--all-features.repository_passes_policypasses, and rustfmt is clean on the changed lines.Measured
Same method as #3274:
pipeline::list_bench's draw sequence on 1 and 5 threads, 7 runs per build interleaved round-robin, medians (ranges). RTX 4060 Laptop, i7-14650HX, release. Seven single-threaded CPU-bound processes I don't control ran throughout, which interleaving spreads evenly over the builds. ns per draw, per thread:Two more interleaved rounds gave, on five threads: with #3274 2893 → 2609 (5 runs) and 2803 → 2691 (7 runs); without it 4818 → 3784 (7 runs).
On main alone it changes nothing measurable: the other shared locks (
TEXTURES_AT, main's mutexes) dominate. Together with #2821 it saves about 0.5–1 µs per draw on five threads, and on top of #2821 + #3274 about 0.1–0.3 µs (−2 to −10%).Conflicts
The text conflicts with #2821, #2099, #3234 and #2848 (lines next to
view_at/view, or the registry's lock calls). With #2821: take this PR's bodies ofview_atandview, and inview_ofchangeVIEWS.lock()toVIEWS.read(). Without that change the merge doesn't compile, so nothing breaks silently. That is the measured tree.What this does not show
hostmutex plus itsArccount (six per draw), andshadow::BUFFERS(four per draw). Removing the mutex alone saved about 80 ns, so most of the remaining cost is the sharedArccounts. That one belongs with the host-copy lookup in #3258.AI use: Claude Code (Claude Opus 5.5) profiled the locks, wrote the change and the test, and ran the benchmarks and test suites listed above.
🤖 Generated with Claude Code
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T15:50:06Z.
Review: APPROVED
Reviewed the diff and verified locally on Windows 11 x64 (RTX 5090):
(entry, generation, View)in thread-localSEENvalidated against the lock-freeAcquire/Releasegeneration tableLIVE(updated underVIEWSinrecordand cleared to0inforget) cleanly avoidsVIEWSmutex contention on hot draw paths while preserving invalidation on release/reuse.cargo test -p victory-gpu --lib descriptor:: -- --test-threads=1 --skip dynamic_slots_are_held_until_released(RTX 5090): 22 passed, 0 failed (includingthreads_that_looked_views_up_see_them_rewritten_and_released).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T15:44:43Z.
WARP verification report (test report only, no code changes)
b90ab5f963bcca43(control); WARP software adapter forced withVICTORY_WARP=1 VICTORY_D3D12_WARP=1,--features diagnostics, d3d10warp.dll 10.0.26100.9818; dxil.dll 1.8.2502.11 (Windows Kit 10.0.26100.0, viaVICTORY_DXIL).--exact),-j 4, synthetic tests only, no game data.descriptor::tests::threads_that_looked_views_up_see_them_rewritten_and_released: passes on the PR (1 passed).victory-gpulib suite: PR 247 passed, 0 failed, 1 ignored; main 246 passed, 0 failed, 1 ignored. No failures on either.AI use: Claude Code (Claude Sonnet 5.5)
Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-27T13:04:29Z.
Thanks @oni-swr. You were right:
threads_that_looked_views_up_see_them_rewritten_and_releasedguards the behaviour, but it passes on main too, so it doesn't show the change.New commit
9e07df21addsdescriptor::tests::a_view_looked_up_before_does_not_wait_for_the_view_registry. A thread looks a view up once. Then the test thread holdsVIEWSexclusively, the way a title thread writing a view does, and the same thread looks the view up again. With this PR it gets the view within 1 s from its per-thread cache. On main it blocks until the lock is dropped. While the lock is held nothing can change the entry's live generation, so the PR path can't fall back to the lock and the test isn't flaky.63bcca43+ only this test):the lookup waited for the view registry's lockon RTX and WARP.--features diagnostics,VICTORY_D3D12_WARP=1).victory-gpu --lib: WARP 248 passed / 0 failed / 1 ignored. RTX has the same 2 failures as main, withheap_direct_texture_reads_mark_their_heap_indexskipped.descriptor::host::tests::views_bound_while_another_slot_gets_its_texture_do_not_waitsometimes fails under the full parallel run: 1/10 here, and 2/10 on unpatched main, so it isn't from this PR.-D warnings(default and--all-features),cargo xtask policyand rustfmt on the new lines are clean.The earlier behaviour test stays.
AI use: Claude Code (Claude Opus 5.5).
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.