Shaders: lower v_add_nc_i32, v_sub_nc_i32, v_mul_lo_i32 and the signed 16-bit add and sub #92
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/92"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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_i16andv_sub_nc_i16. They were decoded but refused inemit/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_u32andv_mul_lo_u32. The 16-bit forms go through the existing 16-bit integer path, which already sign-extends_i16operands 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).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 existingconstant_colordead-code warning on non-Windows is untouched).rustfmt --check --edition 2024onlower.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.
Imported from Marvisak/VIctory. Originally posted by DaviTostes on 2026-11-24T00:24:51Z.
Tested
4f2d5dbstacked 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.#[test]s this PR adds for the integer add/sub/mul lowerings are included in that run.AI-assisted (DeepSeek V4.1 Flash coding agent).
Imported from Marvisak/VIctory. Originally posted by lordon1a on 2026-11-24T00:40:13Z.
Verified
4f2d5dbd8on Windows 11 (x86_64-pc-windows-gnullvm,rustc 1.100.0, applied cleanly tomain@35b054ec0): pass.cargo xtask policy: 150 files okcargo test -p victory-shader: 60 passed, 0 failed (+3 new lowering tests forv_add_nc_i32/v_sub_nc_i32/v_mul_lo_i32/16-bit add & sub).AI-assisted.
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 to0xdead0000.v_add_nc_i32,v_sub_nc_i32: wrapping low 32 bitsv_add_nc_i16,v_sub_nc_i16: wrapping low 16 bits, high half kept (0xdead)clamp(which this PR refuses): signed saturation, 32- and 16-bitv_mul_lo_i32: AMD's own assembler (the driver's amd_comgr) rejectsv_mul_lo_i32for gfx1036 ("instruction not supported on this GPU"). The raw VOP3 opcode0x16bthat our table (from Mesa's GFX10 column) namesv_mul_lo_i32writes 0 on this hardware for all 400 pairs:0xd56b000c 0x00020b04withv12 = 0xdeadbeefbeforehand leavesv12 = 0. So on RDNA2 desktop parts the opcode is not a multiply. The console may differ, but lowering it asv_mul_lo_u32means 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.
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
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.