Skip to content

fix(shader): keep the 24-bit factor reads of 16-bit multiplies - #8280

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
thuanquang:fix/mul-lo-u16-keep-24-bit-factors
Oct 20, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
thuanquang:fix/mul-lo-u16-keep-24-bit-factors

Conversation

@thuanquang

@thuanquang thuanquang commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

What

Fixes #8271: agc_driver_mul_lo_u16_high_half fails 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_u16 and v_pk_mul_lo_u16 as 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 in shader.md). #7673 added a fold of BitFieldUExtract(x, 0, n) into x when x has no bits at or above n. 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) & 0xffff and stores 0xfffe0001 for 0xffff * 0xffff.

The folder now leaves a BitFieldUExtract in place when an IMul32 uses 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, on main 7d876ad3b:

agc_driver_mul_lo_u16_high_half agc_constant_bit_test
this PR passes 3/3, all six cases passes 3/3
this PR with the IMul32 check removed fails 3/3: thread 0 (0xffffffff, 0xffffffff, 0x00000000) wrote 0xfffe0001, expected 0x00000001 fails: a 24-bit field read that a multiply uses is kept, even for a factor masked to 16 bits
  • main a98590dec fails the GPU test the same way, and main with perf(shader): fold masks, shifts and field extracts through bits they do not use #7673 reverted passes it 3/3.
  • In the SPIR-V dumped with APS5_DUMP_COMPUTE_PIPELINES for the masked-factors case, the module on main differs from the one with perf(shader): fold masks, shifts and field extracts through bits they do not use #7673 reverted only in the two OpBitFieldUExtract ... 0 24 factor reads (and a repeated & 0xffff), see AGC: agc_driver_mul_lo_u16_high_half fails on AMD's Windows driver since #7673 #8271.
  • agc_constant_bit_test gains 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.
  • Khronos validation layer (VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, layer built from Vulkan-ValidationLayers; with VK_LOADER_DEBUG=layer this tree's run logs Insert instance layer "VK_LAYER_KHRONOS_validation"), ANYPS5_NO_SHADER_CACHE=1, ctest -V on agc_constant_bit_test, agc_driver_mul_lo_u16_high_half, agc_integer_narrowing and agc_driver_sdwa_integer_clamp: 0 VUID- messages on main a98590dec (where the GPU test fails as above) and with this PR (4 of 4 pass), and no was not found but was requested line.
  • Full ctest --parallel 4 --timeout 120 on main 7d876ad3b with this PR: 1717 tests, 2 failed: log_macros and log_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

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: Fixes AGC: agc_driver_mul_lo_u16_high_half fails on AMD's Windows driver since #7673 #8271
  • Unblocks: none
  • GPUs tested: AMD Radeon RX 6700 XT (gfx1031), AMD Windows driver 32.0.21045.5002, Windows 11 26200
  • AI-assisted: yes

🤖 Generated with Claude Code

boykopovar#7018 reads the low-half factors of v_mul_lo_u16 and v_pk_mul_lo_u16
as 24-bit fields because AMD's Windows driver stores the full 32-bit
product when it knows both factors fit in 16 bits. boykopovar#7673's fold of
BitFieldUExtract(x, 0, n) into x removed those reads when the program
had masked the factors to 16 bits, so agc_driver_mul_lo_u16_high_half
failed again on that driver. The folder now keeps a field read that a
multiply uses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 8315 docs/dev/debt/shader.md L118

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.

Pull request Shared files not compared
PR 5021 core/libs/prx/libSceAgcDriver/tests/ConstantBitTest.cpp
core/shader/recompiler/Optimization/src/ConstantFolder.cpp
docs/dev/debt/shader.md
PR 5371 docs/dev/debt/shader.md
PR 5426 docs/dev/debt/shader.md
PR 5500 core/shader/recompiler/Optimization/src/ConstantFolder.cpp
docs/dev/debt/shader.md
PR 5941 docs/dev/debt/shader.md
PR 6009 docs/dev/debt/shader.md
PR 6235 docs/dev/debt/shader.md
PR 6280 docs/dev/debt/shader.md
PR 6412 docs/dev/debt/shader.md
PR 6488 docs/dev/debt/shader.md
PR 6977 docs/dev/debt/shader.md
PR 7085 docs/dev/debt/shader.md
PR 7223 docs/dev/debt/shader.md
PR 7332 docs/dev/debt/shader.md
PR 7392 docs/dev/debt/shader.md
PR 7395 docs/dev/debt/shader.md
PR 7484 docs/dev/debt/shader.md
PR 7684 docs/dev/debt/shader.md
PR 7922 docs/dev/debt/shader.md
PR 8004 docs/dev/debt/shader.md

@github-actions github-actions Bot added shader core/shader docs agc libSceAgc* fix error Closes an issue (Fixes #N) labels Oct 20, 2026
@oneandonlydean
oneandonlydean merged commit 88942aa into boykopovar:main Oct 20, 2026
13 checks passed
TheSovietWaffle added a commit to TheSovietWaffle/AnyPS5 that referenced this pull request Oct 20, 2026
boykopovar#8280 keeps the 24-bit factor reads of v_mul_lo_u16 and v_pk_mul_lo_u16
so AMD's Windows driver cannot see that the factors fit in 16 bits. A
negated packed factor is read as that field XORed with 0x8000, so two
cases now run v_pk_mul_lo_u16 with neg_lo on a low lane and neg_hi on a
high lane, with the other half of both factors masked to zero.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs fix error Closes an issue (Fixes #N) shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AGC: agc_driver_mul_lo_u16_high_half fails on AMD's Windows driver since #7673

2 participants