Skip to content

asahi/agx3b: allow 16-bit results and immediate selects with uniform isel comparands - #1619

Merged
DjDeveloperr merged 1 commit into
aurora-silicon:aurora-wipfrom
AxxzyWasTaken:pr/agx3b-isel-uniform-imm
Dec 4, 2026
Merged

DjDeveloperr merged 1 commit into
aurora-silicon:aurora-wipfrom
AxxzyWasTaken:pr/agx3b-isel-uniform-imm

Conversation

@AxxzyWasTaken

Copy link
Copy Markdown

What:
Allow AGX3B explicit isel (ep=25/26/27) to read a single aligned 32-bit uniform comparand (cmp0 or cmp1) beside a 32-bit register with:

  1. 8-bit immediate select arms (imm/imm, reg/imm, imm/reg), and
  2. 16-bit results (both even ep=25 and odd ep=26 destination halves, with 16-bit register or 8-bit immediate select arms).

In agx_lower_uniform_sources.c, keep those uniform comparands in place for both AGX_OPCODE_ICMP and AGX_OPCODE_ICMPSEL on AGX_ISA_ENCODING_AGX3B, and skip agx3_widen_uniform_compare() on AGX3B so 16-bit boolean comparisons stay 16-bit instead of widening to 32-bit registers and inflating GPR pressure. Uniform select arms remain restricted to 32-bit results, and all other refused combinations (two uniform comparands, uniform + immediate comparand, uniform comparand + uniform select, 16-bit comparands, misaligned/high uniforms, and cache/discard hints on uniforms) stay rejected.

Tested:
All tested against base eede989f441 on Apple M4 Max (J616C, G16C B1) and host x86_64 assertions-enabled build (55d92a6631a, compiler binary identical to the silicon-tested build; only test coverage and commit formatting changed after silicon runs):

  • M4 Max silicon bit-exact probes (Apple M4 Max (G16C B1), 0 GPU faults / 0 dmesg errors):
    • 32-bit & boolean isel probe (cmp0_uniform & cmp1_uniform × {imm/imm, reg/imm, imm/reg} + chained 16-bit boolean compares across signed/unsigned conditions and boundary values 0, 1, 0x7fffffff, 0x80000000, 0xffffffff): 1,152 / 1,152 PASS (0 errors).
    • Explicit 16-bit uint16_t isel probe (AGX_MESA_DEBUG=shaders verified emitted ep=25/ep=26 even & odd 16-bit dests, cmp0_uniform & cmp1_uniform, even & odd reg16/reg16, reg16/imm, imm/reg16, imm/imm with 0/99/177/254/255 and cache/discard hints): 256 / 256 PASS (0 errors).
  • M4 Max silicon wall-clock benchmarks (interleaved A/B/B/A, 4×4 = 16 runs per benchmark, private Honeykrisp ICD):
    • Bounds/predicate compute loop (isel_loop_bench.spv, mirroring g2p/nets_quads/leaf_step: 246 → 196 instrs −20.3%, 35 → 25 GPRs, 47 → 0 loop uniform copies, 1024 → 1024 threads, 9 samples × 16 dispatches per run):
      • Base median: 7.2281 ms (8 runs: 7.1855, 7.2108, 7.2553, 7.2706, 7.2880, 7.2454, 7.1947, 7.1872 ms, min 7.1517 ms)
      • Head median: 5.7012 ms (8 runs: 5.6843, 5.6974, 5.7039, 5.7558, 5.6985, 5.7934, 5.7069, 5.6802 ms, min 5.6587 ms)
      • Speedup: −21.12 % (1.268× faster), bit-identical output hash 15d51c610f5f2237 on all 16 runs.
    • Real mg_restrict.spv (441 → 419 instrs −4.99%, 1024 → 1024 threads, 7 samples × 20 dispatches per run): bit-identical output hash ba1f1e8fc15f0f1e on all 16 runs, median 2.212 → 2.186 ms (−1.2%, memory-bound).
  • Offline drm-shim shader-db (88 real compute shaders, 0 occupancy regressions):
    • RW 84 compute shaders on G17P: 72/84 changed, Threads up/down: +0 / −0, total instrs 126,881 → 125,240 (−1,641 / −1.29 %), code size 1,189,834 → 1,183,390 B (−6,444 B), loop uniform copies 1,587 → 1,166 (−421 / −26.53 %). Top reductions: mg_coarsen −16.93%, nets_quads −12.13% (loop ucpy 38→9), sheet_fill −10.07% (GPRs 35→30), leaf_step −8.23% (loop ucpy 24→5), g2p −189 instrs (loop ucpy 90→9).
    • RW 84 compute shaders on G16G: 64/84 changed, Threads up/down: +0 / −0, total instrs 131,842 → 130,366 (−1,476 / −1.12 %), code size −5,940 B, loop uniform copies 1,504 → 1,184 (−320 / −21.28 %).
    • ggml-vulkan mul_mat_vec (4/4 shaders on G17P): 4/4 changed, Threads up/down: +0 / −0, −55 instrs (−0.81 %), −220 B.
  • Host unit tests (-Db_ndebug=false, at exact head 55d92a6631a):
    • agx3_isel_core_test: 251 checks, 0 failures.
    • agx_tests: 2,009 passed, 1 skipped, 0 failed (including updated positive/negative AGX3B uniform-comparand pack, decode, and lowering tests, and preserving M5/AGX3C agx3_widen_uniform_compare coverage).

Risk:
two-way door · scoped strictly to AGX_ISA_ENCODING_AGX3B (encode_explicit() and agx3_isel_uniforms_kept() / agx3_widen_uniform_compare()); M5 (AGX3C/AGX3D) and AGX2 are untouched, and every newly admitted shape was bit-exact verified on G16C B1 silicon.

Not yet:

  • Full Vulkan CTS run on G16G / G17P (targeted 1,408-case silicon probes and real compute shaders verified on M4 Max G16C B1).

…isel comparands

AGX3B explicit isel (ep=25/26/27) already encodes one aligned 32-bit
uniform comparand (f36/f42=3 or f51/f57=3) beside a 32-bit register
with 32-bit register select arms. Silicon verification on Apple M4 Max
(G16C B1) confirms the same uniform-comparand encoding also executes
bit-accurately with 8-bit immediate select arms and with 16-bit results
(both even ep=25 and odd ep=26 destination halves, and even/odd 16-bit
register or 8-bit immediate select arms).

Admit those shapes in agx3_isel_core.c and keep their uniforms in place
in agx_lower_uniform_sources.c for both AGX_OPCODE_ICMP and
AGX_OPCODE_ICMPSEL on AGX3B, while skipping agx3_widen_uniform_compare()
on AGX3B so 16-bit boolean comparisons do not widen to 32-bit registers
and inflate GPR pressure. Uniform select arms remain restricted to
32-bit results, and all other refused combinations (two uniform
comparands, uniform beside immediate comparand, uniform comparand with
uniform select, 16-bit comparands, misaligned/high uniforms, and
cache/discard hints on uniforms) stay rejected.

Signed-off-by: AxxzyWasTaken <axxzytte@gmail.com>
@AxxzyWasTaken
AxxzyWasTaken requested review from a team and DjDeveloperr as code owners December 3, 2026 22:02
@github-actions github-actions Bot added area:compiler Area from CODEOWNERS (bot) blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 3, 2026
@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Merge readiness at 55d92a66: ready to merge

Check Detail
CI at head ok no CI for this change (the hardware row is the gate)
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok in the PR body at 55d92a66
Conflicts ok none
PR text ok Risk: two-way · scoped strictly to AGX_ISA_ENCODING_AGX3B (encode_explicit() and agx3_isel_uniforms_kept() / agx3_widen_uniform_compare()); M5 (AGX3C/AGX3D) and AGX2 are untouched, and every newly admitted shape was bit-exact verified on G16C B1 silicon.

Areas: area:compiler
Merge: gh pr merge 1619 --merge (Owners and Core through the bypass: add --admin).

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

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

Checked at 55d92a6, merged onto aurora-wip 23f7c86 (clean merge, also after mesa#1566's uniform-copy CSE landed).

The code looks right to me:

  • The lowering and the encoder agree. agx3_isel_uniforms_kept() now keeps a uniform comparand only beside a 32-bit register comparand, with select arms that are either registers of the result's width or immediates up to 255. That is exactly what encode_explicit() now accepts. Uniform select arms stay limited to 32-bit results on both sides.
  • An ICMP becomes an ICMPSEL with #1/#0 arms in agx_lower_pseudo(), so keeping its uniform lands on the same encoder form.
  • Anything outside those forms still copies the uniform: immediates above 255, select registers of the other width, 16-bit comparands, high or odd uniforms, and the preamble. So no immediate that doesn't fit can reach the encoder from this path.
  • M5 doesn't change: the M5 path returns before the new code, and only AGX3B skips agx3_widen_uniform_compare().

What I ran (x86 debugoptimized build, assertions on):

  • agx_tests 2,012 pass, 1 skip. agx3_isel_core_test 251 checks, 0 failures. meson test --suite asahi 410 OK, 0 fail, 1 skip.
  • drm-shim compile slice, aurora-wip vs this PR: the 15,641-case wide list (compute, ssbo, robustness, glsl) with each Mac's own feature word, every case covered on each chip. No refused shaders on either side, and no case changed result, on G15S, G16G or G17P.
    • Code changes in 2,215 cases on G15S, 1,638 on G16G and 1,893 on G17P, almost all robustness and compute.
    • Those shaders get 0.3 to 1.0 % smaller in total. None drops to a lower thread count; 10 on G15S and 10 on G16G go up a step.
    • I reran those changed cases A/B on the new tip: same result.
  • shader-db under drm-shim (G16G and G17P with the shim's default feature word):
    • ggml-vulkan, 1,110 compute shaders: instructions −0.67 % (G15S), −0.53 % (G16G), −0.67 % (G17P) on cea627b, and −0.52 / −0.38 / −0.51 % on the new tip, where #1566 already removes some of the same copies. Uniform copies inside loops drop 57 % on G15S and G17P. Threads, spills and fills are unchanged on every chip.
    • GTA V compute, 272 pipelines: −0.28 % (G16G), −0.36 % (G17P), threads unchanged.
  • One thing that looks like a regression but isn't: on G16G, two ggml shaders (four pipelines) grow from 3,499 to 4,062 instructions and from 36 to 40 loops. The register savings bring their 8× unrolled version under 96 halves, so agx_compile_shader_nir_unroll_choice() now keeps it instead of falling back to 4×. They stay at 1,024 threads. That's the unroll rule working as written, so I'm not asking for a change, but it's why G16G's loop-copy count goes up 13 to 14 % while the other chips drop 57 %.

Approving the code. Before it merges it needs CTS rows at this head on our AGX3B Macs. The new forms have only run on G16C (M4 Max), but the encoder change covers the whole AGX3B ISA, so M3 (G15S) and Neo (G17P) code changes too. Kits are sealed for J773g (M4 mini), J700 (Neo) and J516s (M3 Pro). Each runs that chip's changed cases first, then a wide list, and counts refusals and GPU faults.

Small, not blocking: the comment above the admitted shapes in encode_explicit() still says "G17P". The immediate-arm and 16-bit-result forms come from your G16C probes, so it would help to say which chip they were seen on.

@DjDeveloperr

Copy link
Copy Markdown

J516s (MacBook Pro 16-inch M3 Pro, apple,j516s, T6030, G15S B1, kernel 7.3.0-f3822, boot_id=d7cc5a77-dfd1-4371-981c-af9fdcf2de14) zero-reboot Vulkan CTS A/B row for mesa#1619 at head 55d92a6631aeed7571786e730071ba4d93e17b14 (kit work/review-mesa-1609-1619-20261203/kit1619-j516s, KIT.sha256 941743be…, --check PASS):

  • Verdict: PASS — 55,702 cases/arm (28,777 Pass, 26,925 NotSupported, 0 warn, 0 fail, 0 crash, 0 refused on both arms; 0 differing cases; 0 GPU fault/reset/timeout lines; /proc/pid/maps driver check 470/470 ok; 333 s wall).
  • Per-list breakdown (identical on base & head):
    • rt (focus shaders): 875/875 Pass
    • wide: 2,310 Pass / 8,315 NotSupported (10,625)
    • extra: 10,471 Pass / 6,524 NotSupported (16,995)
    • sample: 15,943 Pass / 12,086 NotSupported (28,029)
  • Stack & digests:
    • Arm A (base): aurora-wip 23f7c8697dbc8be4454a8cf1deb6b379bfb4aa1a, tree 8e4289ef5493869bd41ae60b49b12859a5b61e8a, libvulkan_asahi.so a4673636d563…
    • Arm B (head): merge 259b270b0b000169d401bfa7595559d956d949e7, tree bd4ba67e95093cb2584186067cf167291c18ebab, libvulkan_asahi.so 59690798451c…
  • Evidence: work/review-mesa-1609-1619-20261203/kit1619-j516s/out-m3/run.log.

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 4, 2026
@DjDeveloperr

Copy link
Copy Markdown

Hardware row at head 55d92a6631aeed7571786e730071ba4d93e17b14 on J773g (Apple Mac mini M4, G16G B0, 27.2): PASS.

Kit: work/review-mesa-1609-1619-20261203/kit1619-j773g (KIT.sha256 709d8132…, --check PASS).
Kernel: 7.3.0-j773g-w4248 (#1-main, upstream main 89ec99a0, includes linux#4198), Stage 2 1.0.0b19-g06c581d1, boot_id=ba353cdb-b440-4084-90f5-48ffe3fea3cc (fresh unslept boot).
Receipt: work/review-mesa-1609-1619-20261203/kit1619-j773g/out-minihw/summary.txt.

--- RECEIPT mesa#1619 ---
pr head 55d92a6631aeed7571786e730071ba4d93e17b14
arm A base aurora-wip 23f7c8697dbc8be4454a8cf1deb6b379bfb4aa1a tree 8e4289ef5493869bd41ae60b49b12859a5b61e8a lib a4673636d563dfb0fb51271014c3e18fd5b347cbcdd28e084e8ba6b7ed6c0793
arm B head merge 259b270b0b000169d401bfa7595559d956d949e7 tree bd4ba67e95093cb2584186067cf167291c18ebab lib 59690798451cf6bd4863f98cd6523cc56703e8bdcda08ad50f26ca08b7bafaa0
mac Apple Mac mini (M4, 2024) [apple,j773g apple,t8132 apple,arm-platform] kernel 7.3.0-j773g-w4248 boot_id ba353cdb-b440-4084-90f5-48ffe3fea3cc
base: cases 107822 pass 67932 notsupported 39890 warn 0 fail 0 crash 0 refused 0 (all chunks 0)
head: cases 107822 pass 67932 notsupported 39890 warn 0 fail 0 crash 0 refused 0 (all chunks 0)
new fails/refusals on head: 0; cases with a different result: 0
gpu fault/reset/timeout lines in the kernel log during the run: 0
--- END RECEIPT ---
VERDICT PASS mesa#1619 55d92a6631ae on Apple Mac mini (M4, 2024): 107822 cases/arm, 0 differ, 0 new fails, refused base 0 head 0, GPU fault lines 0

@DjDeveloperr

Copy link
Copy Markdown

J700 (MacBook Neo, A18 Pro, G17P B1) at head 55d92a6631ae: PASS, no difference, 0 new fails, 0 refused compiles.

Stock Fedora 44 kernel 7.3.0-41, boot 1045c3da, zero reboot, userspace only. Arm A is aurora-wip 23f7c8697dbc; arm B is this head merged on it (259b270b0b00). (aurora-wip has since moved to 405c0a03 with #1609, an M5-only pass.) Release builds loaded per process through VK_DRIVER_FILES with driconf; every process was checked to load its own arm's library (534 of 534).

cases pass not supported warn fail crash refused/compile-failed
base 60,580 36,983 23,597 0 0 0 0
head 60,580 36,983 23,597 0 0 0 0

0 cases with a different result, 0 cases without a result, and 0 GPU fault, reset or timeout lines in the kernel log during the run.

@DjDeveloperr
DjDeveloperr merged commit 4c04be7 into aurora-silicon:aurora-wip Dec 4, 2026
1 check passed
@DjDeveloperr

Copy link
Copy Markdown

Merged at head 55d92a6631ae as 4c04be716ddc. Hardware rows at that head: J773g (M4, G16) 107,822 cases per arm, and J700 (A18 Pro) 60,580 cases per arm. Both had 0 differ, 0 new fails, 0 refused pipelines and 0 GPU fault lines (#issuecomment-7398271974, #issuecomment-7398458476).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:compiler Area from CODEOWNERS (bot) blast:m5 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants