fix(shader): keep the 24-bit factor reads of 16-bit multiplies #8280
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8280"
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-20T08:24:13Z.
What
Fixes #8271:
agc_driver_mul_lo_u16_high_halffails on AMD's Windows driver 32.0.21045.5002 since #7673 (also reported for an RDNA 2 iGPU in #8266).#7018 reads the low-half factors of
v_mul_lo_u16andv_pk_mul_lo_u16as 24-bit fields (BitFieldUExtract(raw, 0, 24)). That is what the GPU does, and it also hides the factors' width from AMD's Windows driver, which stores the full 32-bit product when it knows both factors fit in 16 bits (the 16-bit integer multiplies entry inshader.md). #7673 added a fold ofBitFieldUExtract(x, 0, n)intoxwhenxhas no bits at or aboven. When the program has already masked both factors to 16 bits (v_and_b32 v4, 0xffff, v4), that fold removes the 24-bit reads, and the driver is back to(x & 0xffff) * (y & 0xffff) & 0xffffand stores 0xfffe0001 for 0xffff * 0xffff.The folder now leaves a
BitFieldUExtractin place when anIMul32uses it. The fold still applies to every other field read. The debt entry says so.Tested
Windows 11 26200, RX 6700 XT (gfx1031), AMD driver 32.0.21045.5002, Release,
ANYPS5_REQUIRE_VULKAN=1, onmain7d876ad3b:agc_driver_mul_lo_u16_high_halfagc_constant_bit_testIMul32check removedthread 0 (0xffffffff, 0xffffffff, 0x00000000) wrote 0xfffe0001, expected 0x00000001a 24-bit field read that a multiply uses is kept, even for a factor masked to 16 bitsmaina98590decfails the GPU test the same way, andmainwith #7673 reverted passes it 3/3.APS5_DUMP_COMPUTE_PIPELINESfor the masked-factors case, the module onmaindiffers from the one with #7673 reverted only in the twoOpBitFieldUExtract ... 0 24factor reads (and a repeated& 0xffff), see #8271.agc_constant_bit_testgains two cases that run without a GPU, so CI (lavapipe, which doesn't miscompile this) still catches the fold coming back. One checks that a 24-bit field read of a value masked to 16 bits still folds into the value; the other, that the same read is kept when a multiply uses it.VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, layer built from Vulkan-ValidationLayers; withVK_LOADER_DEBUG=layerthis tree's run logsInsert instance layer "VK_LAYER_KHRONOS_validation"),ANYPS5_NO_SHADER_CACHE=1,ctest -Vonagc_constant_bit_test,agc_driver_mul_lo_u16_high_half,agc_integer_narrowingandagc_driver_sdwa_integer_clamp: 0VUID-messages onmaina98590dec(where the GPU test fails as above) and with this PR (4 of 4 pass), and nowas not found but was requestedline.ctest --parallel 4 --timeout 120onmain7d876ad3bwith this PR: 1717 tests, 2 failed:log_macrosandlog_macros_timestamps, because ccache rewrites__FILE__in local builds here.Not tested: other AMD GPUs and driver versions; #8266 has the same failure on an RDNA 2 iGPU with this driver.
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-20T08:29:05Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/shader.mdL118Some 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/libs/prx/libSceAgcDriver/tests/ConstantBitTest.cppcore/shader/recompiler/Optimization/src/ConstantFolder.cppdocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mdcore/shader/recompiler/Optimization/src/ConstantFolder.cppdocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.mddocs/dev/debt/shader.md