GPU: use RwLock for read-mostly tables and add per-HostList VA/view caches #1356
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!1356
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1356"
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?
@wbkepler on GitHub · 2026-11-24 17:35 UTC · original
wbkepler:gpu/concurrent-read-locks-and-va-cache→main· +708 −75 · 8 files · 1 commits · openSummary
Reduces multi-thread CPU recording contention and repeated lookup overhead in
victory-gpu:Mutextables queried on per-draw/dispatch/bind hot paths tostd::sync::RwLockwith shared.read()hit paths (shadow::{BUFFERS, LOOSE},descriptor::{SHADER_HEAPS, VIEWS},HostHeap::made,texture::{STAGING, HOST_WRITTEN},resource::PLACED_TEXTURES,draw::host_signature::MADE,pipeline::SHADERS), using.iter().rev().findindescriptor::shader_slot.HostListinlineShadowCache(with nested-buffer-safeCachedRange::Subrange/Exactinterval bounds) andViewCache, cleared onHostList::reset()and invalidated viaAcquire/ReleaseAtomicU64generation counters bumped under write locks inshadow::{register, unregister}anddescriptor::forget.draw.rsper-draw VB/IB/root-view/indirect/table/readable lookups throughHostList::{find_shadow, lookup_view}andHostHeap::mirror_cached.Verification
cargo clippy --workspace --all-targets&-p victory --features diagnostics --all-targets— passed (0 new warnings)cargo test --workspace— passedVICTORY_D3D12_WARP=1 cargo test -p victory-gpu --lib --features diagnostics host::tests— passed (6/6)cargo xtask policy— passed (151 files ok)@Marvisak on GitHub · 2026-11-25 01:23 UTC · original
Automated triage for the maintainers.
Needs rebase. This pull request conflicts with
main(conflicting:crates/victory-gpu/src/descriptor.rs,crates/victory-gpu/src/descriptor/host.rs,crates/victory-gpu/src/draw.rs,crates/victory-gpu/src/host.rs,crates/victory-gpu/src/resource.rs). It will be reviewed once it is rebased onto the currentmain.Generated by Claude Code
@KainanP on GitHub · 2026-11-26 16:26 UTC · original
A data point for the buffer-lookup cache in this PR: on main + #1978 + #2821 + #3258 + #3274 + #3275, a rough thread-local stand-in for it in front of
shadow::find(validated by a generation counter, but with no nested-buffer check) took the list bench's draw sequence from 2,485 to 1,894 ns per draw on 5 threads (−24%) and from 1,351 to 1,242 ns on 1 thread (RTX 4060 Laptop, median of 7). Details are in #2586 (7197644545). YourCachedRangeversion is the correct form of it. Rebased on its own (BUFFERSis aMutexon main, and #2821/#2096 change it), it would likely be the next clear gain for the recording threads.AI use: Claude Code (Claude Opus 5.5) ran the measurement and drafted this comment.
@KainanP on GitHub · 2026-11-26 17:11 UTC · original
@wbkepler I rebased this PR onto current
main(63bcca4), since its per-listCachedRangecache looked like the next clear gain for the title's threads (my earlier note above). The result is on a branch for you to take if you want it. I'm not opening a competing PR.Branch:
KainanP/VIctoryrebase/1356-cached-rangef1346618: your commit, rebased. It keeps its author and message, and only the conflict resolution changed (listed below).4e9715ca: optional, mine. The root views a shader reads as title memory (user data and its offsets inbind, andState::root_view) were added tomainafter this PR. They now go throughHostList::find_shadowtoo.To take it:
Or from a fresh
main:git cherry-pick f1346618 4e9715ca.How the conflicts were resolved
shadow.rs:mainnow has its ownGENERATION(bumped when a copy is made or a copied buffer is released). Bumping it makesmemory::preparerewrite the heaps' page tables. I kept it as it is and gave the cache a separate counter,LOOKUPS/lookup_generation(), bumped on everyregister/unregisterlike yourGENERATIONwas. That way registering a buffer does not force page-table rewrites.unregisterbumps both when the buffer had a copy.find_with_range,lookup_entry,CachedRangeand theRwLocks are as you wrote them.all()reads under the read lock.descriptor/host.rs: onmain,HostHeap::mirroralso makes a slot again whenneeds_remakeholds (a placed texture whose host texture was upgraded since). Your read-lock fast path returned the view whenevermade[index] == key, which would skip that. So I movedneeds_remakeinto a method and the fast path checks it too.main's othermadeusers takeread()(orwrite()in the slow path).descriptor.rs:mainremovedshader_slot, soSHADER_HEAPSstays anRwLockand all ofmain's users takeread().view_at,views_current(new onmain) andviewgo throughslot_key. I leftview()unconditional becausemaincalls it from more places now.texture.rs:mainmovedSTAGING/HOST_WRITTENinto each host copy's state, so those hunks are dropped. The branch doesn't changetexture.rs.resource.rs: the read fast path intexture_atkeepsmain's zeroing of the padding words and itscurrent()check.draw.rs: call sites followmain's signatures (root_view'suav,readable'smarked, thenot_runreasons).mainno longer special-cases constant views in fresh tables, so that hunk only swaps inlookup_view.readable's constant-buffer lookups usefind_shadow.host.rs: the tests and fields are taken from both sides. The cache useslookup_generation().Tests (
cargo test -p victory-gpu, same failures asmainon each adapter):63bcca4memory_tests::heap_direct_texture_reads_mark_their_heap_index, which access-violates on main too)VICTORY_D3D12_WARP=1,--features diagnostics, one thread)Your four tests pass on all three.
host::testspassed 40 runs in a row on RTX, on the branch and on main. Two olderdescriptor::hosttiming tests (a_slot_rewritten_while_its_view_is_prepared_views_the_new_record,views_bound_while_another_slot_gets_its_texture_do_not_wait) are flaky when run in parallel with each other on main too: 88 failures in 150 paired runs on main, 101 on the branch.cargo clippy -p victory-gpu --all-targets -- -D warningspasses with and without--all-features.Measured with the list bench (fork branch
perf/list-call-bench,VICTORY_LIST_BENCH_SCALING=1): each thread records the draw sequence (object constants, root constants, index buffer, indexed draw) into its own list. Release build, ns per draw, median of 11 interleaved runs [min–max]:¹ main + #1978 + #2821 + #3258 + #3274 + #3275. On that stack, this PR overlaps #2821 (both turn
BUFFERS,VIEWSand the heaps'madeinto reader/writer locks) and #3275 (a thread-local view cache). For this measurement only, I kept #2821's and #3275's versions of the overlapping lock changes and this PR's caches (find_with_range,ShadowCache,ViewCache). That merge is not pushed. The indirect-call rows (VICTORY_LIST_BENCH_INDIRECT=1) did not move beyond their spread.The 1-thread cost doesn't change. The gain is in contention on 5 threads, as in the thread-local experiment (−24% there).
Hardware: RTX 4060 Laptop, i7-14650HX, Windows 11. Foreign CPU load: about six unrelated Python jobs (four CPU-bound) ran throughout, so absolute numbers are higher than in my earlier comments. Builds were interleaved run by run. Not measured: the title in game.
AI use: Claude Code (Claude Opus 5.5) did the rebase and conflict resolution, ran the tests and measurements and drafted this comment.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.