Skip to content

agx,borealis: share SSBO vectorization, bounded CSE, loop spill room, and canonical minmax across chips - #941

Merged
DjDeveloperr merged 1 commit into
aurora-wipfrom
perf/agx-shared-ssbo-cse-spill-minmax
Nov 24, 2026
Merged

DjDeveloperr merged 1 commit into
aurora-wipfrom
perf/agx-shared-ssbo-cse-spill-minmax

Conversation

@RyanTheTide

Copy link
Copy Markdown

What: Remove qualification-only chip and encoding gates on five pure NIR/AGX-IR optimization passes so M1/M2 (AGX2) and M3/M4 (G15/G16G) share the same Borealis compiler pipeline as G17P and M5: pre-lowering SSBO CSE and vectorization (hk_shader.c, keeping storage_result_select tied to agx_has_soft_fault()), loop live-through spill reservation (agx_spill.c), AGX3B agx_opt_cse_bounded (agx_compile.c), all-chip agx_nir_opt_canonical_minmax (agx_compile.c), and AGX3 agx3_remove_redundant_physical_copies (agx_opt_register_cache.c).

Tested: At exact head 5fc6c67545a8 (arm64 libvulkan_asahi.so sha256 7929e968dabc54c9fc173350557f03fc1ded37c5cc22fb46a577f8984ebeaf68), host meson test --suite asahi passed 258/258 (0 Fail) and exact-head dEQP-VK CTS (b5_compiler_ssbo, 270 cases covering SSBO layout/phys/robustness, FP32 min/max/clamp denorm_flush, loops, switch, selection, compute SSBO + control suite) passed with 0 failures, 0 GPU faults, and 0 new AVCs across J316s (G13X AGX2), J615 (G15G), J713 (G16G), and Neo (G17P regression).

Risk: Two-way door. Scope is pure NIR/AGX-IR optimization passes in src/asahi/vulkan/hk_shader.c, src/asahi/compiler/agx_spill.c, src/asahi/compiler/agx_compile.c, and src/asahi/compiler/agx_opt_register_cache.c; no ABI, UAPI, or hardware descriptor changes.

Not yet: Exact-head mirror CI, independent review, and optional J413 (G14G) confirmation (AGX2 path already covered by J316s G13X; J413 was locked for a Stage 2 boot trial at submission time).

Implementation details and exact-head 4-generation CTS results

Change

  • src/asahi/vulkan/hk_shader.c: drop agx_chip_g17p_or_m5() around pre-lowering SSBO CSE and nir_opt_load_store_vectorize on nir_var_mem_ssbo so adjacent 32-bit SSBO loads/stores vectorize before 64-bit explicit-IO lowering on AGX2, G15, and G16G too. Tie global_loads.storage_result_select to agx_has_soft_fault(&dev->dev) so soft-fault zero-select remains strictly hardware-capability-driven.
  • src/asahi/compiler/agx_spill.c: drop agx_chip_g17p_or_m5() in compute_w_entry_loop_header() so live-through loop register reservation runs across all chips when !ctx->remat_only.
  • src/asahi/compiler/agx_compile.c:
    • Drop key->dev.chip == AGX_CHIP_G17P in the AGX3B CSE branch so G15 and G16G use agx_opt_cse_bounded instead of falling back to agx_opt_cse_pressure.
    • Drop key->dev.encoding == AGX_ISA_ENCODING_AGX3C around agx_nir_opt_canonical_minmax so AGX2 and AGX3B also elide redundant denorm-flush fadd(..., -0.0) after fmin_agx/fmax_agx.
  • src/asahi/compiler/agx_opt_register_cache.c: widen agx3_remove_redundant_physical_copies() from AGX_ISA_ENCODING_AGX3C to agx_isa_is_agx3() so AGX3B fragment shaders also eliminate redundant post-RA register copies.

Testing

Base: origin/aurora-wip 6fa856f3ba3 (ff972ec79174b291) vs Head: 5fc6c67545a8 (7929e968dabc54c9):

  • Host meson test --suite asahi: 258/258 PASS (0 Fail).
  • Live dEQP-VK (b5_compiler_ssbo, 270 cases: ssbo.layout.* 85/85, ssbo.phys.layout.* 20/20, robustness2.*storage_buffer* 23/30, float_controls.fp32.*denorm_flush* 35/35, glsl.loops.* 35/35, glsl.switch.* 20/20, glsl.operator.selection.* 20/20, compute.*ssbo* 20/25; plus 96-case control suite, 95 on J713 fleet85):
Machine (Chip / Kernel) base3 b5_compiler_ssbo b5 b5_compiler_ssbo b5 control Health
J316s (M1 Pro G13X, fleet87) 258/270 Pass, 0 Fail (12 NS) 258/270 Pass, 0 Fail (12 NS) 87/96 Pass, 0 Fail 0 GPU faults, 0 new AVCs, Enforcing, 0 failed units
J615 (M3 Air G15G, fleet85) 258/270 Pass, 0 Fail (12 NS) 258/270 Pass, 0 Fail (12 NS) 96/96 Pass, 0 Fail 0 GPU faults, 0 new AVCs, Enforcing, 0 failed units
J713 (M4 Air G16G, fleet85) 258/270 Pass, 0 Fail (12 NS) 258/270 Pass, 0 Fail (12 NS) 95/95 Pass, 0 Fail 0 GPU faults, 0 new AVCs, Enforcing, 0 failed units
Neo (A18 Pro G17P, fleet87, reg.) 258/270 Pass, 0 Fail (12 NS) 258/270 Pass, 0 Fail (12 NS) 96/96 Pass, 0 Fail 0 GPU faults, 0 new AVCs, Enforcing, 0 failed units

… and canonical minmax across chips

Remove qualification-only chip and encoding gates on five pure NIR/AGX-IR
optimization passes so M1/M2 (AGX2) and M3/M4 (G15/G16G) share the same
compiler pipeline as G17P and M5:

- Run pre-lowering SSBO CSE and nir_opt_load_store_vectorize on
  nir_var_mem_ssbo uniformly across all chips in hk_shader.c, keeping
  storage_result_select tied to the agx_has_soft_fault() hardware capability.
- Enable loop live-through register reservation in agx_spill.c
  (compute_w_entry_loop_header) across all chips.
- Enable agx_opt_cse_bounded across all AGX3B chips (G15/G16G/G17P) instead
  of falling back to agx_opt_cse_pressure on G15/G16G.
- Run agx_nir_opt_canonical_minmax across all chips (AGX2, AGX3B, AGX3C)
  to elide redundant denorm-flush fadds after fmin_agx/fmax_agx.
- Run agx3_remove_redundant_physical_copies across all AGX3 fragment shaders
  (AGX3B and AGX3C).

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide
RyanTheTide requested review from a team and DjDeveloperr as code owners November 24, 2026 12:57

@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 at 5fc6c67545a8

Blockers:

  • Exact-head asahi CI (build-test on 5fc6c67545a8) is still in_progress (run 45399412813); no code blockers. Ready to approve once build-test finishes green.

Checked:

  • §1 No model gating / capability discipline: drops four qualification-only chip/encoding gates (agx_chip_g17p_or_m5, AGX_CHIP_G17P, AGX_ISA_ENCODING_AGX3C) and ties global_loads.storage_result_select to agx_has_soft_fault(&dev->dev) (DRM_ASAHI_FEATURE_SOFT_FAULTS); no new chip or firmware gates introduced.
  • §2 Code correctness across AGX2/AGX3B/AGX3C:
    • src/asahi/vulkan/hk_shader.c: pre-lowering nir_var_mem_ssbo CSE + vectorization preserves robust_modes when SSBO robustness is enabled and keeps hk_ubo_loads_reorderable UBO-only; storage_result_select = agx_has_soft_fault(&dev->dev) uses nir_bounds_agx / nir_bcsel and enables m5_merge_buffer_words only where soft faults are supported, matching existing UBO soft-fault lowering and element-alignment rules.
    • src/asahi/compiler/agx_spill.c: compute_w_entry_loop_header() / loop_room_for_live_through() is pure SSA structured-CF live-through room calculation, guarded by !ctx->remat_only with assert(ctx->nW <= ctx->k) intact.
    • src/asahi/compiler/agx_compile.c: agx_opt_cse_bounded preserves global peak register pressure (pressure[p] + sizes[a] <= peak) and never eliminates block live-outs; agx_opt_cse_pressure stays covered by test-pressure-cse.cpp. agx_nir_opt_canonical_minmax bails on FP32 denorm-preserve mode, proves non-denormal/non-sNaN provenance (failing closed on buffers, unaligned shared accesses, atomics, and NaN constants), and only strips identity fadd(fmin_agx|fmax_agx, -0.0) flushes.
    • src/asahi/compiler/agx_opt_register_cache.c: agx3_remove_redundant_physical_copies() clears tracking on every non-eliminable/non-reorderable/scheduled/destless instruction (including all exec-mask and CF ops), handles overlapping self-copies safely via old_value[], matches AGX3B MOV_IMM / BITOP(UTIL_LUT2(a)) lowering, and runs before postra_liveness recomputes cache/discard hints.
  • §3–§4 Safety, clean-room, authorship: pure NIR/AGX-IR passes, clean-room diff, human author/committer (Ryan Murray) with matching Signed-off-by:.
  • §5–§6 Evidence & naming: exact-head 4-generation CTS matrix (J316s G13X AGX2, J615 G15G, J713 G16G, Neo G17P regression; 0 Fail, 0 GPU faults, 0 new AVCs, 0 failed units) plus 258/258 host asahi suite pass; Borealis naming followed.
Evidence
  • PR state/head verified live: OPEN, MERGEABLE, 5fc6c67545a8a0c8a5497bf8217cee009f6b3087.
  • Exact-head mirror CI (ci/train-pr941 @ 5fc6c67545a8): policy PASS (run 45399413000), asahi build-test in_progress (run 45399412813).
  • Non-blocking doc nits (no change required): stale chip-specific wording remains in comments at src/asahi/compiler/agx_spill.c:1221 (On G17P and M5...), src/asahi/compiler/agx_compile.c:13819-13820 (AGX3B main programs additionally use the pressure-aware CSE...), and src/asahi/vulkan/hk_shader.c:1332 (/* M5: ... */ on m5_merge_buffer_words).

@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: MERGE at 5fc6c67545a8

Blockers: none

Checked:

  • Exact-head DjDeveloperr/mesa mirror CI is now green on 5fc6c67545a8: asahi (45399412813) PASS and aurora-agent-policy (45399413000) PASS.
  • Code, Hard Rule #8 capability gating, 4-generation CTS results (J316s, J615, J713, Neo), 258/258 host tests, and clean-room/attribution checks were verified in the prior review at this exact head.
Evidence

@DjDeveloperr
DjDeveloperr merged commit 387af5e into aurora-wip Nov 24, 2026
@DjDeveloperr

Copy link
Copy Markdown

Merged into aurora-wip after exact-head review approval (258/258 Asahi unit tests + 4-generation live Borealis Vulkan CTS verification across G13X/G15G/G16G/G17P with zero faults) and exact-head CI verification (asahi run 45399412813, aurora-agent-policy run 45399413000).

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verdict at 5fc6c67545a8

APPROVE

Blockers

None.

Checked

  • Code audit (5fc6c67545a8):
    • Removes qualification-only chip/encoding gates across five compiler/runtime passes without introducing any new model/chip gates:
      • src/asahi/vulkan/hk_shader.c: enables pre-lowering SSBO CSE/vectorization across all chips while keeping storage_result_select = agx_has_soft_fault(&dev->dev) capability-driven.
      • src/asahi/compiler/agx_spill.c: removes agx_chip_g17p_or_m5() in compute_w_entry_loop_header(), preserving !ctx->remat_only.
      • src/asahi/compiler/agx_compile.c: enables agx_opt_cse_bounded across all AGX_ISA_ENCODING_AGX3B non-preamble non-vertex shaders, and runs agx_nir_opt_canonical_minmax across all encodings (verified encoding-agnostic in src/asahi/compiler/agx_nir_lower_fminmax.c:366, bailing on FP32 denorm-preserve and failing closed on non-canonical sources).
      • src/asahi/compiler/agx_opt_register_cache.c: widens agx3_remove_redundant_physical_copies() from AGX_ISA_ENCODING_AGX3C to agx_isa_is_agx3() (verified post-RA single-block value-numbering clears on non-eliminable/non-reorderable/scheduled/destless instructions and runs prior to postra_liveness recomputing cache/discard hints).
  • Unit / drm-shim tests (build-b19, -Dbuildtype=debugoptimized, MESA_SHADER_CACHE_DISABLE=1):
    • Full meson test --suite asahi (excluding asahi_layout_tests): 260/260 PASS, 0 failures.
  • Live hardware verification (Apple M5 Max G17C B1, Linux 7.3, Borealis, MESA_SHADER_CACHE_DISABLE=1):
    • Targeted Vulkan CTS (dEQP-VK.ssbo.layout.single_basic_type.std430.*): 303/303 PASS, 0 failures.
    • Kernel GPU faults: 0.
  • Untested scope:
    • Live AGX2 (G13/G14) and AGX3B (G15/G16G/G17P) hardware runs were not executed on this Apple M5 Max (G17C B1, AGX3C) host (covered by author 4-generation hardware receipts and host drm-shim tests).
    • asahi_layout_tests was excluded from the local meson test --suite asahi run.
Evidence
  • Meson asahi suite (non-layout): 260/260 OK (0 fail).
  • Live Vulkan CTS on Apple M5 Max (G17C B1, Linux 7.3, Mesa 26.3.0-devel (git-5fc6c67545), Borealis):
    • dEQP-VK.ssbo.layout.single_basic_type.std430.*: 303/303 PASS (0 fail)
    • dmesg GPU fault check: 0 GPU faults.

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