perf: look shader-visible heaps up under a shared lock #278
No reviewers
Labels
No labels
accessibility
bloqué : binaire console
bug
chargeur
console-dll
cpu
documentation
duplicate
enhancement
good first issue
gpu
help wanted
invalid
performance
question
runtime-gdk
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LooperSalty--AnyXboxX!278
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-278"
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?
@Skyfrye on GitHub · 2026-11-26 00:13 UTC · original
Skyfrye:nep/shader-heaps-read→main· +106 −13 · 1 files · 1 commits · draftDraft: the in-game A/B is pending (the change, its tests and the profile it comes from are done; a measured run of the world with and without it is not).
Change
SHADER_HEAPSincrates/victory-gpu/src/descriptor.rs, the list of shader-visible descriptor heaps, was aMutex. It is read far more often than written:create_cbv,create_placed_srv,copy_simple→record→mirror→shader_slot) looks its heap up in it;sync_heaps, the pass over records the title copied into placed heaps as bytes, which runs at every submission (about 59 a frame in the world, about 517 a second);create_heap) and dropping one (Drop for Heap) change it.As a mutex, the recording threads stood behind that pass at every submission. It is now a
RwLock(heaps_readfor the lookups, the pass,release_dynamic,evictable_slotsandevict_slots;heaps_writefor making and dropping). Nothing that holds the list takes it again, as before (with the mutex that would have deadlocked).Where this comes from: a 30 s Nsight Systems capture of the world (release build of
mainat3e258c8, launcher fast set, 263 frames, 8.8 fps under the profiler). Time on the CPU taken from the 1 kHz timer samples; waits from the context switches (each switch-in's stack weighed by the time since the thread was switched out to wait). The five recording threads each spend 27-30 % of the time on the CPU, 12-13 % in contended locks and 45-50 % waiting in title code. For one of them (tid 18376), the contended-lock waits by caller, share of wall time:descriptor::mirror←record←create_cbvdescriptor::mirror←record←create_placed_srvdescriptor::mirror←copy_simpleHostHeap::mirror(its ownmadelock, not changed here)draw::State::bind(not changed here)The three
descriptor::mirrorrows are theSHADER_HEAPSlookup (shader_slotis inlined there): 6.7 % of each recording thread's time.Linked issue: none.
Verification
Windows 11 26300, Rust 1.98.1 (MSVC), on upstream
mainat578098b, fromthird_party/victory:The 3 failures are the same on
mainwithout this change (183 passed, 3 failed):descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed,indirect::tests::warp_card_fetch_copies_flagged_pieces_to_their_slots,indirect::tests::warp_card_patch_writes_the_masked_bytes_and_no_others.New tests:
a_heap_lookup_goes_on_during_the_pass_over_copied_records: holds the list assync_heapsdoes and looks a heap up from another thread. Revert check: with the list back to aMutex(both helpers returning its guard) it fails: "the lookup waited for the pass over the heap list (5 tries)". It tries again only when the lookup could have waited behind a heap another test made at that moment, which a mutex makes wait in every try.a_heap_made_after_the_pass_is_found: making a heap waits for the pass, then the next lookup finds it.Pending: an A/B in the world (frame time, and the recording threads' lock waits in a profile).
Oracle and test data
No game file. The tests make descriptor heaps in process memory. The profile numbers come from my own capture of my copy of the game; no game code, address or dump is in this PR.
Checklist
E_NOTIMPL), never a fake success. (Nothing unimplemented here.)AI assistance: written with Claude Code. Claude Opus 5.5 read the Nsight Systems capture (offline symbol resolution, on-CPU and wait accounting), wrote the change and its tests, and wrote this description.
🤖 Generated with Claude Code
@KainanP on GitHub · 2026-11-26 10:32 UTC · original
Test report for #278 on three adapters.
Merges cleanly onto current main. Setup: current
origin/main(c4c93bd) merged with this PR, Windows 11,cargo test --lockedinthird_party/victory. Adapters: RTX 4060 Laptop (DXGI 0), Intel UHD 8086:a78b (16-lane waves, no FP64), WARP. The hardware adapter is picked by name through a local, uncommitted test hook and confirmed in its log; WARP for victory-gpu is--features diagnostics+VICTORY_D3D12_WARP=1. victory-gpu runs with--test-threads=1.victory-gpu --lib"main's 3" =
descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed,indirect::tests::warp_card_fetch_copies_flagged_pieces_to_their_slots,indirect::tests::warp_card_patch_writes_the_masked_bytes_and_no_others. They fail on all three adapters on main too. Both newdescriptor::testspass everywhere. No new failure. These are the same counts you give.Note from reading the diff: Rust's
RwLockon Windows lets a waiting writer hold back new readers. So aread()taken again on a thread that already holds one, whilecreate_heapwaits, would deadlock. Before, theMutexwould have deadlocked at once, so this is not new. But it now only shows when a heap is created at that moment. A doc line onheaps_readsaying "never nest" would keep it that way.AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this.
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.