Shaders: lower v_add_nc_i32, v_sub_nc_i32, v_mul_lo_i32 and the signed 16-bit add and sub #92

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

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


What

Lowers v_add_nc_i32, v_sub_nc_i32, v_mul_lo_i32, v_add_nc_i16 and v_sub_nc_i16. They were decoded but refused in emit/lower.rs ("unsupported"), so any shader using one fell back instead of translating.

Why

The low 32 bits of a sum, difference or product do not depend on the sign, so the 32-bit forms lower exactly as v_add_nc_u32, v_sub_nc_u32 and v_mul_lo_u32. The 16-bit forms go through the existing 16-bit integer path, which already sign-extends _i16 operands and keeps the low half (including op_sel and the high-half destination). Clamp (which saturates), abs, neg and omod stay refused rather than miscompiled.

The diff is local: names added to four existing match arms and the 16-bit name list, plus tests.

Tested

Linux x86_64 only:

  • cargo test -j4 -p victory-shader: 54 passed, 0 failed (3 of them new).
  • Before the change the new tests fail (Unsupported { what: "v_add_nc_i32" }, "v_add_nc_i16"); after it they pass.
  • cargo clippy -j4 -p victory-shader --tests: no new warnings (the existing constant_color dead-code warning on non-Windows is untouched).
  • rustfmt --check --edition 2024 on lower.rs: clean.

The new tests build a synthetic pixel program in memory (no game data), lower it, and check that the signed 32-bit forms produce the same DXIL as their unsigned twins, that the 16-bit forms lower with op_sel variants, and that clamp is still refused.

Not run: the Windows runtime, a GPU, DXC validation of the emitted DXIL.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6571725184 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/92). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T00:23:43Z. --- ## What Lowers `v_add_nc_i32`, `v_sub_nc_i32`, `v_mul_lo_i32`, `v_add_nc_i16` and `v_sub_nc_i16`. They were decoded but refused in `emit/lower.rs` ("unsupported"), so any shader using one fell back instead of translating. ## Why The low 32 bits of a sum, difference or product do not depend on the sign, so the 32-bit forms lower exactly as `v_add_nc_u32`, `v_sub_nc_u32` and `v_mul_lo_u32`. The 16-bit forms go through the existing 16-bit integer path, which already sign-extends `_i16` operands and keeps the low half (including op_sel and the high-half destination). Clamp (which saturates), abs, neg and omod stay refused rather than miscompiled. The diff is local: names added to four existing match arms and the 16-bit name list, plus tests. ## Tested Linux x86_64 only: - `cargo test -j4 -p victory-shader`: 54 passed, 0 failed (3 of them new). - Before the change the new tests fail (`Unsupported { what: "v_add_nc_i32" }`, `"v_add_nc_i16"`); after it they pass. - `cargo clippy -j4 -p victory-shader --tests`: no new warnings (the existing `constant_color` dead-code warning on non-Windows is untouched). - `rustfmt --check --edition 2024` on `lower.rs`: clean. The new tests build a synthetic pixel program in memory (no game data), lower it, and check that the signed 32-bit forms produce the same DXIL as their unsigned twins, that the 16-bit forms lower with op_sel variants, and that clamp is still refused. Not run: the Windows runtime, a GPU, DXC validation of the emitted DXIL.
DaviTostes commented 2026-11-24 06:54:39 +00:00 (Migrated from github.com)

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


Tested 4f2d5db stacked on #39 on Arch Linux x86_64, rustc 1.98.1: pass.

  • cargo test --workspace: 158 passed, 0 failed, 3 ignored; merge with #39 clean.
  • The six #[test]s this PR adds for the integer add/sub/mul lowerings are included in that run.
  • No game data used.

AI-assisted (DeepSeek V4.1 Flash coding agent).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118042688 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/92#issuecomment-7118042688). Originally posted by [DaviTostes](https://github.com/DaviTostes) on 2026-11-24T00:24:51Z. --- Tested `4f2d5db` stacked on **#39** on **Arch Linux x86_64, rustc 1.98.1**: **pass**. - `cargo test --workspace`: **158 passed, 0 failed, 3 ignored**; merge with #39 clean. - The six `#[test]`s this PR adds for the integer add/sub/mul lowerings are included in that run. - No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
lordon1a commented 2026-11-24 06:54:41 +00:00 (Migrated from github.com)

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


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

  • cargo xtask policy: 150 files ok
  • cargo test -p victory-shader: 60 passed, 0 failed (+3 new lowering tests for v_add_nc_i32/v_sub_nc_i32/v_mul_lo_i32/16-bit add & sub).

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7118309506 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/92#issuecomment-7118309506). Originally posted by [lordon1a](https://github.com/lordon1a) on 2026-11-24T00:40:13Z. --- Verified `4f2d5dbd8` on Windows 11 (`x86_64-pc-windows-gnullvm`, `rustc 1.100.0`, applied cleanly to `main@35b054ec0`): **pass**. - `cargo xtask policy`: 150 files ok - `cargo test -p victory-shader`: **60 passed, 0 failed** (+3 new lowering tests for `v_add_nc_i32`/`v_sub_nc_i32`/`v_mul_lo_i32`/16-bit add & sub). AI-assisted.
Lyrnc commented 2026-11-24 06:56:20 +00:00 (Migrated from github.com)

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


RDNA2 hardware check: the add/sub forms match, with one note on v_mul_lo_i32.

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. 400 operand pairs (edge values 0, 1, 0x7fff, 0x8000, 0xffff, 0x7fffffff, 0x80000000, 0xffffffff, … in all pairs, plus 300 random). The 16-bit destinations were preset to 0xdead0000.

match
v_add_nc_i32, v_sub_nc_i32: wrapping low 32 bits 400/400 each
v_add_nc_i16, v_sub_nc_i16: wrapping low 16 bits, high half kept (0xdead) 400/400 each
for reference, with clamp (which this PR refuses): signed saturation, 32- and 16-bit 400/400 each

v_mul_lo_i32: AMD's own assembler (the driver's amd_comgr) rejects v_mul_lo_i32 for gfx1036 ("instruction not supported on this GPU"). The raw VOP3 opcode 0x16b that our table (from Mesa's GFX10 column) names v_mul_lo_i32 writes 0 on this hardware for all 400 pairs: 0xd56b000c 0x00020b04 with v12 = 0xdeadbeef beforehand leaves v12 = 0. So on RDNA2 desktop parts the opcode is not a multiply. The console may differ, but lowering it as v_mul_lo_u32 means translating an opcode that the RDNA2 tools don't emit. Refusing it until a title is seen using it may be safer.

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:7123869015 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/92#issuecomment-7123869015). Originally posted by [Lyrnc](https://github.com/Lyrnc) on 2026-11-24T06:22:36Z. --- RDNA2 hardware check: **the add/sub forms match**, with one note on `v_mul_lo_i32`. **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. 400 operand pairs (edge values `0, 1, 0x7fff, 0x8000, 0xffff, 0x7fffffff, 0x80000000, 0xffffffff`, … in all pairs, plus 300 random). The 16-bit destinations were preset to `0xdead0000`. | | match | |---|---| | `v_add_nc_i32`, `v_sub_nc_i32`: wrapping low 32 bits | 400/400 each | | `v_add_nc_i16`, `v_sub_nc_i16`: wrapping low 16 bits, high half kept (`0xdead`) | 400/400 each | | for reference, with `clamp` (which this PR refuses): signed saturation, 32- and 16-bit | 400/400 each | **`v_mul_lo_i32`:** AMD's own assembler (the driver's amd_comgr) rejects `v_mul_lo_i32` for gfx1036 ("instruction not supported on this GPU"). The raw VOP3 opcode `0x16b` that our table (from Mesa's GFX10 column) names `v_mul_lo_i32` writes **0** on this hardware for all 400 pairs: `0xd56b000c 0x00020b04` with `v12 = 0xdeadbeef` beforehand leaves `v12 = 0`. So on RDNA2 desktop parts the opcode is not a multiply. The console may differ, but lowering it as `v_mul_lo_u32` means translating an opcode that the RDNA2 tools don't emit. Refusing it until a title is seen using it may be safer. 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.
Marvisak commented 2026-11-25 01:07:37 +00:00 (Migrated from github.com)

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


Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-shader/src/emit/lower.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148342941 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/92#issuecomment-7148342941). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:16:48Z. --- <!-- victory-triage v1 head=4f2d5dbd8f1cf04414dd2d6c07671d34478bae0c verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-shader/src/emit/lower.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `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/92:upstream-pr/92'
git switch 'upstream-pr/92'

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