Skip to content

agx: accept half-register counts in M5 right shifts - #1568

Merged
DjDeveloperr merged 1 commit into
aurora-wipfrom
fix/agx-shift-mask-16bit-count
Dec 3, 2026
Merged

DjDeveloperr merged 1 commit into
aurora-wipfrom
fix/agx-shift-mask-16bit-count

Conversation

@DjDeveloperr

Copy link
Copy Markdown

What: On M5 (G17G, G17S, G17C, G17D) a compute shader with d[i] >> gl_LocalInvocationIndex makes vkCreateComputePipelines fail: "AGX3 binary packer refused bfeil". The shift-mask pass of #1493 drops the & 31 of 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 (base 80a0ac5d0cdd; aurora-wip has 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_tests 1971 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
Evidence

Compiled with each driver's noop shim, every compiled binary hashed, base against head:

set chip compiles changed binaries
GTA V pipelines G17S 32,343 0
GTA V pipelines G17D 16,585 0
GTA V pipelines G16G 86,829 0
GTA V pipelines G17P 86,874 0
GTA V pipelines G13S 64,712 0
GTA V pipelines G18G 11,734 0
600 generated shaders (uniform field decode next to per-invocation shifts) 14 chips 600 each; on G17G/G17S/G17D 351 at base, 600 at head 0 of those that compile at base
600 generated self-checking shifts (>>, <<, signed, extracts, narrow values) 14 chips 600 each; on G17G/G17S/G17D 273 at base, 600 at head 0 of those that compile at base

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 at 662a23a16b50:

  • 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, for ushr only.

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>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners December 3, 2026 03:28

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@DjDeveloperr

Copy link
Copy Markdown
Author

J700 (MacBook Neo, A18 Pro, G17P B1): PASS at 662a23a16b50, no regression

Stock Fedora 44 kernel 7.3.0-41 (feature word 0x0000007a2001fc06), zero reboot, userspace only. Base is the merge base 80a0ac5d0cdd (the same base arm as mesa#1567). Shader cache off, drivers loaded per process, nothing installed.

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.

@DjDeveloperr

Copy link
Copy Markdown
Author

J714s (M5 Pro, T6050, G17S B1, AGX3C, stock 7.3.0-m5-pr67, boot eca1eecc, SLC ON 16 planes, headless) #1568 662a23a16b50a5b1d219f4c30c6f656ba460ff40 vs base 80a0ac5d0cdd997706b16dabb0149c6eede32a95: PASS (shiftcheck 600 shaders 4bb03b36f74e ABBA base/head/head/base: base TOTAL 600 WRONG 0 NOPIPE 327 twice 0 diffs, head TOTAL 600 WRONG 0 NOPIPE 0 twice 0 diffs; dEQP-VK 384-case caselist.txt 9365d76b4188: 384/384 Pass on both arms, 0 diffs; 0 new GPU/kernel faults; DSOs base 0979719ac761, head 8b9e06c58f15).

@DjDeveloperr
DjDeveloperr merged commit d59f5ae into aurora-wip Dec 3, 2026
@DjDeveloperr
DjDeveloperr deleted the fix/agx-shift-mask-16bit-count branch December 3, 2026 04:12
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.

2 participants