Shaders: lower v_mad_i64_i32; signed 64-bit operands sign-extend a literal #85
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/85"
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 Zettrox/ztrx. Originally posted by Ingenioeren on 2026-11-25T09:25:17Z.
What
v_mad_i64_i32is lowered. It was refused (Unsupported { what: "v_mad_i64_i32" }). It now sharesv_mad_u64_u32's lowering, with its factors sign-extended. Its carry-out mask is left missing, because the unsigned sum's carry is not the signed instruction's.Lower::src64zero-extended every literal. Per the RDNA 2 ISA, §6.2.1 "Literal Expansion to 64 bits" ("64-bit signed integer: sign extended to 64 bits"), that is wrong forv_ashrrev_i64's source,v_cmp_*_i64andv_mad_i64_i32'sS2.i64addend.v_mad_u64_u32and the*_u64compares still zero-extend.Why
Upstream VIctory lowers
v_mad_i64_i32and has the same literal rule (#447 there, plus thev_mad_i64_i32addend case being fixed in Marvisak/VIctory#2253). ztrx's history diverged before those changes, so it still refuses the instruction and gets the sign wrong. For example,v_ashrrev_i64 v[5:6], 4, -100currently produces a high dword of 0 instead of0xffffffff.How tested
I added a new synthetic test,
emit::valu_tests::signed_64_bit_operands_sign_extend_their_literal, which builds GFX10 code in the test and uses no game shaders. It covers:v_mad_i64_i32: low and high dwords with register operands (signed factors and0x80000000²);v_mad_i64_i32/v_mad_u64_u32with a literal-100addend;v_ashrrev_i64with a literal;v_cmp_eq_i64/v_cmp_lt_i64with a literal.cargo test --locked --offline -p victory-shader --lib signed_64_bit_operands:lower: Unsupported { offset: 40, what: "v_mad_i64_i32" };v_mad_i64_i32 -100 hi [0, 0, 0, 0] = 0x0, want 0xffffffff;v_mad_i64_i32in the literal rule: fails withv_ashrrev_i64 hi ... = 0x0, want 0xffffffff;cargo test --locked --offline -p victory-shader: 209 passed, 2 failed. The two failures (emit::rect::tests::the_rectangle_stage_is_a_geometry_shaderandrectangles_are_drawn_whole, "Container part 'Pipeline State Validation' does not match") also fail onmainon this PC with its localdxil.dll, so they are unrelated.cargo clippy --locked --offline -p victory-shader --all-targets: no warnings.cargo run -p xtask -- policy --staged:asset policy: 2 files ok.Not tested: the test hardware was an AMD RX 6750 XT plus WARP, not an NVIDIA card. This is a code-level translation fix, so it should not depend on the vendor, but there was no NVIDIA run and no game run.
AI assistance: prepared with Claude Code, reviewed by Ingenioeren.
🤖 Generated with 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.