Skip to content

agx: AGX3 Dynamic Caching: last uses in divergent control flow, no static-split register budget - #603

Merged
DjDeveloperr merged 3 commits into
aurora-wipfrom
djdev/agx3-dynamic-caching
Nov 21, 2026
Merged

DjDeveloperr merged 3 commits into
aurora-wipfrom
djdev/agx3-dynamic-caching

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 21, 2026 •

Copy link
Copy Markdown

Problem

On AGX3 (M3, M4, A18 Pro, M5) no program and no launch declares a register count: on-chip storage is allocated as
threads use it, and a source operand marked as a register's last use releases that register for the whole SIMD-group.
Borealis and the shared AGX compiler still follow the AGX2 static split in two places:

  • Last-use hints stop at divergent control flow. agx_opt_register_cache marks no last use in a divergent block,
    because a masked-off thread may still need the register. Nearly all work in loops and data-dependent branches
    therefore carries none: the large gpubench ray-tracing kernels had last-use hints on 0.4–2.6 % of their register
    sources. Native AGX3 shader output marks last uses on about half of all register sources, inside divergent control
    flow as densely as outside it.
  • The register budget comes from the AGX2 occupancy table. A compute shader with a 1024-thread workgroup gets 104
    halves and spills the rest, and any shader rematerialises constants into a reduced budget to reach a smaller
    occupancy step; when that budget is missed the rematerialising spiller falls back to scratch spills below the file
    limit. AGX3B and AGX3C only need to spill at the register file limit.

Change

  1. agx: keep the values a fused break leaves with live (all chips; the same commit as agx: keep the values a fused break leaves with live #575). agx_opt_break_if
    leaves the exit edge on the emptied then block, so post-RA liveness missed what the loop exit reads at a fused break,
    and that value could get a last-use hint at the break's compare.
  2. agx: mark last uses in divergent control flow on AGX3. A divergent block keeps every register a masked-off thread
    may still read: such a thread waits at a block program order has not reached yet (the target of an edge that jumps
    over this block, or, inside a loop, a block the loop leaves to while the loop runs again). The registers live into
    those pending blocks are the block's inactive set: its writes do not end them and none of its reads is their last
    use. Inactive sets and liveness are solved together to a fixpoint; everything else gets last-use hints as in uniform
    control flow. The divergent-shuffle scratch register (must stay zero in inactive lanes) never gets one. Selected by
    the AGX3 instruction set (both AGX3B and AGX3C); AGX2's hint only discards the register-cache copy and keeps the old
    rule. The g17p_divergent_quad_loop byte pin changes by five single-bit hints in its divergent loop body; with
    divergent last uses off it is byte-identical to the old pin.
  3. agx: drop the static register split's budget on AGX3. Where no register count is declared (AGX3B, AGX3C), the
    budget is the register file alone: no workgroup register bound and no wave-saving rematerialisation. AGX2 and AGX3D
    (which declares its register count per dispatch, registers_16) keep both.

No runtime switch and no chip list; selection follows directly from the instruction-set properties (agx_isa_is_agx3
and emit_agx3d).

Testing

  • Unit tests & CI (meson test --suite asahi, fedora:44 container on head e5441540): 141 pass, 0 fail. Includes
    new unit tests covering divergent if/else sharing a register, a loop's exited-thread register, a reuse no masked
    thread needs, the shuffle scratch, the fused-break exit (fails before commit 1, passes after), and the
    instruction-set selection.
  • Static corpus (G17P drm-shim, 10,982 shaders across shader-db, 14 Minecraft shader packs, vanilla Minecraft,
    gpubench, synthetic Vulkan):
    0 new failures. Across gpubench pipelines plus rt.rays/rt.scene, last-use hints
    increase 36.2 % -> 44.1 % of register sources and 29.0 % -> 39.7 % inside divergent control flow (large RT kernels
    0.4/1.9/2.6 % -> 30.9/25.3/35.4 %), with instructions, registers, and spills unchanged. Dropping the static-split
    budget removed 59 spills / 51 fills -> 0 on a 1024-thread shader-pack compute kernel and 14.7 % of corpus spills
    overall.
  • A18 Pro (J700, G17P / AGX3B) hardware proof (Borealis + GL):
    • CTS (VK-GL-CTS 1.4.7.1, 85,556 cases): 51,872 dEQP-VK cases (reconvergence.* full 6,253/6,253 Pass,
      subgroups, compute, glsl, ray_query, ray_tracing_pipeline, mesh_shader, spirv_assembly,
      memory_model: 31,414 Pass, 20,458 NotSupported) + 33,684 GL/GLES cases (dEQP-GLES3, dEQP-GLES31, KHR-GL46:
      32,160 Pass, 1,504 NotSupported, 17 QualityWarning, 3 CompatibilityWarning) — 0 Fail, 0 Crash, 0 Timeout, 0 GPU
      recoveries, 0 kernel faults, 0 AVC denials, 0 failed units
      .
    • Same-boot A/B performance: regs.group local=1024, n=12 -9.72 % GPU time (3880.1 -> 3503.0 us, 16/16
      CRC-identical) and local=1024, n=44 -9.28 % latency (34388.5 -> 31198.9 us); 103-row gpubench suite
      neutral overall (geomean 1.0020, median 1.0000; 93 win / 4 equal / 4 gap vs macOS 25G83, 1.304x overall).
  • M5 Pro (J714s, G17S B1 / AGX3C) hardware proof (Borealis + GL): 51,872 dEQP-VK cases + 14/14 GL smoke with 0
    regressions
    (all non-pass mesh with_i16 cases reproduced identically on base in 4/4 chunk reps and passed 22/22
    alone on both arms); gpubench B/H/B/H neutral within ±0.5 % across all 8 rows; Geekbench 6.7.1 Vulkan neutral
    (+0.28 %, all workloads within ±0.7 %); 0 kernel GPU errors.
  • M4 Mac mini (J773g, G16G B0 / AGX3B) hardware proof (Borealis): 44,235 / 44,235 dEQP-VK cases identical
    (reconvergence.* full 6,253, sampled subgroups/compute/spirv_assembly 11,756, vk-mustpass-short + vk-smoke
    26,226; 0 diffs, 0 Fail/Crash/Timeout), vulkaninfo 1,417/1,417 identical, 99-row gpubench ABBA neutral (geomean
    0.9976), 0 kernel GPU errors.

Assisted-by: LLM (Antigravity:Gemini 4 Neon)

agx_opt_break_if moves a conditional break into the block after its if,
but the edge to the break target stays on the emptied then block. Post-RA
liveness therefore did not see what the loop exit reads at the break, and
a value read at the exit but last read in the loop by the break's own
compare got a last-use hint there. On AGX3 a last-use hint releases the
register, so every thread taking the break could then read a released
register at the loop exit.

Take the break target's live-in as live at the break itself. A break's
block is not a predecessor of its target, so with fused breaks the
analysis repeats until nothing changes. Only hints that were wrong go
away.

Found while reviewing the G17P last-use change that follows.

Signed-off-by: Diljit Singh <hey@djdev.me>
Divergent blocks got no last-use hints, because another side of the
branch, run later with these threads masked off, may still read the
register. Most of the work in loops and data-dependent branches therefore
carried none: the large gpubench ray-tracing kernels had last-use hints on
0.4 to 2.6% of their register sources. Apple's AGX3 compiler marks last
uses inside divergent control flow as densely as outside it, on about
half of all register sources.

On AGX3 a last-use hint releases the register for the whole SIMD-group:
a wrong one destroys the value. So a divergent block now keeps every
register a masked-off thread may still read. Such a thread waits at a
block that program order has not reached yet: the target of an edge that
jumps over this block or, inside a loop, a block the loop leaves to,
while the loop runs again. The registers live into those pending blocks
are the block's inactive set: its writes do not end them and none of its
reads is their last use. Everything else gets last-use hints as in
uniform control flow. Inactive sets and liveness feed each other and are
solved together; both only grow, so the iteration ends. Blocks outside
divergent control flow keep logical liveness. The pending sets grow with
the square of the block count, so shaders with more than 4096 blocks keep
no divergent hints.

The scratch register agx_lower_divergent_shuffle routes register lane
indices through must read zero in every inactive thread, as the shuffle
adds the index up over the whole quad, so it never gets a hint.

This follows the instruction set: both AGX3 encodings take it. AGX2's hint
only discards the register-cache copy and keeps the old rule.

Over the gpubench pipelines on the G17P drm-shim, last-use hints go from
36% to 44% of register sources, and from 29% to 40% inside divergent
control flow (25 to 35% in the large ray-tracing kernels), with
instructions, registers and spills unchanged. On the full static corpus
(shader-db, Minecraft shader packs, gpubench; 10,982 shaders) no shader
fails that did not before.

Signed-off-by: Diljit Singh <hey@djdev.me>
The register budget of a compute shader comes from the AGX2 occupancy
table, so a 1024-thread workgroup gets 104 halves and spills the rest,
and any shader rematerialises constants into a reduced budget when that
reaches a smaller occupancy step ("save a wave"). When that reduced
budget cannot be met, the rematerialising spiller falls back to scratch
spills below the register file limit.

Both follow from AGX2's static register split: every program declares a
register count and the hardware divides its register file by it. The
AGX3B and AGX3C encodings declare no register count, in the program or
its launch; their on-chip storage is allocated as threads use it. There
is no occupancy step to reach, and Apple's AGX3 compiler only spills at
the register file limit. A 1024-thread workgroup with the whole file runs
correctly there, with its barriers, and faster than one spilling to 104
halves.

So on those encodings the budget is the register file alone: no
workgroup bound and no wave-saving rematerialisation. AGX2 and AGX3D,
which declares its register count per dispatch again, keep both.

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

Copy link
Copy Markdown
Author

M5 Pro (J714s, G17S B1) correctness row

  • Head vs base: e5441540 vs 7ba29572 (merge-base on aurora-wip), native release builds of Borealis (libvulkan_asahi.so) and gallium asahi, same boot on kernel 7.3.0-m5-sship7 (default command line, ASAHI_M5_BRINGUP=1).
  • dEQP-VK (VK-GL-CTS 1.4.7.1, 51,872 cases across two runs):
    • reconvergence.* (full, 6,253) + subgroups (1/4) + compute (1/8) = 26,854 cases: 12,675 Pass, 14,179 Skip, 0 Fail / 0 Crash / 0 Flake.
    • glsl (1/4) + ray_query (1/10) + ray_tracing_pipeline (1/8) + mesh_shader (1/10) + spirv_assembly (1/14) + memory_model (1/8) = 25,018 cases: 10,059 Pass, 14,934 Skip, 1 Crash, 9 Fail, 15 Flake.
      • 3 failures reproduced on 7ba29572 in the immediate base rerun (dEQP-VK.mesh_shader.ext.builtin.cull_distance_mix, dEQP-VK.mesh_shader.ext.pipeline.builtin.shader_objects.cull_distance, dEQP-VK.mesh_shader.ext.misc.many_task_work_groups_y).
      • The remaining 7 dEQP-VK.mesh_shader.ext.in_out.with_i16.permutation_{2,7,10,24,29,33,38}.mesh_only Fails and 15 Flakes were replayed on both arms on a single boot:
        • 4 alternating repetitions per arm of the 400-case chunk containing those cases: identical on every repetition on both e5441540 and 7ba29572 (6 Fail / 152 Pass / 242 Skip, exact same 6 failing cases including the with_i16 cases).
        • 2 alternating repetitions per arm of the 22 disputed cases in isolation: 22/22 Pass on both e5441540 and 7ba29572.
        • The with_i16 failures are pre-existing chunk-context-dependent failures on G17S, not regressions of this PR.
  • GL surfaceless smoke (index-coverage): 14/14 Pass on both arms.
  • Health: GPU liveness (vulkaninfo + compute dispatch) OK before and after; 0 regressions.
  • Performance A/B: A clean gpubench + Geekbench 6.7.1 Vulkan A/B without the preceding pre-existing many_task_work_groups_y watchdog timeout will follow separately.

Assisted-by: LLM (Google:Gemini 4 Neon)

@DjDeveloperr

Copy link
Copy Markdown
Author

M5 Pro (J714s, G17S B1) register-pressure sweep (baseline driver)

Ran a 1M-thread dependent-FMA compute microbenchmark (1 and 2 chains, 4096 steps/thread, N = 0..104 extra values held live across the loop, bit-exact CPU fmaf verification) on M5 Pro (kernel 7.3.0-m5-sship7, baseline Borealis driver vk-aac82bea8e, ASAHI_M5_BRINGUP=1):

  • local=256 (unbounded, 0 spills): throughput stays flat from 71 to 213 GPRs where the AGX2 occupancy table predicts 1024 -> 448 threads:
    • 1 chain: 726.9 GFLOPS at 71 GPRs (N=40), 730.9 at 103 GPRs (N=56), 733.2 at 157 GPRs (N=80), 737.6 at 185 GPRs (N=96), 741.1 GFLOPS at 211 GPRs (N=104, AGX2-predicted 448 threads).
    • 2 chains: 1469.4 GFLOPS at 73 GPRs (N=40), 1451.9 at 131 GPRs (N=64), 1473.5 at 187 GPRs (N=92), 1383.2 GFLOPS at 213 GPRs (N=104).
  • local=1024 (AGX2 workgroup register cap at 104 halves): forces 4:5 up to 60:60 spills:fills starting at N=56 (1 chain) / N=48 (2 chains), dropping throughput nearly 2x (730.9 -> 390.5 GFLOPS for 1 chain; 1477.0 -> 787.7 GFLOPS for 2 chains).

This directly confirms on M5 Pro hardware that AGX3C exhibits dynamic register allocation with no static-split occupancy cliffs up to 213 GPRs, and that the static 104-half workgroup cap causes ~2x throughput regressions via unnecessary spilling.

Assisted-by: LLM (Google:Gemini 4 Neon)

@DjDeveloperr

Copy link
Copy Markdown
Author

M4 Mac mini (J773g, T8132, G16G B0 / AGX3B) hardware A/B row

  • Head vs base: e5441540e7 vs 7ba2957236 (merge-base on aurora-wip), identical release builds of Borealis (libvulkan_asahi.so), same boot on Linux 7.3.0-ARCH-m4drv8, zero kernel GPU faults / submit failures across all 12 runs, zero cooling-limit trips (all timed runs started at PMP die hotspot 60.3–66.5 °C, load 0.31–0.49, fan ~1000 rpm).
  • vulkaninfo (1,417 fields): 0 diffs outside driverInfo and driver/pipeline/shader UUIDs.
  • dEQP-VK (VK-GL-CTS 1.4.7.1, 44,235 cases per arm, --jobs 6):
    • dEQP-VK.reconvergence.* (full, 6,253 cases): 6,249 Pass, 4 NotSupported — 0 diffs, 0 Fail/Crash/Timeout.
    • subgroups (1/10) + compute (1/20) + spirv_assembly (1/20) (11,756 cases): 4,321 Pass, 7,435 NotSupported — 0 diffs, 0 Fail/Crash/Timeout.
    • vk-mustpass-short (87 cases) + vk-smoke (26,153 cases; 26,226 unique cases): 87/87 must-pass Pass; 13,017 Pass, 13,209 NotSupported total — 0 diffs, 0 Fail/Crash/Timeout.
  • gpubench-vk ABBA (base, head, base, head; non-RT chunks core-a,core-b,core-c,multi,feat,mem,tvb, 111 rows):
    • 98 equal, 12 skipped in both arms (multi-queue rows on 1-queue device), 1 flagged worse.
    • Geometric mean head/base (better-adjusted): 0.9976 across the 98 positive-metric rows (0.9704 raw across all 99, skewed solely by a negative near-zero timestamp delta in query kind=timestamp d=16: -0.035 us vs -0.543 us).
    • Single flagged row: render.heavy kind=fill res=1080p d=2 (713.3 vs 728.9 us/submit, -2.19%, noise 0.29%), which oscillates between the same ~713 us and ~729–731 us states seen across d=4..64 (where d=8/16/32 went +1.14–1.16% in head's favor).

Assisted-by: LLM (Gemini:4 Neon)

@DjDeveloperr

Copy link
Copy Markdown
Author

M5 Pro (J714s, G17S B1) Borealis performance A/B row

  • Head vs base: e5441540 vs 7ba29572 (merge-base on aurora-wip), native release builds of Borealis (libvulkan_asahi.so), same boot on kernel 7.3.0-m5-sship7 (default command line, ASAHI_M5_BRINGUP=1), clean run with no preceding CTS timeout.
  • gpubench-vk (B H B H, --runs 3 --run-ms 400, pinned CPU 12): all 8 rows within ±0.5 % (neutral):
    • compute.heavy alu d1: 5084.2 / 5089.5 base vs 5105.6 / 5100.3 head GFLOPS (+0.3 %)
    • compute.heavy alu d4: 7892.0 / 7886.6 base vs 7886.6 / 7892.0 head GFLOPS (0.0 %)
    • compute.heavy bw d1: 206.7 / 206.7 base vs 207.0 / 207.0 head GB/s (+0.2 %)
    • compute.heavy bw d4: 270.4 / 270.8 base vs 270.8 / 270.8 head GB/s (+0.1 %)
    • compute.light d1: 158.0 / 158.1 base vs 158.8 / 158.9 head us (+0.5 %)
    • compute.light d16: 18.87 / 18.87 base vs 18.88 / 19.02 head us (+0.4 %)
    • render.light d1: 175.8 / 176.3 base vs 174.7 / 175.7 head us (-0.5 %)
    • render.light d16: 27.38 / 27.45 base vs 27.39 / 27.47 head us (+0.0 %)
  • Geekbench 6.7.1 Vulkan (H vs B):
    • Head (e5441540): https://browser.geekbench.com/v6/compute/6983329 — 57.00 s workloads (58.8 s wall)
    • Base (7ba29572): https://browser.geekbench.com/v6/compute/6983332 — 56.86 s workloads (58.6 s wall; +0.24 %, every individual workload within ±0.7 %: Background Blur 6.97 vs 6.92 s, Face Detection 6.10 vs 6.15 s, Horizon Detection 8.89 vs 8.86 s, Edge Detection 8.01 vs 7.97 s, Gaussian Blur 8.58 vs 8.55 s, Feature Matching 6.61 vs 6.60 s, Stereo Matching 5.95 vs 5.96 s, Particle Physics 5.89 vs 5.85 s).
    • Earlier offline frame-anatomy capture on the same commits measured 5,118.61 ms head vs 5,218.12 ms base compute GPU time (-1.91 %, 0 spills).
  • Health: GPU liveness (vulkaninfo + compute dispatch) OK before and after; 0 kernel GPU faults/errors.

Assisted-by: LLM (Google:Gemini 4 Neon)

@DjDeveloperr

Copy link
Copy Markdown
Author

M5 Pro (J714s, G17S B1) performance A/B row

  • Head vs base: e5441540 vs 7ba29572, native release builds of Borealis (libvulkan_asahi.so), same boot on kernel 7.3.0-m5-sship7 (default command line, ASAHI_M5_BRINGUP=1), clean run without any preceding CTS watchdog timeout.
  • gpubench (B H B H, --runs 3 --run-ms 400 --timestamps off, 0 regressions):
    • compute.heavy alu d1: base 5084.2 / 5089.5 GFLOPS vs head 5105.6 / 5100.3 GFLOPS (+0.3 %)
    • compute.heavy alu d4: base 7892.0 / 7886.6 GFLOPS vs head 7886.6 / 7892.0 GFLOPS (0.0 %)
    • compute.heavy bw d1: base 206.70 / 206.70 GB/s vs head 207.03 / 207.03 GB/s (+0.2 %)
    • compute.heavy bw d4: base 270.45 / 270.78 GB/s vs head 270.78 / 270.78 GB/s (+0.1 %)
    • compute.light d1: base 157.98 / 158.10 µs vs head 158.79 / 158.92 µs (+0.5 %)
    • compute.light d16: base 18.87 / 18.87 µs vs head 18.88 / 19.02 µs (+0.4 %)
    • render.light d1: base 175.82 / 176.29 µs vs head 174.67 / 175.67 µs (−0.5 %)
    • render.light d16: base 27.38 / 27.45 µs vs head 27.39 / 27.47 µs (0.0 %)
  • Geekbench 6.7.1 Vulkan (same boot, H then B):
    • Head e5441540: https://browser.geekbench.com/v6/compute/6983329 (total wall 58.56 s: Background Blur 6.97 s, Face Detection 6.10 s, Horizon Detection 8.89 s, Edge Detection 8.01 s, Gaussian Blur 8.58 s, Feature Matching 6.61 s, Stereo Matching 5.95 s, Particle Physics 5.89 s)
    • Base 7ba29572: https://browser.geekbench.com/v6/compute/6983332 (total wall 58.40 s: Background Blur 6.92 s, Face Detection 6.15 s, Horizon Detection 8.86 s, Edge Detection 7.97 s, Gaussian Blur 8.55 s, Feature Matching 6.60 s, Stereo Matching 5.96 s, Particle Physics 5.85 s)
    • Delta: +0.28 % wall (every workload within ±0.7 %, neutral within noise).
  • Health: GPU liveness (vulkaninfo + compute dispatch) OK before and after; 0 kernel GPU errors.

Assisted-by: LLM (Google:Gemini 4 Neon)

@DjDeveloperr

Copy link
Copy Markdown
Author

A18 Pro (J700, G17P B1 / AGX3B) hardware proof

All three AGX3 hardware rows (A18 Pro G17P below, M5 Pro G17S above, and M4 mini G16G above) are now complete with 0 regressions across conformance, performance, and kernel health.

1. Conformance (VK-GL-CTS 1.4.7.1, 85,556 cases — 0 Fail / 0 Crash / 0 Timeout)

  • Driver: Borealis (libvulkan_asahi.so) + gallium GL built with the 3 commits of this PR (git-aef3a57010, default behavior), private prefix on default kernel 7.3.0-41.fc44.aurora.aarch64 (boot 48965fbf, no reboot, system driver sha256 unchanged).
  • dEQP-VK (51,872 cases across 9 subsets): 31,414 Pass, 20,458 NotSupported, 0 Fail, 0 Crash, 0 Timeout, 0 GPU recoveries:
    • dEQP-VK.reconvergence.* (full, 6,253): 6,253 Pass
    • subgroups (1/4, 12,156): 6,121 Pass, 6,035 NotSupported
    • compute (1/8, 8,445): 1,579 Pass, 6,866 NotSupported
    • glsl (1/4, 7,100): 5,750 Pass, 1,350 NotSupported
    • ray_query (1/10, 4,936): 3,470 Pass, 1,466 NotSupported
    • ray_tracing_pipeline (1/8, 2,835): 1,714 Pass, 1,121 NotSupported
    • mesh_shader (1/10, 2,807): 2,650 Pass, 157 NotSupported
    • spirv_assembly (1/14, 5,023): 3,401 Pass, 1,622 NotSupported
    • memory_model (1/8, 2,317): 476 Pass, 1,841 NotSupported
  • GL / GLES (33,684 cases across 3 subsets): 32,160 Pass, 1,504 NotSupported, 17 QualityWarning, 3 CompatibilityWarning, 0 Fail, 0 Crash, 0 Timeout, 0 GPU recoveries:
    • dEQP-GLES3 (1/3, 14,808): 14,734 Pass, 60 NotSupported, 11 QualityWarning, 3 CompatibilityWarning
    • dEQP-GLES31 (1/3, 12,499): 12,457 Pass, 36 NotSupported, 6 QualityWarning
    • KHR-GL46 (1/3, 6,377): 4,969 Pass, 1,408 NotSupported
  • Health: GPU liveness (vulkaninfo + compute dispatch + triangle) PASS before and after; 0 kernel GPU faults/warnings/capacity refusals; 0 AVC denials; 0 failed systemd units; private prefixes cleanly removed.

2. Same-boot performance A/B (regs.* probes + 103-row gpubench suite)

  • Driver arms: same-boot A/B on 7.3.0-43 (boot 513ad84b, 0 kernel faults, 0 AVC denials, 0 failed units) comparing shipped base 15fe5010 vs candidate with this PR's 3 commits.
  • regs.* Dynamic Caching probes (16/16 CRC-identical across arms):
    • regs.group local=1024, n=12: -9.72 % GPU time (3880.1 -> 3503.0 us, latency -9.24 %: 4074.8 -> 3698.4 us, zero p5–p95 overlap); disabling the budget change reverts identically to 3880.3 us.
    • regs.group local=1024, n=44: -9.28 % latency (34388.5 -> 31198.9 us, p5 GPU time -8.0 %: 33905 -> 31186 us); disabling the budget change reverts identically to 34427.0 us.
    • Unbounded/low-register invariance checks (regs.wide n=4/12, regs.group local=64/256 n=12): agree within < 0.1 %.
  • gpubench suite (103 matched rows): overall geomean time ratio 1.0020 (median 1.0000); both base and candidate score 93 win / 4 equal / 4 gap vs macOS 25G83 (1.304x overall geomean). Thermal-invariant rows (compute.heavy alu, render.heavy fill 1080p d1) are exact ties (1181.04 vs 1181.04 us, 682.9 vs 683.1 us); small sustained-chunk drifts track fanless chassis temperature (+4..+6 °C between steps).

3. Companion firmware resource-policy experiment (null result)

  • Separately tested raising the G17P per-engine firmware resource-policy target from the 0x60 floor to 0x132 (compute first write) / 0xc9 (tiling) / 0xd0 (fragment) in a same-boot kernel A/B on A18 Pro (45 gpubench rows across compute, fill, rt.rays, and rt.scene, 0 faults, 0 AVC): null result (0.00 % delta on thermal-invariant compute/fill/RT rows, confirming G17P residency on these workloads is not throttled by the 0x60 policy floor, so no kernel change is needed alongside this Mesa PR).

Assisted-by: LLM (Antigravity:Gemini 4 Neon)

@DjDeveloperr
DjDeveloperr marked this pull request as ready for review November 21, 2026 20:17

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

No blockers found. The divergent last-use analysis looks right to me. I have one evidence question and a few small requests.

What I checked in physical_liveness() (src/asahi/compiler/agx_opt_register_cache.c:229), against how agx_compile.c builds the CFG:

  • if/else: threads that go to the else wait at else_block while the then side runs, and threads that finish the then side wait at after_block while the else side runs. Both are covered by the forward-edge rule (blocks strictly between A and T).
  • Loops: the only back edge is the latch's (emit_loop adds only latch -> loop_header, and NIR has no continue here), and the exits are the break edges from body blocks. So every exit target ends up in the tail's pending set, and the loop rule spreads it over header..latch for the following iterations. With nested loops this composes: an inner-loop exit inside the outer loop is skipped by t >= h && t <= l, and an outer exit is spread over the inner loop too.
  • cf_divergent comes from divergent_nesting > 0, so uniform blocks nested in a divergent region also use physical liveness. Blocks outside any divergent region keep logical liveness, which is correct because every thread is there.
  • Writes in a divergent block don't end the inactive set, and the inactive set is added back after each instruction, so a reused register held by masked-off threads keeps no last use. A fused break ORs the target's live-in before its own sources, in both analyses.
  • Shuffle scratch r1 (halves 2..3 on AGX3) never gets a hint while physical liveness is active. The 4096-block cap falls back to no divergent hints, and the free paths have no leaks.
  • The new rules are selected by the instruction-set properties (agx_isa_is_agx3, emit_agx3d), not by a chip list. There is no knob.

Findings:

  1. Evidence on the head (A18 Pro row). The J700 CTS row lists the driver as git-aef3a57010, and the A/B uses base 15fe5010. Neither is e5441540 or its merge-base 7ba29572, which the J773g and J714s rows used. Please confirm that aef3a57010 carries the same src/asahi/compiler tree as e5441540 (an empty git diff e5441540 aef3a57010 -- src/asahi/compiler is enough). Otherwise rerun at least dEQP-VK.reconvergence.* and subgroups on the head. A wrong last-use hint destroys a live value, so the G17P row should be on the exact code.
  2. AGX3D. agx_divergent_last_use() (agx_opt_register_cache.c:378) is true for every AGX3 encoding, so G18G (emit_agx3d) also gets the divergent hints, while agx_has_static_register_split() (agx_register_allocate.c:3030) keeps the static split there. No row covers AGX3D. Either say what shows that the AGX3D last-use hint releases the register the same way, or keep AGX3D on the old rule for divergent blocks until a G18 row exists (&& !ctx->key->dev.emit_agx3d, the same property commit 3 uses).
  3. Compile time. The pending sets are n x n bits and the inactive/liveness fixpoint walks every pending target of every block on each pass, so the large RT kernels pay the most. The corpus run shows no new failures but gives no time. Please add the compile-time delta for the slowest few shaders in the 10,982-shader corpus (head vs base).
  4. Test gap. The loop test is a single loop. One nested-loop case would pin down the propagation step: a thread that has left the outer loop must keep its register while the inner loop runs again, and a register live only into the inner loop's exit must still get its last use after that exit. Both checks are cheap in test-agx-register-cache.cpp.
  5. Commit 1 is the same commit as #575. Please say in whichever lands second that the duplicate was dropped on rebase.

HW rows we can add:

  • Neo (J700, G17P), this head, default kernel command line: dEQP-VK.reconvergence.* (full), dEQP-VK.subgroups.*, dEQP-VK.compute.*, dEQP-VK.glsl.loops.*, dEQP-GLES3.functional.shaders.loops.*, plus regs.group local=1024 n=12/44 A/B vs the merge-base. Pass: 0 Fail/Crash/Timeout vs base, CRC-identical regs.*, 0 GPU recoveries or kernel GPU faults.
  • J616s (M4 Pro, also G17P): the same CTS subsets. Pass: identical to base.
  • M1 Pro or M2 (AGX2; only commit 1 applies): dEQP-VK.glsl.loops.* and dEQP-GLES3.functional.shaders.loops.*. Pass: identical to base.
  • An M3 (G15) row would close the remaining AGX3B family member if one is reachable; it is not required.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr

Copy link
Copy Markdown
Author

Thanks for the review! Answering the verification point and follow-up plan:

  1. Neo G17P build equivalence (aef3a57010 vs PR head e5441540): confirmed directly from git:
    • git diff 5b6a4e2e605d e5441540e732 -- src/asahi/compiler changes only the golden byte pin in src/asahi/compiler/test/test-agx3-graphics-compile.c (0 lines of production compiler code differ).
    • git diff 5b6a4e2e605d aef3a5701048 -- src/asahi/compiler adds only the TEST ONLY AGX_DC_TEST env-var hooks (nodivlu/split/dense/full/base=), all of which short-circuit to false when AGX_DC_TEST is unset (how ab1b arm B and the entire 85,556-case dcv2c1 CTS slot ran).
    • So the Neo G17P ab1b and dcv2c1 runs executed identical compiler codegen to e5441540.
  2. Non-blocking follow-ups (items 2, 3, 4): we will land a clean post-merge follow-up PR covering the emit_agx3d guard/rationale in agx_divergent_last_use(), a nested-loop case in test-agx-register-cache.cpp, and the slowest-shader compile-time delta.
  3. Superseded #575: will close #575 as superseded once #603 merges.

Assisted-by: LLM (Antigravity:Gemini 4 Neon)

@DjDeveloperr
DjDeveloperr merged commit ce4db96 into aurora-wip Nov 21, 2026
@DjDeveloperr

Copy link
Copy Markdown
Author

Merged into aurora-wip as ce4db96e9234fe1f7b88cefa2a601c230ec03ad2 (exact verified tree f9ee8d01bbb3c12d1351ffc2b1aa97c066fdb035).

  • CI on exact head e5441540e732: fork mirror asahi run 44945597747 succeeded (asahi.yml identical to aurora-wip); agent-policy.sh pr passed.
  • Hardware proof: A18 Pro (J700, G17P), M5 Pro (J714s, G17S), and M4 mini (J773g, G16G) rows above all clean with 0 regressions and 0 GPU errors.

Assisted-by: LLM (Google:Gemini 4 Neon)

@DjDeveloperr

Copy link
Copy Markdown
Author

Mirror asahi CI (ci/train-pr603, exact head e5441540e732cb6cf1c9292114de986415e45555): GREEN — https://github.com/DjDeveloperr/mesa/actions/runs/44945597747

RyanTheTide added a commit that referenced this pull request Nov 21, 2026
Resolve the agx_register_allocate.c conflict with #603 (Dynamic Caching):
keep this branch's single agx_ra() (no retry without remat) and #603's
agx_has_static_register_split() condition on the wave-saving remat, so
AGX3B/AGX3C still skip it. Update two comments that still named
agx_ra_impl().

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide
RyanTheTide deleted the djdev/agx3-dynamic-caching branch November 27, 2026 13:20
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