shader: lower v_min3/v_max3/v_med3 on 16-bit integers #65
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/65"
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:32:38Z.
What is broken
VOP3 0x352–0x359 decode, but none of them translates:
v_min3_i16v_min3_u16v_max3_i16v_max3_u16v_med3_i16v_med3_u16A program using any of them fails with
v_min3_i16 is not supported(and likewise for the others). I found these by translating a one-instruction program for every VOP3 opcode the decoder names. The 32-bit integer and f16 forms already lower; only the 16-bit integer forms were missing.The change (
emit/lower.rs, invalu16_opbeside the other 16-bit integer operations)It follows AMD's RDNA2 ISA (§12.12, opcodes 850–857):
op_selpicks. For_i16they are sign-extended.min3/max3: two min/max steps.med3: the middle value, computed asmax(min(a, b), min(max(a, b), c)). The ISA's form (find the max of the three, then take the max of the other two) gives the same value for integers.op_sel[3]. The other half is kept, as for every 16-bit VOP3 result on GFX10 (write_half).Tests
emit::lower::tests::int16_min3_max3_med3_translate(every host): each encoding decodes to its name, and a program that stores the result translates. The store keeps the instruction from being dropped as dead code. Without thelower.rschange it fails atv_min3_i16.valu_tests::v_min3_max3_med3_16bit_integer_forms_match_rdna2(Windows/GPU): three hand-computed cases per opcode. They include0x8000as both −32768 and 32768,0xFFFFas −1 and 65535, and a tie. The inputs' high halves are non-zero so a lowering that reads them would fail.opt+llirunning the emitted DXIL), plus oneop_selcase (src0 and src2 from the high halves, result to the high half). 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.
🤖 Generated with Claude Code
Pull request closed