perf(gpu): isolate hot descriptor lock stripes on cache lines #572

Manually merged
github merged 3 commits from github-bot/gh-572 into main 2026-12-05 17:30:21 +00:00 AGit
Owner

@⁠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 UTC

Benchmark — Windows x64, four workers

Pinned CI log · head 02686aa0771d147a47d77c473a7cbecd45fb6c0d · six alternating ABBA/BAAB blocks, 12 samples per arm, 250,000 acquisitions per worker.

Workload Compact Padded Result
Adjacent independent lock stripes 35.60 ms 1.91 ms −94.6% elapsed CPU-side time
Already separated stripes — — No clear improvement

The fixture exercises the actual MadeLocks representation. This intentionally stresses false sharing; it is not GPU execution or gameplay FPS. The benchmark includes thread synchronization and completion.

Change

  • Separate hot descriptor mutex stripes by 128 bytes for large heaps; retain compact storage for small heaps.
  • Preserve the existing stripe hash, mutex semantics and descriptor-key handling. No new runtime flag.
  • Trade additional memory for reduced cache-line contention: padded storage is 2 MiB per large heap, versus the platform-dependent compact mutex allocation.

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)

Workload Compact median Padded median Change
Adjacent stripes 33.240 ms 1.466 ms −95.59%
Already separated stripes 1.479 ms 1.514 ms +2.36% (descriptive; not an established regression)

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 02686aa reproduced adjacent-stripe timing at 0.071× baseline (8 workers), separated stripes 0.999×. Their independent Made::lock/key-write fixture reports the following padded/compact median ratios:

Actual hashed access pattern 2 workers 4 workers 8 workers
Disjoint regions 0.64–0.77 0.86 median 0.61–0.64
Interleaved neighboring indices 0.75–0.88 0.53–0.62 0.42–0.45

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):

Workers Separated Interleaved
1 +22.59% +18.02%
2 −5.99% −37.90%
4 −38.27% −53.45%

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.

**@⁠tommiehansen** on GitHub · 2026-12-05 10:51 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/572) `tommiehansen:perf/descriptor-lock-cache-lines` → `main` · +179 −3 · 1 files · 3 commits · merged 2026-12-05 17:28 UTC ## Benchmark — Windows x64, four workers [Pinned CI log](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47504804406/job/145626557056) · head `02686aa0771d147a47d77c473a7cbecd45fb6c0d` · six alternating ABBA/BAAB blocks, 12 samples per arm, 250,000 acquisitions per worker. | Workload | Compact | Padded | Result | |---|---:|---:|---| | Adjacent independent lock stripes | 35.60 ms | 1.91 ms | **−94.6% elapsed CPU-side time** | | Already separated stripes | — | — | No clear improvement | The fixture exercises the actual `MadeLocks` representation. This intentionally stresses false sharing; it is not GPU execution or gameplay FPS. The benchmark includes thread synchronization and completion. ## Change - Separate hot descriptor mutex stripes by 128 bytes for large heaps; retain compact storage for small heaps. - Preserve the existing stripe hash, mutex semantics and descriptor-key handling. No new runtime flag. - Trade additional memory for reduced cache-line contention: padded storage is 2 MiB per large heap, versus the platform-dependent compact mutex allocation. Inspired by [ReVIctory's descriptor lock layout](https://github.com/ReTerryDavis/ReVIctory/commit/edc321aa822626d80811afc01afd6e3625585301). ## 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](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47512283755) 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) | Workload | Compact median | Padded median | Change | |---|---:|---:|---:| | Adjacent stripes | 33.240 ms | 1.466 ms | **−95.59%** | | Already separated stripes | 1.479 ms | 1.514 ms | +2.36% (descriptive; not an established regression) | 12 samples per arm from six alternating ABBA/BAAB blocks. This independently reproduces the original targeted CPU false-sharing result. [Raw CI log](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47512928521/job/145652078893). No gameplay FPS claim. ### Independent hashed-path benchmark [Kal0s-design's review](https://git.gtahub.st/github/lobomfz--VIctory-xmem/pulls/572) on `02686aa` reproduced adjacent-stripe timing at 0.071× baseline (8 workers), separated stripes 0.999×. Their independent `Made::lock`/key-write fixture reports the following padded/compact median ratios: | Actual hashed access pattern | 2 workers | 4 workers | 8 workers | |---|---:|---:|---:| | Disjoint regions | 0.64–0.77 | 0.86 median | 0.61–0.64 | | Interleaved neighboring indices | 0.75–0.88 | 0.53–0.62 | 0.42–0.45 | 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](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47517950486/job/145667597931). Added reproducible actual hashed path benchmark with disjoint/interleaved and single-thread controls in test-only revision `a09c8bd`. [Fresh CI](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47519705785). ### Hashed-path native follow-up (2026-12-05) [Native audit `a09c8bd`](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47519705785/job/145673065808), 8 alternating ABBA blocks, 16 samples per arm. Ratio of per-arm medians (CPU time, not gameplay): | Workers | Separated | Interleaved | |---|---:|---:| | 1 | +22.59% | +18.02% | | 2 | −5.99% | −37.90% | | 4 | −38.27% | −53.45% | 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](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47525020456), 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.
Inspired by ReTerryDavis/ReVIctory edc321aa822626d80811afc01afd6e3625585301; retain xmem's stripe count, hash, lock lifetime and poison recovery. Keep compact locks for small heaps.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-05 10:56:33 +00:00
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-05 11:57 UTC · original

Verified head 02686aa077 natively 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

**@⁠Kal0s-design** on GitHub · 2026-12-05 11:57 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/572#issuecomment-7437570908) Verified head 02686aa0771d147a47d77c473a7cbecd45fb6c0d natively 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<ID3D12Resource>> 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
Author
Owner

@⁠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 a09c8bd and documented your results. No production code change.

**@⁠tommiehansen** on GitHub · 2026-12-05 12:28 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/572#issuecomment-7437972805) 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 `a09c8bd` and documented your results. No production code change.
github manually merged commit 04e32f7ea3 into main 2026-12-05 17:30:20 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.