Repository navigation
v_pk_{lshl,lshr,ashr}rev_b16: lower without bit-field extract to avoid the AMD Windows driver wave32 miscompile (SHADER-777) - #4461
Conversation
…ows driver keeps the high half (SHADER-777) The OpBitFieldUExtract amount and the identical lo/hi expressions gave a wrong high half in wave32 on AMD driver 25.10.36 and 26.10.1 (valu_fuzz f16 seed 1, programs 534, 1146, 1540, 1556 at 32 lanes). Adds the semantic test over all op_sel combinations, GPU test cs_w32_pk_shift, the design.md row, and re-anchors the pk_lshl mutation. AI-assisted.
Kam471
left a comment
There was a problem hiding this comment.
Ran this at 79be6dc5 on Windows 11: tests/semantic/test_pk_shift_16.py -> 2 tests, OK; compileall and git diff --check clean.
The three packed 16-bit shift forms now lower to plain shifts (no bit-field extract), avoiding the AMD Windows driver wave32 miscompile while keeping the high-half behavior; the new GPU fixture cs_w32_pk_shift and the semantic cases cover it. I cannot run the AMD driver path here, but the CPU translation is pinched. No blocking issue.
|
SHADER-777 raw-ISA check on AI-assisted verification using synthetic inputs. |
Flyander
left a comment
There was a problem hiding this comment.
Reviewed 79be6dc: the lowering keeps each 16-bit result half independent and implements shift amounts from the selected source half without bit-field extracts. Semantic cases cover all op_sel combinations; the independent raw-ISA run confirms the hardware result on AMD wave32.
|
Apple M2 no-regression check at head 79be6dc (macOS 26.4, MoltenVK 1.4.2 direct, subgroup 4..32, llvm-mc 23.1.6, clean full build exit 0).
AI-assisted. |
|
Tested
No GPU, no game data. AI-assisted. |
|
AI-assisted Windows hardware & semantic verification for SHADER-777 (
|
|
The miscompile goes back further than 25.10.36: the AMD Windows driver 24.10.24 has it too, on the same four wave32 programs, and this PR fixes all four. AI-assisted (Claude Code), synthetic programs only, no game files. Hardware: AMD Ryzen 5 7600X, Windows 11 Home 26300. GPU: AMD Radeon(TM) Graphics iGPU (RDNA2 gfx1036, subgroup 32..64), AMD driver 24.10.24 (Vulkan driver 2.0.302). MSVC 14.44, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8, Python 3.12.10. Implicit layers off,
Every mismatch is in a register last written by
Together with @BetterJdue's raw-ISA run (1557/1557 on the hardware itself), this points at the driver's compilation, not the GPU, from 24.10 through 26.10. Whole-suite run of this head,
The new
|
Kam471
left a comment
There was a problem hiding this comment.
Overlap to resolve: #4622 (fiestorra, opened after this) fixes the same SHADER-777 high-half read with a smaller change — shift + mask for the high half, leaving the low half's offset-0 OpBitFieldUExtract in place — and also updates the v_pk_lshlrev_b16 mutation anchor and the docs row. git merge-tree --write-tree refs/remotes/pr/4461 refs/remotes/pr/4622 -> conflict in docs/design.md, tests/semantic/test_mutations.py and tools/rdna2spirv.py.
This PR is the earlier claimant, removes the field extract for both halves and carries the GPU fixture cs_w32_pk_shift.asm plus a semantic test; #4622 is the smaller minimal form. Please have one close or drop its overlapping hunk so the coordinator is not choosing between two conflicting translations of the same fix.
|
Tested Fuzzer, same machine and driver,
GPU suite at this head (
The extra test is the new Note: Tools: llvm-mc 23.1.6 (conda-forge), Vulkan SDK 1.4.363.0, Python 3.11.9, AI-assisted. Synthetic programs and counts only, no game files. Created with Perplexity |
|
Tested
Scope on RDNA4, @Vonsek, in case it helps a follow-up. Each program: a 16-bit producer writes
So on this card the trigger is the AI-assisted (Claude Code). Synthetic inputs only, no game files. |
|
@Vonsek: since this PR is scoped to the shifts, I'll look for a driver-proof lowering of the |
docs/design.md AI-assisted.
|
Follow-up with two more seeds, on the same Radeon iGPU (gfx1036, AMD Windows driver 24.10.24) as my comment above. On
Each one is again the high half of a
On main, |
|
Tested 96a59a8 merged with main 98fa503 on Linux (WSL2), Python 3.12.16: pass (draft; GPU run not done)
|
|
Tested 96a59a8 on AMD Radeon RX 6800 (RDNA2, discrete, gfx1030), AMD 26.8.1 (Windows 32.0.21045.5002), Windows 11 Pro 25H2 (build 26200): pass.
Only the fuzz was run here; I did not run the new AI-assisted (Claude Code). |
No textual conflicts remained after main moved (docs/design.md merged cleanly). AI-assisted.
|
A standalone reproducer for this, from a different fuzz seed, and a check of this PR against it: this lowering fixes it; #4622's does not. The description says the miscompile is "not reproducible with a small standalone shader". The min gives AMD Radeon iGPU of a Ryzen 9 9950X3D (RDNA2 gfx1036, Windows driver 32.0.21042.62, subgroup 32..64) next to an NVIDIA RTX 4080 (621.01), Windows 11 Pro 26300,
The RTX 4080 gives the wanted words in every cell. What narrows it:
In the sweep this came from (seeds 4080 and 9950, 200 programs per wave, native and emulated, both GPUs) it is the only If it is useful, I can turn the two instructions into a GPU fixture for No game files; the program above is hand-cut from the fuzzer's synthetic output. AI-assisted (Claude Code ran the sweep and the reduction). |
…d half readers docs/design.md already says a high 16-bit half is read with `>> 16` alone, with no narrowing after it, because AMD's Windows LLPC miscompiles that combination (ItsNotRexed#1506). The three packed 16-bit shifts were the exception: they read the value half with `OpBitField{S,U}Extract(s1, 16, 16)`. An AMD Windows driver 25.10.36 on a gfx1036 reads a field extract at offset 16 with the offset taken mod 16, so both result halves got the low half of the source - 5 of 2000 wave32 programs of `tools/valu_fuzz.py --family f16 --programs 2000 --seed 1` (@Darkz0rz, SHADER-777 in the coordination issue). The same 2000 programs match 2000/2000 on a second gfx1036 (Radeon iGPU of a Ryzen 7 7800X3D, Windows driver 31.0.24002.92), and the SPIR-V that run produced does contain those offset-16 extracts. So this is a lowering that survives both drivers, not a value change: BitField{S,U}Extract(x, 16, 16) equals `x >> 16` with the matching right shift, checked over 200,010 inputs including 0, 1, 0xFFFF, 0x10000, 0x80000000, 0xFFFFFFFF, 0x7FFFFFFF and 0x8000. Extracts at offset 0 are left as they were. Reading the halves through Gen.u16_half / Gen.i16_half also aligns the signed op with the `%int` convention used everywhere else in the file: `v_pk_ashrrev_i16` now weights its value as `%int` (as_int of the source, sign-extended), shifts with `OpShiftRightArithmetic %int`, and only then bitcasts to `%uint` before the 0xFFFF mask, so sign extension comes from the type instead of from a driver choosing to read an arithmetic shift on an unsigned operand as arithmetic. For the shift amount a high half reads `(s0 >> 16) & 15` and a low half keeps `OpBitFieldUExtract(s0, 0, 4)`; the "16-bit high-half reads" row now says both, which is what the code does. Counted over all 26 503 listings: 1 v_pk_lshlrev_b16 in one compute listing and 1 v_pk_lshrrev_b16 in another, no v_pk_ashrrev_i16 and no _sdwa form. Translating the corpus on this branch and on main 902358c with the same flags gives 26 503 entries on both sides with the same index.json sha256, 26 501 .spv identical, and the 2 that differ differ only in shape: opcode histograms -2 OpBitFieldUExtract / +1 OpBitwiseAnd / +1 OpShiftRightLogical in one (instruction count unchanged) and -3 / +3 / +1 in the other (one extra instruction, for a constant shift amount). The full tests/semantic suite gives the same 6245 tests with failures=3, errors=2 as main, all five in test_loop_ballot_barrier; test_pk16_diff, test_ps_semantics, test_value_semantics and test_alu_pk_int16 are green. ps_ops4 and ps_ops6 are exact at 4096/4096 on the gfx1036 iGPU and on an NVIDIA RTX 4090 (driver 32.0.16.2124). tests/test_u16_high_half.py gains the shape assertions for the three ops over four op_sel/op_sel_hi combinations, validated with spirv-as and spirv-val, plus one case pinning that every arithmetic shift in v_pk_ashrrev_i16 is %int; those four cases fail on main and pass here. Coordinated as SHADER-784 in ItsNotRexed#4571, verifying @Darkz0rz's SHADER-777. Overlaps ItsNotRexed#4461 (Vonsek, the earlier claim of the same item, with a broader lowering and a GPU fixture); flagged on both.
|
Coordination, not a review. @Kam471 flagged that this and #4622 do the same item (SHADER-777) and conflict in I am not going to leave two PRs doing the same job. Say which one you want to keep and I will act on it: close One measurement from here in case it is useful for your row: over all 26 503 game listings there is 1 |
fiestorra
left a comment
There was a problem hiding this comment.
Independent verification on a second pair of GPUs and drivers, plus the whole corpus. AI-assisted (my own agent), run
locally at 13144aa5; your branch is two merges behind current main (merge-base ec34b54f, main is 3faac557), so
the parity numbers below are against main 902358c8, which is where I keep my own baseline.
Machine. Windows 11, Ryzen 7 7800X3D. GPU 1: Radeon 780M iGPU of that CPU (gfx1036, 0x1002:0x164e), Windows
driver 31.0.24002.92, compute subgroup 32..32 (this driver reports no 64-wide compute subgroup, so I cannot run your
program 378 at 64 lanes). GPU 2: NVIDIA GeForce RTX 4090 (Ada), driver 32.0.16.2124, subgroup 32..32. llvm-mc 21,
Vulkan SDK 1.4.363.0, harness built from your branch with cmake -S runtime -B runtime/build -G Ninja.
New GPU test. cs_w32_pk_shift PASS, cs_cvt_pk_u8 PASS, 2/2 on both devices:
| device / driver | cs_w32_pk_shift |
|---|---|
| Radeon 780M iGPU (gfx1036), 31.0.24002.92 | PASS 0x0 0xb2c5b2c5 0xfd96fd96 0xf658ff4d 0x1658074d 0x96283420 0x3c00 0xb2c5e9a1 |
| RTX 4090, 32.0.16.2124 | PASS, same words |
Two more driver combinations on top of your gfx1036 / 26.10.1 and the RTX 5080.
Whole game corpus, same flags as the build (--no-asm --wave64-emulate, 8 shards), your tools/rdna2spirv.py vs
main 902358c8. 26,503 entries on both sides, the same index.json sha256
7E9ACA940D0007A7399D9748861FE3751CF1736654249E1CE342628FA37861D6, 26,501 .spv byte-identical, 0 entries lost
or newly rejected. The 2 files that change are the only 2 listings in the corpus that hold a packed shift at all — over
all 26,503 listings: 1 v_pk_lshlrev_b16, 1 v_pk_lshrrev_b16, 0 v_pk_ashrrev_i16, no _sdwa form. Sizes
166,900 → 166,924 and 111,092 → 111,116 bytes: +24 bytes each, which is the wider amount/mask expression your row
describes, on real game input. My #4622 changes exactly the same 2 files in exactly the same way (shape only, one
smaller and one larger).
Translator suite. python -m unittest discover -s tests/semantic → 6247 tests, failures = 3, errors = 2, skipped =
1, expected failures = 1. Main 902358c8 on the same machine gives 6245 tests with the same failure and error counts;
the +2 are your new tests. Run on that one file alone in both trees, the failing set is identical and none of it
touches packed shifts:
SUBFAILED(mode='emulate_64_sg32') test_divergent_loop_wave64_emulate_and_native_cs
SUBFAILED(mode='emulate_128_sg32') test_divergent_loop_wave64_emulate_and_native_cs
SUBFAILED(mode='emulate_40_partial_sg32') test_divergent_loop_wave64_emulate_and_native_cs
SUBFAILED(emulate=True) test_nested_divergent_loops_emulate
SUBFAILED(emulate=True) test_bug4b_loop_carried_split_sgpr_pair_ballot
5 failed, 15 passed, 19 subtests passed
tests/semantic/test_pk_shift_16.py, tests/test_pk16_diff.py, tests/test_u16_high_half.py and the
docs/design.md row checks: 66 passed, 306 subtests. tests/semantic/test_mutations.py: 3 passed, 26 subtests — your
re-anchored v_pk_lshlrev_b16 amount mutation is caught. Note for when you rebase: on current main the
v_mul_legacy_f32 anchor in that file is stale (moved by c82fbe37), which adds two unrelated failures that
#3883/#4527 re-anchor; they are not yours.
One thing I would change, and it is the same point @tupacfan04 raised on my #4622. Your v_pk_ashrrev_i16 path
shifts as OpShiftRightArithmetic %uint: the sign extension comes from bit 31 of a word you deliberately filled to
bits [31:16], and whether an arithmetic shift of an unsigned operand replicates that bit is up to the compiler —
GLSL and MSL treat >> on uint as a logical shift, and the repo's own 16-bit signed reader (Gen.i16_half,
docs row "16-bit high-half reads", #1506) weights the value as %int for exactly that reason. Your fixture and your
fuzz programs pass on LLPC and on the RTX 5080, so this is a portability concern rather than a failure I can show on
hardware — but if both PRs landed with arithmetic shifts on %uint, the rule the contract table states would depend
on driver behaviour. Weighting it as %int (OpBitcast %int, shift, OpBitcast %uint before the mask) matches the
existing helper, matches what @tupacfan04 asked me for, and makes the two PRs agree on the one point where they
differ. My branch keeps the existing half readers and only changes the amount read; yours removes the bit-field
extracts everywhere, which is the wider change.
Not blocking: I have no claim on which of these two lands. I have said on #4622 and in #5256 that I will close it, or
drop my translator hunk and keep only the %int alignment plus the shape assertions in tests/test_u16_high_half.py,
whichever you and @Kam471 prefer — your version is the earlier claim and the broader test coverage.
|
Small correction to my review above, which named my AMD GPU wrongly: the integrated graphics of the Ryzen 7 7800X3D is |
…d half readers docs/design.md already says a high 16-bit half is read with `>> 16` alone, with no narrowing after it, because AMD's Windows LLPC miscompiles that combination (ItsNotRexed#1506). The three packed 16-bit shifts were the exception: they read the value half with `OpBitField{S,U}Extract(s1, 16, 16)`. An AMD Windows driver 25.10.36 on a gfx1036 reads a field extract at offset 16 with the offset taken mod 16, so both result halves got the low half of the source - 5 of 2000 wave32 programs of `tools/valu_fuzz.py --family f16 --programs 2000 --seed 1` (@Darkz0rz, SHADER-777 in the coordination issue). The same 2000 programs match 2000/2000 on a second gfx1036 (Radeon iGPU of a Ryzen 7 7800X3D, Windows driver 31.0.24002.92), and the SPIR-V that run produced does contain those offset-16 extracts. So this is a lowering that survives both drivers, not a value change: BitField{S,U}Extract(x, 16, 16) equals `x >> 16` with the matching right shift, checked over 200,010 inputs including 0, 1, 0xFFFF, 0x10000, 0x80000000, 0xFFFFFFFF, 0x7FFFFFFF and 0x8000. Extracts at offset 0 are left as they were. Reading the halves through Gen.u16_half / Gen.i16_half also aligns the signed op with the `%int` convention used everywhere else in the file: `v_pk_ashrrev_i16` now weights its value as `%int` (as_int of the source, sign-extended), shifts with `OpShiftRightArithmetic %int`, and only then bitcasts to `%uint` before the 0xFFFF mask, so sign extension comes from the type instead of from a driver choosing to read an arithmetic shift on an unsigned operand as arithmetic. For the shift amount a high half reads `(s0 >> 16) & 15` and a low half keeps `OpBitFieldUExtract(s0, 0, 4)`; the "16-bit high-half reads" row now says both, which is what the code does. Counted over all 26 503 listings: 1 v_pk_lshlrev_b16 in one compute listing and 1 v_pk_lshrrev_b16 in another, no v_pk_ashrrev_i16 and no _sdwa form. Translating the corpus on this branch and on main 902358c with the same flags gives 26 503 entries on both sides with the same index.json sha256, 26 501 .spv identical, and the 2 that differ differ only in shape: opcode histograms -2 OpBitFieldUExtract / +1 OpBitwiseAnd / +1 OpShiftRightLogical in one (instruction count unchanged) and -3 / +3 / +1 in the other (one extra instruction, for a constant shift amount). The full tests/semantic suite gives the same 6245 tests with failures=3, errors=2 as main, all five in test_loop_ballot_barrier; test_pk16_diff, test_ps_semantics, test_value_semantics and test_alu_pk_int16 are green. ps_ops4 and ps_ops6 are exact at 4096/4096 on the gfx1036 iGPU and on an NVIDIA RTX 4090 (driver 32.0.16.2124). tests/test_u16_high_half.py gains the shape assertions for the three ops over four op_sel/op_sel_hi combinations, validated with spirv-as and spirv-val, plus one case pinning that every arithmetic shift in v_pk_ashrrev_i16 is %int; those four cases fail on main and pass here. Coordinated as SHADER-784 in ItsNotRexed#4571, verifying @Darkz0rz's SHADER-777. Overlaps ItsNotRexed#4461 (Vonsek, the earlier claim of the same item, with a broader lowering and a GPU fixture); flagged on both.
|
Verified at 13144aa, and this is a FAIL-class close-recommendation: main's a148559 already fixes the same driver miscompile from the same evidence (AMD driver 25.10.36, valu_fuzz --family f16 --seed 1), re-anchoring the same test_mutations entry to '{half} = OpShiftRightLogical' — mutually exclusive with this PR's anchor. I verified the two lowerings are value-equivalent per half for every op_sel/op_sel_hi combination, so nothing is lost by keeping main's. The PR also still conflicts with current main in runtime/test/shaders/check.py, scripts/run_gpu_tests.py, tests/semantic/test_mutations.py and tools/rdna2spirv.py. What is worth salvaging rather than closing outright: runtime/test/shaders/cs_w32_pk_shift.asm plus its expected words (I recomputed all eight hand-derived words — all correct), the disasm fixture and regen_fixtures registration, and tests/semantic/test_pk_shift_16.py (2 tests OK at your head); the design.md row would need rewriting since main keeps offset-0 OpBitField*Extract. Your own suites were green at the head (pk_shift_16, mutations, alu_pk_int16, alu_int_minmax_shift_not, alu_add_u16, rule_gpu_fixtures, missing_encoding, docs guards), and test_rdna2_decode's single failure reproduces identically at the merge-base — not yours. Suggestion: close the translator part as superseded, salvage the GPU test onto main. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run). |
|
A second case from another seed, in a different shape: here the wrong word is not the shift's result.
So this PR's lowering also removes a wrong result in an instruction it does not touch, and #4622's still does not help on this driver. In the sweep it came from (seeds 31337 and 20261123, 200 programs per wave) it is the Radeon's only No game files; the program is hand-cut from the fuzzer's synthetic output. AI-assisted (Claude Code ran the sweep and the reduction). |
Requested by Lucas · project thread
Claimed in the coordination issue as: SHADER-777, #4257
What and why
v_pk_lshlrev_b16,v_pk_lshrrev_b16andv_pk_ashrrev_i16were lowered withOpBitFieldUExtractfor the shift amount and two near-identical lo/hi expressions. On the AMD Windows driver (25.10.36, and still 26.10.1) the compiled wave32 pipeline returns a wrong high half for some programs:valu_fuzz --family f16 --seed 1programs 534, 1146, 1540, 1556 at 32 lanes (plus 378 at 64) mismatch the hardware oracle on the Radeon with the old lowering. The minimal trigger found by bisection is the three-instruction shift sequence inside the fuzz prologue; it is not reproducible with a small standalone shader, so the regression evidence is those programs, not a red GPU fixture.New lowering: the amount per half is
(src0 >> 16*sel) & 15, each value half is placed in bits 31:16, and the result halves come from a right shift of that word (lshl: shift left then mask), so no bit-field extract is used and the two halves are different expressions. The result is bit-identical to the old lowering in the translator reference.Tested
6/6 programs that ran match, 378 at 64 lanes skipped by the harness: no full 64-wide subgroups). With the old lowering the Radeon mismatches on the four 32-lane programs.tools/pk16_diff.py --programs 150over the three ops: 150 pass on both GPUs.tests/semantic/test_pk_shift_16.py: all 16op_sel/op_sel_hicombinations x 3 ops x 6 value pairs against a Python reference, plus the expected words of the new GPU testcs_w32_pk_shift(registered incheck.pyandscripts/run_gpu_tests.py; PASS on both GPUs, old lowering also passes it, so it guards semantics, not the driver bug).test_mutations.py: thev_pk_lshlrev_b16mutation re-anchored on the new amount read; it is caught.python -m unittest discover -s tests/semantic: 7458 tests; the only failures (loop_ballot_barrier, cmp_class_f64, and thev_mul_legacy_f32mutation anchor) fail identically on upstream main, none touch this change.tests/test_docs_design_rows.py: OK.Checklist
docs/design.md, with how it was confirmed (new row "Packed 16-bit shifts").AI-assisted.