Skip to content

asahi: enable native AGX3 compute constant programs and persistent compute BOs - #895

Merged
DjDeveloperr merged 1 commit into
aurora-wipfrom
djdev/asahi-agx3-compute-cprog
Nov 24, 2026
Merged

DjDeveloperr merged 1 commit into
aurora-wipfrom
djdev/asahi-agx3-compute-cprog

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 24, 2026 •

Copy link
Copy Markdown

Summary

Brings Gallium Asahi's native AGX3 compute path closer to Borealis:

  • Native AGX3 compute constant programs (agx_chip_native_preamble(), currently G17P only): compiles non-internal native AGX3 compute shaders with agx3_native_cprog + g17p_native_uniforms, gated by agx_g17p_cs_cprog_qualified() with automatic fallback to no-preamble compilation when the launch contract is not met. Emits external constant program and TPS input metadata in agx_g17p_append_compute(), hoisting UBO/SSBO parameter loads out of every compute thread.
  • Persistent compute executable BO (agx3_compute_bo, every agx_chip_native_agx3() chip: G15G/G15S/G15C, G16G, G17P): caches the AGX3 compute code container in a persistent executable BO on agx_compiled_shader instead of reallocating and copying the shader binary into batch->pipeline_pool at a fresh GPU VA on every glDispatchCompute(), preserving USC instruction-cache locality and eliminating per-dispatch copy overhead.
  • Sampler packing is unchanged. An earlier revision rewrote NEAREST mip filtering to AGX_MIP_FILTER_NONE; that was dropped because Borealis never emits it and it broke textureQueryLod on chips without a HAL200 query_lod bank.

Verification

  • git diff --check: clean.
  • Live Apple M4 (G16G B0, 26B123) silicon (measured on the earlier revision adc415a2, which still had the dropped sampler change; G16G gets the persistent compute BO, not compute cprog):
    • gpubench: gl-native compute.heavy alu +3.6%; overall gl-native 70/70 PASS (1.100× vs Metal 4, up from 1.019×); full suite 440/440 PASS (0 faults, 0 bad CRCs).
    • OpenGL CTS:
      • KHR-GL46.compute_shader.*: 42/42 PASS
      • KHR-GL46.texture_query_lod.*: 3/3 PASS

Assisted-by: LLM (Antigravity)

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr

Copy link
Copy Markdown
Author

G17P B1 verification: base 9322511c94e vs head adc415a279480909a04f2b44dac9b6a13bf41b02

  • Machine: MacBook Neo (Apple A18 Pro, G17P B1), kernel 7.3.0-41.fc44.aurora.aarch64.
  • Builds: Mesa cross-built for both arms.
    • base 9322511c94e+0, tarball sha256 d582dadb3c6433eabfb5d2d7ac45fd7fef7b907ce375e459e0c94d56b19b5397
    • head adc415a2794+0, tarball sha256 cdf0c1a1ed4d3de96b89b829b7bd5abc6b409b8cfdf8f589957b2a0dc4d4bdf8
  • Setup: GPU held exclusively for the run, MESA_SHADER_CACHE_DISABLE=true.

gpubench (suite b701a2b, GL on the native asahi driver):

  • Driver selection: EGL_PLATFORM=surfaceless, MESA_LOADER_DRIVER_OVERRIDE=asahi.
  • Arguments: --depths 1 --warmup-ms 100 --runs 3 --run-ms 400.
  • Order: base, head, head, base. Every run passed its CRC check.
test base (µs/submit) head (µs/submit) change
compute.heavy kind=alu 1476.0 / 1470.6 1384.1 / 1384.1 −6.06%
compute.uber kind=divergent 1261.8 / 1261.8 1253.9 / 1257.9 −0.47%
compute.uber kind=uniform 504.4 / 504.4 504.4 / 501.3 −0.31%
compute.light 103.3 / 102.5 102.7 / 102.6 −0.22%
compute.image res=1080p 264.2 / 259.1 263.2 / 264.7 +0.88%
  • compute.heavy and compute.uber divergent: the base and head runs don't overlap.
  • The other three are within run-to-run spread.

GLES 3.1 CTS (aosp gles31-main, EGL pbuffer, head): dEQP-GLES31.functional.compute.*.

  • 194 cases: 194 pass, 0 fail.

Kernel log over the run: 0 new GPU faults, 0 fault-pattern lines.

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

Gemini 4 Neon on @satchlj's behalf.

Reviewed exact head adc415a279480909a04f2b44dac9b6a13bf41b02 with an isolated Gallium Asahi build and runtime verification on J775c (Apple M5 Max / G17C B1, kernel 7.3.0-lobata-j775c+).

Blocking finding

  1. agx_mip_filter_from_sampler_state() drops mip_filter to AGX_MIP_FILTER_NONE on textureQueryLod across G15, AGX2, G18G, and M5 — and does not match Borealis:
    • agx_mip_filter_from_sampler_state() (src/gallium/drivers/asahi/agx_state.c:596-604) rewrites PIPE_TEX_MIPFILTER_NEAREST with min_lod == 0.0f && max_lod == 0.0f && lod_bias == 0.0f to AGX_MIP_FILTER_NONE across all four sampler packing sites (agx_create_sampler_state() at line 697, agx_pack_g17_api_sampler() at lines 6298 and 6327, and agx_native_sampler_state() at line 6356).
    • In agx_upload_samplers(), the textureQueryLod companion bank only restores cfg.mip_filter = agx_mip_filter_from_pipe(sampler->base.min_mip_filter) (agx_state.c:6524-6525) inside the SAMPLER_HAL200 path (agx_chip_sampler_has_lod_bias(dev->chip) — G16G/G17P). Every other chip family retains AGX_MIP_FILTER_NONE for LOD queries:
      • G15 (M3 / Gen4): agx_state.c:6519-6522 takes the !agx_chip_sampler_has_lod_bias(dev->chip) early memcpy(query, ordinary, sampler_length); continue;, copying AGX_MIP_FILTER_NONE straight into the query_lod bank without restoring mip_filter.
      • AGX2 (G13/G14): agx_create_sampler_state() (agx_state.c:697) packs AGX_MIP_FILTER_NONE into so->desc, and AGX2 has no separate query_lod bank (agx_state.c:6595-6626 copies sampler->desc directly).
      • M5 (G17G/G17S/G17C) and G18G: agx_pack_g17_api_sampler() (agx_state.c:6298) packs AGX_MIP_FILTER_NONE into SAMPLER_GEN5, and neither path has a query_lod companion bank (agx_state.c:6537, agx_nir_lower_bindings.c:460).
    • Both the commit message and agx_state.c:593 justify this rewrite as "Match Borealis native sampler packing", but Borealis never emits AGX_MIP_FILTER_NONE (src/asahi/vulkan/hk_sampler.c:69-79,183 maps VK_SAMPLER_MIPMAP_MODE_NEAREST unconditionally to AGX_MIP_FILTER_NEAREST, and src/asahi/vulkan/hk_native_sampler.c:72,93,115 forwards state->mip_filter verbatim).
    • Suggested fix: Either drop the AGX_MIP_FILTER_NONE rewrite (matching Borealis and avoiding textureQueryLod regressions on G15/AGX2/G18G/M5), or restrict it strictly to chips that populate a dedicated query_lod companion bank and also restore agx_mip_filter_from_pipe() in the !agx_chip_sampler_has_lod_bias G15 branch (agx_state.c:6519-6522), leaving AGX2/G18G/M5 untouched.

Non-blocking note

  • The commit message describes native compute constant programs as enabled on G16G/G17P, whereas agx_chip_native_preamble() (AGX_QUIRK_NATIVE_PREAMBLE) is currently G17P-only (src/asahi/lib/tests/test-chip.c:159); persistent agx3_compute_bo applies across all agx_chip_native_agx3() chips (G15G/G15S/G15C/G16G/G17P).
  • Persistent cs->agx3_compute_bo lifetime, BO flags (AGX_BO_EXEC | AGX_BO_LOW_VA), cache sync (agx_bo_assert_range), batch retention (agx_batch_add_bo for both cs->agx3_compute_bo and constant_bo), and teardown (agx_delete_compiled_shader) audited clean.

Verification performed on J775c (M5 Max / G17C B1, 7.3.0-lobata-j775c+, head adc415a279480909a04f2b44dac9b6a13bf41b02)

  • Isolated Gallium build (build-gallium): 1884/1884 (rc=0); verified eglinfo -B loaded OpenGL 4.6 (Core Profile) Mesa 26.3.0-devel (git-adc415a279) / OpenGL ES 3.2 Mesa 26.3.0-devel (git-adc415a279) on Apple M5 Max (G17C B1).
  • Unit tests:
    • meson test -C build-gallium --suite asahi --print-errorlogs: 100/100 PASS (0 fail)
    • src/gallium/drivers/asahi/asahi-native-descriptor: 468 checks passed
  • Runtime CTS (EGL_PLATFORM=surfaceless, --deqp-surface-type=fbo --deqp-surface-width=256 --deqp-surface-height=256, MESA_SHADER_CACHE_DISABLE=1):
    • deqp-gles31 dEQP-GLES31.functional.compute.basic.*: 41/41 PASS (0 fail)
    • deqp-gles31 dEQP-GLES31.functional.compute.shared_var.*: 136/136 PASS (0 fail)
    • deqp-gles31 dEQP-GLES31.functional.compute.indirect_dispatch.*: 18/18 PASS (0 fail)
    • deqp-gles3 dEQP-GLES3.functional.texture.mipmap.2d.basic.nearest_nearest*: 9/9 PASS (0 fail)
    • deqp-gles3 dEQP-GLES3.functional.texture.mipmap.2d.*_lod.*: 8/8 PASS (0 fail)
    • deqp-gles3 dEQP-GLES3.functional.texture.filtering.2d.sizes.*: 36/36 PASS (0 fail)
    • deqp-gles3 dEQP-GLES3.functional.texture.mipmap.2d.base_level.*: 4/4 PASS (0 fail)
  • Kernel log (dmesg): 0 err,crit,alert,emerg entries and 0 GPU faults/timeouts/resets.
  • Untested scope: On J775c (G17C), agx_g17p_append_compute() takes the early if (g17g) branch and agx_chip_native_preamble(G17C) is false, so the G17P compute constant program (cs_cprog) and persistent agx3_compute_bo paths were verified by code audit and host unit tests (100/100), not executed live on G16G/G17P hardware. Empirical textureQueryLod execution on G17C Gallium is also currently blocked by agx3_pack_binary.c:4578 (texture operand gate), so the textureQueryLod sampler defect is established by code inspection.

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

@DjDeveloperr
DjDeveloperr force-pushed the djdev/asahi-agx3-compute-cprog branch from adc415a to 535d252 Compare November 24, 2026 07:34
@DjDeveloperr

Copy link
Copy Markdown
Author

Thanks @satchlj for the review. Both findings are fixed in new head 535d252358e04d1be84f65ed72a3bd471aab0e77, which is also rebased onto aurora-wip aad09f81778b.

1. AGX_MIP_FILTER_NONE rewrite (blocking). I took the first option you suggested and dropped the rewrite.

  • Removed agx_mip_filter_from_sampler_state().
  • All four packing sites are back on agx_mip_filter_from_pipe(state->min_mip_filter): agx_create_sampler_state(), both agx_pack_g17_api_sampler() arms, and agx_native_sampler_state().
  • The HAL200 query_lod restore in agx_upload_samplers() is no longer needed and is gone too.

Sampler packing is now byte-identical to base on every chip, including G13/G14, G15, G16G, G17P, M5 and G18G. That matches Borealis, which maps NEAREST to AGX_MIP_FILTER_NEAREST unconditionally. git diff aurora-wip no longer touches mip_filter.

2. Commit message scope (non-blocking). The commit message, the PR description and the agx_g17p_cs_cprog_qualified() comment now state the real gates:

  • Compute constant programs: agx_chip_native_preamble(), which is G17P only today.
  • Persistent agx3_compute_bo: every agx_chip_native_agx3() chip (G15G/G15S/G15C, G16G, G17P).

No gating changed. The M4 numbers in the description are marked as measured on adc415a2 and as coming from the persistent BO, not cprog.

Checks on 535d2523:

  • git diff --check: clean.
  • agent-policy.sh pr (LOCAL against aurora-wip): clean.
  • Fork mirror CI on DjDeveloperr/mesa ci/m4fix-pr895:

Assisted-by: LLM (Claude:Opus 5.5)

…mpute BOs

Bring Gallium Asahi's native AGX3 compute path closer to Borealis:

- On chips with a native preamble (agx_chip_native_preamble(), currently
  G17P only), compile non-internal compute shaders with a native constant
  program (agx3_native_cprog + g17p_native_uniforms), gated by
  agx_g17p_cs_cprog_qualified() with automatic fallback to no-preamble
  compilation when the launch contract is not met. Emit the external
  constant program and TPS input metadata in agx_g17p_append_compute(),
  hoisting UBO/SSBO parameter loads out of every compute thread.
- On every native AGX3 chip (agx_chip_native_agx3(): G15G/G15S/G15C,
  G16G and G17P), cache the compute code container in a persistent
  executable BO on agx_compiled_shader (agx3_compute_bo) instead of
  reallocating and copying the shader binary into batch->pipeline_pool
  at a fresh GPU VA on every glDispatchCompute(), preserving USC
  instruction-cache locality and eliminating per-dispatch copy overhead.

Signed-off-by: Diljit Singh <hey@djdev.me>
@DjDeveloperr
DjDeveloperr force-pushed the djdev/asahi-agx3-compute-cprog branch from 535d252 to 97b9230 Compare November 24, 2026 07:48
@DjDeveloperr

Copy link
Copy Markdown
Author

I rebased this onto aurora-wip a6b78e14e1d9, now that #893 has merged. The new head is 97b923094b8c7d6d752207574f87f71242de4763.

#895's own changes, including the post-review fix, are unchanged. The only conflict was in agx_state.c, and both sides are kept:

Checks on 97b92309:

  • git diff --check: clean.
  • agent-policy.sh pr: clean.
  • Fork CI on DjDeveloperr/mesa ci/m4fix-pr895:

Assisted-by: LLM (Claude:Opus 5.5)

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

Gemini 4 Neon on @satchlj's behalf.

Re-reviewed exact head 535d252358e04d1be84f65ed72a3bd471aab0e77 (asahi: enable native AGX3 compute constant programs and persistent compute BOs) on J775c (Apple M5 Max, G17C B1, kernel 7.3.0-lobata-j775c+).

Findings

  • The previously flagged AGX_MIP_FILTER_NONE / textureQueryLod commit has been dropped; the PR is now scoped cleanly to the native AGX3 compute constant-program and persistent cs->agx3_compute_bo change in agx_state.c / agx_state.h.
  • Verified agx_g17p_cs_cprog_qualified() gating (agx_chip_native_agx3(dev->chip) && agx_chip_native_preamble(dev->chip)), cs->agx3_compute_bo lifecycle and cleanup in agx_delete_compiled_shader(), shader_bo NULL handling when cs_cprog is active, and batch BO residency (agx_g17p_append_compute() pins cs->agx3_compute_bo, constant_bo / cs->bo, and linked->bo).
  • Note: GitHub currently reports this PR as CONFLICTING against current aurora-wip, so it will need a rebase before landing.

Verification (isolated build, no system Mesa install)

  • Build: ninja -C build-b4 (Gallium Asahi + Borealis Vulkan + Zink + tests) — clean (0 errors).
  • Unit tests: meson test -C build-b4 --suite asahi --print-errorlogs — 165/165 PASS.
  • Runtime sanity (J775c / G17C B1, isolated LIBGL_DRIVERS_PATH / LD_LIBRARY_PATH):
    • eglinfo -B: confirmed Apple M5 Max (G17C B1), OpenGL 4.6 (Core Profile) Mesa 26.3.0-devel (git-535d252358).
    • deqp-gles3 --deqp-case="dEQP-GLES3.functional.fragment_ops.interaction.*": 100/100 PASS.
    • dmesg: 0 GPU faults/hangs/errors.
  • Untested scope: G17P/G16G live compute constant-program execution is not directly exercised on G17C (M5 Max), as agx_chip_native_preamble() is false on M5; verified via code inspection + unit test suite + G17C regression sanity.

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

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

Copy link
Copy Markdown
Author

Merged onto aurora-wip at c9909c9e9120cdbc8a42aeacb912e3022bd3c17a (verified merge tree a8518c7a38c8fef444c4f65fe206765222b07925) after exact-head @satchlj approval (97b923094b8c), fork-mirror asahi CI pass (45350882423, -Db_ndebug=false), and G16G B0 + G17P B1 + G17C B1 hardware verification.

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

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