perf(shader): cluster shifted, strided, and scalar-base guest loads #351

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

@⁠tommiehansen on GitHub · 2026-12-03 19:11 UTC · original
tommiehansen:perf/shader-cluster-shifts-saddr → main · +353 −48 · 4 files · 4 commits · open

Standard benchmark — 2026-12-05

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

Workload Baseline (ms) Candidate (ms) Time change Verification
Extended guest-load clusters 10.770 8.041 −25.31% Structurally valid; semantics unverified
Guest-load clusters 11.214 11.124 −0.91% Identical; no significant difference

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

  • Off-by-default and main parity: Existing opt-in clustering flag remains off; rejected cases were byte-identical in targeted tests.
  • Docs move with code: Updated existing settings description; upstream already exposes clustering in menu.
  • No unrelated cleanup: Single guest-load clustering expansion.
  • A test must exercise the change: 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.
  • Queue checked on 2026-12-04: #352/#467 overlap proof/lowering/cache; #518 proposes default-on. Independent branch, reconcile before landing.
  • Run cargo xtask policy on 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_of previously checked only single-constant right-hand operands (v_and_b32, v_or_b32, v_add_nc_u32, v_sub_nc_u32, direct Bin::Shl). Real GFX10 address arithmetic misses that proof in three common cases:

  1. v_lshlrev_b32 (and v_lshl_add_u32 / v_lshl_or_b32 / v_add_lshl_u32) lowers the shift amount through m31(Const(k)) = Bin::And(Const(k), Const(31)), which is not folded prior to clustering, so low_bits_of returned (0, 0).
  2. Two-operand aligned sums/subtracts (aligned_base + (idx << 4)), bit operations (And/Or/Xor/LShr), and strided multiplies (idx * 16) returned (0, 0).
  3. GFX10 global_load_* instructions using saddr (64-bit SGPR base + 32-bit VGPR offset) were rejected by try_guest_load_cluster.

Changes

  • crates/victory-shader/src/emit/bitcode.rs: Replace the narrow low_bits_of match with known_bits(&self, v, depth) propagating per-bit (known_mask, known_value) across And, Or, Xor, constant Shl (including And(Const(k), 31)), constant LShr, Add, Sub, and Mul.
  • crates/victory-shader/src/emit/lower.rs: Extend try_guest_load_cluster with ClusterBase::{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 to bounded guest global load clusters v3 (leaving default translation and TRANSLATOR_VERSION unchanged).

Verification

Unit tests (cargo test -p victory-shader --lib)

  • Result: 296 passed, 0 failed, 2 ignored.
  • Added emit::bitcode::tests::known_bits_tracks_masked_shifts_lshr_xor_mul_and_sums verifying known-bit propagation and brute-force soundness over sample inputs.
  • Added emit::lower::tests::guest_load_clusters_accept_shifted_multiplied_and_saddr_addresses:
    • v_lshlrev_b32 + v_add_nc_u32: nonuniform_handles 4 → 1, smaller DXIL.
    • v_mul_lo_u32 v2, v0, 16: nonuniform_handles 4 → 1, smaller DXIL.
    • global_load_dword with aligned saddr s[4:5] + shifted VGPR offset v2: nonuniform_handles 4 → 1, smaller DXIL.
    • Rejected saddr cases (stride-crossing base, page-crossing, mismatched saddr, overlapping destinations, out-of-order offset): 2 → 2, byte-identical DXIL.

Benchmark Suite (origin/main 45591b0 vs c15e194, A/B/B/A 8 runs/side, --suite shaders --cpu-only, VICTORY_CLUSTER_GUEST_LOADS=1)

Benchmark Baseline (ms) Candidate (ms) Change p-value Equivalence Classification
shaders/guest_load_clusters 5.588 5.610 +0.32% 0.1776 identical No significant difference
shaders/node_probe_emit 1.098 1.094 -0.14% 0.5732 identical No significant difference
shaders/structurise_guard_runs 9.460 9.563 +1.14% 0.0849 identical Inconclusive
shaders/translate_corpus 2.214 2.221 +0.54% 0.7454 identical Inconclusive
shaders/uniform_guest_loads 1.459 1.462 +0.13% 0.5753 identical No significant difference
shaders/gpu_execute - - - - n/a Unsupported (--cpu-only)

Reproducible commands:

cargo test -p victory-shader --lib
./tools/benchmark-suite/run compare origin/main perf/shader-cluster-shifts-saddr --suite shaders --cpu-only --base-env VICTORY_CLUSTER_GUEST_LOADS=1 --cand-env VICTORY_CLUSTER_GUEST_LOADS=1

Limitations

  • Verified in CPU-only mode on Apple M5 (macOS ARM64). Windows target compilation (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 45591b0f6daf6f5d2a738307d72713428c958633 and the candidate was c15e194d41a2e72ead5188e59c8fa57476a62c35. The two revisions differ by the change in this PR.

Workload Baseline median Candidate median Paired duration change 95% CI
Shifted, strided, and SADDR guest-load clusters 5.451 ms 4.211 ms −24.31% −29.38% to −18.87%

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.

./tools/benchmark-suite/run compare 45591b0f6daf6f5d2a738307d72713428c958633 c15e194d41a2e72ead5188e59c8fa57476a62c35 --cpu-only --suite shaders --profile standard --blocks 4 --base-env VICTORY_CLUSTER_GUEST_LOADS=1 --cand-env VICTORY_CLUSTER_GUEST_LOADS=1

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 b581f7e0a8086158953a64068ba29305d5450d68 into 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)

Synthetic CPU workload Base (ms) Candidate (ms) Paired time change
Extended guest-load translation 10.6522 8.1541 −23.26%

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.

**@⁠tommiehansen** on GitHub · 2026-12-03 19:11 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/351) `tommiehansen:perf/shader-cluster-shifts-saddr` → `main` · +353 −48 · 4 files · 4 commits · open ## Standard benchmark — 2026-12-05 [Reproducible CI result](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47503640056/job/145622974620) · head `a7cccd128d00` · Linux hosted CPU-only, Standard, four ABBA blocks (8 runs per arm). | Workload | Baseline (ms) | Candidate (ms) | Time change | Verification | |---|---:|---:|---:|---| | Extended guest-load clusters | 10.770 | 8.041 | **−25.31%** | Structurally valid; semantics unverified | | Guest-load clusters | 11.214 | 11.124 | **−0.91%** | Identical; no significant difference | 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 - [ ] Off-by-default and main parity: Existing opt-in clustering flag remains off; rejected cases were byte-identical in targeted tests. - [x] Docs move with code: Updated existing settings description; upstream already exposes clustering in menu. - [x] No unrelated cleanup: Single guest-load clustering expansion. - [ ] A test must exercise the change: `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. - [x] Queue checked on 2026-12-04: #352/#467 overlap proof/lowering/cache; #518 proposes default-on. Independent branch, reconcile before landing. - [ ] Run `cargo xtask policy` on 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_of` previously checked only single-constant right-hand operands (`v_and_b32`, `v_or_b32`, `v_add_nc_u32`, `v_sub_nc_u32`, direct `Bin::Shl`). Real GFX10 address arithmetic misses that proof in three common cases: 1. `v_lshlrev_b32` (and `v_lshl_add_u32` / `v_lshl_or_b32` / `v_add_lshl_u32`) lowers the shift amount through `m31(Const(k)) = Bin::And(Const(k), Const(31))`, which is not folded prior to clustering, so `low_bits_of` returned `(0, 0)`. 2. Two-operand aligned sums/subtracts (`aligned_base + (idx << 4)`), bit operations (`And`/`Or`/`Xor`/`LShr`), and strided multiplies (`idx * 16`) returned `(0, 0)`. 3. GFX10 `global_load_*` instructions using `saddr` (64-bit SGPR base + 32-bit VGPR offset) were rejected by `try_guest_load_cluster`. ## Changes - `crates/victory-shader/src/emit/bitcode.rs`: Replace the narrow `low_bits_of` match with `known_bits(&self, v, depth)` propagating per-bit `(known_mask, known_value)` across `And`, `Or`, `Xor`, constant `Shl` (including `And(Const(k), 31)`), constant `LShr`, `Add`, `Sub`, and `Mul`. - `crates/victory-shader/src/emit/lower.rs`: Extend `try_guest_load_cluster` with `ClusterBase::{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 to `bounded guest global load clusters v3` (leaving default translation and `TRANSLATOR_VERSION` unchanged). ## Verification ### Unit tests (`cargo test -p victory-shader --lib`) - **Result:** 296 passed, 0 failed, 2 ignored. - Added `emit::bitcode::tests::known_bits_tracks_masked_shifts_lshr_xor_mul_and_sums` verifying known-bit propagation and brute-force soundness over sample inputs. - Added `emit::lower::tests::guest_load_clusters_accept_shifted_multiplied_and_saddr_addresses`: - `v_lshlrev_b32` + `v_add_nc_u32`: `nonuniform_handles` **4 → 1**, smaller DXIL. - `v_mul_lo_u32 v2, v0, 16`: `nonuniform_handles` **4 → 1**, smaller DXIL. - `global_load_dword` with aligned `saddr` `s[4:5]` + shifted VGPR offset `v2`: `nonuniform_handles` **4 → 1**, smaller DXIL. - Rejected `saddr` cases (stride-crossing base, page-crossing, mismatched `saddr`, overlapping destinations, out-of-order offset): **2 → 2**, byte-identical DXIL. ### Benchmark Suite (`origin/main` `45591b0` vs `c15e194`, A/B/B/A 8 runs/side, `--suite shaders --cpu-only`, `VICTORY_CLUSTER_GUEST_LOADS=1`) | Benchmark | Baseline (ms) | Candidate (ms) | Change | p-value | Equivalence | Classification | |---|---:|---:|---:|---:|---|---| | `shaders/guest_load_clusters` | 5.588 | 5.610 | +0.32% | 0.1776 | identical | No significant difference | | `shaders/node_probe_emit` | 1.098 | 1.094 | -0.14% | 0.5732 | identical | No significant difference | | `shaders/structurise_guard_runs` | 9.460 | 9.563 | +1.14% | 0.0849 | identical | Inconclusive | | `shaders/translate_corpus` | 2.214 | 2.221 | +0.54% | 0.7454 | identical | Inconclusive | | `shaders/uniform_guest_loads` | 1.459 | 1.462 | +0.13% | 0.5753 | identical | No significant difference | | `shaders/gpu_execute` | - | - | - | - | n/a | Unsupported (`--cpu-only`) | Reproducible commands: ```sh cargo test -p victory-shader --lib ./tools/benchmark-suite/run compare origin/main perf/shader-cluster-shifts-saddr --suite shaders --cpu-only --base-env VICTORY_CLUSTER_GUEST_LOADS=1 --cand-env VICTORY_CLUSTER_GUEST_LOADS=1 ``` ## Limitations - Verified in CPU-only mode on Apple M5 (macOS ARM64). Windows target compilation (`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 `45591b0f6daf6f5d2a738307d72713428c958633` and the candidate was `c15e194d41a2e72ead5188e59c8fa57476a62c35`. The two revisions differ by the change in this PR. | Workload | Baseline median | Candidate median | Paired duration change | 95% CI | |---|---:|---:|---:|---:| | Shifted, strided, and SADDR guest-load clusters | 5.451 ms | 4.211 ms | **−24.31%** | −29.38% to −18.87% | 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. ```sh ./tools/benchmark-suite/run compare 45591b0f6daf6f5d2a738307d72713428c958633 c15e194d41a2e72ead5188e59c8fa57476a62c35 --cpu-only --suite shaders --profile standard --blocks 4 --base-env VICTORY_CLUSTER_GUEST_LOADS=1 --cand-env VICTORY_CLUSTER_GUEST_LOADS=1 ``` 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 `b581f7e0a8086158953a64068ba29305d5450d68` into 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](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47466412636) 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) | Synthetic CPU workload | Base (ms) | Candidate (ms) | Paired time change | |---|---:|---:|---:| | Extended guest-load translation | 10.6522 | 8.1541 | −23.26% | 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](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47512649200/job/145651188657). ### 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](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47577540731) · [first comparison](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47577247764/job/145853300696). Current merge base: `8c4e663`. GitHub reports mergeable/clean. [Unchanged upstream Windows control](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47577277910) reproduces the existing descriptor PSO failure. No force-push or upstream merge.
Extend VICTORY_CLUSTER_GUEST_LOADS alignment proofs to propagate known bit masks and values across binary shifts (including m31-masked v_lshlrev_b32), LShr, And, Or, Xor, Add, Sub, and Mul, and support GFX10 global_load_* saddr (64-bit SGPR base + 32-bit VGPR offset). Preserve single-page and guard safety checks and keep rejected cases bit-identical.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-03 19:17:23 +00:00
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-03 20:15 UTC · original

Tested c15e194 on 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.
    • Per op (And, Or, Xor, Shl, LShr, Add, Sub, Mul): every unknown/0/1 combination on 5 bit positions per operand, with all concretizations of the unknown bits. That was about 50M checks with 0 mismatches.
    • 400k random expression trees, depth up to 9 (evaluated with your depth limit of 8), with shift amounts both as a raw constant and as And(k, 31). That was about 10M evaluations and 0 cases where low_bits_of claimed a bit the real value didn't have.
    • Three mutants (Mul using la + lb, Add/Sub using max instead of min, Xor using ma | 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.
  • Saddr (lower.rs:4986-5004 and 5058-5067).
    • The sum/carry sequence matches the one in memory_flat: the VGPR offset is zero-extended and the carry goes into the high word.
    • Taking the min of the two known-bit counts and adding the residues mod 2^bits is correct.
    • I checked it end to end against a 64-bit reference address (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.
  • All loads in a cluster still need the same base (next != base at 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.
  • With the switch unset, try_guest_load_cluster is never reached (lower.rs:3473), and low_bits_of has 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, and known_bits is read-only.
  • The cache key is bumped (v2 -> v3).

Tests:

  • The two new tests ran 20x with VICTORY_CLUSTER_GUEST_LOADS unset and 20x with it set to 1, and passed every time. Neither one creates a D3D12 device.
  • Full cargo test -p victory-shader --lib -- --test-threads=4 on 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.
  • Clippy -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 (v3 here, smem-wide there). 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

**@⁠Kal0s-design** on GitHub · 2026-12-03 20:15 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/351#issuecomment-7390942742) Tested c15e194 on 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. - Per op (And, Or, Xor, Shl, LShr, Add, Sub, Mul): every unknown/0/1 combination on 5 bit positions per operand, with all concretizations of the unknown bits. That was about 50M checks with 0 mismatches. - 400k random expression trees, depth up to 9 (evaluated with your depth limit of 8), with shift amounts both as a raw constant and as `And(k, 31)`. That was about 10M evaluations and 0 cases where `low_bits_of` claimed a bit the real value didn't have. - Three mutants (Mul using `la + lb`, Add/Sub using max instead of min, Xor using `ma | 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. - Saddr (lower.rs:4986-5004 and 5058-5067). - The sum/carry sequence matches the one in `memory_flat`: the VGPR offset is zero-extended and the carry goes into the high word. - Taking the min of the two known-bit counts and adding the residues mod 2^bits is correct. - I checked it end to end against a 64-bit reference address (`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. - All loads in a cluster still need the same base (`next != base` at 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. - With the switch unset, `try_guest_load_cluster` is never reached (lower.rs:3473), and `low_bits_of` has 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, and `known_bits` is read-only. - The cache key is bumped (v2 -> v3). Tests: - The two new tests ran 20x with VICTORY_CLUSTER_GUEST_LOADS unset and 20x with it set to 1, and passed every time. Neither one creates a D3D12 device. - Full `cargo test -p victory-shader --lib -- --test-threads=4` on 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. - Clippy `-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 (`v3` here, `smem-wide` there). 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
Author
Owner

@⁠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.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/351#issuecomment-7394001906) Tested this together with #352 (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/351#issuecomment-7396329025) 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

Reviewed against main @ 0fd7614, diff taken from the merge base. I ran the two new tests here: cargo test -p victory-shader --lib passes, 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_bits is sound operation by operation. The multiply case uses l = 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.
  • The saddr carry handling is right: the VGPR voff is zero-extended to 64 bits before the Add + IULT carry, so a 32-bit offset can never wrap into the high half.
  • crates/victory-gpu/src/shader_cache.rs:137 bumps "bounded guest global load clusters v3". Cache invalidation is the single most-forgotten step in this area and it is here.
  • Rejects assert bit-identical DXIL, and the accept/reject split in guest_load_clusters_accept_shifted_multiplied_and_saddr_addresses is 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=1 to 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 saddr registers and voff (crates/victory-shader/src/emit/lower.rs:4920-5050, next != base rejects), 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.

**@⁠Luxuride** on GitHub · 2026-12-04 12:10 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/351#issuecomment-7411073668) Reviewed against `main` @ `0fd7614`, diff taken from the merge base. I ran the two new tests here: `cargo test -p victory-shader --lib` passes, 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_bits` is sound operation by operation. The multiply case uses `l = 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. - The `saddr` carry handling is right: the VGPR `voff` is zero-extended to 64 bits before the `Add` + `IULT` carry, so a 32-bit offset can never wrap into the high half. - `crates/victory-gpu/src/shader_cache.rs:137` bumps `"bounded guest global load clusters v3"`. Cache invalidation is the single most-forgotten step in this area and it is here. - Rejects assert bit-identical DXIL, and the accept/reject split in `guest_load_clusters_accept_shifted_multiplied_and_saddr_addresses` is 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=1` to 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 `saddr` registers and `voff` (`crates/victory-shader/src/emit/lower.rs:4920-5050`, `next != base` rejects), 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.
github-bot changed title from shader: cluster shifted, strided, and saddr guest loads to perf(shader): cluster shifted, strided, and scalar-base guest loads 2026-12-04 22:19:53 +00:00
Author
Owner

@⁠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 a7cccd1 measures 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.

**@⁠tommiehansen** on GitHub · 2026-12-05 10:21 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/351#issuecomment-7436383905) Thanks for reviewing the address proof and noting the missing measurement. The [new Standard CPU comparison](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47503640056/job/145622974620) at a7cccd1 measures 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.
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/351/head:github-bot/gh-351'
git switch 'github-bot/gh-351'

Merge

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