Skip to content

Port upstream #162: lower v_sad_u8, v_sad_hi_u8, v_sad_u16, v_sad_u32 and v_msad_u8 - #33

Merged
DesertGamer merged 2 commits into
DesertGamer:mainfrom
lcg007xd-c:port/upstream-162-sad
Nov 25, 2026
Merged

DesertGamer merged 2 commits into
DesertGamer:mainfrom
lcg007xd-c:port/upstream-162-sad

Conversation

@lcg007xd-c

Copy link
Copy Markdown
Contributor

What this changes

This ports the v_sad half of Marvisak/VIctory#162 by Rareuncommon. Commit 5d6889e is cherry-picked with -x, so it keeps their authorship.

VIPort decodes v_sad_u8, v_sad_hi_u8, v_sad_u16, v_sad_u32 and v_msad_u8 (VOP3 0x15a–0x15d, 0x171), but has no lowering for them. A shader that uses one is refused as a whole:

GFX10 code at 0x24: v_sad_u8 is not supported

The upstream merge is in VIPort's history, but the lowering arm is not in the tree. It was lost in a later merge.

The lowering is src2 plus the sum of the unsigned differences |a − b| of the operands' bytes, halves or whole dword, wrapping at 32 bits. v_sad_hi_u8 shifts the sum into the high half. v_msad_u8 skips a byte whose mask byte (src1) is 0.

#162 also contained v_mul_hi_u32_u24 / v_mul_hi_i32_i24 (344704e). This tree already lowers those, through mul_hi_24, so that commit is not taken. Its test helper lowers_valu is used by the v_sad test, though. A second commit adds that helper verbatim from upstream.

Checked

  • No game data of any kind (files, extracts, screenshots, dumps, saves): see docs/asset-policy.md
  • No binary files or archives
  • No new dependency, build.rs, git hook, .cargo config, CI change or script (or an issue explains why)
  • No download, no started program, no network connection added (or an issue explains why)
  • cargo test --workspace passes (only viport-shader --lib on Linux, see below)
  • cargo clippy --workspace --all-targets --locked -- -D warnings passes (for viport-shader, with CI: clear the clippy errors that keep main red since a3e7f17 #21 merged in locally)
  • The code I wrote is formatted with rustfmt; I did not reformat lines I did not change

What I ran

On Linux, Rust 1.98.1:

  • cargo test -p viport-shader --lib --locked: 191 passed, 0 failed, 3 ignored, including emit::lower::tests::sums_of_absolute_differences_lower.
  • With the lowering arm disabled, that test fails with the error above, for VOP3 0x15a first.
  • cargo clippy -p viport-shader --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings: clean with CI: clear the clippy errors that keep main red since a3e7f17 #21 merged in. Without it, the only errors are the two already on main.

Not run: the translated shaders on a GPU, against the hardware. I have no Windows machine. The test only checks that the five instructions lower to valid IR. Upstream did not add a hardware test for these either.

Overlaps

#27 moves the lower.rs unit tests into emit/lower_tests.rs. If it lands first, the new helper and test have to move with them, and I will rebase. #22 and #28 also edit lower.rs, in other functions.

🤖 Generated with Claude Code

Rareuncommon and others added 2 commits November 25, 2026 18:11
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 5d6889e)
Upstream added it with the v_mul_hi_*_24 lowering (344704e), which this
tree already has in another form; only the helper is taken.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DesertGamer
DesertGamer merged commit ed412af into DesertGamer:main Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants