shader: lower v_mad_u32_u16, v_mad_i32_i16, v_mad_u16 and v_mad_i16 #73
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/73"
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 uiliannn/VItoriaBr. Originally posted by lcg007xd-c on 2026-11-25T21:41:23Z.
What is broken
The 16-bit multiply-adds decode but do not translate:
v_mad_u32_u16v_mad_i32_i16v_mad_u16v_mad_i16A program using one fails with
v_mad_u32_u16 is not supported(and likewise for the others). I found them by translating a one-instruction program for every VOP3 opcode the decoder names. The 24-bit forms (v_mad_u32_u24,v_mad_i32_i24) already lower.Semantics (AMD's RDNA2 ISA, §12.12, opcodes 832, 862, 883, 885)
v_mad_u32_u16:D.u32 = S0.u16 * S1.u16 + S2.u32.v_mad_i32_i16is the same with signed 16-bit factors and a 32-bit sum.op_selpicks which half of src0 and src1 is read.v_mad_u16:D.u16 = S0.u16 * S1.u16 + S2.u16, which "supports saturation (… 16-bit integer domain)".v_mad_i16is the same with signed values. The 16-bit result goes to the halfop_sel[3]selects, and the other half is kept.The change (
emit/lower.rs)v_mad_u32_u16/v_mad_i32_i16(ininteger, beside the 24-bit forms): the two halves come fromhalf_src, which honoursop_sel, and are sign-extended for the signed form. The sum wraps. Clamp is still refused here, as for the other 32-bit integer operations.v_mad_u16/v_mad_i16(invalu16_op): three halves, sign-extended for_i16. The exact sum fits in 32 bits: at most0xFFFE0001 + 0xFFFFunsigned, and within ±2³⁰ + 2¹⁵ signed. So clamp compares the exact value with the 16-bit limits. Thenwrite_halfwrites it.Tests
emit::lower::tests::sixteen_bit_multiply_adds_translate(every host): each encoding decodes to its name, and a program that stores the result translates. The 16-bit-result forms are also tried with clamp. Without thelower.rschange it fails:v_mad_u32_u16 clamp 0: GFX10 code at 0x24: v_mad_u32_u16 is not supported.valu_tests::sixteen_bit_multiply_adds_match_rdna2(Windows/GPU): two hand-computed cases per opcode, the 16-bit-result ones with and without clamp. They cover0xFFFF * 0xFFFF, a wrapping 32-bit sum, −1 × −32768, and saturation at both 16-bit ends. Every source has junk in the high half it must not read.lli. I added threeop_selcases: high halves of src0/src1 for both 32-bit forms, andv_mad_i16reading src2's high half and writing v0's high half with clamp. I also checked clampedv_mad_i16/v_mad_u16against a Rust reference on a 9 × 11 grid. All match.Run here (Linux, Rust 1.98.1):
cargo test -p victory-shader --lib --locked: 188 passed, 0 failed, 2 ignored.CARGO_FEATURE_PURE=1 cargo clippy -p victory-shader --all-targets --target x86_64-pc-windows-msvc -- -D warnings: clean.Not run here: the GPU case, since I have no Windows machine. The test and the GPU case sit at different places in their files from those of #65 and #71, so the three merge in any order.
🤖 Generated with Claude Code
Imported from uiliannn/VItoriaBr. Originally posted by lmouz823-lang on 2026-11-28T02:32:53Z.
I can take Windows GPU validation at exact head
fe7f00f0f5618bb3e900558d5ef872480be75e6f. I will run the exact translation and multiply-add GPU tests on RTX 4060 Laptop and WARP with the SDK DXIL validator, then add a small fixed-expectation regression for op_sel high-half source selection, destination-half selection and preservation of a nonzero unwritten half. I will include a temporary negative control, restore the implementation and report actual execution and any test-only patch here. AI-assisted with Codex.Imported from uiliannn/VItoriaBr. Originally posted by lmouz823-lang on 2026-11-28T04:04:32Z.
Native Windows validation completed for exact head
fe7f00f0f5618bb3e900558d5ef872480be75e6fon RTX 4060 Laptop and WARP.The original translation and GPU tests each execute exactly one test and pass. The original GPU cases perform 12 dispatches per backend. I added one GPU regression with 18 fixed expectation rows, covering 30 opcode/modifier configurations and 30 dispatches per backend, 60 total. It also passes on both backends with
VICTORY_STRICT_TESTS=1and no skips. Each targeted invocation reports zero ignored tests. Coverage is limited to these exact shader tests and the listed checks.The addition checks source-half selectors individually, both source high halves for the 32-bit forms, src2's high half for the 16-bit forms, both destination halves, and signed/unsigned 16-bit saturation. The 32-bit forms keep their full-width src2. An explicit
v_mov_b32 v0, v4seeds the destination with0xA5A55A5A, and fixed full-dword expectations verify the unselected half survives. Expectations follow AMD's RDNA2 ISA, section 12.12.A negative control temporarily discards the old destination value in
write_half. The original GPU test still passes, while the new test fails on hardware at its firstv_mad_u16case with0x00000011instead of0xA5A50011. After restoring the implementation and removing diagnostics, verified fresh compilation and final runs of both GPU tests and the original translation test all pass. A failed restoration attempt is archived separately and excluded from these final results.The explicit SDK
dxil.dll1.8.2502.11 createdIDxcValidator. Temporary diagnostics after the validation/hash assertions confirmed all 30 new shader modules and all six original modules reached that success point. The diagnostics are absent from the patch. Independent review checked the fixed values, instruction encodings, sentinel wiring, counts and final source restoration.Environment was Windows 11 Pro build 26200, i9-14900HX, NVIDIA 610.88, Rust 1.98.1 MSVC, release. Package Clippy with
--all-targets -- -D warnings, the asset policy (195 files),git diff --check, and rustfmt on the added function pass. The final diff adds only this test function, 147 lines. Native RDNA2 execution, game performance and the full workspace suite remain unverified.Reproduction uses these exact filters with the usual Windows GPU build prerequisites and an installed SDK validator.
AI assistance from Codex covered the test, execution, independent review and this report.
Test-only patch against this PR head
Pull request closed