Shaders: v_mad_i64_i32 sign-extends a 32-bit literal addend #2254
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2254
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2254"
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?
@BastienRodz on GitHub · 2026-11-25 08:59 UTC · original
BastienRodz:shader/mad-i64-i32-literal→main· +36 −1 · 2 files · 1 commits · openWhat'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
@Dathinel on GitHub · 2026-11-25 09:06 UTC · original
Integration check with #171:
5a8a792andd1d21f9merged 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
5a8a792alone, 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.@kotekompotek on GitHub · 2026-11-25 09:20 UTC · original
Verified on real hardware:
mad_i64_i32_sign_extends_literal_addendpasses on a GTX 1050 running SM 6.6 through the Agility SDK (the machine's in-box runtime stops at 6.5). Both arms behave as coded —v_mad_i64_i32sign-extends the literal addend (high dword0xFFFFFFFFfor-100),v_mad_u64_u32zero-extends it. Matches RDNA2 ISA §6.2.1.@Calvix2k on GitHub · 2026-11-25 09:40 UTC · original
Same fix as #2261 (which I closed in favour of this one after seeing it):
src64's sign-extending arm matchingv_mad_i64_i32. No objection to the change.If useful, my branch
codex/shader-mad-i64-literal-2253has two extra checks that can be lifted: the emitted DXIL forv_mad_i64_i32with a literal addend readsadd i64 %24, -100(visible without a GPU), and a GPU case that reads the high dword of0 * 0 + -100(all ones) and10 * 10 + -100(0) withv_mad_u64_u32as the zero-extending control. Your test plus the two hardware runs already cover the behaviour, so this is only if you want the DXIL half.@BastienRodz on GitHub · 2026-11-25 09:40 UTC · original
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.
@BastienRodz on GitHub · 2026-11-25 09:44 UTC · original
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
dump_dxiltemp-file fix is unrelated to this one and could go in on its own.@sinan-cmyk on GitHub · 2026-11-25 10:33 UTC · original
Offline measurement on a retail dump
Result: no count change against
main.I merged head
5a8a7929ontomain940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 23,918 with this PR.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).
@Marvisak on GitHub · 2026-11-25 12:44 UTC · original
Automated triage for the maintainers.
Merge candidate. In
crates/victory-shader/src/emit/lower.rs, thesrc64arm that sign-extends a 32-bit literal for signed 64-bit operands now also matchesv_mad_i64_i32, whosesrc2is a signed 64-bit addend. That is the same rule the existing arm cites (LLVM's AMDGPU operand rules).v_mad_u64_u32keeps zero extension.The new test
mad_i64_i32_sign_extends_literal_addendchecks the high dword of results on the GPU, with the unsigned form as a control. A GTX 1050 run in the thread passes. Dathinel's control shows the fix also matters for the carry when combined with #171. CIcheckpasses, the offline count is unchanged, and the branch merges cleanly. #2261 (the same fix) was already closed in favour of this one.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.