Skip to content

agx: fuse disjoint shifted ior and masked shifts into imadshl_agx - #1559

Merged
DjDeveloperr merged 4 commits into
aurora-silicon:aurora-wipfrom
IronsideXXVI:j604-agx-bitfield-fuse-disjoint-ior
Dec 3, 2026
Merged

DjDeveloperr merged 4 commits into
aurora-silicon:aurora-wipfrom
IronsideXXVI:j604-agx-bitfield-fuse-disjoint-ior

Conversation

@IronsideXXVI

@IronsideXXVI IronsideXXVI commented Dec 2, 2026 •

Copy link
Copy Markdown

What: Extend agx_nir_opt_bitfield_slices() with a follow-up opt_disjoint_ior_instr() pass (running after adjacent bitfield slice merging completes, with DCE + upper-bound cache reset when slice merging makes progress) to fuse two disjoint 32-bit bit-unpack patterns into imadshl_agx(other, 1, ..., sh) (1 <= sh <= 4):

  1. ior(other, base << k) (or imadshl_agx(0, 1, base, k)) when single-use and known_zero_bits_u32() proves zero overlapping 1-bits ((~kz(other) & (~kz(base) << k)) == 0).
  2. ior(other, iand(ushr(x, s), ((1 << w) - 1) << tz)) when single-use, other is known zero across the mask, and upper-bound analysis (nir_unsigned_upper_bound() + u32_upper_bound()) proves s <= 32 - (tz + w) (non-wrapping shift), folding directly to imadshl_agx(other, 1, ubitfield_extract(x, s + tz, w), tz).

Also teach known_zero_bits_u32() that carry-free unit-multiplier imadshl_agx(a, 1, c, k) preserves the intersection of a's and (c << k)'s known-zero bit masks so chained disjoint shifts continue to fuse.

Tested:

  • Merge with aurora-wip d59f5aee1d9 (head f8a608c0a01), x86-64, clang, asserts on: libvulkan_asahi.so and all compiler tests build; 59 of 59 compiler tests pass, agx_tests 1980 passed / 0 failed / 1 skipped. The built-in kernels this changes are the same 27 (G16G), 27 (G17P) and 29 (G17S), with the same code, as before the merge.
  • J773g (M4) and J700 (A18 Pro) at f5ff0023b6c, before the merge: PASS, see the receipts in the comments.
  • Offline build & Asahi suite atop origin/aurora-wip (cb983a61cb1, head 98547a87cbb, gcc 16.1.1, aarch64, -Dbuildtype=release -Db_ndebug=false): libvulkan_asahi.so built with 0 warnings in touched files; meson test -t 4 --suite asahi 398 Ok / 0 Fail / 1 Skipped; agx_tests 1971 passed / 0 failed / 1 skipped (7/7 *BitfieldSlices*, including value-checked SharedByteOffsets.BitfieldSlicesDisjointIorShlAndShiftedMask and SharedByteOffsets.BitfieldSlicesMergeBeforeDisjointIorFusion).
  • Offline G16G compile diff across all 16 llama-bench pipelines showed q4_K -160 instrs (HOT -6), q6_K -112 instrs (HOT -8), MUL_MAT_VEC -16 instrs (HOT -4), 0:0 spills. (Earlier J604 llama-bench numbers came from a combined build and are not standalone proof for this commit.)

Risk: two-way door · AGX3B and AGX3C (M3, M4, A18 Pro, M5, and M6 through AGX3C) across all shader stages (not compute-only) — agx_nir_opt_bitfield_slices() runs under is_agx3. Carry-free ior -> imadshl_agx replacement and known_zero_bits_u32() propagation are strictly gated on disjoint known-zero bit masks, and the ushr + iand -> ubitfield_extract rewrite is strictly gated on proven non-wrapping shift bounds s + tz + w <= 32 and single-use scalar operands. Running disjoint ior fusion after slice merging guarantees no existing bitfield slice merge is hidden.

Not yet:

  • J773g (M4) and J700 (A18 Pro): CTS for image copy, clear, mipmap and resolve, which run the 27 changed built-in kernels.
  • J714s (M5, AGX3C): CTS subset, gpubench compute.* and one graphics row.
  • llama-bench with a Q6_K model (neither Mac had one).
Offline & unit test details
  • Base: origin/aurora-wip (cb983a61cb1, standalone, zero stacking dependencies)
  • Head: 98547a87cbbe836e43403bab186ed62f484dd76e
  • Files: src/asahi/compiler/agx_nir_lower_shared_bitsize.c, src/asahi/compiler/test/test-shared-byte-offsets.cpp
  • Unit tests:
    • SharedByteOffsets.BitfieldSlicesDisjointIorShlAndShiftedMask: verifies both positive fusions, negative guards (unbounded shift idx and overlapping bit 4), and concrete value equivalence before/after the pass.
    • SharedByteOffsets.BitfieldSlicesMergeBeforeDisjointIorFusion: verifies value equivalence and exact post-DCE ALU counts for all 3-term merge/chain cases (((x & 3) | ((y & 3) << 4)) | (ubfe(x, 2, 2) << 2) -> 3 ALUs, ((x & 3) | ((y & 3) << 2)) | ((z & 3) << 4) -> 5 ALUs, ((x & 15) | ((y & 15) << 4)) | (ubfe(x, 4, 4) << 8) -> 6 ALUs, and a non-slice second term ((x & 3) | ((y & 0x0f0f) << 4)) | (ubfe(x, 2, 2) << 2) -> 3 ALUs).

Extend agx_nir_opt_bitfield_slices() to recognize two common 32-bit
quantized bit-unpack patterns when adjacent slice merging does not apply:

1. Disjoint ior(other, base << k) (including imadshl_agx(0, 1, base, k))
   with 1 <= k <= 4 and a single-use shifted operand: when known-zero-bit
   analysis proves (~known_zero_bits_u32(other) & (~known_zero_bits_u32(base) << k)) == 0,
   bitwise OR has no carries and folds directly into imadshl_agx(other, 1, base, k).

2. Disjoint ior(other, iand(ushr(x, s), ((1 << w) - 1) << tz)) with
   1 <= tz <= 4, single-use inner ops, other known zero across mask, and
   upper-bound analysis proving s <= 32 - (tz + w) (non-wrapping shift):
   folds into imadshl_agx(other, 1, ubitfield_extract(x, s + tz, w), tz),
   removing the separate mask instruction and fusing shift+or.

Add unit test SharedByteOffsets.BitfieldSlicesDisjointIorShlAndShiftedMask
covering both positive fusions and negative guards for unbounded shifts and
overlapping bit positions.

Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
@IronsideXXVI
IronsideXXVI requested review from a team and DjDeveloperr as code owners December 2, 2026 20:52

@DjDeveloperr DjDeveloperr 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.

HOLD at 894f01856237: no hardware row at the head yet, and one case where slices that merge today stop merging. I found no wrong result.

Correctness, checked line by line

  • ior(other, base << k): 1 <= k <= 4, 32-bit scalar, and the known-zero masks must not overlap after the shift, so the OR has no carry and imadshl_agx(other, 1, base, k) gives the same bits. Shift amounts are masked with 31 as NIR does.
  • ior(other, iand(ushr(x, s), mask)): with s <= 32 - (tz + w) and w >= 1, s + tz is at most 31, so the extract offset cannot reach 32. That matters because bfeil does not wrap. iadd cannot overflow.
  • u32_upper_bound() falls back to the full range on every possible wrap, on depth 0 and on 8/64-bit sources. I found no case where it is too low.
  • The GEMM matcher runs after this pass and evaluates imadshl_agx as well as ior (agx_nir_match_gemm.c:68-125), so shared-index expressions still match. I found no other later pass that depends on these 32-bit iors.

Should fix: the fusion runs before the tree has been merged. nir_shader_alu_pass reaches an inner ior before its root. Fusing it there hides its terms from collect_add_or_terms() at the root, and known_zero_bits_u32() returns little for the fused form, so the rest of the chain cannot fuse either. ALU counts after the pass and DCE (scratch unit test on x86-64):

pattern base this head fuse only at the root
(x & 3) | ((y & 3) << 4) | (ubfe(x, 2, 2) << 2) 4 6 3
(x & 3) | ((y & 3) << 2) | ((z & 3) << 4) 7 6 5
(x & 15) | ((y & 15) << 4) | (ubfe(x, 4, 4) << 8) 7 6 7

The last column returns early from step 3 when the only use of the ior is another ior; the existing BitfieldSlices* tests still pass with it. It is not a clean win (third row), so which order you want is your call; I have not pushed anything. The first row is a step back from aurora-wip and should go away either way.

Scope is wider than the text says. is_agx3 here is AGX3B and AGX3C: M3, M4, A18 Pro and M5, in every shader stage, not only compute. Please say so in Risk.

Performance claim. The tok/s figures come from a combined build, so they say nothing about this patch. 3b swaps ushr + iand + ior for iadd + ubfe + imadshl, which is three for three unless the iadd is shared, so it needs its own A/B (base vs head, same boot, policy/mesa-performance-claims.md).

Nits: nir_unsigned_upper_bound() handles ubfe but not ubitfield_extract/imadshl_agx; u32_upper_bound() here and u32_interval() in #1560 are two copies of the same walk, so one shared helper would be better. The new unit test counts opcodes only; a value check would be stronger. This PR and #1560 conflict at the end of test-shared-byte-offsets.cpp, so the second one to land needs a forward merge.

Local check. Merge into 3146ce4726a1 (tree aa7effd07dd8), assert-enabled x86-64: asahi, poly and vulkan suites 464 ok, 0 failed, 1 skipped; agx_tests 1970 passed, 1 skipped. Merges cleanly into the current tip e4346bdb3a55. Commit and sign-off are fine.

Rows owed at the head

  • J773g (M4, G16G B0) or your J604: llama-bench Q4_K_M and Q6_K pp512/tg32, base vs head ABBA, plus gpubench compute.* with CRC match and dEQP-VK.glsl.operators.*, dEQP-VK.spirv_assembly.instruction.compute.*, 0 regressions. Expect parity or better.
  • J714s (M5 Pro, G17S, AGX3C): the same CTS subset, gpubench compute.* and one graphics row, no regression. Required, as the code runs on AGX3C.
  • J700 (A18 Pro, G17P): gpubench compute.* and the CTS subset. Good to have.

…zero bits

Split step 3 (disjoint ior -> imadshl_agx fusion) out of
opt_bitfield_slice_instr() into a separate opt_disjoint_ior_instr() pass
that runs after adjacent bitfield slice merging completes (with DCE and a
cleared upper-bound cache in between when slice merging made progress).
This prevents an inner ior from fusing before its enclosing tree has had
a chance to merge adjacent bitfield slices in collect_add_or_terms(),
fixing the 4 -> 6 ALU regression on
((x & 3) | ((y & 3) << 4)) | (ubfe(x, 2, 2) << 2) and dropping it to 3 ALUs.

Also teach known_zero_bits_u32() that unit-multiplier imadshl_agx(a, 1, c, k)
is carry-free when a and (c << k) have disjoint non-zero bit masks, so
chained disjoint shifts such as ((x & 3) | ((y & 3) << 2)) | ((z & 3) << 4)
fuse both shifts (5 ALUs) while inner-only patterns such as
((x & 15) | ((y & 15) << 4)) | (ubfe(x, 4, 4) << 8) still fuse the inner
shift (6 ALUs).

Add value-equivalence checks to BitfieldSlicesDisjointIorShlAndShiftedMask
and add BitfieldSlicesMergeBeforeDisjointIorFusion covering all four
3-term merge/chain cases.

Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
@IronsideXXVI

Copy link
Copy Markdown
Author

Thanks for the detailed review and for catching the inner-ior ordering regression. Pushed forward commit 98547a87cbb addressing the code and description notes:

  • Merge before fuse + carry-free known_zero_bits_u32(): Split step 3 out of opt_bitfield_slice_instr() into a separate opt_disjoint_ior_instr() pass that runs after adjacent slice merging finishes (with nir_opt_dce() and a cleared ranges cache in between when slice merging made progress), and taught known_zero_bits_u32() that carry-free unit-multiplier imadshl_agx(a, 1, c, k) preserves kz(a) & kz(c << k). Post-DCE ALU counts across all three patterns in your table:
    • (x & 3) | ((y & 3) << 4) | (ubfe(x, 2, 2) << 2): 3 ALUs (fixed 4 -> 6 regression, down to 3)
    • (x & 3) | ((y & 3) << 2) | ((z & 3) << 4): 5 ALUs (both shifts fuse)
    • (x & 15) | ((y & 15) << 4) | (ubfe(x, 4, 4) << 8): 6 ALUs (inner shift still fuses)
  • Unit tests with value checks: Added concrete value-equivalence evaluation before/after the pass to BitfieldSlicesDisjointIorShlAndShiftedMask and added BitfieldSlicesMergeBeforeDisjointIorFusion covering all three patterns above plus a non-slice second term ((x & 3) | ((y & 0x0f0f) << 4) | (ubfe(x, 2, 2) << 2) -> 3 ALUs).
  • Offline verification at 98547a87cbb: libvulkan_asahi.so built cleanly (0 warnings in touched files), agx_tests 1971 passed / 0 failed / 1 skipped (7/7 *BitfieldSlices*), meson test -t 4 --suite asahi 398 Ok / 0 Fail / 1 Skipped.
  • PR description: Updated Risk to cover AGX3B and AGX3C (M3, M4, A18 Pro, M5) across all shader stages, removed the combined-build tok/s claim as standalone evidence, and listed the owed standalone J604 / AGX3C / A18 Pro rows in Not yet.
  • Shared helper / agx: interleave provably disjoint shared-memory stores before workgroup barriers #1560 conflict: Keeping both PRs standalone on aurora-wip for now; once either agx: fuse disjoint shifted ior and masked shifts into imadshl_agx #1559 or agx: interleave provably disjoint shared-memory stores before workgroup barriers #1560 lands, we will forward-merge the second one to unify u32_upper_bound() / u32_interval() into one helper and resolve the end-of-file test conflict.

nir_unsigned_upper_bound() caches by SSA index, and every implementation
numbers its defs from zero. agx_nir_opt_bitfield_slices() used one table
for the whole shader, so a bound found in the main shader could be used
for an unrelated value of the preamble:

- ushr(ishl(x, a), c) lost the truncation of x << a, a wrong value
  (already possible before the disjoint ior fusion);
- the new masked-shift fusion formed a ubitfield_extract whose offset
  reaches 32.

Start every implementation with an empty table, like
agx_nir_lower_address() and agx_nir_lower_bitfield_u2f().

Add a test for it, and one for two overlaps the existing tests do not
reach: a carry inside a unit imadshl_agx, and a masked shift that shares a
bit with the other operand.

Signed-off-by: DjDeveloperr <hey@djdev.me>

@DjDeveloperr DjDeveloperr 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.

Verdict: FINISH, then merge, at f5ff0023b6ca. Only hardware rows are missing; no open code finding.
Blockers: none in the code. Rows owed at this head: J773g (M4, G16G), J700 (A18 Pro, G17P), J714s (M5 Pro, G17S, the only AGX3C row). We are queuing all three on our Macs.

The points from the last review, checked at 98547a87cbbe

  1. Fusing before slices merge: fixed. My three patterns now give 3, 5 and 6 ALU ops (base 4, 7, 7). Compiled for G16G, G17P and G17C, none of 14 fixed shaders gets longer.
  2. Scope, performance text and value checks: fixed. Putting the old order back, or dropping the DCE, makes the new test fail.

One bug, fixed in f5ff0023b6ca (a fix commit on top of yours, nothing rewritten). agx_nir_opt_bitfield_slices() kept one range table for the whole shader, but nir_unsigned_upper_bound() caches by SSA index, and the main shader and the preamble both number from zero. A bound from the main shader was then used in the preamble:

  • ushr(ishl(x, 12), 4) lost its truncation: 0x0fffff00 became 0xffffff00. aurora-wip already has this one;
  • your masked-shift fusion built an extract whose offset reaches 32.

The commit empties the table for each function. It adds a test that fails on 98547a87cbbe, and one for two overlaps your tests did not reach (a carry inside imadshl_agx(a, 1, c, k), and a masked shift that shares a bit with the other operand).

Checked: disjointness, carries, shift and width limits, 16/32-bit bounds; 64-bit values are never matched. 150,000 random shaders with 45,920 fusions: 0 wrong values. AGX3B, AGX3C and, through AGX3C, G18G (M6) compile it, and all three encode the shifted iadd with shifts 1 to 4; AGX2 never sees it. No Apple material, no chip gate, commits and sign-offs fine.

Evidence and notes
  • Merge with aurora-wip 4f2853ac8250 (tree 3b6ab80c6c79), assert-enabled x86-64: asahi, poly and vulkan suites 465 ok, 0 failed, 1 skipped; agx_tests 1975 passed, 1 skipped. It also merges cleanly into 80a0ac5d0cdd.
  • Mutations: 19 changes to the new conditions. The tests or the fuzzer catch all that change a value, except one: u32_upper_bound() ishl without its wrap check survives (nothing generated reaches it; the code reads right). Four others only cost performance or are equivalent.
  • llama MUL_MAT q4_K/q6_K, 35 shaders, offline: 21 change, none longer. G16G 65,675 to 65,174 instructions; G17P 59,722 to 59,222 with soft faults on and 59,017 to 58,547 with them off. Spills equal. With soft faults on, two G17P shaders lose a thread step (768 to 704, 704 to 640), so this still needs timing.
  • GTA V pipelines, base vs head: G16G 23 of 4,429 shorter, 0 longer; G17P 22 shorter, 0 longer; G17S 145 of 26,443 shorter, 12 longer (+4 to +235 instructions; c7a1b8c6400de375 4,572 to 4,666, where I looked, is register copies), net -2,024, threads equal or better; G18G 31 of 12,720 shorter, 0 longer. The fix commit changes none of the G16G and G17S ones.
  • Not blocking: agx_nir_opt_shared_vec2() bounds its index with nir_unsigned_upper_bound(), which knows ior but not imadshl_agx. In a unit test, two shared loads indexed by lo | (hi << k), k 2 to 4, no longer pair after this pass. In a full compile of the same shape they still pair and the shader is one instruction shorter, so I have not seen it cost anything.
  • Not blocking: u32_upper_bound() repeats most of term_upper_bound() in the same file.
  • The CTS group is dEQP-VK.glsl.operator.*; glsl.operators.* (my last review had it wrong too) matches no case. I corrected it in the description and added M6 to Risk.

Rows: base cb983a61cb14, head f5ff0023b6ca, zero reboot. CTS glsl.operator, glsl.builtin.function.{integer,pack_unpack}, spirv_assembly.instruction.compute, spirv_assembly.type.scalar, compute.*shared*, memory_model.shared, image.store, graphicsfuzz (32,965 cases, 0 differences); MUL_MAT q4_K/q6_K against the CPU with instruction counts on both arms; gpubench compute.* ABBA with CRCs. J773g adds llama-bench Q4_K_M and Q6_K ABBA, J700 the MUL_MAT timing, J714s GTA V ABBA.

@DjDeveloperr

DjDeveloperr commented Dec 3, 2026 •

Copy link
Copy Markdown

J773g (Apple M4, T8132, G16G B0 / AGX3B, stock 7.3.0-ARCH-m4main-6c83a2a6, boot_id=bc9fa24e-37f4-4fa0-b91d-31ed138b3356, zero-reboot userspace ICD swap, MESA_SHADER_CACHE_DISABLE=true, VK_LOADER_LAYERS_DISABLE='~implicit~') exact-head A/B at f5ff0023b6caa9a4eb466568dbd547f9640ad7fb (libvulkan_asahi.so SHA-256 a6d18ffdb44c..., git-f5ff0023b6) vs base cb983a61cb14 (31b76f5c888d..., git-cb983a61cb):

Verdict: PASS (correctness, CTS, shaderdb, detlogits, GPUBench CRCs, and 0 faults; timings flat within noise / thermal spread).

  • Loader verification (LD_DEBUG=libs vulkaninfo --summary): both arms verified calling init: on their respective libvulkan_asahi.so, Apple M4 (G16G B0), Borealis.
  • Step 1 — Vulkan CTS (caselist.txt, 32,965 cases, SHA-256 ead522f2..., serial base then head):
    • base: 21,791 Pass / 11,174 NotSupported / 0 Fail
    • head: 21,791 Pass / 11,174 NotSupported / 0 Fail
    • 0 status differences.
  • Step 2 — MUL_MAT correctness + AGX_MESA_DEBUG=shaderdb:
    • test-backend-ops test -o MUL_MAT -p 'type_a=(q4_K|q6_K),' -b Vulkan0: 192/192 passed on both arms (rc=0).
    • shaderdb: 21/35 shaders changed, all 21 shorter (59,900 -> 59,398 total instrs, -502 instrs). Note: 2 shaders trade 1 thread step under soft-faults-on (1273 instrs / 768 threads -> 1256 / 704, and 3152 / 704 -> 3093 / 640).
  • detlogits ABBA (NGEN=64, tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf):
    • All 4 slots (base, head, head, base) bit-exact identical (cmp 0 diffs, SHA-256 5e211a7ac5c34d9ac220db6cd4522441ab5092f008efa34077c6123fdea644cc).
  • Step 3 — Timing ABBA:
    • llama-bench (tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf, -ngl 99 -p 512 -n 32 -r 5, base / head / head / base; no standalone Q6_K GGUF staged on J773g):
      • pp512: base 1225.81 ± 3.21 / 1227.19 ± 4.51 (mean 1226.50 t/s) vs head 1231.25 ± 4.39 / 1222.64 ± 18.97 (mean 1226.95 t/s, +0.04%, flat)
      • tg32: base 114.89 ± 1.19 / 114.74 ± 1.20 (mean 114.82 t/s) vs head 114.57 ± 1.22 / 113.92 ± 1.34 (mean 114.25 t/s, -0.50%, within 1 stddev)
    • test-backend-ops perf -o MUL_MAT -p 'type_a=(q4_K|q6_K),' -b Vulkan0 (ABBA, 46 q4_K + 7 q6_K shapes):
      • q4_K median -0.15%, q6_K median -0.21% (slot 1 base vs slot 2 head were within <0.7% across q4_K and q6_K; slots 3/4 showed transient GPU clock-step excursions on both arms, e.g. q6_K m=4096,n=8: 3889.8 / 3885.6 / 3891.9 / 6477.4 us).
  • Step 4 — gpubench-vk (compute.*, 20 configs / 40 series, ABBA --verify):
    • 40/40 valid: true, 0 deterministic CRC mismatches (compute.light submit-count-seeded CRCs match expected).
    • Median us_per_submit delta range -1.63% (small_disp d=1) to +3.70% (tile16_1080 d=4: base 171.43 / 173.81 us vs head 178.36 / 179.64 us; all other 39 series within -1.63%..+2.07%).
  • Kernel faults/warnings (dmesg delta): 0 (F0=2 -> F1=2).

Follow-up shader check (tile16_1080 and tg32):

  • compute.tile_reduce --param tile=16 --param res=1080p (AGX_MESA_DEBUG=shaderdb,binaries): bit-exact identical on both base (cb983a61cb) and head (f5ff0023b6) — 149 instrs, 65 alu, 1806 code size, 23 gprs, 1024 threads, binary dump SHA-256 fb6809b5f6b9ef588c7873cb682ae6e50830a83cabe53830c2f2416cd6e41239 on both arms (cmp 0 diffs). The +3.70% on tile16_1080 d=4 is not caused by this PR.
  • llama-bench -p 0 -n 32 -r 1 (tg32, AGX_MESA_DEBUG=shaderdb): compiles 14 compute shaders; neither of the two thread-step-losing MUL_MAT shaders (1273/768 -> 1256/704 or 3152/704 -> 3093/640) is used by tg32. Only 1 shader changes in tg32: 588 instrs, 91 gprs, 1024 threads -> 582 instrs, 91 gprs, 1024 threads (shorter, threads unchanged).

@DjDeveloperr

Copy link
Copy Markdown

J700 (MacBook Neo, A18 Pro, G17P B1) at f5ff0023b6ca: PASS after a pre-registered re-run of one GPUBench test, with one gap named below

Stock Fedora 44 kernel 7.3.0-41 (feature word 0x0000007a2001fc06, soft faults off), zero reboot, userspace only. Base is the merge base cb983a61cb14. Both arms are cross-builds with identical options, loaded per process; nothing was installed. SLC on.

What ran

Part Result
CTS, the recipe's 32,965 cases, base then head 32,965 of 32,965 on both arms (22,157 Pass, 10,808 NotSupported), 0 status differences
MUL_MAT q4_K/q6_K against the CPU 192 of 192 OK on both arms, 0 failures
Shaders the pass changes 21 of 35, all shorter, 0 longer: 59,017 → 58,547 instructions, threads unchanged, spills 963 → 963
MUL_MAT perf, 64 rows, 5 samples per arm head/base median 0.9989 (0.9822 to 1.0164), 0 slower and 1 faster than the base spread
llama-bench, TinyLlama Q4_K_M pp512 551.05 → 546.14 tok/s (0.9911, spread 8.24 %), tg32 45.74 → 45.77 tok/s (1.0008, spread 7.69 %)
GPUBench compute.*, 20 configurations, 40 rows 39 rows inside the base spread. light depth 8: 1.0084, 0.84 % slower against a base spread of 0.78 %, so this row fails the kit's bar. All CRCs equal
Kernel log 0 GPU-side lines, 0 WARN, SLC on

The light depth-8 failure, and what followed

  • I fixed the re-run's rule before running it: ten ABBA rounds of light (20 slots per arm) at depths 1, 8 and 32, and the new rounds decide, with the first failure reported. The rule is loose on purpose: the head median must not be above the base by more than the base spread of the pooled windows.
  • Re-run: depth 1 102.30 → 102.70 µs (1.0039, spread 2.80 %), depth 8 16.077 → 15.969 µs (0.9933, spread 4.74 %), depth 32 13.544 → 13.445 µs (0.9927, spread 38 %): PASS at all three. Bootstrap 95 % intervals over the rounds: 1.0008 to 1.0076, 0.9904 to 1.0008, 0.9815 to 0.9960. Depth 1 was slower in 8 of 10 rounds, by about 0.4 %, so a real effect that small can't be excluded.
  • The compiled shaders are identical: all 20 GPUBench configurations compile to byte-identical code in base and head on this GPU (58 shader parts, AGX_MESA_DEBUG=binaries, base repeats itself). So the first failure isn't caused by the compiled shaders. A CPU-side layout effect isn't excluded (the library's .text grew by 608 bytes). The first run's spread came from only two base slots, which misses slot-to-slot drift.

A gap in this row: the PR also changes 27 of the 97 built-in G17P GPU kernels (84,432 → 84,088 bytes, none larger): decompress, fast clear, copy image, mipmap, reset compression metadata and resolve. They are compiled when Mesa is built, so neither the MUL_MAT counts nor the shader dump shows them, and the CTS list above wasn't chosen for them. A small base/head CTS group for image copy, clear, mipmap and resolve is being built for the J700 and the J773g; it isn't in this row.

Not covered: there was no Q6_K model, light at depth 1 is the only depth whose interval sits above 1.0, and the two runs were on the stock kernel only. (Two earlier starts of the second half were stopped and redone; they carry no measurements.)

@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.

The fusion follows slice merging and checks that the shifted operands cannot overlap. The masked path also bounds the full extract within the source word. The per-function range cache prevents a main-shader bound from leaking into the preamble. J773g and J700 receipts are in. The current base has a merge conflict in the range-cache work, so the resolved head needs a fresh read. The G17S row is pending.

Forward-merge origin/aurora-wip (d59f5ae) and resolve the conflict in
src/asahi/compiler/agx_nir_lower_shared_bitsize.c where both branches
introduced per-implementation bitfield_slice_state range tables.

Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
@IronsideXXVI

Copy link
Copy Markdown
Author

Thanks @RyanTheTide for the review/approval and @DjDeveloperr for the J773g/J700 receipts.

Forward-merged origin/aurora-wip (d59f5aee1d9) in f8a608c0a01 (no force-push) and resolved the conflict in src/asahi/compiler/agx_nir_lower_shared_bitsize.c where both branches added per-implementation bitfield_slice_state range tables (2 files changed, 537 insertions(+) vs aurora-wip).

Offline verification at f8a608c0a01:

  • libvulkan_asahi.so + agx_tests: clean build, 0 warnings in touched files
  • agx_tests --gtest_filter="*BitfieldSlices*": 10/10 passed
  • agx_tests: 1980 passed / 0 failed / 1 skipped (NativeFMA.ExactDyadicOracle)
  • meson test -t 4 --suite asahi: 399 Ok / 0 Fail / 1 Skipped

@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.

The merge resolution preserves the reviewed production logic. Comparing the compiler source with the previously reviewed head shows only a blank-line change, and the disjoint fusion uses the shared per-function range cache. The reported exact-head bitfield and compiler suites pass.

@DjDeveloperr

Copy link
Copy Markdown

f8a608c0a016 checked: the merge only brings in aurora-wip, builds, and passes the compiler tests. Nothing pushed by us; the author's merge stands.

  • What the merge changed. From f5ff0023b6ca to f8a608c0a016 the same 42 files change as from cb983a61cb14 to d59f5aee1d9d, no others. Against d59f5aee1d9d only the PR's two files differ. agx_nir_lower_shared_bitsize.c is the file of f5ff0023b6ca minus one blank line: agx: keep range bounds per implementation in two late passes #1567's range-table fix and ours were the same code, so it is kept once. The test file gains agx: keep range bounds per implementation in two late passes #1567's test; both tests stay, as they cover different shifts.
  • Checks (x86-64, clang, asserts on): libvulkan_asahi.so and all compiler tests build, 0 warnings in the compiler file; 59 of 59 compiler tests pass, agx_tests 1980 passed, 0 failed, 1 skipped (NativeFMA.ExactDyadicOracle), all 10 BitfieldSlices* tests pass.
  • Built-in kernels. Old base/head: the drivers that ran the J773g and J700 rows. New base/head: d59f5aee1d9d and a merge that differs from this head only by that blank line. The PR changes the same kernels on both bases, to the same code: 27 on G16G (84,456 to 84,112 bytes), 27 on G17P (84,432 to 84,088), 29 on G17S (99,988 to 99,564). Four others moved with aurora-wip itself, equally in base and head and at the same size: increment_ia_restart, increment_ia_restart_nonnull, tess_isoline, tess_quad (G16G and G17P). I didn't trace which merge moved them.

Rows. The J773g and J700 rows at f5ff0023b6ca tested the same PR code. Runtime shaders (llama, GPUBench, CTS) were not recompiled on the new base, so this comment doesn't prove those rows carry. Owed at f8a608c0a016: the copy, clear, mipmap and resolve CTS group over the 27 built-in kernels on J773g and J700 (base d59f5aee1d9d). J714s (G17S) has no row posted.

@DjDeveloperr

Copy link
Copy Markdown

J773g (Mac16,10, T8132, Apple M4 G16G B0, os-fw 27.2 / 26B123) verification of mesa#1559 built-in kernel CTS group at head f8a608c0a01664eb08253a8d97ecc0a3c4f49728 vs base d59f5aee1d9d8556c1ab32677365a1307a078f19: PASS.

Provenance & custody

  • Host / kernel: J773g stock 7.3.0-ARCH-m4main-6c83a2a6, boot_id=72d2ce11-d81c-4956-803d-95328f7a4f7d (zero-reboot, no driver install, MESA_SHADER_CACHE_DISABLE=true, VK_LOADER_LAYERS_DISABLE='~implicit~', MESA_VK_WSI_HEADLESS_SWAPCHAIN=1).
  • Sealed kit (work/j700-mesa1559-libagx-cts-20261203/, verified unmodified):
    • base ICD (d59f5aee1d9d): libvulkan_asahi.so SHA-256 2dc817937e57862ec9f43bb91871e929c1eb6cbea00208f509f726668279376c
    • head ICD (f8a608c0a016): libvulkan_asahi.so SHA-256 57a7075bfa2cc522b7e5031d28b36059fcb861312bff143b947df510bb02d9cb
    • probe ICD (reachability evidence only): libvulkan_asahi.so SHA-256 cea1f196158bab35b433b9978f97a449608fa1f74fe612349fc89cdd1e2df8b7
  • CTS: /root/m4cts/cts-vk/deqp-vk SHA-256 d3ef839af652df22ee79e3c9746ff43175feb4776ceb40cce94bbbe339ec3c7f; all 37 mustpass source files in cts.json matched byte-for-byte (0 mismatches); lists/caselist.txt (3,027 cases) SHA-256 a6e3dffbc5b5bf4526f34ab051246b8bf312db0ff3115f7c74ecab905930d18a.

1. Built-in kernel CTS group (3,027 cases across c0..c5, interleaved)

Arm Total Pass NotSupported Fail / Crash / Timeout Status diffs vs base
base (d59f5aee1d9d) 3,027 3,003 24 0 —
head (f8a608c0a016) 3,027 3,003 24 0 0

2. Targeted readback tests (base, head, head, base + probe)

All 6 readback tests passed on real Apple M4 (G16G B0) hardware across every slot (rc=0, PASS, 0 differences):

  • msaa_r8_2x: PASS (base/head/head/base + probe) — reaches FAST_CLEAR_0, FAST_CLEAR_5
  • decompress_1x_layered: PASS — reaches AGX3_DECOMPRESS_3, FAST_CLEAR_4, RESET_COMPRESSION_METADATA
  • decompress_2x_layered: PASS — reaches AGX3_DECOMPRESS_4, FAST_CLEAR_3
  • decompress_4x_layered: PASS — reaches AGX3_DECOMPRESS_5, FAST_CLEAR_3, RESET_COMPRESSION_METADATA
  • mip_plain: PASS (7 mip chains: PASS) — reaches MIPMAP_UNORM8X4, MIPMAP_UNORM8X4_ODD
  • resolve_plain: PASS (all 12 2x/4x cases bad bytes 0 max 0, identical CRCs base vs head) — reaches RESOLVE_UNORM8X4

3. Hardware reachability (probe ICD LIBAGX-DISPATCH trace)

  • 24 / 27 changed G16G kernels reached on real J773g hardware (19 via CTS + 5 additional via the readback tests):
    • CTS (19): AGX3_DECOMPRESS_{0,1,2}, COPY_IMAGE, FAST_CLEAR_{0..4,6..8,10..13}, MIPMAP_UNORM8X4, RESET_COMPRESSION_METADATA, RESOLVE_UNORM8X4
    • Test-only (5): AGX3_DECOMPRESS_{3,4,5}, FAST_CLEAR_5, MIPMAP_UNORM8X4_ODD
    • Unreached (3, expected non-Vulkan-reachable): FAST_CLEAR_9, FAST_CLEAR_14, MIPMAP_UNORM8X4_2LEVEL

GPU health

  • 0 new kernel/GPU fault or recovery lines (health: failed 0 errno 0 degraded 0 before and after).

@DjDeveloperr

Copy link
Copy Markdown

J700 (MacBook Neo, A18 Pro, G17P B1) at f8a608c0a016: PASS on the changed built-in kernels

Stock 7.3.0-41, userspace only, zero reboot, one boot (feature word 0x0000007a2001fc06, so soft faults are off), base d59f5aee1d9d (merge base with aurora-wip) against head, the two libvulkan_asahi.so builds differing only in this PR's pass and its test.

Check Result
CTS, 3,027 cases chosen because they launch at least one of the built-in kernels this PR changes 3,027 of 3,027 recorded and Pass on both arms, 0 status differences, 0 head-only failures
The readback tests, each in base, head, head, base order (msaa_r8_2x, decompress_{1,2,4}x_layered, mip_plain, resolve_plain) PASS: exit 0 in all runs, head's output byte-equal to base's
Kernel reach, measured with a probe build: of the 27 changed kernels on G17P, how many run in these cases or tests 24 covered (19 by CTS cases that pass on both arms, 5 only by the readback tests). 3 not reachable from Vulkan here: FAST_CLEAR_9 and FAST_CLEAR_14 (16-byte multisampled images are never compressed) and MIPMAP_UNORM8X4_2LEVEL (only the GL driver launches it)
Size 27 of 97 kernels change, none is larger (84,432 to 84,088 bytes in total)
GPU faults, recoveries, lost devices, kernel WARN/BUG 0

The J773g half of this group (G16G, same case list) is in the lead's receipt: #1559 (comment)

Not covered: the readback tests were built from f5ff0023's sources (unchanged at this head for what they test).

@DjDeveloperr

Copy link
Copy Markdown

J714s (Apple M5 Pro / T6050 / G17S B1) exact-head receipt at f8a608c0a01664eb08253a8d97ecc0a3c4f49728: PASS

  • Host / Kernel: J714s (G17S B1), stock 7.3.0-m5-pr67 (boot 1fc7b819-1f59-42e6-a8ae-65220b717da6, SLC ON 16 planes, zero reboot).
  • Kit: work/j700-mesa1559-libagx-cts-20261203 (lists/caselist.txt SHA-256 a6e3dffbc5b5bf4526f34ab051246b8bf312db0ff3115f7c74ecab905930d18a).
  • Arms:
    • base (d59f5aee1d9d): 2dc817937e57862ec9f43bb91871e929c1eb6cbea00208f509f726668279376c (git-d59f5aee1d)
    • head (f8a608c0a016): 57a7075bfa2cc522b7e5031d28b36059fcb861312bff143b947df510bb02d9cb (git-f8a608c0a0)
    • probe (f8a608c0a016): cea1f196158bab35b433b9978f97a449608fa1f74fe612349fc89cdd1e2df8b7 (git-f8a608c0a0)
  • CTS (3,027 cases, deqp-vk 1.4.7.1, headless WSI, --procs 2, MESA_SHADER_CACHE_DISABLE=1):
    • base: 3,027 / 3,027 Pass (7.94s)
    • head: 3,027 / 3,027 Pass (7.97s)
    • probe: 3,027 / 3,027 Pass (7.96s)
    • Status differences: 0 (base vs head = 0, head vs probe = 0).
  • Readback tests (6/6 PASS across base, head, head, base, probe — 30/30 rc=0):
    • msaa_r8_2x, decompress_1x_layered, decompress_2x_layered, decompress_4x_layered, mip_plain, resolve_plain: all 5/5 rc=0.
  • GPU / kernel fault delta: 0 (before=0, after=0).

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.

3 participants