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

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

@⁠tedin7 on GitHub · 2026-11-24 00:23 UTC · original
tedin7:vic-vop-nc-i32 → main · +115 −7 · 1 files · 1 commits · open

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.

**@⁠tedin7** on GitHub · 2026-11-24 00:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/92) `tedin7:vic-vop-nc-i32` → `main` · +115 −7 · 1 files · 1 commits · open ## 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.
These were decoded but refused. The low bits of a sum, difference or product do not depend on the sign, so they lower as their unsigned twins; the 16-bit forms use the existing 16-bit path, which already sign-extends _i16 operands. Clamp, abs and neg are still refused.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:49:56 +00:00
Author
Owner

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

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).

**@⁠DaviTostes** on GitHub · 2026-11-24 00:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/92#issuecomment-7118042688) 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).
Author
Owner

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

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.

**@⁠lordon1a** on GitHub · 2026-11-24 00:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/92#issuecomment-7118309506) 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.
Author
Owner

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

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.

**@⁠Lyrnc** on GitHub · 2026-11-24 06:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/92#issuecomment-7123869015) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:16 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 00:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/92#issuecomment-7148342941) <!-- 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 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/92/head:github-bot/gh-92'
git switch 'github-bot/gh-92'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-92'
git switch 'github-bot/gh-92'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-92'
git switch 'github-bot/gh-92'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-92'
git switch 'main'
git merge --squash 'github-bot/gh-92'
git switch 'main'
git merge --ff-only 'github-bot/gh-92'
git switch 'main'
git merge 'github-bot/gh-92'
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!92
No description provided.