Skip to content

rdna2spirv: v_pk_mul_lo_u16 forms each half as ((x << 16) * y) >> 16 (AMD driver drops the mask) - #6836

Merged
shayderrr merged 1 commit into
ItsNotRexed:mainfrom
evilclanker9000:claude/fz-pkmul-lo
Nov 23, 2026
Merged

shayderrr merged 1 commit into
ItsNotRexed:mainfrom
evilclanker9000:claude/fz-pkmul-lo

Conversation

@evilclanker9000

Copy link
Copy Markdown
Contributor

Requested by Lucas · project thread

Claimed in the coordination issue as: EGEN-PKMUL-LO, #5032 (comment)

What and why

pk16_diff --oracle hw,vk (#6306) found v_pk_mul_lo_u16 giving a stray high half on the AMD Windows driver (Radeon iGPU gfx1036, 26.10.1) in wave32 and wave64 (3 of 600 random programs per run): s_mov_b32 s8, 0xaaaa0000; v_pk_mul_lo_u16 v1, v3, s8 op_sel:[0,1] op_sel_hi:[0,0] with v3.lo = 0x1234 computed at run time gave 0x0c229e88 where RDNA2 gives 0x00009e88. The translator formed each half as (x * y) & 0xffff; the driver drops that mask when the other half of the result folds to a constant 0 (here 0x1234 * 0). A bit-field extract or a shift pair in place of the mask gave the same wrong word. Each half is now ((x << 16) * y) >> 16, the same 16-bit wrap, which the driver compiles correctly (RTX 5080 and the interpreter are right with both forms).

Tested

  • New GPU test cs_pk_mul_lo_const (four products with an SGPR, a literal and an inline constant; the other operand comes from the buffer fill at run time; words measured natively on gfx1036 in game MODE: 0x00009e88 0x03675433 0x00230000 0x00077f6c). Passes on the AMD Radeon iGPU (26.10.1) and the NVIDIA RTX 5080 (616.92) with the change. On main the Radeon fails (0x0c229e88 ...), the RTX 5080 passes (the problem is the AMD driver's).
  • tests/semantic/test_pk_mul_lo_const.py runs the same shader in the interpreter for the words and asserts that no multiplication result goes straight through a 0xffff mask (red on main, green now); the values alone cannot go red there.
  • python -I tools/pk16_diff.py --programs 3000 --seed 7 --ops v_pk_mul_lo_u16: 0 mismatches. python -m unittest discover -s tests/semantic: 5,822 tests, three failures, all test_float_nan_fract v_min3/max3/med3_f32 cases that fail identically on unmodified main. regen_fixtures.py --check, tests/test_shader_checks.py (fixture count and canned dump updated) and test_docs_* pass.
  • docs/design.md: the packed 16-bit row gains the form and why.
  • Not covered here: the same symptom in v_ashrrev_i16 with a constant operand and in SDWA destination narrowing on the Radeon (findings in Coordinating who works on what (28) (moved to #5156) #5032); no reformulation I tried fixes those.

AI-assisted: yes.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

pk16_diff --oracle hw,vk (ItsNotRexed#6306) found v_pk_mul_lo_u16 with a constant half of 0 giving
a stray high half on the AMD Windows driver (Radeon iGPU 26.10.1): 0x1234 * 0xaaaa came
out 0x0c229e88 for 0x00009e88. The translated (x * y) & 0xffff lost its mask when the
other half of the result folded to zero; written as a bit-field extract or a shift pair
of the product it did too. ((x << 16) * y) >> 16 is the same wrap and the driver gets
it right (RTX 5080 and the interpreter were right with both forms).

New GPU test cs_pk_mul_lo_const (SGPR, literal and inline constants, words measured on
gfx1036): fails on main on the Radeon, passes with the change on both GPUs.

AI-assisted.
@CharlyRien

Copy link
Copy Markdown

Tested 169724d (merged on main) on RTX 3090 (NVIDIA 616.56, Windows 11 23H2): pass. AI-assisted.

  • run_gpu_tests: the new cs_pk_mul_lo_const passes (0x9e88 0x3675433 0x230000 0x77f6c 0x9e88 0x3675433 0x230000 0x77f6c). 187/236 passed, 48 skipped; the only change from main is this new case.
  • Full ctest: same results as main on this host.

This is an NVIDIA data point for the rewritten v_pk_mul_lo_u16, alongside the AMD case the PR targets.

@Mob1K7105

Copy link
Copy Markdown

Tested 169724d99 merged onto main 1cc6e3c1 on AMD RDNA2 under RADV: Radeon RX 6700 XT (NAVI22, gfx1031, subgroup 32..64), Mesa 26.3.1-arch3.5, Linux, llvm-mc 23.1.5. Result: pass, no regression. Test programs built from 1cc6e3c1 (the PR changes no C++).

LEONIDA_W64_EMULATE main this PR
0 218/235 passed, 16 skipped 219/236 passed, 16 skipped
1 218/235 passed, 16 skipped 219/236 passed, 16 skipped
  • The only status change is the new cs_pk_mul_lo_const: PASS in both modes, 0x9e88 0x3675433 0x230000 0x77f6c twice, the words measured on gfx1036.
  • No existing test module changes: all 244 are byte-identical to main's in both modes, so the new form only reaches v_pk_mul_lo_u16.
  • scripts/run_semantic_tests.py -j 6 tests/semantic: 434 files, 5,822 tests, 0 failed. On this machine the test_float_nan_fract failures mentioned in the description do not occur.
  • Driver-specific, as the description says: the new fixture translated by main's rdna2spirv.py also passes on RADV (same words, both modes). Mesa's compiler keeps the 0xffff mask that AMD's Windows driver drops, so RADV is a no-regression check here, not a reproduction.

Not run: pk16_diff --oracle hw,vk (on Linux the hardware oracle submits raw command buffers through the kernel driver; I didn't do that on this desktop machine), Windows/AMD's own driver.

AI-assisted (Claude Code). Synthetic fixtures only, no game files.

@wasonidas

Copy link
Copy Markdown

Independent check of 169724d99d41c00cbb3b001b19420e47a2f8ca84 against main 8f208d09, Windows 11 build 26300, integrated Radeon gfx1036 driver 32.0.21042.62, RTX 5080 driver 621.24, LLVM/Clang 23.1.5 and SPIRV-Tools v2026.4.

On Radeon, the same synthetic cs_pk_mul_lo_const fixture produced 32 wrong words out of 128 at each subgroup width on main (32 and 64), and zero on the PR. Main returned 0x0c229e88 as the first word of every lane, while the PR returned 0x00009e88 and matched all other words. The native HIP comparison passed all 128 words at both widths. The bounded seed-7 differential run matched 600/600 per wave size without skips. Both builds matched 128/128 on RTX 5080 at subgroup 32.

Both modules passed Vulkan 1.2 SPIR-V validation. The focused CPU regression passed on the PR and failed on its parent at the expected assertion. CPU differential: 3,000/3,000. No game data. AI-assisted.

@thesubtleties

Copy link
Copy Markdown

Tested 169724d9: pass, no regressions. CachyOS Linux 7.3.5, LLVM 23.1.5:

Pass/skip/fail status per test matches main 1cc6e3c1 on both GPUs, apart from any new fixture named above. No game files. AI-assisted (Claude Code).

@shayderrr shayderrr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

In tools/rdna2spirv.py, mul_lo now emits each half as ((x << 16) * y) >> 16 — shift, 32-bit multiply, shift back — instead of (x * y) & 0xffff. AMD's Windows driver 26.10.1 dropped the low-half mask when the other half folded to a zero constant (0x1234 * 0xaaaa produced 0x0c229e88 instead of 0x9e88). A new GPU fixture runtime/test/shaders/cs_pk_mul_lo_const.asm, disassembler fixture, and tests/semantic/test_pk_mul_lo_const.py pin the constant-half case, registered in check.py and run_gpu_tests.py.

Why merge

Keeps v_pk_mul_lo_u16 bit-exact on AMD's Windows driver, where the masked form miscompiled a constant zero half. Essential for correct static recompilation of RDNA2 pixel shaders on Windows.

Verdict: Approve

@shayderrr

Copy link
Copy Markdown
Collaborator

Summary

In tools/rdna2spirv.py, mul_lo now emits each half as ((x << 16) * y) >> 16 — shift, 32-bit multiply, shift back — instead of (x * y) & 0xffff. AMD's Windows driver 26.10.1 dropped the low-half mask when the other half folded to a zero constant (0x1234 * 0xaaaa produced 0x0c229e88 instead of 0x9e88). A new GPU fixture runtime/test/shaders/cs_pk_mul_lo_const.asm, disassembler fixture, and tests/semantic/test_pk_mul_lo_const.py pin the constant-half case, registered in check.py and run_gpu_tests.py.

Why merge

Keeps v_pk_mul_lo_u16 bit-exact on AMD's Windows driver, where the masked form miscompiled a constant zero half. Essential for correct static recompilation of RDNA2 pixel shaders on Windows.

Verdict: Approve

@shayderrr
shayderrr merged commit bc773d3 into ItsNotRexed:main Nov 23, 2026
0 of 5 checks passed
@dandasma

Copy link
Copy Markdown
Contributor

For the record, on an AMD Radeon RX 9070 (RDNA4), AMD Windows driver 26.10.1, Windows 11 (main 2b906bc + 169724d9): cs_pk_mul_lo_const gives 0x9e88 0x3675433 0x230000 0x77f6c (twice) with this PR, and also with main's old lowering (3/3 each). So this driver doesn't show the stray high half on RDNA4, at least for these four products; the new lowering is harmless there (full suite unchanged apart from the new test).

AI-assisted (Claude Code).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants