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

Open
github-bot wants to merge 3 commits from github-bot/gh-57 into main AGit
Owner

@⁠lcg007xd-c on GitHub · 2026-11-25 20:57 UTC · original
lcg007xd-c:port/sad-lowering → main · +109 −0 · 1 files · 3 commits · open

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

**@⁠lcg007xd-c** on GitHub · 2026-11-25 20:57 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/57) `lcg007xd-c:port/sad-lowering` → `main` · +109 −0 · 1 files · 3 commits · open **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)
The high dword of the 48-bit product whose low dword v_mul_u32_u24 and v_mul_i32_i24 already give: the low
24 bits of each operand, zero- or sign-extended, through the existing mul_hi.

The test module gets lowers_valu, a one-thread compute program with root constants in v1..v4 and a buffer
store of v0 (built with lower_with), so a vector instruction can be checked for lowering without a GPU.

AI-assisted (Claude Code).

(cherry picked from commit 344704e02850eb227fe61d4fd54e6657c17ea68d)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
src2 plus the sum of the unsigned differences |a - b| of the operands' bytes (v_sad_u8), halves (v_sad_u16)
or whole dwords (v_sad_u32), wrapping at 32 bits. v_sad_hi_u8 adds the byte sum shifted to the high half;
v_msad_u8 leaves out a byte whose mask byte (src1) is 0.

AI-assisted (Claude Code).

(cherry picked from commit 5d6889e8be76f630445a4057f81221b723898583)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:42:44 +00:00
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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