Repository navigation
Shaders: v_mad_i64_i32 sign-extends a 32-bit literal addend - #2254
BastienRodz wants to merge 1 commit into
Conversation
src64 sign-extends a literal for operations named *_i64 (Marvisak#447), but v_mad_i64_i32's addend is S2.i64 too, and its name ends in _i32, so a negative literal there was zero-extended: 0 * 0 + -100 gave 0xffffff9c with a high dword of 0. RDNA 2 ISA 6.2.1: a 64-bit signed integer source sign-extends its literal. v_mad_u64_u32 keeps zero-extending. Co-Authored-By: Gemini 4 Neon <noreply@google.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DenRakEiw
left a comment
There was a problem hiding this comment.
Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, with dxil.dll validator):
cargo test -p victory-shader --lib mad_i64_i32_sign_extends_literal_addend— passed on both RTX 5090 hardware andVICTORY_D3D12_WARP=1cargo clippy -p victory-shader --all-targets— 0 warningscargo xtask policy— ok (183 files ok)
Clean fix sign-extending 32-bit literal addends in v_mad_i64_i32, verified end-to-end on hardware and WARP. Looks good.
AI-assisted (Gemini 4 Neon).
|
Integration check with #171: 5a8a792 and d1d21f9 merged cleanly. I tested a synthetic v_mad_i64_i32 with a literal -100, then used v_cndmask_b32 to read the MAD's scalar carry mask. For 0 × 0 − 100 and 10 × 10 − 100, bit 64 of the exact signed result is 1 and 0 respectively. The combined tree returned those values on both Windows hardware and WARP. Both PRs' existing MAD regression tests also passed on that tree. The controls distinguish the two fixes. At 5a8a792 alone, the high-dword regression passes but the new probe stops before dispatch with “a lane mask from a carry”. On the combined tree with only this PR's literal-extension predicate removed, the probe dispatches but returns 0 instead of 1 for the first case. The two changes cover complementary behavior when a shader consumes the carry. AI-assisted, synthetic inputs only. |
|
Verified on real hardware: |
|
Same fix as #2261 (which I closed in favour of this one after seeing it): If useful, my branch |
|
Thanks for closing #2261 in favour of this one. I'll leave the test as it is, since the GPU case and the hardware runs here cover it, but the DXIL check on your branch is a good pointer if the maintainer wants a GPU-free check too. |
catminou4
left a comment
There was a problem hiding this comment.
Tested locally: merged into main 940d32f, cargo test -p victory-shader --locked on macOS arm64 — 144 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here).
Note: this is the same one-line v_mad_i64_i32 literal sign-extension fix as #2261 (which additionally fixes a dump_dxil temp-file race between parallel tests and cites the RDNA2 ISA rule). Both pass locally; whichever merges second will conflict on the same lower.rs lines — suggest keeping one (I'd take #2261 for the test-infra fix).
|
For the record, #2261 is already closed: Calvix2k closed it in favour of this PR (see the comment above), so there's no second change to conflict with. Its |
Offline measurement on a retail dumpResult: no count change against I merged head 5a8a792 onto No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right. No shader names or data are included, per the asset policy. AI-assisted (Claude Code). |
|
Automated triage for the maintainers. Merge candidate. In The new test Generated by Claude Code |
What's wrong
Lower::src64sign-extends a 32-bit literal for operations named*_i64(#447).v_mad_i64_i32adds a signed 64-bitS2but its name ends in_i32, so a literal addend was zero-extended:0 * 0 + -100gave0x00000000_ffffff9c. RDNA 2 ISA §6.2.1 says a 32-bit literal used as a 64-bit signed integer is "sign extended to 64 bits", and §12.12 definesV_MAD_I64_I32asS0.i32 * S1.i32 + S2.i64.What the fix does
The sign-extending arm in
src64also matchesv_mad_i64_i32.v_mad_u64_u32and the other unsigned and bitwise 64-bit operands keep zero-extending.Tests
New
emit::valu_tests::mad_i64_i32_sign_extends_literal_addend(next tosigned_64_bit_operands_sign_extend_their_literal): the high dword ofv_mad_i64_i32with a-100literal addend for0 * 0,10 * 10and-100000 * 100000, and ofv_mad_u64_u32with the same literal (zero-extended) for0 * 0and10 * 10.main(940d32f) it fails:hardware: v_mad_i64_i32 [0, 0, 0, 0],left: 0,right: 4294967295.signed_64_bit_operands_sign_extend_their_literalpass (Wine 10, vkd3d-proton 3.1 on llvmpipe).Not tested
Not run on an AMD/NVIDIA GPU or through
dxil.dllhere. Whether title shaders usev_mad_i64_i32with a literal addend is not measured. #171 also touchesv_mad_i64_i32(carry and clamp), not its literal; whichever lands second rebases trivially.Fixes #2253
AI-assisted (Gemini 4 Neon found and wrote it, Claude Code reviewed and verified it). No game data used.
🤖 Generated with Claude Code