fix(shader): read low-half 16-bit multiply factors as 24-bit fields #7018
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7018"
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 thuanquang on 2026-10-17T05:53:29Z.
What
On AMD's Windows driver,
v_mul_lo_u16andv_pk_mul_lo_u16can store the full 32-bit product instead of its low 16 bits: into a register whose high half is zero,0xffff * 0xffffcame out as0xfffe0001where the GPU writes0x00000001.The recompiler extracts the 16-bit factors, multiplies them and masks the product with
0xffffbefore the 16-bit write. The SPIR-V it emits is correct: dumped from the recompile result, it hasOpIMulof the two extracted values followed byOpBitwiseAndwith0xffff. On driver 32.0.21045.5002 (RX 6700 XT) the stored value keeps all 32 bits when both factors are values the driver knows fit in 16 bits, the product is reduced to 16 bits, and nothing else is merged into the stored value. Measured shapes, each a separate shader:mainvs the GPUv_and_b32 v10, 0xffff, v6thenv_mul_lo_u16 v10, v4, v5v_add_nc_u16into a clearedv10, thenv_mul_lo_u16 v10, v10, v5v_pk_mul_lo_u16of factors whose high halves are zerov_mov_b32 v10, v6(unknown old value) thenv_mul_lo_u16v_pk_mul_lo_u16of factors whose low halves are zero, or of any valuesv_and_b32,v_bfe_u32or a shift pair, 16-bit factorsv_mul_u32_u24, thenv_and_b32 0xffffA factor taken from the low half of its source is now read as the low 24 bits of the register (
readU16Factor); the low 16 bits of the product depend only on the low 16 bits of the factors, so the stored value is unchanged on drivers that keep the mask. High-half (op_sel) factors are read as before. The technical debt entry records the driver behaviour, since nothing else in the code says why the field is 24 bits wide.The GPU side of the table comes from running the same instructions directly on the GPU with the
tools/hw-oracletemplate, launched through the driver's HIP runtime; there the GPU also keeps the destination's old high half for these VOP3 16-bit ops (with0xabcd0000prefilled,0xabcdsurvives), which the recompiler already models.Tested
Windows 11 26200, AMD Radeon RX 6700 XT (gfx1031), driver 32.0.21045.5002, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON,ANYPS5_REQUIRE_VULKAN=1:agc_driver_mul_lo_u16_high_half: six single-multiply shaders over 64 threads of edge and random values, checking the whole register: the first five shapes of the table, plusv_pk_mul_lo_u16with low halves zero. Onmainit fails:mul lo u16: v_mul_lo_u16 into a register whose high half is zero: thread 0 (0xffffffff, 0xffffffff, 0x00000000) wrote 0xfffe0001, expected 0x00000001. With this change it passes 3/3. On drivers that keep the mask it passes before and after, so lavapipe CI does not show the difference.v_mul_lo_u16/v_pk_mul_lo_u16shapes over 432 rows each:main192, 256, 0, 192, 192, 0 and 0 mismatches; with this change 0 in every shape.agc_driver_vop3_integer,agc_driver_packed_alu,agc_driver_packed_integer_clampandagc_driver_packed_integer_negatepass.ctest --parallel 4 --timeout 120onmain2bfe0045dwith this change: 1368 tests, 3 fail:agc_driver_lds_mixed_width_atomics(#5271) andagc_driver_layered_volume_vertex_no_gpl(#4768), which fail onmainon this GPU too, andagc_driver_preparation_scope_settle, which failed once under--parallel 4, passes 5/5 alone and contains neither instruction.python tools/check_conventions.py --base origin/mainwith this title and body passes.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T06:41:50Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/shader/recompiler/Translation/include/Translation/TranslationContext.hppdocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mdcore/shader/recompiler/Translation/src/VectorInstructions.cppdocs/dev/debt/shader.mdcore/shader/recompiler/Translation/src/VectorInstructions.cppdocs/dev/debt/shader.mdcore/shader/recompiler/Translation/src/VectorInstructions.cppdocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mdcore/shader/recompiler/Translation/include/Translation/TranslationContext.hppcore/shader/recompiler/Translation/src/VectorInstructions.cppdocs/dev/debt/shader.mdImported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-17T08:08:57Z.
Another AMD driver, since the description lists other AMD drivers as untested.
Windows 11 (26300), Radeon 860M (RDNA 3.5,
1002:1114), driver 32.0.13058.8001, WinLibs GCC 15.2.0, Release,ANYPS5_REQUIRE_VULKAN=1. Tree:main17cfb1f4cwith #7018, #7034, #7036, #7038, #7040, #7041 and #7042 merged together (onlydocs/dev/debt/shader.mdconflicted, for #7040); "main" is the same tree with the six recompiler files reverted tomainand the tests kept.agc_driver_mul_lo_u16_high_half: passes 3 of 3 with this change, and also passes onmain: this driver keeps the0xffffmask, as the description expects for drivers other than 32.0.21045.5002. So the change is neutral here.agc_driver_packed_alupasses 3 of 3.AI-assisted: yes (Claude Code).