Repository navigation
Conversation
…field extract 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 took the shift amount with `OpBitFieldUExtract(s0, 16, 4)` and the value 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, and BitFieldUExtract(x, 16, 4) equals `(x >> 16) & 15`; checked over 200,010 inputs including 0, 1, 0xFFFF, 0x10000, 0x80000000, 0xFFFFFFFF, 0x7FFFFFFF and 0x8000. Extracts at offset 0 are left as they were. Coordinated as SHADER-784 in ItsNotRexed#4571, verifying SHADER-777. Counted over all 26 503 listings: 1 v_pk_lshlrev_b16 in 1 compute listing and 1 v_pk_lshrrev_b16 in another, no v_pk_ashrrev_i16 and no _sdwa form. Translating the corpus before and after with the same flags gives 26 503 translated and 26 473 valid in both, with 26 471 of the .spv identical in size and SHA-256; the two that change are the two holding those instructions, and their differences are only the replaced extracts. ps_ops4 and ps_ops6 pass on that gfx1036 iGPU and on an NVIDIA RTX 4090 (driver 32.0.16.2124).
cd68a2e to
a148559
Compare
|
Tested a148559 on Windows 11 with an RTX 4090 (32.0.16.2101) and AMD Radeon Graphics (32.0.21043.5001): the packed-shift checks pass. I translated a hand-written compute listing with all three packed shifts. It uses all 16 combinations of the two source selectors for each instruction. I assembled the translator output with The same inputs also pass on the merge base The focused Python checks passed on CPython 3.14.7: 69 unittest cases across the packed integer, differential and semantic tests, plus 33 pytest cases in I also ran the three tests in AI-assisted. |
|
Tested What I ran:
Code review:
|
Kam471
left a comment
There was a problem hiding this comment.
Ran tests/semantic/test_mutations.py at a148559b on Windows 11 with LLVM_MC set: fails 2 of 3 tests, but both failures are the pre-existing v_mul_legacy_f32 anchor, not this change. The same two failures reproduce on main d0835dd9 with no PR applied:
AssertionError: mutation anchor must occur exactly once:
' elif op == "v_mul_legacy_f32": ... self.emit(f"{r} = OpSelect %float {either} %f0 {m}")'
That anchor still describes the pre-flush v_mul_legacy_f32 block (c82fbe37 moved it), and #3883 / #4527 re-anchor it. The packed-shift mutation this PR does re-anchor is caught (no failure names v_pk_lshlrev_b16), so the translator change itself is consistent. git diff --check clean.
Duplicate: #4461 (Vonsek, opened 01:34) lowers the same three packed shifts with no bit-field extract at all, adds a GPU fixture (cs_w32_pk_shift.asm), a semantic test and its own mutation anchor. git merge-tree refs/remotes/pr/4461 refs/remotes/pr/4622 -> conflict in docs/design.md, tests/semantic/test_mutations.py and tools/rdna2spirv.py. #4461 is the earlier claimant (SHADER-777) and the broader fix; this PR is the smaller high-half-only lower. One of the two should close or drop its overlapping hunk — flagged on #4461 too.
|
APPROVE. One thing to reconcile: No AI-assisted review, no game files, no GPU. |
|
Tested a148559 merged with main d0835dd on WSL2 Ubuntu, Python 3.12.16: pass for the change, one pre-existing red.
|
|
Tested
No game files. Tested and written by Claude (Claude Code), posting from @theswiss24's account. |
|
Tested head
AI-assisted (Devin). |
|
One more point from a second check: nothing pins the value-path fix. The only new check is the shift-amount mutation ( Also, The pre-existing AI-assisted review, no game files, no GPU. |
Coordinated as SHADER-784 in #4571 — the check of
SHADER-777, @Darkz0rz's finding that a packed
v_pk_ashrrev_i16comes back wrong on an AMD gfx1036 with driver25.10.36. The claim and the measurement are posted as
comment 7088898718 and
comment 7089629163 (in #4257, which
moved to #4421 and then to #4571 while I was running them).
What changes
docs/design.md("16-bit high-half reads", #1506) already says that a high 16-bit half is read with>> 16alone,with no
& 0xFFFFand noOpBitFieldSExtract … 0 16after it, because AMD's Windows LLPC drops the shift in thatcombination. The three packed 16-bit shifts were the only place that did it the other way:
v_pk_lshlrev_b16,v_pk_lshrrev_b16andv_pk_ashrrev_i16took the shift amount withOpBitFieldUExtract(s0, 16, 4)and the valuewith
OpBitField{S,U}Extract(s1, 16, 16). They now take a half withOpShiftRightLogical/OpShiftRightArithmeticby 16 (and
& 15for the amount); extracts at offset 0 are untouched, and the arithmetic/logical choice for thevalue is the one the op needs.
How it was confirmed
The driver behaviour is real, and it is driver-version dependent. @Darkz0rz measured, on a gfx1036 with AMD Windows
driver 25.10.36, 5 of 2,000
tools/valu_fuzz.py --family f16 --programs 2000 --seed 1programs wrong in wave32 andnone in native wave64: the high result half came back as the low half of the source, which is the offset taken
mod 16 — the same class as the note already in
tools/rdna2spirv.pyabout Intel's driver.It does not appear on my gfx1036. The same command (
--programs 2000 --seed 1 --wave 32, translator at03b09a08) on the Radeon iGPU of a Ryzen 7 7800X3D, Windows driver 31.0.24002.92:2000/2000 programs that ran match; 0 mismatched, 0 skipped, 0 not translated, 0 harness errors, and 0 skipped meansvk_compute_testpinned32-lane subgroups. It covers the programs the finding names, and I checked that the SPIR-V that run emitted
OpBitFieldSExtract %uint x 0x10 0x10for one of them, so the field-extract form really was compiled there. Thechange is therefore a lowering that survives both drivers, not a value change.
The two forms give the same value. Over 200,010 inputs (0, 1, 0xFFFF, 0x10000, 0x80000000, 0xFFFFFFFF,
0x7FFFFFFF, 0x8000 and 200 000 random):
BitField{S,U}Extract(x, 16, 16)equalsx >> 16with the matchingOpShiftRight{Arithmetic,Logical},BitFieldUExtract(x, 16, 4)equals(x >> 16) & 15, and — left as it was —BitFieldSExtract(x, 0, 16)equalsasr(lshl(x, 16), 16).Counted over the corpus
All 26 503 listings contain 1
v_pk_lshlrev_b16in 1 compute listing (op_sel_hi:[0,1]) and 1v_pk_lshrrev_b16in 1 other (
op_sel:[1,0] op_sel_hi:[0,0]), nov_pk_ashrrev_i16and no_sdwaform; both currently emit anextract at offset 16, so on the affected driver exactly those two compute shaders would be wrong.
Translating all 26 503 listings with the same flags (
--wave64-emulate, 8 shards,--no-asm) — once with mainaa2988cc/03b09a08(the translator is identical between them,git diffis empty), once with this branch — gives26 503 translated and 26 473 passing
spirv-valin both, with the same 30 rejects, and file by file26 471 of the 26 473
.spvidentical in size and SHA-256, withindex.jsonbyte-identical. The 2 that differare the 2 with those instructions. Disassembling them before and after, the only difference is the replaced extract:
in one,
OpBitFieldUExtract %uint x 16 16becomesOpShiftRightLogical %uint x 16(4 bytes shorter); in the other,the amount
OpBitFieldUExtract %uint %uint_8 16 4becomesOpShiftRightLogical %uint %uint_8 16+& 15and everyother step of the two halves is unchanged.
Tested
run_gpu_tests.py --filter ops: 11/12 pass on the gfx1036 iGPU (driver 31.0.24002.92) and 11/12 on an NVIDIARTX 4090 (driver 32.0.16.2124),
ps_ops4andps_ops6(the fixtures withv_pk_lshlrev/lshrrev/ashrrev,including
op_sel:[1,0,0] op_sel_hi:[0,0,0]) 4096/4096 pixels exact on both.cs_wm_half_opsis skipped on bothdevices for the same reason it is before this change (no 64-wide compute subgroup pinned).
python -m unittest discover -s tests/semanticon the branch and, in the same tree with the change stashed, onmain: 7456 tests, 7 failures and 2 errors in both, the same tests (
test_mutations×2 for thev_mul_legacy_f32anchor,test_loop_ballot_barrier×3 failures + 2 errors,test_cmp_class_f64×2),skipped=1,expected failures=1. So this adds no failure and breaks no packed-shift test.tests/test_pk16_diff.py15/15 andtests/semantic/test_alu_pk_int16.py,test_ps_semantics,test_value_semantics,test_negative_controlspass.tests/semantic/test_mutations.pykeeps detecting the"reads the low shift amount for both halves" mutation with its anchor moved to the new code.
tests/test_u16_high_half.py: 32 pass, 1 fail identically before and after —test_d16_buffer_store_no_redundant_extract_after_shr16fails atspirv-valwithOperand '135[%135]' requires a previous definitionon abuffer_store_format_d16fixture, unrelated to this change and reported as a finding.scripts/check_no_game_data.py,tests/semantic/regen_fixtures.py --check,python -m compileall -q make_game.py tools tests: clean.Related, not dependencies
Gen.u16_half/Gen.i16_half, and the packedshifts were the exception. The Intel "offset mod 16" note in
tools/rdna2spirv.pyis the same failure mode onanother vendor.
v_pk_mul_f16result depending on the same AMD driver family.AI-assisted: an agent ran the measurements and wrote the change; the doc row follows from them. GPUs and drivers are
named above.