GPU: draws find the views their tables hold without the view registry's lock #3275
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
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
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
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/Marvisak--VIctory!3275
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@KainanP on GitHub · 2026-11-26 15:26 UTC · original
KainanP:perf/view-lookups-unlocked→main· +133 −6 · 1 files · 1 commits · openPart 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".--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; I reviewed the results.
🤖 Generated with Claude Code
@oni-swr on GitHub · 2026-11-26 15:44 UTC · original
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)
@Dukestar69 on GitHub · 2026-11-26 15:50 UTC · original · approved these changes
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).
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.