fix(recompiler): select v_fma_mix source precision by OP_SEL_HI and the half by OP_SEL #205
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/205"
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 oneandonlydean on 2026-10-01T03:24:00Z.
What
v_fma_mix_f32andv_fma_mixlo_f16/v_fma_mixhi_f16take each source as an f32 or as one half of a packed f16 register. Per source,OP_SEL_HIset means the source is f16 andOP_SELthen picks its low or high half;OP_SEL_HIclear means the source is an f32 (the encoding LLVM uses for these instructions).TranslationContext::readMixF32had the two bits swapped: it usedopSelas the f16 switch andopSelHias the half. So a low-half f16 source (op_sel_hiset,op_selclear) was read as the whole register's 32 bits as an f32, a tiny or garbage value, while a high-half source happened to come out right. The fix swaps them;v_dot2cand the cube ops that also go throughreadMixF32never setop_selon their operands and are unaffected.In PPSA21564 the material shaders lerp packed f16 colours with exactly these instructions (e.g.
v_fma_mix_f32 v10, 1.0, v11, -v8 op_sel_hi:[0,1,1]for the low half, the same withop_sel:[0,1,1]for the high half). Red and blue live in the low halves and collapsed to near zero in the G-buffer albedo (a grey moon came out as(12, 180, 12)), while green and alpha survived, so every lit surface had a green cast and red details went black. With the fix the albedo reads(178, 178, 178).Before (left), with this fix (middle) and the real PS5 (right):
Tested
agc_driver_mix_precision_testsrecompiles hand-assembled mix instructions and runs them on the GPU against a model of the guest instructions: low and high f16 halves, the 1.0 inline constant with negation, mixed f32 and f16 sources, the abs modifier,mixlo/mixhikeeping the other half, andop_selset on an f32 source. On main it fails with "thread 0 result 0 is -0.007825, expected 3.250000"; with the fix it passes. Like the other GPU tests (agc_driver_recorder_tests,agc_driver_mesh_tests) it is built but not part of ctest, since it needs a Vulkan device.ctest --test-dir build: 79/79 pass on current main with this branch.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