perf(gpu): isolate hot descriptor lock stripes on cache lines #572
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!572
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-572"
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?
@tommiehansen on GitHub · 2026-12-05 10:51 UTC · original
tommiehansen:perf/descriptor-lock-cache-lines→main· +179 −3 · 1 files · 3 commits · merged 2026-12-05 17:28 UTCBenchmark — Windows x64, four workers
Pinned CI log · head
02686aa0771d147a47d77c473a7cbecd45fb6c0d· six alternating ABBA/BAAB blocks, 12 samples per arm, 250,000 acquisitions per worker.The fixture exercises the actual
MadeLocksrepresentation. This intentionally stresses false sharing; it is not GPU execution or gameplay FPS. The benchmark includes thread synchronization and completion.Change
Inspired by ReVIctory's descriptor lock layout.
Verification
Two targeted tests passed in both debug and release on Windows, checking layout/stripe selection and concurrent updates; the explicit release timing audit passed. Baseline/candidate timing uses the same revision and different lock representations. No physical AMD or gameplay timing has been measured. Nextgen/native validation should exercise descriptor creation under concurrent workloads; shader-only Vulkan timings are not evidence of this CPU-side optimization's benefit.
Independent pinned CI
RDNA ports audit repeats the native lock tests and timings. Descriptor mutex padding is a CPU synchronization change: unrelated Nextgen Vulkan controls are not evidence of its speedup. No gameplay or GPU FPS claim.
Repeat native CI (2026-12-05)
12 samples per arm from six alternating ABBA/BAAB blocks. This independently reproduces the original targeted CPU false-sharing result. Raw CI log. No gameplay FPS claim.
Independent hashed-path benchmark
Kal0s-design's review on
02686aareproduced adjacent-stripe timing at 0.071× baseline (8 workers), separated stripes 0.999×. Their independentMade::lock/key-write fixture reports the following padded/compact median ratios:Single-thread controls 0.97–1.005×. No gameplay timing. Third native CI on original head: adjacent 36.0793 → 1.83005 ms (−94.93% pooled median); separated 1.75485 → 1.80445 ms (+2.83%, paired block median +1.98%; variable). Control. Added reproducible actual hashed path benchmark with disjoint/interleaved and single-thread controls in test-only revision
a09c8bd. Fresh CI.Hashed-path native follow-up (2026-12-05)
Native audit
a09c8bd, 8 alternating ABBA blocks, 16 samples per arm. Ratio of per-arm medians (CPU time, not gameplay):Native correctness passed. The single-worker hashed cases show a new regression candidate; the multiworker gains do not cancel that cost. Repeat with matched cache states and investigate the larger padded working set/dispatch cost before default activation. No production code change in this review revision.
Matched warmup and spacing screen
Native audit, 16 samples/arm for each condition. Relative to compact locks, 128-byte spacing now costs +1.31%/+1.44% at one worker (separated/interleaved), rather than the previous +22.59%/+18.02%; four workers improve −21.83%/−41.28%. The 16-byte experimental layout gives −0.04%/+0.17% at one worker, −17.59%/−24.74% at two, −36.42%/−35.23% at four. The 32-byte layout gives −45.24%/−37.14% at four. These are ratios of per-arm medians, not a significance claim. Hosted runner had four workers available. Existing production layout unchanged; smaller spacing merits a separate production candidate with direct false-sharing and memory checks. No gameplay timing.
github-bot referenced this pull request2026-12-05 11:18:26 +00:00
@Kal0s-design on GitHub · 2026-12-05 11:57 UTC · original
Verified head
02686aa077natively on Windows (MSVC, toolchain 1.98.1) on an x86-64 desktop CPU with one NVIDIA desktop card. The PR sits directly on current main, so main and the PR differ only by this change.I read the change and see no semantic difference. Made::lock still uses the same multiplicative hash and keeps the top 14 bits, MadeLocks::at returns the same Mutex<()> for a given stripe in both variants, and poisoning is still swallowed the same way. Nothing in host.rs takes the size or layout of Made or its locks. The only transmute_copy calls in the file are the pResource ones further down, and they're unrelated. The padded variant is chosen when the title's slot count is at least 16384. The dynamic slots past count are not included in that check. Sampler heaps (2048) and other small heaps keep the old compact box. On this toolchain size_of::<Mutex<()>>() is 2 bytes. That makes the compact table 32 KiB, with 32 stripes per 64-byte line, and the padded table 2 MiB. So the extra memory is about 2 MiB per large view heap. I didn't count how many such heaps a title keeps alive. For scale, the same heap already holds one Mutex<Option> per slot including the 2^18 dynamic ones, which is at least 4 MiB on its own.
There's no overlap with #203, #506 or #534, which change the VIEWS table in descriptor.rs (plus brlock.rs and lib.rs), or with #510, which changes draw.rs. This PR only touches the per-heap Made stripes in descriptor/host.rs. The files are disjoint and so are the locks.
I ran the victory-gpu lib tests with descriptor::tests::views_die_with_their_resource skipped. Main gives 353 passed, 4 failed and 23 ignored. The PR gives 354 passed, 5 failed and 24 ignored, which includes the two new tests passing and the new ignored benchmark. Both runs show the same four known native failures, the two indirect host_list tests and the two pipeline::host library loads. The fifth failure on the PR run was watch::tests::the_rest_of_the_one_asking_has_a_number_of_its_own, which is known to be flaky here. It passed three times out of three when run on its own, in both debug and release builds. The two new tests also pass in release.
In the repeat CI log the run used 4 workers, and recomputing the medians from its 12 samples per arm gives exactly the numbers in the table. The separated-stripe blocks 4 and 5 there jump by about 1.7x in both arms, so the +2.36% looks like runner noise. I only opened that repeat run, not the first one.
I re-ran the PR's own made_lock_padding_benchmark in release three times. It ran with 8 workers, giving 36 samples per arm. With adjacent stripes the padded median was 0.071x the compact one. With already separated stripes the ratio was 0.999x, so no slowdown there either.
The PR's benchmark puts workers on stripes 0, 1, 2 and so on directly. Real callers never pick stripes that way. They go through the hash, and neighbouring descriptor indices land between 6258 and 10126 stripes apart, so neighbouring slots don't produce that pattern. To see whether the gain survives the real mapping, I wrote a local throwaway bench that goes through Made::lock and writes the key. It ran in release, compact vs padded, 8 alternating ABBA/BAAB blocks with a warm-up run before each sample, 16 samples per arm, and three separate process runs per thread count. Compact has the same layout as main's Box<[Mutex<()>]>, so compact vs padded here is effectively main vs PR. The numbers are padded median over compact median, given as the range over the three runs.
With adjacent stripes and direct access, the same idea as the PR's bench, I got 0.26 at 2 threads, 0.12 to 0.13 at 4 and about 0.07 at 8. With each thread walking consecutive indices through the hash in its own region of a 1M-slot heap, I got 0.64 to 0.77 at 2 threads, 0.86 median at 4 (one noisy run at 0.40) and 0.61 to 0.64 at 8. With threads interleaved on neighbouring indices, I got 0.75 to 0.88 at 2 threads, 0.53 to 0.62 at 4 and 0.42 to 0.45 at 8.
So the gain on the real hashed path is much smaller than the headline 95 percent, roughly 10 to 60 percent depending on thread count, but it points the same way. With a single thread, where the 32 KiB compact table stays in L1 and the padded one doesn't, all three patterns came out between 0.97 and 1.005, so I saw no cost from the bigger table either. My guess is that with 2-byte mutexes and only 512 cache lines for 16384 stripes, unrelated stripes share a line often enough to matter. Two caveats. These loops do nothing but lock and unlock, while real lock holders build descriptors, so the share of frame time involved is much smaller than the ratios suggest. And the machine may have had other builds running in the background during the 8-thread runs. I haven't measured any gameplay or GPU timing.
Looks correct to me, and the trade of about 2 MiB per large view heap seems reasonable for what it buys.
AI-assisted: yes
@tommiehansen on GitHub · 2026-12-05 12:28 UTC · original
Thanks! The hashed-path measurements are especially useful for putting the adjacent-stripe result in perspective. Added both access patterns and a single-thread control to the benchmark in
a09c8bdand documented your results. No production code change.