Skip to content

fix(shader): reduce 16-bit multiply products by subtraction - #8315

Closed
TheSovietWaffle wants to merge 1 commit into
boykopovar:mainfrom
TheSovietWaffle:fix/shader-mul-lo-u16-masked-factors
Closed

TheSovietWaffle wants to merge 1 commit into
boykopovar:mainfrom
TheSovietWaffle:fix/shader-mul-lo-u16-masked-factors

Conversation

@TheSovietWaffle

Copy link
Copy Markdown
Contributor

What

#8266: agc_driver_mul_lo_u16_high_half fails on main on an AMD Radeon RDNA 2 iGPU (1002:164e, AMD Windows driver 32.0.21045.5002), on the case #7018 added for factors the program masks to 16 bits:

AGC graphics: mul lo u16: v_mul_lo_u16 of factors masked to 16 bits into a register whose high half is zero: thread 0 (0xffffffff, 0xffffffff, 0x00000000) wrote 0xfffe0001, expected 0x00000001

#7018 works around this driver's miscompile (it keeps the full 32-bit product of two values it knows fit in 16 bits when the product is masked to 16 bits) by reading the factors as 24-bit fields. When the program has already masked a factor with v_and_b32 0xffff, the constant folder drops that 24-bit read (BitFieldUExtract(x & 0xffff, 0, 24) is x & 0xffff), so the driver again sees (a & 0xffff) * (b & 0xffff) & 0xffff (APS5_DUMP_IR). A shift pair is folded back into the same mask, and BitFieldUExtract(p, 0, 16), which reaches the driver, loses the same bits.

Changes:

  • v_mul_lo_u16 and the low lane of v_pk_mul_lo_u16 reduce the product as p - ((p >> 16) << 16), which is p & 0xffff for every p and survives the folder in that form. The high lane of v_pk_mul_lo_u16 is shifted into place without a mask, as its high bits are shifted out.
  • The 16-bit integer multiply entry in docs/dev/debt/shader.md names the subtraction and this device.

Tested

Windows 10 Pro 22H2 (19045), WinLibs GCC 15.2.0 r7, Release, on main 661f8b717.

  • agc_driver_mul_lo_u16_high_half (all six cases): fails on main on the Radeon, passes with the change on both GPUs below; on the RTX 3080 it passes either way. With only v_mul_lo_u16 changed, the Radeon then fails the next case the same way (v_pk_mul_lo_u16 of factors whose high halves are zero ... wrote 0xfffe0001), which the first failure had hidden. With the BitFieldUExtract or shift-pair reduction instead of the subtraction, the Radeon still fails the masked-factor case.
  • Full agc suite (817 tests) on both GPUs with the change: all pass on the Radeon; on the RTX 3080 only agc_driver_pass_input_hazard fails, as it does on main.
  • tools/check_conventions.py --base origin/main and git diff --check pass. tools/pr_overlap.py was not run (no gh on this host).
  • Not tested: the RX 6700 XT from fix(shader): read low-half 16-bit multiply factors as 24-bit fields #7018 (the subtraction should not change its result, as the low 16 bits are the same), RADV.

Checklist

🤖 Generated with Claude Code

On AMD's Windows driver 32.0.21045.5002 a Radeon RDNA 2 iGPU (1002:164e)
still stored the full 32-bit product of v_mul_lo_u16 when the program
masked both factors to 16 bits: the constant folder drops the 24-bit
field read of a masked value, so the driver again saw
(a & 0xffff) * (b & 0xffff) & 0xffff. A bitfield extract or a shift
pair is folded into the same mask. The product is now reduced as
p - ((p >> 16) << 16) for v_mul_lo_u16 and the low lane of
v_pk_mul_lo_u16; the high lane is shifted into place unmasked.

Fixes boykopovar#8266.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the fix error Closes an issue (Fixes #N) label Oct 20, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks for this. #8280 fixes the same failure a different way: it keeps the 24-bit factor reads that #7018 introduced as the workaround for this driver, and it has passed review and CI. It hasn't been run on your iGPU yet, though, and that's the device #8266 was reported on.

Could you run agc_driver_mul_lo_u16_high_half on your RDNA 2 iGPU (AMD Windows driver 32.0.21045.5002) with #8280's head a5e1f83417 merged into main? If it passes, we'd go ahead with #8280 and close this one as covered. If it fails there, your subtraction approach becomes the follow-up, and it would need a CPU case in agc_constant_bit_test, so the folder can't turn the subtraction back into a mask. The v_pk_mul_lo_u16 neg-modifier form you cover is a known gap in #8280, so that part would still be welcome either way.

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

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 4072 core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp
PR 5021 docs/dev/debt/shader.md
PR 5371 docs/dev/debt/shader.md
PR 5426 docs/dev/debt/shader.md
PR 5500 docs/dev/debt/shader.md
PR 5799 core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp
docs/dev/debt/shader.md
PR 5941 docs/dev/debt/shader.md
PR 6009 docs/dev/debt/shader.md
PR 6010 core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp
docs/dev/debt/shader.md
PR 6011 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 6604 docs/dev/debt/shader.md
PR 6612 docs/dev/debt/shader.md
PR 6679 docs/dev/debt/shader.md
PR 6924 docs/dev/debt/shader.md
PR 6959 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 7410 core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp
docs/dev/debt/shader.md
PR 7426 docs/dev/debt/shader.md
PR 7484 docs/dev/debt/shader.md
PR 7684 docs/dev/debt/shader.md
PR 7803 docs/dev/debt/shader.md
PR 7829 docs/dev/debt/shader.md
PR 7888 docs/dev/debt/shader.md
PR 7922 docs/dev/debt/shader.md
PR 7942 docs/dev/debt/shader.md
PR 7945 docs/dev/debt/shader.md
PR 7965 docs/dev/debt/shader.md
PR 8004 docs/dev/debt/shader.md
PR 8055 core/shader/recompiler/Translation/include/Translation/TranslationContext.hpp
docs/dev/debt/shader.md
PR 8077 docs/dev/debt/shader.md
PR 8083 docs/dev/debt/shader.md
PR 8134 docs/dev/debt/shader.md
PR 8267 docs/dev/debt/shader.md
PR 8276 docs/dev/debt/shader.md
PR 8277 docs/dev/debt/shader.md
PR 8281 docs/dev/debt/shader.md
PR 8295 docs/dev/debt/shader.md
PR 8325 docs/dev/debt/shader.md
PR 8339 docs/dev/debt/shader.md
PR 8403 docs/dev/debt/shader.md
PR 8406 docs/dev/debt/shader.md
PR 8410 docs/dev/debt/shader.md
PR 8425 docs/dev/debt/shader.md
PR 8429 docs/dev/debt/shader.md

@github-actions github-actions Bot added shader core/shader docs labels Oct 20, 2026
@TheSovietWaffle

Copy link
Copy Markdown
Contributor Author

@oneandonlydean ran it: #8280's head a5e1f83417 merged into main 4f99cbffd, on the RDNA 2 iGPU (1002:164e, AMD Windows driver 32.0.21045.5002), Windows 10 22H2, WinLibs GCC 15.2.0, Release, ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1:

  • agc_driver_mul_lo_u16_high_half passes 3 of 3, all six cases (it fails on main there). The RTX 3080 (617.42) passes 3 of 3 too.
  • agc_constant_bit_test passes.

So #8280 covers this device as well, and I'm fine with closing this one as covered.

On the negated v_pk_mul_lo_u16 form: this PR doesn't change how negated factors are read (readU16Factor still XORs the 24-bit field with 0x8000), and I haven't tested a negated case on this driver, so I can't say yet whether it has the same problem. If you'd like, I can add a negated packed case to MulLoU16HighHalf.cpp on top of #8280 and run it on the iGPU, as a separate PR.

AI-assisted: yes (Claude Code).

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks for running it on the iGPU, that settles it: #8280 covers this device, so we'll close this one as covered once #8280 merges.

Yes please on the negated v_pk_mul_lo_u16 case. A separate PR on top of #8280 that adds a negated packed case to MulLoU16HighHalf.cpp, with your iGPU and RTX 3080 results, is exactly the check that's still missing. If the negated form turns out to fail there too, the fix can go in the same PR.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 20, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks for confirming #8280 on your RDNA 2 iGPU and RTX 3080. With #8280 merged (88942aa), this one is covered, so I'm closing it as agreed. A separate PR with the negated packed-multiply case is very welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs fix error Closes an issue (Fixes #N) needs rebase Conflicts with main, rebase needed shader core/shader

Projects

None yet

2 participants