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

Open
tedin7 wants to merge 1 commit from upstream-pr/120 into main
tedin7 commented 2026-11-24 00:40:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by tedin7 on 2026-11-24T00:40:48Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6571934501 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/120). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T00:40:48Z. --- 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.
lordon1a commented 2026-11-24 06:54:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by lordon1a on 2026-11-24T00:51:43Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118512093 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/120#issuecomment-7118512093). Originally posted by [lordon1a](https://github.com/lordon1a) on 2026-11-24T00:51:43Z. --- 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.
DaviTostes commented 2026-11-24 06:54:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T01:10:04Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7118824758 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/120#issuecomment-7118824758). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T01:10:04Z. --- 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.
Lyrnc commented 2026-11-24 06:56:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Lyrnc on 2026-11-24T06:26:44Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123940004 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/120#issuecomment-7123940004). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-24T06:26:44Z. --- 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.
mercuryVM commented 2026-11-24 09:37:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T09:37:30Z.

Review: APPROVED


Tested cb40cdc on Windows 11, RTX 5070, MSVC: the workspace passes (186 outside victory-shader; victory-shader --lib single-threaded: 69). victory translate <title exe> --validate --pipelines gives the same counts before and after: 12 of 12 programs emitted, 12 validated, 12 pipelines.

Checked against the GFX10 ISA:

  • s_absdiff_i32: |a − b| of the wrapping difference, with SCC = result ≠ 0.
  • s_sext_i32_i8/i16: shift left, then arithmetic shift right.
  • s_pack_ll gives {b.lo, a.lo}, s_pack_lh gives {b.hi, a.lo}, and s_pack_hh gives {b.hi, a.hi}, written high:low.

SCC is only written where the decoder says the instruction writes it (inst.write(Reg::Scc)), so sext and pack correctly leave SCC alone.

No issues found.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6036817502 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/120#pullrequestreview-6036817502). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T09:37:30Z. **Review:** APPROVED --- Tested cb40cdc on Windows 11, RTX 5070, MSVC: the workspace passes (186 outside `victory-shader`; `victory-shader --lib` single-threaded: 69). `victory translate <title exe> --validate --pipelines` gives the same counts before and after: 12 of 12 programs emitted, 12 validated, 12 pipelines. Checked against the GFX10 ISA: - `s_absdiff_i32`: `|a − b|` of the wrapping difference, with SCC = result ≠ 0. - `s_sext_i32_i8/i16`: shift left, then arithmetic shift right. - `s_pack_ll` gives `{b.lo, a.lo}`, `s_pack_lh` gives `{b.hi, a.lo}`, and `s_pack_hh` gives `{b.hi, a.hi}`, written high:low. SCC is only written where the decoder says the instruction writes it (`inst.write(Reg::Scc)`), so sext and pack correctly leave SCC alone. No issues found. AI-assisted (Claude Code).
alexdeliu commented 2026-11-24 18:05:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by alexdeliu on 2026-11-24T17:22:44Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139103980 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/120#issuecomment-7139103980). Originally posted by [alexdeliu](https://github.com/alexdeliu) on 2026-11-24T17:22:44Z. --- 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>
Marvisak commented 2026-11-25 01:07:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:25:14Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148490745 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/120#issuecomment-7148490745). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:25:14Z. --- <!-- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/120:upstream-pr/120'
git switch 'upstream-pr/120'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/120'
git switch 'upstream-pr/120'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/120'
git switch 'upstream-pr/120'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/120'
git switch 'main'
git merge --squash 'upstream-pr/120'
git switch 'main'
git merge --ff-only 'upstream-pr/120'
git switch 'main'
git merge 'upstream-pr/120'
git push origin 'main'
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
Marvisak/VIctory!120
No description provided.