Shaders: lower v_sad_u8/u16/u32, v_sad_hi_u8 and v_msad_u8 (port of VIctory#162) #57

Closed
lcg007xd-c wants to merge 0 commits from upstream-pr/57 into main
lcg007xd-c commented 2026-11-25 20:57:29 +00:00 (Migrated from github.com)

Imported from uiliannn/VItoriaBr. Originally posted by lcg007xd-c on 2026-11-25T20:57:29Z.


Stacked on #56. This branch contains that PR's commit, because it uses its lowers_valu test helper. Once #56 is merged, this diff is the single SAD commit.

What

v_sad_u8, v_sad_hi_u8, v_sad_u16, v_sad_u32 and v_msad_u8 (VOP3 0x15A-0x15D, 0x171) had no lowering, so a shader that used them failed to translate. Each one is now src2 plus the sum of |a - b| over the operands' bytes, halves or whole dwords, wrapping at 32 bits:

  • v_sad_hi_u8 adds the byte sum shifted into the high half.
  • v_msad_u8 skips a byte whose reference byte (src1) is 0.

Port

Cherry-pick (-x) of github.com/Marvisak/VIctory@5d6889e from upstream. Rareuncommon is still the commit author. The only conflict was a test added next to VItoriaBr's buffer_cache_invalidations_lower_as_no_ops. Both tests are kept.

Test

sums_of_absolute_differences_lower lowers all five. With only this commit's match arm reverted, it fails, and with it, it passes.

How this was checked (Linux, no Windows PC or game files)

  • The portable CI commands pass locally on this branch: cargo clippy -p victory-core -p victory-pe -p victory-pipeline -p victory-shader -p victory-formats -p victory-game -p xtask --all-targets --locked -- -D warnings, then cargo test on the same crates (rebased on current main).
  • cargo clippy with the same crates and --target x86_64-pc-windows-msvc (check only, no link) is clean.
  • lower.rs has the same number of rustfmt differences before and after this change, so the added code is rustfmt-clean.

Not tested: Windows runtime, GPU, and the game itself. In particular, the numeric results were not run on a GPU here. The new test only proves the instructions now lower, and Windows CI validates the module where dxil.dll is available.

🤖 Generated with Claude Code

<!-- greyfinch-sync:uiliannn/VItoriaBr:issue:5499054742 --> Imported from [uiliannn/VItoriaBr](https://github.com/uiliannn/VitoriaBr2.0/pull/57). Originally posted by [lcg007xd-c](https://github.com/lcg007xd-c) on 2026-11-25T20:57:29Z. --- **Stacked on #56.** This branch contains that PR's commit, because it uses its `lowers_valu` test helper. Once #56 is merged, this diff is the single SAD commit. ## What `v_sad_u8`, `v_sad_hi_u8`, `v_sad_u16`, `v_sad_u32` and `v_msad_u8` (VOP3 0x15A-0x15D, 0x171) had no lowering, so a shader that used them failed to translate. Each one is now `src2` plus the sum of `|a - b|` over the operands' bytes, halves or whole dwords, wrapping at 32 bits: - `v_sad_hi_u8` adds the byte sum shifted into the high half. - `v_msad_u8` skips a byte whose reference byte (`src1`) is 0. ## Port Cherry-pick (`-x`) of https://github.com/Marvisak/VIctory/commit/5d6889e from upstream. Rareuncommon is still the commit author. The only conflict was a test added next to VItoriaBr's `buffer_cache_invalidations_lower_as_no_ops`. Both tests are kept. ## Test `sums_of_absolute_differences_lower` lowers all five. With only this commit's match arm reverted, it fails, and with it, it passes. ## How this was checked (Linux, no Windows PC or game files) - The portable CI commands pass locally on this branch: `cargo clippy -p victory-core -p victory-pe -p victory-pipeline -p victory-shader -p victory-formats -p victory-game -p xtask --all-targets --locked -- -D warnings`, then `cargo test` on the same crates (rebased on current `main`). - `cargo clippy` with the same crates and `--target x86_64-pc-windows-msvc` (check only, no link) is clean. - `lower.rs` has the same number of `rustfmt` differences before and after this change, so the added code is rustfmt-clean. Not tested: Windows runtime, GPU, and the game itself. In particular, the numeric results were not run on a GPU here. The new test only proves the instructions now lower, and Windows CI validates the module where `dxil.dll` is available. 🤖 Generated with [Claude Code](https://claude.com/claude-code)

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
uiliannn/VItoriaBr!57
No description provided.