perf(shader): cluster shifted, strided, and scalar-base guest loads #351
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!351
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-351"
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:11 UTC · original
tommiehansen:perf/shader-cluster-shifts-saddr→main· +353 −48 · 4 files · 4 commits · openStandard benchmark — 2026-12-05
Reproducible CI result · head
a7cccd128d00· Linux hosted CPU-only, Standard, four ABBA blocks (8 runs per arm).Baseline
b581f7e; clustering enabled on both arms. CPU translation only; execution equivalence remains unverified for changed output.Negative values indicate reduced CPU time. Synthetic workloads, not gameplay FPS.
What this does
Cluster shifted, strided, and scalar-base guest loads.
Checks
known_bits_tracks_masked_shifts_lshr_xor_mul_and_sums,guest_load_clusters_accept_shifted_multiplied_and_saddr_addresses; 296 previously passing. Explicit pre-change/final-head rerun pending.cargo xtask policyon the final revision; no new game assets or build output intended.Verified
Current review head:
1dd0c125ee735c486dc1d9d98757249871eeb5ac. Existing measurements and commands are retained below at their original revisions. No fresh compile, policy or hardware test is claimed by this metadata review.Cost
4→1 handles in selected synthetic shaders; CPU suite generally neutral, hardware benefit unknown.
Detailed implementation and historical validation
Problem
Under
VICTORY_CLUSTER_GUEST_LOADS=1(#305),Module::low_bits_ofpreviously checked only single-constant right-hand operands (v_and_b32,v_or_b32,v_add_nc_u32,v_sub_nc_u32, directBin::Shl). Real GFX10 address arithmetic misses that proof in three common cases:v_lshlrev_b32(andv_lshl_add_u32/v_lshl_or_b32/v_add_lshl_u32) lowers the shift amount throughm31(Const(k)) = Bin::And(Const(k), Const(31)), which is not folded prior to clustering, solow_bits_ofreturned(0, 0).aligned_base + (idx << 4)), bit operations (And/Or/Xor/LShr), and strided multiplies (idx * 16) returned(0, 0).global_load_*instructions usingsaddr(64-bit SGPR base + 32-bit VGPR offset) were rejected bytry_guest_load_cluster.Changes
crates/victory-shader/src/emit/bitcode.rs: Replace the narrowlow_bits_ofmatch withknown_bits(&self, v, depth)propagating per-bit(known_mask, known_value)acrossAnd,Or,Xor, constantShl(includingAnd(Const(k), 31)), constantLShr,Add,Sub, andMul.crates/victory-shader/src/emit/lower.rs: Extendtry_guest_load_clusterwithClusterBase::{V64, Saddr}, combining the low-bit congruences of the SGPR low word and VGPR offset while preserving every single-page (one_guest_page), destination-overlap, guard, and offset-order check. Rejected cases fall back to ordinary lowering with bit-identical DXIL.crates/victory-gpu/src/shader_cache.rs: Bump the opt-in cluster cache key tobounded guest global load clusters v3(leaving default translation andTRANSLATOR_VERSIONunchanged).Verification
Unit tests (
cargo test -p victory-shader --lib)emit::bitcode::tests::known_bits_tracks_masked_shifts_lshr_xor_mul_and_sumsverifying known-bit propagation and brute-force soundness over sample inputs.emit::lower::tests::guest_load_clusters_accept_shifted_multiplied_and_saddr_addresses:v_lshlrev_b32+v_add_nc_u32:nonuniform_handles4 → 1, smaller DXIL.v_mul_lo_u32 v2, v0, 16:nonuniform_handles4 → 1, smaller DXIL.global_load_dwordwith alignedsaddrs[4:5]+ shifted VGPR offsetv2:nonuniform_handles4 → 1, smaller DXIL.saddrcases (stride-crossing base, page-crossing, mismatchedsaddr, overlapping destinations, out-of-order offset): 2 → 2, byte-identical DXIL.Benchmark Suite (
origin/main45591b0vsc15e194, A/B/B/A 8 runs/side,--suite shaders --cpu-only,VICTORY_CLUSTER_GUEST_LOADS=1)shaders/guest_load_clustersshaders/node_probe_emitshaders/structurise_guard_runsshaders/translate_corpusshaders/uniform_guest_loadsshaders/gpu_execute--cpu-only)Reproducible commands:
Limitations
victory-gpu), RADV ISA compilation, AMD GPU shader execution, and in-game frame-time measurements require external Windows/Linux AMD GPU hardware.Pass 2B — matched-switch benchmark
Apple M5, macOS ARM64, Standard profile, four paired A/B/B/A blocks. Both sides enabled guest-load clustering. The baseline was
45591b0f6daf6f5d2a738307d72713428c958633and the candidate wasc15e194d41a2e72ead5188e59c8fa57476a62c35. The two revisions differ by the change in this PR.The three qualifying fixtures reduced directory lookups from 12 to 3, guest raw loads from 12 to 3, nonuniform handles from 12 to 3, and inspected DXIL instructions from 425 to 173. Both rejected fixtures retained the same digest. The timing remained provisional because the changed DXIL was structurally validated on CPU. The other measured workloads were inconclusive. The four-block estimate retained one IQR outlier and had an approximate 80% minimum detectable effect of 9.16%.
Kal0s-design independently reported no mismatch in brute-force known-bit and SADDR-address checks, including carry and single-page bounds. If #352 lands first, the combined translator cache key must identify both changes.
These numbers describe synthetic CPU translation and emitted DXIL. AMD GPU execution, runtime frame time, and gameplay FPS were outside this run.
Queue refresh — 2026-12-05
Merged upstream main
b581f7e0a8086158953a64068ba29305d5450d68into the existing branch without rewriting history. New head:a7cccd128d002f1be1cef9d48b897fe60171baf3. #351 and #352 still overlap textually; recheck the second against main after the first lands.Fresh pinned CI audit is the verification record for this revision; previous tests apply to the previously stated heads. #528 remains a separate policy prerequisite, not a runtime dependency. No new gameplay or GPU timing claim.
Standard CI raw-artifact follow-up (2026-12-05)
Descriptive CPU translation result only: transformed DXIL is structurally valid but semantic equivalence is unverified for this workload. Four complete ABBA blocks, eight runs per arm. Independently checked all 16 raw checkpoint revisions, per-run sample concatenation, medians and digests against results.json. The Python review gate incorrectly interprets
rounds=8(runs per arm) as eight ABBA blocks; its automatic verdict remains inconclusive pending a harness fix. The CIs above, where stated, are the Rust report's per-workload estimates. Generic software Vulkan control passed with identical SPIR-V, not activation of this PR. No physical GPU or gameplay FPS claim. Pinned CI/artifacts.Current upstream reconciliation —
4fcb876(2026-12-05)Reconciled the current guest-address API while retaining the wider address proof and separate opt-in shader-cache key. Two Standard paired CPU runs against current main: extended guest clustering −13.88% and −14.03%, with structurally valid but not yet semantically verified changed shader output. Other workloads show no significant change or are inconclusive. Linux full tests, Windows focused tests and production compilation passed. The full Windows suite retains the same descriptor PSO failure as unchanged main; no new failure. CI · first comparison.
Current merge base:
8c4e663. GitHub reports mergeable/clean. Unchanged upstream Windows control reproduces the existing descriptor PSO failure. No force-push or upstream merge.@Kal0s-design on GitHub · 2026-12-03 20:15 UTC · original
Tested
c15e194on Windows 11, native MSVC build, toolchain 1.98.1.What I looked at:
known_bits(bitcode.rs:495). I copied the transfer functions as-is into a standalone checker and compared them against brute force.And(k, 31). That was about 10M evaluations and 0 cases wherelow_bits_ofclaimed a bit the real value didn't have.la + lb, Add/Sub using max instead of min, Xor usingma | mb) were each caught right away. A fourth mutant, which loosened the Shl guard, wasn't caught. That's because the checker treats shifts by 32 or more as poison and skips them, so it doesn't cover that case. From the code, though, the Shl/LShr arms only fire on a fully known amount below 32 and give up otherwise, so I don't see a problem there.memory_flat: the VGPR offset is zero-extended and the carry goes into the high word.base + zext(voff) + sext(offset)), including lo+voff wrapping past 2^32. That was about 6.7M addresses, with 0 accepted spans that left the 64 KiB page and 0 mismatches against the emitted lo/hi.next != baseat lower.rs:5024). For saddr that means the same SGPR pair and VGPR offset values. As a quick local check, I added one more case to your rejection list where the first load's dst is the offset register (v2). It wasn't clustered, and the DXIL matched the switch-off output.try_guest_load_clusteris never reached (lower.rs:3473), andlow_bits_ofhas no other callers, so the output should be the same as main. With the switch on, all refusals still happen before any IR is emitted, andknown_bitsis read-only.Tests:
cargo test -p victory-shader --lib -- --test-threads=4on one NVIDIA desktop card plus WARP: 416 passed, 1 failed, 4 ignored. On main I get 414 / 1 / 4 with the same failure (size_tests::a_reused_descriptor_register_read_only_behind_its_flag, WARP rejects the compute pipeline), so the only difference is your two new tests. The branch is a few commits behind main, but none of them touch victory-shader.-p victory-shader --all-targets: no warnings in the changed code. The ones it reports are all in code the PR doesn't touch, plus the existing bench compile error.Heads-up: this PR and #352 conflict textually. One conflict is the cache key string in shader_cache.rs (
v3here,smem-widethere). The other is the test module in lower.rs, where both PRs add tests at the same place. Both are easy to resolve, but whichever lands second needs a cache key that covers both changes.I didn't find any problems.
AI-assisted: yes
@fsrajner on GitHub · 2026-12-03 22:17 UTC · original
Tested this together with #352 (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
Reviewed against
main@0fd7614, diff taken from the merge base. I ran the two new tests here:cargo test -p victory-shader --libpasses, so this one is not "cannot build on Linux" — it builds and its tests run on a plain Linux box.Verdict: good to take, with one caveat about what it is.
What I verified:
known_bitsis sound operation by operation. The multiply case usesl = min(la + zb, lb + za), which is the trailing-zero-bound argument, not a guess, and the masked-shift / OR / XOR cases each keep the low-bit mask they claim.saddrcarry handling is right: the VGPRvoffis zero-extended to 64 bits before theAdd+IULTcarry, so a 32-bit offset can never wrap into the high half.crates/victory-gpu/src/shader_cache.rs:137bumps"bounded guest global load clusters v3". Cache invalidation is the single most-forgotten step in this area and it is here.guest_load_clusters_accept_shifted_multiplied_and_saddr_addressesis 4/4.The one caveat is not a defect: there is no measurement, so nothing shows real shaders reach these address shapes often enough to matter. If you want
VICTORY_CLUSTER_GUEST_LOADS=1to ever be the default, a hit-rate count out of a shader log is the number that would do it. Until then this lands as groundwork, which is fine.Two things worth knowing: a later cluster member must repeat the exact same
saddrregisters andvoff(crates/victory-shader/src/emit/lower.rs:4920-5050,next != baserejects), so register-reused chains stay unfused — conservative, just narrower than the title suggests. And this conflicts textually with the other shader-address PR in the pile (same two files); land this one first.shader: cluster shifted, strided, and saddr guest loadsto perf(shader): cluster shifted, strided, and scalar-base guest loadsgithub-bot referenced this pull request2026-12-05 10:24:40 +00:00
@tommiehansen on GitHub · 2026-12-05 10:21 UTC · original
Thanks for reviewing the address proof and noting the missing measurement. The new Standard CPU comparison at
a7cccd1measures 25.31% lower translation time for the extended clustering fixture. Changed outputs are structurally valid but not yet semantically verified in Vulkan. Real shader hit rate and FPS remain unproven.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.