perf(shader): prove uniform shifted addresses and share wide SMEM page lookups #352

Open
github-bot wants to merge 4 commits from github-bot/gh-352 into main AGit
Owner

@⁠tommiehansen on GitHub · 2026-12-03 19:16 UTC · original
tommiehansen:perf/shader-wide-smem-uniform-shifts → main · +189 −10 · 5 files · 4 commits · open

Why

Wide SMEM loads can issue separate guest page lookups per four-dword chunk even when one page is proven, and dispatch-uniform shifted addresses can miss an existing uniformity proof.

What changes

Accept proven dispatch-uniform shift operands within existing walk budget; share one address/view for wide single-page SMEM loads while preserving per-chunk fault notes. Unproven/page-crossing cases retain original emission. Existing VICTORY_UNIFORM_GUEST_LOADS and VICTORY_CLUSTER_GUEST_LOADS opt-ins with separate cache keys.

Benchmark results

Reproducible CI result · head 602f4ee56a5b · Linux hosted CPU-only, Standard, four ABBA blocks (8 runs per arm).

Workload Baseline (ms) Candidate (ms) Time change Verification
Uniform SMEM and wide loads 8.645 7.699 −11.04% Structurally valid; semantics unverified

Baseline b581f7e; uniform and cluster guest loads enabled on both arms. CPU translation only; other measured workloads showed no significant difference or inconclusive results.

Negative values indicate reduced CPU time. Synthetic workloads, not gameplay FPS.

Current 376aa90 two Standard runs: targeted −2.35% inconclusive and −4.87% improved, structural only. Corpus +4.73% first-run regression not reproduced (−0.71% nonsignificant). Comparison.

Why this should be merged

Remove repeated page/handle work for wide proven loads while preserving fallback. Verify semantic execution and real AMD costs before default activation.

Validation

Current reconciliation CI passes Linux full, Windows focused and production compile; same upstream descriptor PSO failure. Unit tests cover uniform shifts and wide-load/page-crossing controls.

Compatibility and dependencies

Related #351/#467/#518 lowering/cache; keep separate proof and compatibility checks.

Previous detailed description, historical measurements and checklist.

**@⁠tommiehansen** on GitHub · 2026-12-03 19:16 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/352) `tommiehansen:perf/shader-wide-smem-uniform-shifts` → `main` · +189 −10 · 5 files · 4 commits · open ## Why Wide SMEM loads can issue separate guest page lookups per four-dword chunk even when one page is proven, and dispatch-uniform shifted addresses can miss an existing uniformity proof. ## What changes Accept proven dispatch-uniform shift operands within existing walk budget; share one address/view for wide single-page SMEM loads while preserving per-chunk fault notes. Unproven/page-crossing cases retain original emission. Existing VICTORY_UNIFORM_GUEST_LOADS and VICTORY_CLUSTER_GUEST_LOADS opt-ins with separate cache keys. ## Benchmark results [Reproducible CI result](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47503640056/job/145622974558) · head `602f4ee56a5b` · Linux hosted CPU-only, Standard, four ABBA blocks (8 runs per arm). | Workload | Baseline (ms) | Candidate (ms) | Time change | Verification | |---|---:|---:|---:|---| | Uniform SMEM and wide loads | 8.645 | 7.699 | −11.04% | Structurally valid; semantics unverified | Baseline `b581f7e`; uniform and cluster guest loads enabled on both arms. CPU translation only; other measured workloads showed no significant difference or inconclusive results. Negative values indicate reduced CPU time. Synthetic workloads, not gameplay FPS. Current 376aa90 two Standard runs: targeted −2.35% inconclusive and −4.87% improved, structural only. Corpus +4.73% first-run regression not reproduced (−0.71% nonsignificant). [Comparison](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47577247764/job/145853300385). ## Why this should be merged Remove repeated page/handle work for wide proven loads while preserving fallback. Verify semantic execution and real AMD costs before default activation. ## Validation [Current reconciliation CI](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47577540731) passes Linux full, Windows focused and production compile; same upstream descriptor PSO failure. Unit tests cover uniform shifts and wide-load/page-crossing controls. ## Compatibility and dependencies Related #351/#467/#518 lowering/cache; keep separate proof and compatibility checks. [Previous detailed description, historical measurements and checklist](https://github.com/tommiehansen/VIctory-xmem/blob/04dd44857abe222961157663b89a4dfed4c7277c/archive/pr-descriptions-20261206.md).
Extend uniform_user_address to accept dispatch-uniform bit shifts (Shl, LShr, AShr) so shifted user-data scalar loads receive uniform descriptor handles under VICTORY_UNIFORM_GUEST_LOADS=1, and allow s_load_dwordx8/x16 under VICTORY_CLUSTER_GUEST_LOADS=1 to share one address_plus + memory_view directory lookup when statically proven within one 64 KiB guest page while preserving per-chunk fault notes and byte-identical fallbacks.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-03 19:17:36 +00:00
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-03 19:57 UTC · original

Tested b188fd0 natively on Windows 11 (MSVC, toolchain 1.98.1), D3D12 tests on one NVIDIA desktop card plus WARP.

What I looked at

  • Shifts in uniform_user_address (bitcode.rs:468): a shift of two proven-uniform values is still a pure function of them, and the walk budget is untouched since left is decremented before the match. I also checked the lowering side: every scalar shift the translator emits masks its amount (s_lshl/lshr/ashr_b32 and s_bfm_b32 with & 31, the 64-bit forms with & 63, bfe too), so there is no oversized-shift poison that could make a "uniform" value differ per lane.
  • one_guest_page on the new SMEM path (lower.rs:5306-5333). I brute-forced it outside the repo against the code it replaces: the per-chunk address_plus(lo, hi, offset + 4*first) plus the page/in-page split from memory_view, versus one address_plus(lo, hi, offset) plus 4*first. Full 21-bit signed SMEM offset range for x8 and x16, lo around 0, 64K multiples and the top of the 32-bit range, hi 0 and 0xFF, known-bit counts 0 to 32 with junk above the known bits, plus 200M random cases with 1 to 64 words. ~3.9G cases, ~366M accepted, no case where the page or the byte differed or a chunk ran past the 64K page. Widening the bound by 4 bytes made it fail right away, so the check does bite.
  • low_bits_of gets the post-soffset lo and the immediate offset is only folded in inside one_guest_page, same contract as the existing cluster call at lower.rs:4968/4982. The fault note count also matches the old path (count/4 notes, once instead of per chunk).
  • With both switches unset I'm arguing from code, not from a DXIL diff: the then closure never runs, the None arm is the old code, and the uniform proof is short-circuited by !uniform_guest_loads(). Cache key bytes only change when a switch is on, and both key strings were bumped.

Tests

  • wide_smem_and_uniform_shifted_guest_loads, grouped_guest_ranges_never_cross_a_page_or_read_an_extra_word and the bitcode tests: 20/20 with the env vars unset and 20/20 with both set to 1. The new test uses the thread-local overrides so it doesn't depend on the env. It is lowering-only, no device involved, so the shared wide path itself was not run on a GPU here.
  • Full cargo test -p victory-shader --lib -- --test-threads=4: 415 passed, 1 failed, 4 ignored (about 12.5 min), the extra pass being the new test. Same single failure as main (00aa4d3) on the same machine, which gives 414 passed, 1 failed, 4 ignored, the failure being emit::size_tests::a_reused_descriptor_register_read_only_behind_its_flag (WARP rejects the compute pipeline, already there on main).
  • clippy -p victory-shader --all-targets: nothing new. All warnings are in code the PR doesn't touch, and the run still stops on the existing E0603 in benches/guard_runs.rs, same as main. The lib and lib-test targets were linted before that.

No issues found.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-03 19:57 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/352#issuecomment-7390493748) Tested b188fd0 natively on Windows 11 (MSVC, toolchain 1.98.1), D3D12 tests on one NVIDIA desktop card plus WARP. What I looked at - Shifts in `uniform_user_address` (bitcode.rs:468): a shift of two proven-uniform values is still a pure function of them, and the walk budget is untouched since `left` is decremented before the match. I also checked the lowering side: every scalar shift the translator emits masks its amount (`s_lshl/lshr/ashr_b32` and `s_bfm_b32` with `& 31`, the 64-bit forms with `& 63`, `bfe` too), so there is no oversized-shift poison that could make a "uniform" value differ per lane. - `one_guest_page` on the new SMEM path (lower.rs:5306-5333). I brute-forced it outside the repo against the code it replaces: the per-chunk `address_plus(lo, hi, offset + 4*first)` plus the page/in-page split from `memory_view`, versus one `address_plus(lo, hi, offset)` plus `4*first`. Full 21-bit signed SMEM offset range for x8 and x16, `lo` around 0, 64K multiples and the top of the 32-bit range, hi 0 and 0xFF, known-bit counts 0 to 32 with junk above the known bits, plus 200M random cases with 1 to 64 words. ~3.9G cases, ~366M accepted, no case where the page or the byte differed or a chunk ran past the 64K page. Widening the bound by 4 bytes made it fail right away, so the check does bite. - `low_bits_of` gets the post-soffset `lo` and the immediate offset is only folded in inside `one_guest_page`, same contract as the existing cluster call at lower.rs:4968/4982. The fault note count also matches the old path (`count/4` notes, once instead of per chunk). - With both switches unset I'm arguing from code, not from a DXIL diff: the `then` closure never runs, the `None` arm is the old code, and the uniform proof is short-circuited by `!uniform_guest_loads()`. Cache key bytes only change when a switch is on, and both key strings were bumped. Tests - `wide_smem_and_uniform_shifted_guest_loads`, `grouped_guest_ranges_never_cross_a_page_or_read_an_extra_word` and the bitcode tests: 20/20 with the env vars unset and 20/20 with both set to 1. The new test uses the thread-local overrides so it doesn't depend on the env. It is lowering-only, no device involved, so the shared wide path itself was not run on a GPU here. - Full `cargo test -p victory-shader --lib -- --test-threads=4`: 415 passed, 1 failed, 4 ignored (about 12.5 min), the extra pass being the new test. Same single failure as main (00aa4d3) on the same machine, which gives 414 passed, 1 failed, 4 ignored, the failure being `emit::size_tests::a_reused_descriptor_register_read_only_behind_its_flag` (WARP rejects the compute pipeline, already there on main). - clippy `-p victory-shader --all-targets`: nothing new. All warnings are in code the PR doesn't touch, and the run still stops on the existing E0603 in benches/guard_runs.rs, same as main. The lib and lib-test targets were linted before that. No issues found. AI-assisted: yes
Author
Owner

@⁠fsrajner on GitHub · 2026-12-03 22:17 UTC · original

Tested this together with #351 (and #354/#364) on top of main (the two conflict in lower.rs tests and the shader_cache.rs key; I kept both tests and used one key). In this scene it made no measurable difference for us. The card is the limit here (~22 ms GPU wait per frame), so the extra lookups are probably not where our time goes. Thanks for the switches, they made the A/B easy.

Setup: RX 9070 XT 16 GB, Ryzen 7 7800X3D, CachyOS, RADV from this repo's setup.sh (Mesa 26.3.1 + patches). Series X, 3840x2160 output, FSR 4 Quality (4.1.2), RT at defaults, headless gamescope. Same save (the intro), the game stops 120 s after the first press; metric over the 5 s stats: frame windows after loading. 2 runs per variant, main = 6064c04.

variant ms/frame (runs) 5 s windows > 40 ms worst 5% worst window long frames (longest)
main 45 (45, 45) 83.8% 60.3 ms 72.1 ms 1145 (217 ms)
main + UNIFORM_GUEST_LOADS=1 + CLUSTER_GUEST_LOADS=1 46 (46, 46) 88.9% 60.8 ms 67.0 ms 1176 (190 ms)
main + #351 + #352 + #354 + #364 45 (44, 45) 86.1% 59.8 ms 65.2 ms 1215 (251 ms)
same + UNIFORM_GUEST_LOADS=1 + CLUSTER_GUEST_LOADS=1 44 (43, 46) 83.8% 60.3 ms 62.3 ms 1179 (171 ms)

Run-to-run spread here is about ±1 ms/frame, and the worst window moves between 56 and 72 ms, so all of these are within noise.

**@⁠fsrajner** on GitHub · 2026-12-03 22:17 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/352#issuecomment-7394002352) Tested this together with #351 (and #354/#364) on top of main (the two conflict in `lower.rs` tests and the `shader_cache.rs` key; I kept both tests and used one key). In this scene it made no measurable difference for us. The card is the limit here (~22 ms GPU wait per frame), so the extra lookups are probably not where our time goes. Thanks for the switches, they made the A/B easy. **Setup:** RX 9070 XT 16 GB, Ryzen 7 7800X3D, CachyOS, RADV from this repo's `setup.sh` (Mesa 26.3.1 + patches). Series X, 3840x2160 output, FSR 4 Quality (4.1.2), RT at defaults, headless gamescope. Same save (the intro), the game stops 120 s after the first press; metric over the 5 s `stats: frame` windows after loading. 2 runs per variant, main = 6064c04. | variant | ms/frame (runs) | 5 s windows > 40 ms | worst 5% | worst window | long frames (longest) | |---|---|---|---|---|---| | main | 45 (45, 45) | 83.8% | 60.3 ms | 72.1 ms | 1145 (217 ms) | | main + `UNIFORM_GUEST_LOADS=1` + `CLUSTER_GUEST_LOADS=1` | 46 (46, 46) | 88.9% | 60.8 ms | 67.0 ms | 1176 (190 ms) | | main + #351 + #352 + #354 + #364 | 45 (44, 45) | 86.1% | 59.8 ms | 65.2 ms | 1215 (251 ms) | | same + `UNIFORM_GUEST_LOADS=1` + `CLUSTER_GUEST_LOADS=1` | 44 (43, 46) | 83.8% | 60.3 ms | 62.3 ms | 1179 (171 ms) | Run-to-run spread here is about ±1 ms/frame, and the worst window moves between 56 and 72 ms, so all of these are within noise.
Author
Owner

@⁠tommiehansen on GitHub · 2026-12-04 00:04 UTC · original

Thanks @⁠fsrajner for running this on live 4K RT (RX 9070 XT). That ~22 ms GPU-wait-bound regime matching baseline within +/-1 ms variance aligns with the scope of this PR (reducing CPU-side guest shader translation / load pressure rather than shifting GPU shader bottleneck limits).

**@⁠tommiehansen** on GitHub · 2026-12-04 00:04 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/352#issuecomment-7396329878) Thanks @⁠fsrajner for running this on live 4K RT (RX 9070 XT). That ~22 ms GPU-wait-bound regime matching baseline within +/-1 ms variance aligns with the scope of this PR (reducing CPU-side guest shader translation / load pressure rather than shifting GPU shader bottleneck limits).
Author
Owner

@⁠Luxuride on GitHub · 2026-12-04 12:10 UTC · original

Same quality as the sibling shader-address PR, and x8/x16 descriptor loads are common enough that this is the half more likely to pay for itself. Two things to do before it goes in.

What I verified (tests run here on Linux, cargo test -p victory-shader --lib, they pass):

  • uniform() (crates/victory-shader/src/emit/bitcode.rs:470) accepting Bin::Shl | LShr | AShr of uniform operands is sound: a shift by a uniform amount of a uniform value stays uniform.
  • The page maths in memory_smem (crates/victory-shader/src/emit/lower.rs:5263) is consistent — count is dwords throughout, so u32::from(count) into the words parameter matches the span / 4 the sibling PR uses, and the page-crossing x8 case is pinned by an identical-DXIL assertion.
  • It does not secretly depend on the sibling PR: one_guest_page(bits, residue, offset, words) already takes words on main (lower.rs:33).

The two asks:

  1. Drop the thread-local test hook. #[cfg(test)] thread_local! TEST_UNIFORM_GUEST_LOADS: Cell<Option<bool>> in emit/mod.rs is a second override next to the env switch, and when unset it silently falls back to the env — which is how a test ends up passing without exercising the path it names. One process-wide OnceLock, like quad_guard_on() already does, is cheaper and cannot be half-set.
  2. Rebase on the sibling PR. git merge-tree between the two heads conflicts in crates/victory-shader/src/emit/lower.rs and crates/victory-gpu/src/shader_cache.rs; whoever lands second rebases. Landing that one first and this on top is the cheapest order.

Missing, same as its sibling: no hit-rate, no perf number. For a change whose whole point is "these loads are common", one count would make the case.

**@⁠Luxuride** on GitHub · 2026-12-04 12:10 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/352#issuecomment-7411073929) Same quality as the sibling shader-address PR, and x8/x16 descriptor loads are common enough that this is the half more likely to pay for itself. Two things to do before it goes in. What I verified (tests run here on Linux, `cargo test -p victory-shader --lib`, they pass): - `uniform()` (`crates/victory-shader/src/emit/bitcode.rs:470`) accepting `Bin::Shl | LShr | AShr` of uniform operands is sound: a shift by a uniform amount of a uniform value stays uniform. - The page maths in `memory_smem` (`crates/victory-shader/src/emit/lower.rs:5263`) is consistent — `count` is dwords throughout, so `u32::from(count)` into the words parameter matches the `span / 4` the sibling PR uses, and the page-crossing x8 case is pinned by an identical-DXIL assertion. - It does not secretly depend on the sibling PR: `one_guest_page(bits, residue, offset, words)` already takes words on `main` (`lower.rs:33`). The two asks: 1. **Drop the thread-local test hook.** `#[cfg(test)] thread_local! TEST_UNIFORM_GUEST_LOADS: Cell<Option<bool>>` in `emit/mod.rs` is a second override next to the env switch, and when unset it silently falls back to the env — which is how a test ends up passing without exercising the path it names. One process-wide `OnceLock`, like `quad_guard_on()` already does, is cheaper and cannot be half-set. 2. **Rebase on the sibling PR.** `git merge-tree` between the two heads conflicts in `crates/victory-shader/src/emit/lower.rs` and `crates/victory-gpu/src/shader_cache.rs`; whoever lands second rebases. Landing that one first and this on top is the cheapest order. Missing, same as its sibling: no hit-rate, no perf number. For a change whose whole point is "these loads are common", one count would make the case.
github-bot changed title from shader: prove uniform shifted scalar addresses and share wide SMEM page lookups to perf(shader): prove uniform shifted addresses and share wide SMEM page lookups 2026-12-04 22:19:54 +00:00
Author
Owner

@⁠tommiehansen on GitHub · 2026-12-05 10:21 UTC · original

Thanks for the uniform-address review. The new Standard CPU comparison at 602f4ee measures 11.04% lower translation time for uniform SMEM/wide loads. Semantic Vulkan coverage and real-shader hit rate remain open, as does the test-hook feedback. The overlap with #351 still needs reconciliation before landing both.

**@⁠tommiehansen** on GitHub · 2026-12-05 10:21 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/352#issuecomment-7436384931) Thanks for the uniform-address review. The [new Standard CPU comparison](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47503640056/job/145622974558) at 602f4ee measures 11.04% lower translation time for uniform SMEM/wide loads. Semantic Vulkan coverage and real-shader hit rate remain open, as does the test-hook feedback. The overlap with #351 still needs reconciliation before landing both.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/352/head:github-bot/gh-352'
git switch 'github-bot/gh-352'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-352'
git switch 'github-bot/gh-352'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-352'
git switch 'github-bot/gh-352'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-352'
git switch 'main'
git merge --squash 'github-bot/gh-352'
git switch 'main'
git merge --ff-only 'github-bot/gh-352'
git switch 'main'
git merge 'github-bot/gh-352'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.