fix(shader): VOP3 op_sel on v_alignbit/alignbyte_b32 and 16-bit max3/min3/med3 #504
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/504"
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 boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T10:42:01Z.
What
op_selon the VOP3 forms ofv_alignbit_b32,v_alignbyte_b32,v_max3_i16,v_max3_u16,v_min3_i16,v_min3_u16andv_med3_u16threwVOP3 source modifiers are not implemented. It is now decoded:v_max3/min3_{i16,u16},v_med3_u16: the same selectorsv_med3_i16already uses (op_sel[0..2]take the high half of each source,op_sel[3]writes the high half of the destination and keeps the low half).v_alignbit_b32,v_alignbyte_b32:op_sel[1:0]choose the byte of src2 that holds the shift,op_sel[2]has no effect, andop_sel[3]writes the low 16 bits of the result into the high half and zeroes the low half. This is not in the RDNA2 ISA doc, so it comes from the hardware (below). It reuses the SDWA byte selector on src2 andWORD_1+UNUSED_PADon the destination.Also fixed in
v_alignbyte_b32: the shift came fromsrc2 & 31and gave 0 orsrc0for values >= 4. The RDNA2 ISA says({S0, S1} >> (8 * S2.u[1:0])), and the hardware agrees.clamp,absandnegon these ops still throw. Integer clamp is a separate batch.Behaviour measured on HW (RDNA2, gfx1035)
op_selvalues on each of the 8 ops (includingv_med3_i16), 512 random rows, prior destination value seeded: 65536 of 65536 results match the model above.v_alignbit_b32with src2 =0x05060708:op_sel0/1/2/3 shift by 8/7/6/5;op_sel[2]alone gives the same result as 0;op_sel[3]→0xfeba0000.v_alignbyte_b32with src2 =0x1d0b1704:op_sel0/1/2/3 shift by 0/3/3/1 bytes (byte & 3).Tested
Two new execution tests, with 32 rows each and expected values from the hardware (the Python model matches every cell):
agc_driver_vop3_align_op_sel_tests: alignbit/alignbyte with 8op_selvalues each. Rows are picked so each selected byte covers shift 0, < 16, >= 16 and >= 32 (alignbit), and everybyte & 3with the byte < 4 and >= 4 (alignbyte).agc_driver_vop3_integer16_ternary_op_sel_tests: 16 max3/min3/med3 i16/u16 variants with mixedop_sel. Rows cover each source winning, ties and negative halves.Both pass on RADV and lavapipe. The tests fail without the fix: the old
src2 & 31on alignbyte, dropping the src2 byte select, selecting by half instead of by byte, keeping the low half onop_sel[3], dropping the destination select, and ignoring source/destinationop_selon the 16-bit ops all fail.clampstill throws (decoder probe). The full Release ctest passes exceptagc_driver_pixel_helper_lanes, which also fails onmainon local RADV.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T21:07:58Z.
Thanks. I checked this against the RDNA2 ISA (
V_ALIGNBYTE_B32shifts by8 * S2.u[1:0], so main'ssrc2 & 31was wrong) and LLVM's VOP3Instructions.td. LLVM definesV_ALIGNBIT_B32_opsel/V_ALIGNBYTE_B32_opselfor gfx10 with the note "Hardware uses opsel[1:0] to byte-select src2", which matches your capture, and llvm-mc for gfx1013 accepts every op_sel form in the test. The 16-bit max3/min3/med3 path is the same one med3_i16 already used, and I reproduced all 512 expected cells of the align test from your model.One small question: the same LLVM comment says "Other opsel bits are ignored", while your capture has
op_sel[3]moving the low half into the high half and zeroing the low half. I'm fine going with the hardware, since no compiler emits that bit here. Could you confirm that theop_sel[3]rows came straight from the gfx1035 capture and weren't modelled?The alignbyte change touches a path existing shaders already use, so I'll run it through my PPSA21564 check before merging. Otherwise it's ready to merge from my side.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T21:08:40Z.
Yes, they came straight from the gfx1035 capture. The generator stores the oracle output as
Expectedand only asserts that the model matches it, so the model never fills a cell. The test has three alignbit and three alignbyte forms withop_sel[3]set (op_sel8, 9 and 15). In the full sweep (all 16op_selvalues, 512 rows) every one of the 8op_sel[3]forms per op gave the same result: the low 16 bits of the shifted value moved to the high half and the low half zeroed, whatever the destination held before. So on this hardware the bit is not ignored for these two ops, even though LLVM never sets it.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T22:38:11Z.
Thanks for confirming. Since the generator only checks the model against the captured
Expectedvalues, theop_sel[3]rows are hardware results, and it's good to know the bit is honoured on these two ops even though LLVM never sets it.agc_driver_vop3_align_op_selandagc_driver_vop3_integer16_ternary_op_selstill pass on my NVIDIA machine on current main, and fail on main's code.I'll run it through my PPSA21564 check next and merge it after that if it's clean.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T08:31:17Z.
Gated on PPSA21564: no visual or FPS change.