fix(recompiler): zero the high half of 16-bit SDWA results written as a whole dword #214
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/214"
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-01T12:08:34Z.
What
An SDWA instruction with
dst_sel:DWORD dst_unused:UNUSED_PADwrites its 16-bit result zero-extended to the whole destination register.TranslationContext::write16BitstreatedsdwaSel6 (DWORD) like the plain VOP encoding of a 16-bit instruction, which on GFX10 keeps the destination's high half, so the SDWA form kept stale high bits instead of zeroing them. The decoder already marks SDWA destinations withexplicitSdwaDst;write16Bitsnow sends those throughwriteRawU32(zero-padded). Plain 16-bit encodings anddst_sel:WORD_0/WORD_1withUNUSED_PRESERVEare unchanged.A common idiom packs two halves this way:
v_cvt_f16_f32_sdwa lo ... dst_sel:DWORD dst_unused:UNUSED_PAD, the same forhi, thenv_lshl_add_u32 dst, hi, 16, lo. With stale bits left inlo, the integer add carries them into the high half.In PPSA21564 the FidelityFX depth of field combine pass packs its RG and BA outputs exactly like that, so G and A of the composited scene picked up garbage: a green haze with values up to about 1500 and black tile-shaped blocks over the intro cinematic's crowd and space shots. About 33 other shaders in the title use the same form (GPU skinning computes and a particle shader).
Before (left), with this fix (middle) and the real PS5 (right), in the crowd and space shots:
Tested
agc_driver_sdwa_destination_testsruns guest code on the GPU and checksv_cvt_f16_f32_sdwawith DWORD/UNUSED_PAD zeroing the high half, the plainv_cvt_f16_f32_e32keeping it,WORD_1with UNUSED_PRESERVE keeping the low half, the pad, pad,v_lshl_add_u32packing idiom, andv_add_f16_sdwawith DWORD/UNUSED_PAD. On main it fails with "thread 0 result 0 is 0xabcdbf00, expected 0x0000bf00"; with the fix it passes. Likeagc_driver_mix_precision_testsit needs a Vulkan device, so it is built but not part of ctest.ctest --test-dir build: 89/89 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