fix(shader): compute v_cvt_pknorm_*_f32, v_ldexp_f32 and v_pack_b32_f16 on the bits #596
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/596"
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-05T01:29:23Z.
What
Found by running decoded-but-never-executed VOP3 ops against the hardware.
v_pack_b32_f16: neg/abs were applied to bit 31 of the source dword, not to the selected half. On the low half they were ignored (fails on RADV and lavapipe). The halves are now read withreadF16Bits, as the other f16 ops do.v_cvt_pknorm_i16_f32/v_cvt_pknorm_u16_f32used GLSLPackSnorm2x16/PackUnorm2x16. The spec leaves the rounding to the driver (round()), and NaN is undefined there. Lavapipe gives0x8001for NaN and rounds some ties the other way. Now done on the bits bynormF32, the f32 version ofnormF16: exactmantissa * scalein 64 bits, round to nearest even, NaN to 0, saturate at |x| >= 1.v_ldexp_f32used GLSLLdexp, whose NaN payload and denormal results are up to the driver. Lavapipe quiets sNaN and drops the sign of-|NaN|. Now the exponent field is rewritten on the bits.FPLdexp,PackSnorm2x16andPackUnorm2x16had no other users, so this PR removes them from the IR and the SPIR-V backend.Behaviour measured on HW
Measured on an RDNA2 GPU (gfx1035) with 4096 rows, in the mode the recompiler assumes (IEEE=0, f32 denormals flushed). The Python model matches all 4096 rows:
0x8001). The rest isx * 32767orx * 65535rounded once to nearest even. The product is not rounded to f32 first: 376 of the rows differ if it is.With IEEE=1 and denormals on, the HW quiets sNaN and returns denormal ldexp results. That mode isn't modelled, same as for the other f32 ops.
Tested
New
agc_driver_vop3_pack_ldexp(tests/execution/Vop3PackLdexp.cpp). It runs 32 lanes with the expected values from the HW. The rows cover NaN/sNaN, ±0, denormals, inf, ±1 boundaries, exact rounding ties for both scales, and ldexp exponents reaching 255 and 0. It also runsv_lerp_u8andv_mul_lo_i32, which no test executed. Both were already correct. gfx1035 has nov_mul_lo_i32, so its expected values are the low 32 bits of the product.mainthe test fails: on RADV forv_pack_b32_f16with neg/abs (lane 0 pack_b32_f169 is 0x0001d40f, expected 0x0001540f), and on lavapipe also for pknorm and ldexp NaN rows. Each piece (pack modifiers, norm sticky bit, tie rule, NaN, ldexp overflow, underflow, NaN, denormal input and exponent clamp) was mutated, and each mutation makes the test fail.agc_driver_global_load_addtid,agc_driver_pixel_helper_lanesandagc_driver_vop3_carry_out. Those fail on local RADV onmaintoo (wave32 on RADV's 64-wide subgroup).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 adriadam10 on 2026-10-05T01:43:05Z.
Rebased on current main (
ebf29f8d): conflict was only the adjacentvFmaLegacyF32declaration from #595 inTranslationContext.hpp, both kept. Commit content otherwise unchanged;agc_driver_vop3_pack_ldexp_testsand the full ctest pass again (RADV + lavapipe).Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T02:47:22Z.
Thanks, this checks out. I disassembled the test kernel with
llvm-mc -mcpu=gfx1013and every word is what the comments say: both pknorm forms (with-v4, |v5|and-|v4|, -v5),v_ldexp_f32with-|v4|,v_pack_b32_f16with neg/abs and both op_sel cases,v_lerp_u8andv_mul_lo_i32.normF32keeps the wholemantissa * scaleproduct in 64 bits with one guard bit and a sticky bit, so the rounding is a single round to nearest even, and NaN, saturation, the snorm0x8001minimum and the flushed denormals all come out as you measured.vLdexpF32rewrites the exponent field with the offset clamped to 512 either way, which covers every exponent, keeps NaN and inf unchanged, and still goes through the F32 result path, so clamp and omod behave as before.readU32still applies abs and neg on bit 31, so the pknorm and ldexp source modifiers keep working. Thev_pack_b32_f16fix is a real bug: main applied neg and abs to bit 31 of the dword, so on the low half they were lost. Nothing else on main or in the other open PRs usesFPLdexp,PackSnorm2x16orPackUnorm2x16, so removing them is fine, and the branch merges cleanly with your other open shader PRs.One note for the merge order rather than the code: PPSA21564 uses
v_cvt_pknorm_i16_f32andv_cvt_pknorm_u16_f32a lot (891 of the 5,688 shaders I have dumped, all without modifiers). For ordinary inputs only exact ties and NaN change, but since it touches so many shaders I'll run it through my visual check of PPSA21564 before it goes in.v_ldexp_f32andv_pack_b32_f16don't appear there at all.Ready to merge from my side once that run is done.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T05:04:09Z.
Gated on PPSA21564: no visual or FPS change.