Skip to content

mesa-aurora: ship Rusticl as opencl-aurora - #3720

Draft
maralcbr wants to merge 4 commits into
masterfrom
mac/opencl-aurora
Draft

maralcbr wants to merge 4 commits into
masterfrom
mac/opencl-aurora

Conversation

@maralcbr

@maralcbr maralcbr commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Omarchy has no OpenCL on Apple Silicon: mesa-aurora builds no Rusticl and nothing ships an ICD, so clGetPlatformIDs returns -1001. This adds opencl-aurora, a split package of mesa-aurora with Rusticl for the asahi Gallium driver. The Mac Lab needs it for its clpeak rows. Arch's opencl-mesa is a different Mesa, so it is not an option.

What changes

  • A third meson build, Rusticl only, for asahi only (no GL, EGL, GLX or Vulkan). At this Mesa, -Dgallium-rusticl=true forces CLC on, and CLC forces SPIRV-Tools on (-Dspirv-tools=disabled is an error). With SPIRV-Tools found, libvtn links it, and libgallium and libvulkan_asahi link libvtn. libRusticlOpenCL links its Gallium driver statically, not through libgallium, so a build of its own keeps SPIRV-Tools, which Arch Linux ARM moves without a versioned soname, out of the GL and Vulkan drivers. mesa-aurora and vulkan-aurora come from the same build as before.
  • -Dstatic-libclc=all: libclc's SPIR-V is linked in, so there is no run-time libclc depend.
  • opencl-aurora ships libRusticlOpenCL.so* and /etc/OpenCL/vendors/rusticl.icd. It depends on mesa-aurora=$epoch:$pkgver-$pkgrel, clang (libclang-cpp; stable's ALARM has no clang-libs), spirv-llvm-translator, spirv-tools, libLLVM.so (makepkg versions it: libLLVM.so=23.1-64), opencl-icd-loader and the libraries it links. It provides opencl-driver and conflicts with opencl-mesa. Nothing installs it: it is not in any meta package's depends.
  • It keeps the pkgbase's groups=('omarchy-platform-apple-silicon'). That group is the Apple platform tag for the pacman platform guard, which optional Apple-only packages such as widevine and fex-emu also carry; it is not an install-all group.
  • check() keeps every old guard on the main build and adds one for Rusticl: the ICD file exists; libRusticlOpenCL is executable (so makepkg versions its libLLVM.so depend), links the same libLLVM.so.<major>.<minor> as libgallium (one LLVM per process), and does not link libgallium. SPIRV-Tools is allowed there and only there.
  • tests/aurora-edge: the recipe tests pinned "no mesa-aurora package links SPIRV-Tools". They keep it for mesa-aurora and vulkan-aurora, check opencl-aurora's depends, provides and conflicts, and cover the new guard (another LLVM, no LLVM, linking libgallium, not executable, no ICD file). Each libgallium case must fail on the libgallium guard, not on the later Rusticl one. This file outside pkgbuilds/ also keeps the PR from merging itself.
  • rebuild_on gains spirv-tools and spirv-llvm-translator, since only opencl-aurora links them and Arch Linux ARM moves SPIRV-Tools without a soname bump. rebuilt_against records the versions this build used (from the CI log).
  • On top of omarchy-pkgs#3783 (Mesa sync to aurora-wip a58f52b53bb1), which brings in aurora-silicon/mesa#906. The pin moves from tag aurora-7.3.0-2 to aurora-7.3.0-3 (26.3.0_devel.20261128.234136.9b08a21bf0f, pkgrel 1), which adds one carry, below. release/owners.json from bin/release-owners mesa-aurora on Arch: only the mesa-aurora line, adding opencl-aurora and opencl-driver. Every rule holds, no approved line.

FP32 compute: the agx-keep-weak-ffma carry

On 7.3 the first push's packages ran OpenCL fp32 about 10× slower than at e705eca (M2 Max 9–10.5 → 1.0–0.31 TFLOPS, M1 Pro 4.6–5.2 → 0.53–0.09); fp16 and bandwidth were unchanged. The cause is aurora-silicon fe376944ae1 (aurora-silicon/mesa#930), which turned the FP32 FMA tininess repair (agx_nir_lower_fma_rte) on for every chip. Rusticl runs nir_opt_algebraic before agx_shader_initialize(), and that pass turns OpenCL mad() (ffma_weak) into a strict ffma, so every mad() took the repair: a branch and about 160 instructions of 64-bit integer code each. clpeak's fp32 kernels grew from about 1.5k to 327k instructions. GL is not affected (no RTE float controls), and Borealis runs the repair before any algebraic pass.

aurora-7.3.0-3 carries our asahi/compiler: keep OpenCL mad() out of the FP32 FMA repair as an ours entry in carry.toml:

 agx_nir_options.float_mul_add32
-  has_ffma | fuse
+  has_ffma | fuse | keep_weak_ffma      # ffma_weak survives the frontend's nir_opt_algebraic

 agx_shader_initialize / hk_preprocess_nir_internal
   agx_nir_lower_fma_rte                 # repairs only strict ffma: fma(), OpFmaKHR
 agx_preprocess_nir_internal
+  agx_nir_lower_ffma_weak               # as nir_opt_algebraic would have: ffma, or fmul+fadd if contractable
 agx_compile_shader_nir_internal
+  agx_nir_lower_ffma_weak               # ffma_weak from later lowering (interpolation, libagx)
 agx_emit_alu
+  case nir_op_ffma_weak: -> ffma

A new NativeFMA.MadSurvivesFrontendAlgebraic test replays Rusticl's order. It is not upstream yet; the entry's upstream field says so.

RUSTICL_ENABLE

Mesa's loader passes the kernel's DRM driver name through unchanged: linux-aurora 7.3 calls it aurora, 7.2 asahi. Rusticl's allowlist (gallium-rusticl-enable-drivers=auto) names only asahi, so at the old pin the GPU was missing on 7.3. aurora-silicon/mesa#906, now in the pin, maps each name to the other in get_enabled_devs. The Apple GPU then shows with no RUSTICL_ENABLE on either kernel, and RUSTICL_ENABLE=asahi (what the lab sets) or =aurora both select it. No environment.d file is packaged.

Proof

7.3, with the carry

m1-pro (M1 Pro, G13S C0, 16 cores, 1296 MHz), kernel 7.3.0-0testedgeC, AC. A local bin/build of this recipe from a single-commit copy of the aurora-7.3.0-3 tree (same tree hash, 657f13e1e80b, so git-e5dba70bb7 in the driver string); check() 277/277 meson tests. Same unpack-and-overlay method as below, nothing installed, host checked clean after. clpeak --single-precision-compute, runs interleaved in one boot:

Build float float2 float4 float8 float16
e705eca (first push, before #930) 4.57 4.83 5.23 5.04 5.05 TFLOPS
aurora-7.3.0-2 (a6853add) 0.53 0.33 0.14 0.12 0.09 TFLOPS
aurora-7.3.0-3 (this pin) 4.57 4.83 5.22 4.47 2.99 TFLOPS
control: a6853add with the repair off on AGX2 4.57 4.83 5.22 4.47 2.99 TFLOPS

The carry removes all of the repair's cost: it matches a build with the repair off. fp16 (4.6–5.2 TFLOPS) and bandwidth (147–177 GB/s) match across e705eca, aurora-7.3.0-2 and this pin. clinfo -l finds the GPU with RUSTICL_ENABLE unset. The float8/float16 gap to e705eca is a separate upstream change between the two Mesa bases (same instruction counts, more registers in some kernels), not FMA-related; it is a follow-up, not this PR. PR CI for this push: build (mesa-aurora, aarch64) passes, packages in its artifacts.

First push

From the first push (Mesa e705eca, kernel 7.2.11).

  • PR CI: build (mesa-aurora, aarch64) passes: Rusticl built, 216/216 meson tests, check() green, all three packages made. self-tests pass.
  • Packages (run 45981742559, artifacts kept until 4 December 2026, 20:40 Brisbane): opencl-aurora (7.7 MB, sha256 ca5ca113…4d644585), mesa-aurora (7.5 MB, 7fade14d…a06ef2), vulkan-aurora (5.1 MB). gh run download 45981742559 -R omacom/omarchy-pkgs -p 'opencl-aurora-*' -p 'mesa-aurora-1*'.
  • Contents: mesa-aurora has no Rusticl or OpenCL file and no library in it links SPIRV-Tools. libRusticlOpenCL NEEDED: libLLVM.so.23.1, libclang-cpp.so.23.1, libLLVMSPIRVLib.so.23.1, libSPIRV-Tools{,-opt,-link}.so, libdrm, libexpat, libz, libzstd, libstdc++, libgcc_s, libm, libc, each covered by a depend. makepkg wrote libLLVM.so=23.1-64.
  • On a Mac, nothing installed: m2-max (M2 Max, kernel 7.2.11, mesa-aurora 20261031 installed) with a local build of this recipe. Both packages plus clinfo, clpeak and spirv-llvm-translator from the stable mirror unpacked under /tmp; run in unshare -m with read-only overlays over /usr and /etc; /tmp cleared after. The host still has no /etc/OpenCL and no libRusticlOpenCL.
    • clinfo -l, no env: Platform #0: rusticl, Device #0: Apple M2 Max (G14C B1). Same with RUSTICL_ENABLE=asahi: OpenCL 3.1, OpenCL C 1.2, 30 compute units, 1398 MHz, driver 26.3.0-devel (git-e705eca833). Not llvmpipe.
    • RUSTICL_ENABLE=asahi clpeak --opencl --global-memory-bandwidth --single-precision-compute: fp32 9.22 / 9.72 / 10.5 / 10.5 / 10.5 TFLOPS (float to float16); global memory bandwidth 323 / 346 / 339 / 342 / 348 GB/s.

Rusticl prints Patched Mesa libclc not detected on start: it is built against Arch's upstream libclc, as Arch's opencl-mesa is. Kernels ran correctly in clpeak; a patched libclc is a later change if it matters.

Omarchy has no OpenCL driver on Apple Silicon. Build Rusticl for asahi in
a meson build of its own, so SPIRV-Tools stays out of libgallium and
libvulkan_asahi, and package it as opencl-aurora.
The recipe tests pinned the old rule that no mesa-aurora package links
SPIRV-Tools. Keep it for mesa-aurora and vulkan-aurora, and cover the new
Rusticl guard in check().
libRusticlOpenCL links both by soname, and neither follows llvm-libs on its
own schedule, so name them as rebuild triggers at the versions this build
used. The libgallium cases of the check() test now fail if the Rusticl
guard is what refused them.

Signed-off-by: Marcelo Alcantara <maralc@gmail.com>
Carries agx-keep-weak-ffma on omacom/mesa: since fe376944ae1 every OpenCL
mad() took the FP32 FMA repair, so fp32 compute ran about 10x slower on
M1 and M2.

Signed-off-by: Marcelo Alcantara <maralc@gmail.com>

This branch has not been deployed

No deployments
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.

1 participant