Shaders: lower s_absdiff_i32, s_sext_i32_i8/i16 and s_pack_ll/lh/hh_b32_b16 #120

Open
github-bot wants to merge 1 commit from github-bot/gh-120 into main AGit
Owner

@⁠tedin7 on GitHub · 2026-11-24 00:40 UTC · original
tedin7:vic-s-pack-2 → main · +66 −0 · 1 files · 1 commits · open

What

  • Lowers s_absdiff_i32 (|a - b| of the wrapped difference, SCC = result != 0), s_sext_i32_i8, s_sext_i32_i16, and s_pack_ll_b32_b16, s_pack_lh_b32_b16, s_pack_hh_b32_b16 (halves picked as in the GFX10 ISA).

Why

  • They decode and are tracked in ir.rs, but sop() rejected them, so any shader using one failed to translate with Unsupported.

Tested

  • Linux x86_64 only. Commands run:
    • cargo test -j4 -p victory-shader scalar_pack with the lowering disabled (test only): fails with Unsupported { offset: 16, what: "s_absdiff_i32" }.
    • cargo test -j4 -p victory-shader after the change: 56 passed (origin/main 237f2e8), 0 failed (the new test included).
    • cargo clippy -j4 -p victory-shader --tests: no new warnings (existing: dead_code constant_color in emit/mod.rs, a boolean-simplification note in resource.rs).
    • rustfmt --edition 2024 --check on lower.rs: clean.
  • The test uses synthetic machine code (no game data) and checks that lowering succeeds, not the emitted DXIL values.
  • NOT run: Windows runtime, GPU, or a real console shader.
  • The test reuses the existing lowers() helper in the tests module.
**@⁠tedin7** on GitHub · 2026-11-24 00:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/120) `tedin7:vic-s-pack-2` → `main` · +66 −0 · 1 files · 1 commits · open What - Lowers `s_absdiff_i32` (|a - b| of the wrapped difference, SCC = result != 0), `s_sext_i32_i8`, `s_sext_i32_i16`, and `s_pack_ll_b32_b16`, `s_pack_lh_b32_b16`, `s_pack_hh_b32_b16` (halves picked as in the GFX10 ISA). Why - They decode and are tracked in ir.rs, but `sop()` rejected them, so any shader using one failed to translate with `Unsupported`. Tested - Linux x86_64 only. Commands run: - `cargo test -j4 -p victory-shader scalar_pack` with the lowering disabled (test only): fails with `Unsupported { offset: 16, what: "s_absdiff_i32" }`. - `cargo test -j4 -p victory-shader` after the change: 56 passed (origin/main 237f2e8), 0 failed (the new test included). - `cargo clippy -j4 -p victory-shader --tests`: no new warnings (existing: dead_code `constant_color` in emit/mod.rs, a boolean-simplification note in resource.rs). - `rustfmt --edition 2024 --check` on lower.rs: clean. - The test uses synthetic machine code (no game data) and checks that lowering succeeds, not the emitted DXIL values. - NOT run: Windows runtime, GPU, or a real console shader. - The test reuses the existing `lowers()` helper in the tests module.
These decode and are tracked in ir.rs but the lowering had no case for them, so any shader using one failed to translate with Unsupported.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:51:00 +00:00
Author
Owner

@⁠lordon1a on GitHub · 2026-11-24 00:51 UTC · original

Verified cb40cdcc2 on Windows 11 (x86_64-pc-windows-gnullvm, rustc 1.100.0, applied cleanly to main@4c0bb89): pass.

  • cargo xtask policy: 151 files ok
  • cargo test -p victory-shader -- --skip v_med3_f32_matches_rdna2_with_nan: 69 passed, 0 failed (skipped the pre-existing main Intel Iris Xe med3 failure tracked in #110).

AI-assisted.

**@⁠lordon1a** on GitHub · 2026-11-24 00:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/120#issuecomment-7118512093) Verified `cb40cdcc2` on Windows 11 (`x86_64-pc-windows-gnullvm`, `rustc 1.100.0`, applied cleanly to `main@4c0bb89`): **pass**. - `cargo xtask policy`: 151 files ok - `cargo test -p victory-shader -- --skip v_med3_f32_matches_rdna2_with_nan`: **69 passed, 0 failed** (skipped the pre-existing `main` Intel Iris Xe `med3` failure tracked in #110). AI-assisted.
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 01:10 UTC · original

Tested cb40cdc on Arch Linux x86_64, rustc 1.98.1: pass.

  • cargo test -p victory-shader: 56 passed, 0 failed (2 test binaries), including the 1 test this PR adds.
  • Scope note: #142 also lowers s_absdiff_i32/s_sext_i32_i8/i16/s_pack_*, and is open; one of the two should be closed.
  • The full workspace still needs #112 for the victory-gpu E0425.
**@⁠DaviTostes** on GitHub · 2026-11-24 01:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/120#issuecomment-7118824758) Tested `cb40cdc` on **Arch Linux x86_64, rustc 1.98.1**: **pass**. - `cargo test -p victory-shader`: **56 passed, 0 failed** (2 test binaries), including the 1 test this PR adds. - Scope note: #142 also lowers `s_absdiff_i32`/`s_sext_i32_i8/i16`/`s_pack_*`, and is open; one of the two should be closed. - The full workspace still needs #112 for the `victory-gpu` E0425.
Author
Owner

@⁠Lyrnc on GitHub · 2026-11-24 06:26 UTC · original

RDNA2 hardware check of the new scalar instructions: all match, including s_absdiff_i32 on the wrapped difference.

Setup. AMD Radeon iGPU of a Ryzen 7 9800X3D, gfx1036 (RDNA2), AMD driver 32.0.21042.62, Windows 11 Pro 26200. Hand-written instructions in a HIP kernel (assembled by the AMD driver's amd_comgr). RDNA2 desktop silicon, not the console's. No game data. 141 operand pairs: all pairs of 0, 1, 2, 0x7fffffff, 0x80000000, 0xffffffff, 0x40000000, 0xc0000000, 0x12345678, plus 60 random. SCC was read right after each instruction.

  • s_absdiff_i32: |a - b| of the difference wrapped to 32 bits, SCC = result != 0: 141/141. For example, |1 - 0x80000000| gives 0x7fffffff (not 0x80000001), and |0 - 0x80000000| gives 0x80000000, as your lowering computes.
  • s_pack_ll_b32_b16, s_pack_lh_b32_b16, s_pack_hh_b32_b16: {lo/hi(src1), lo/hi(src0)}: 141/141 each.
  • s_sext_i32_i8 / s_sext_i32_i16, measured for #142: sign extension, SCC unchanged.

AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run.

**@⁠Lyrnc** on GitHub · 2026-11-24 06:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/120#issuecomment-7123940004) RDNA2 hardware check of the new scalar instructions: **all match**, including `s_absdiff_i32` on the wrapped difference. **Setup.** AMD Radeon iGPU of a Ryzen 7 9800X3D, **gfx1036 (RDNA2)**, AMD driver 32.0.21042.62, Windows 11 Pro 26200. Hand-written instructions in a HIP kernel (assembled by the AMD driver's amd_comgr). RDNA2 desktop silicon, not the console's. No game data. 141 operand pairs: all pairs of `0, 1, 2, 0x7fffffff, 0x80000000, 0xffffffff, 0x40000000, 0xc0000000, 0x12345678`, plus 60 random. SCC was read right after each instruction. - `s_absdiff_i32`: `|a - b|` of the difference wrapped to 32 bits, SCC = result != 0: 141/141. For example, `|1 - 0x80000000|` gives `0x7fffffff` (not `0x80000001`), and `|0 - 0x80000000|` gives `0x80000000`, as your lowering computes. - `s_pack_ll_b32_b16`, `s_pack_lh_b32_b16`, `s_pack_hh_b32_b16`: `{lo/hi(src1), lo/hi(src0)}`: 141/141 each. - `s_sext_i32_i8` / `s_sext_i32_i16`, measured for #142: sign extension, SCC unchanged. AI use: Claude Code (Claude Opus 5.5) wrote the probes, ran them on the GPU above and drafted this comment; the numbers come from the hardware run.
Author
Owner

@⁠alexdeliu on GitHub · 2026-11-24 17:22 UTC · original

Merged onto main @ ffe310eb, this PR (cb40cdcc) no longer compiles its tests. crates/victory-shader/src/emit/lower.rs:7391 calls the lowers(&words) test helper. Since 25b0f888 it is lowers(words, rsrc2); main's tests pass 0.

Checked with CI's steps (both clippy runs with -D warnings, cargo test --workspace) on Windows 11, AMD RX 9070. Every open PR: https://gist.github.com/alexdeliu/ef9ef0ebc1776ff104b5aa8eaea18e87

**@⁠alexdeliu** on GitHub · 2026-11-24 17:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/120#issuecomment-7139103980) Merged onto `main` @ `ffe310eb`, this PR (`cb40cdcc`) no longer compiles its tests. `crates/victory-shader/src/emit/lower.rs:7391` calls the `lowers(&words)` test helper. Since 25b0f888 it is `lowers(words, rsrc2)`; main's tests pass `0`. <sub>Checked with CI's steps (both clippy runs with `-D warnings`, `cargo test --workspace`) on Windows 11, AMD RX 9070. Every open PR: https://gist.github.com/alexdeliu/ef9ef0ebc1776ff104b5aa8eaea18e87</sub>
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:25 UTC · original · edited 2026-11-25 01:14 UTC

Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-shader/src/emit/lower.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/120#issuecomment-7148490745) · edited 2026-11-25 01:14 UTC <!-- victory-triage v1 head=cb40cdcc21a77510b5b747c578059c1e11fff4ba verdict=needs-rebase at=2026-11-25T01:14:50Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-shader/src/emit/lower.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
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/120/head:github-bot/gh-120'
git switch 'github-bot/gh-120'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-120'
git switch 'github-bot/gh-120'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-120'
git switch 'github-bot/gh-120'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-120'
git switch 'main'
git merge --squash 'github-bot/gh-120'
git switch 'main'
git merge --ff-only 'github-bot/gh-120'
git switch 'main'
git merge 'github-bot/gh-120'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!120
No description provided.