perf(shader): prove uniform shifted addresses and share wide SMEM page lookups #352
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!352
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-352"
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-03 19:16 UTC · original
tommiehansen:perf/shader-wide-smem-uniform-shifts→main· +189 −10 · 5 files · 4 commits · openWhy
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).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
376aa90two 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.
@Kal0s-design on GitHub · 2026-12-03 19:57 UTC · original
Tested
b188fd0natively on Windows 11 (MSVC, toolchain 1.98.1), D3D12 tests on one NVIDIA desktop card plus WARP.What I looked at
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 sinceleftis decremented before the match. I also checked the lowering side: every scalar shift the translator emits masks its amount (s_lshl/lshr/ashr_b32ands_bfm_b32with& 31, the 64-bit forms with& 63,bfetoo), so there is no oversized-shift poison that could make a "uniform" value differ per lane.one_guest_pageon the new SMEM path (lower.rs:5306-5333). I brute-forced it outside the repo against the code it replaces: the per-chunkaddress_plus(lo, hi, offset + 4*first)plus the page/in-page split frommemory_view, versus oneaddress_plus(lo, hi, offset)plus4*first. Full 21-bit signed SMEM offset range for x8 and x16,loaround 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_ofgets the post-soffsetloand the immediate offset is only folded in insideone_guest_page, same contract as the existing cluster call at lower.rs:4968/4982. The fault note count also matches the old path (count/4notes, once instead of per chunk).thenclosure never runs, theNonearm 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_wordand 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.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 beingemit::size_tests::a_reused_descriptor_register_read_only_behind_its_flag(WARP rejects the compute pipeline, already there on main).-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
@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.rstests and theshader_cache.rskey; 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 sstats: framewindows after loading. 2 runs per variant, main =6064c04.UNIFORM_GUEST_LOADS=1+CLUSTER_GUEST_LOADS=1UNIFORM_GUEST_LOADS=1+CLUSTER_GUEST_LOADS=1Run-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.
@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).
@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) acceptingBin::Shl | LShr | AShrof uniform operands is sound: a shift by a uniform amount of a uniform value stays uniform.memory_smem(crates/victory-shader/src/emit/lower.rs:5263) is consistent —countis dwords throughout, sou32::from(count)into the words parameter matches thespan / 4the sibling PR uses, and the page-crossing x8 case is pinned by an identical-DXIL assertion.one_guest_page(bits, residue, offset, words)already takes words onmain(lower.rs:33).The two asks:
#[cfg(test)] thread_local! TEST_UNIFORM_GUEST_LOADS: Cell<Option<bool>>inemit/mod.rsis 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-wideOnceLock, likequad_guard_on()already does, is cheaper and cannot be half-set.git merge-treebetween the two heads conflicts incrates/victory-shader/src/emit/lower.rsandcrates/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.
shader: prove uniform shifted scalar addresses and share wide SMEM page lookupsto perf(shader): prove uniform shifted addresses and share wide SMEM page lookups@tommiehansen on GitHub · 2026-12-05 10:21 UTC · original
Thanks for the uniform-address review. The new Standard CPU comparison at
602f4eemeasures 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.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.