descriptor: use a per-slot reader-writer lock (BrLock) for VIEWS #534
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/lobomfz--VIctory-xmem!534
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-534"
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?
@cerealfordinner on GitHub · 2026-12-04 23:29 UTC · original
cerealfordinner:upstream-pr-descriptor-brlock→main· +144 −23 · 3 files · 1 commits · openUses a per-slot reader-writer lock (
BrLock, newbrlock.rs) for the descriptor VIEWS table instead of a single lock, so readers of different slots don't serialize.cargo check -p victory-gpu --lib --target x86_64-pc-windows-gnu: clean (one pre-existing dead-code warning).Note: this touches the same descriptor VIEWS table as open PRs #506 and #510 — flagging in case they'd rather land first; happy to rebase or close if it overlaps.
Signed-off-by: cerealfordinner [email protected]
@Kal0s-design on GitHub · 2026-12-05 00:52 UTC · original
Checked
a9684daon native Windows with MSVC (one NVIDIA desktop card plus WARP, didn't run the game). The base is current main, so everything below compares againstb581f7e.Debug and release builds of victory-gpu are clean and the workspace builds in debug. Clippy gives the same warning counts as main with and without
diagnostics, and none of them are in brlock.rs.cargo test -p victory-gpu --libfails the same 5 tests on both sides (the two indirect host_list ones, the two pipeline library loads, a flaky watch test). The 40descriptor::tests pass at 1, 2, 4, 8 and 16 test threads, three runs each. With--features diagnosticsand VICTORY_D3D12_DEBUG=1 the NVIDIA results match main. On WARP both sides also failviews_are_made_beside_the_heap_and_copied_in, and main hit the flaky watch test there too.views_die_with_their_resourcestill dies with an access violation, on main and on the PR alike, and it isn't the lock. The fake resource 0x7777_0000 goes intoentry(), thenrecords::entry_made(descriptor.rs:791) reachesrecords::kind, which callsresource::buffer_byteson it (records.rs:707). That function only checks for null before reading the object (resource.rs:3178-3183). A barewords_for(View::Shader(fake, None))crashes the same way, and a view whose only resource is a fake counter doesn't.On the lock itself, it isn't per slot of the table, which is how I first read the title. It's still one lock over all of
Views. What's split is the reader count, 32 counters on their own cache lines (brlock.rs:13), each thread taking one round robin (brlock.rs:34-43), so there's no hashing and nothing to collide. That's actually good, becauselist,index,by_resourceandshapesstill change together under one writer. Cross-map consistency is what it was and there's no lock order to get wrong. A title like "big-reader lock" would avoid the confusion.The orderings look right to me. The reader's
fetch_addthenwriting.load(68-69) and the writer'swriting.storethen slot loads (81, 84) are all SeqCst, so they can't both miss each other, and the Release unlocks (107, 133) pair with those loads. Readers step back when the flag is up, so writers win. Reading again on a thread that already holds a read deadlocks if a writer is waiting, same as std. None of the call sites nest (836, 851, 912, 1231, 1236).The one thing I'd change is the waiting.
pause(45-52) spins 64 times and then callsyield_nowforever, it never parks. A reader stuck behind a writer keeps a core busy the whole time, and writers do real work in there.entry()writes the records row (descriptor.rs:791),shape()does the same (747), andforgetwalks every entry of a resource. If a writer gets preempted mid-write, every recording thread that wants a read sits spinning, where std's RwLock would park them. It didn't cost anything in the numbers below, so not a blocker, but a fallback after N yields (WaitOnAddress onwriting, or park/unpark) would be cheap insurance.I also ran two throwaway stress tests (not committed). One hit
BrLockdirectly, readers checking that three fields always match while writers bump them, from 4 readers with 1 writer up to 256 with 1 and 128 with 8. No torn reads, no lost writes, writers kept going. The other went through the real VIEWS path, threads callingwords_forandview_aton a hot set of views plus new views followed byforgetat 0, 1 and 10 per 1000 ops. Every result was checked. No mismatches and no hangs (180 s watchdog). This only exercises the lock path, since constant and placed views never reach VIEWS, so a real frame won't see ratios like these. Release build, three runs each, alternating PR and main, in Mops/sSingle thread is the same within noise. Main gets slower as threads are added while the PR scales, and that still holds when the machine is oversubscribed, spinning and all.
#506 changes the maps inside
Views, not the lock, so the two only meet in the initializer and should rebase easily either way. #510 is draw.rs only.AI-assisted: yes
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.