Repository navigation
agx: accept half-register counts in M5 right shifts - #1568
Conversation
agx_nir_opt_redundant_shift_masks() drops the mask of a shift count that is already small enough. The count is then often the zero extension of a half, such as gl_LocalInvocationIndex, and copy propagation folds that extension into the shift on M5 (it keeps it on G18G and AGX3B). Left shifts and extracts already take such a count. The plain right shift refused it, so `d >> gl_LocalInvocationIndex` failed to compile with "AGX3 binary packer refused bfeil". The encoding is known. The srl form of the agx3c table takes the count's width in a field of its own, f39, whatever the other operands and the extract width f57 are. Apple's extract of a word by a half count is that instruction with f39 = 1 (agx3_alu_bfeil_m5() in test-agx3-m5-instructions.c), and so is the all-half shift. agx3_alu_srl_reg() already encodes it, so let the packer pass the width on. The packer only takes a form it refused, so no shader that compiled before changes. G18G keeps the widening and the refusal. Fixes: fc22daf ("agx: fold constant-XOR shuffles, enable 16-bit shuffle_xor, and strip redundant late shift masks") Signed-off-by: DjDeveloperr <hey@djdev.me>
RyanTheTide
left a comment
There was a problem hiding this comment.
Reviewed 662a23a. The M5 packer accepts the half-width count and sets its width independently of the shifted value. The existing 32-bit and G18G paths stay equivalent. The reported tests cover both instruction encoding and the shader compilation failure. Hardware execution is pending.
J700 (MacBook Neo, A18 Pro, G17P B1): PASS at
|
| Check | Result |
|---|---|
| 600 shift shaders, base / head / head / base | 600 right, 0 wrong, 0 without a pipeline, on every run |
| CTS, mesa#1567's 384 cases per arm | 384 Pass on both, 0 differences |
| Compiled code of the 600 shaders | byte-identical in both arms (1,200 parts) |
| Health | 0 GPU-side kernel lines, 0 WARN or BUG lines |
What this does and doesn't show: the change is for the M5 only (a right shift by a 16-bit count), and both arms compile identical code on this GPU. So this is a no-regression row: it doesn't exercise the fix. The J714s remains the gate.
|
J714s (M5 Pro, T6050, G17S B1, AGX3C, stock |
What: On M5 (G17G, G17S, G17C, G17D) a compute shader with
d[i] >> gl_LocalInvocationIndexmakesvkCreateComputePipelinesfail: "AGX3 binary packer refused bfeil". The shift-mask pass of #1493 drops the& 31of a count that is already small, copy propagation then hands the shift the 16-bit register the count came from, and the packer took only a 32-bit count there. It now takes both widths, as it already does for left shifts and extracts.Tested: Local only at
662a23a16b50(base80a0ac5d0cdd;aurora-wiphas since gained only #1181, which changes no compiler file), no Mac yet. Assert-enabled x86-64: asahi, poly and vulkan suites 465 ok, 0 failed, 1 skipped, before and after;agx_tests1971 passed before, 1974 after (the three new tests), 1 skipped. All three new tests fail on the base. 600 generated compute shaders: 249 fail to compile on G17G, G17S and G17D before, 0 after; 0 fail on the other 11 chips, before and after.Risk: two-way door · M5 only. The packer only accepts a form it refused, so a shader that compiled before does not change; a shader that failed before runs an encoding that M5 has not run yet from this path.
Not yet: hardware rows: M5 Pro (J714s) runs 600 self-checking shift shaders at base and head; M4 (J773g) and A18 Pro (J700) run them as no-regression.
Details
srlform takes the count's width in its own field:39=1..2, one bit (39[0+1]>4.15), and no predicate ties it to the value's width (f24), the result's width (f10) or the extract width (f57). A plain shift is f57 = 0.test-agx3-m5-instructions.chas Apple's one-bit extract of a word by a half count: the same instruction with f39 = 1 and f57 = 1 (agx3_alu_bfeil_m5()). The all-half shift (f10 = f24 = f39 = 1, f57 = 0) is witnessed too (agx3_alu_shift_reg_g18g()), and Apple's signedint >> inton M5 reads a half count (agx3_alu_asr_reg_m5()).agx3_alu_srl_reg()already encodes the width; the packer passed a constantfalse.agx_optimizer_copyprop()keeps the widening move, so the count stays 32-bit. G18G's packer keeps refusing the mixed widths.fc22dafe903), merged 2026-12-02 02:30 UTC. Before it, the& 31kept the count in a 32-bit register.agx_tests(1976 passed, 1 skipped). agx: legalize unsupported AGX3C operands in the first pass and drop the retry #651, agx: fuse disjoint shifted ior and masked shifts into imadshl_agx #1559, agx: interleave provably disjoint shared-memory stores before workgroup barriers #1560, borealis: give pending timestamp copies carriers where stamps are host-published #1561, agx: add bounded greedy fallback to agx_opt_licm() #1562, asahi: promote loop-weighted M5 select/FMA constants and reuse rodata #1564 and agx: add post-scheduling RA-budgeted dominator-tree CSE for uniform copies #1566 apply on top as they are.Evidence
Compiled with each driver's noop shim, every compiled binary hashed, base against head:
>>,<<, signed, extracts, narrow values)The 14 chips are G13G, G13S, G14G, G15G, G15S, G15C, G16G, G16S, G16C, G17P, G17G, G17S, G17D and G18G. On head no chip refuses any of the 1,200 shaders. The expected results of the self-checking set are right on lavapipe (600 of 600).
Failing on
80a0ac5d0cdd, passing at662a23a16b50:AGX3PackBinary.M5RightShiftReadsHalfCountLikeTheNativeExtract: the extract packs to the witnessed bytes, the shift is refused; with the fix the two differ in f57 only.AGX3PackBinary.M5RightShiftTakesEitherCountWidth: all widths of value, count and result, and that G18G's refusals stay.AGX3SubgroupShuffleXor.ShiftsByStrippedHalfCountsCompile: whole compiles of>>,<<and signed>>on every chip. On the base exactly G17G, G17S, G17C and G17D fail, forushronly.