Skip to content

asahi: keep every M5 colour attachment in the tilebuffer - #948

Merged
RyanTheTide merged 2 commits into
aurora-wipfrom
djdev/asahi-gl-m5-mrt-clear
Nov 24, 2026
Merged

RyanTheTide merged 2 commits into
aurora-wipfrom
djdev/asahi-gl-m5-mrt-clear

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 24, 2026 •

Copy link
Copy Markdown

What: The M5 GL profile drew a framebuffer with two or more colour attachments either one attachment per render pass, or with attachment 0 in the tilebuffer and every fragment loading and storing the others as images, both far slower than the draw. This keeps every attachment of a single-sample layout that fits in the tile resident, with one background and one end-of-tile program built from the shared agx_bg_eot.c shaders in the same argument layout Borealis uses, and passes the tile partitions to the single-sample M5 epilog so masked or partial attachments still compile.

Tested: J714s M5 Pro (G17S B1) on the composed test build git-dba993db23, which carries these two commits (rebased here with context-only changes): dEQP-GLES3.functional.draw_buffers* 76/76 pass, fbo.color.* 302/302 pass, 0 GPU/MMU faults. A 4×RGBA8 1440p render runs 2.16× faster at queue depth 4 (564.33 → 261.78 µs) and 1.82× at depth 1 (706.21 → 388.80 µs). New shim tests pass in mirror CI on this head (links under Evidence).

Risk: two-way · M5 family (G17G, G17S, G17C); the Gallium driver only, single-sample multi-attachment framebuffers.

Not yet: an isolated hardware re-run with only these commits on aurora-wip (the rows above come from the composed build), if reviewers want one; no G17G or G17C row.

Details

1/2 asahi: keep every M5 colour attachment in the tilebuffer. Borealis already keeps all attachments in the tilebuffer on M5: one background program clears or reloads each attachment and one end-of-tile program stores each through its own PBE (hk_build_m5_mrt_bg_eot). Both drivers take those shaders from agx_bg_eot.c, so Gallium only needs their admission and argument layout:

  • agx_g17g_mrt_resident_layout() admits what hk_m5_mrt_layout_supported() does for a single-sample layout: two or more attachments that all fit in the tilebuffer, each with a multi-target end-of-tile store class, in a layout agx_g17p_classify_mrt() names. It reads only the formats and the sample count, so the batch's layout, its epilogs and the framebuffer fetches compiled for it agree.
  • agx_build_native_g17g_mrt_bg_eot() passes the dense PBE table and per-target tile offsets to the end of tile, and the per-attachment clear colours and reload textures to the background.
  • Such a batch lays every attachment out in the tilebuffer, and its draws and clears run once.

Multisampled, layered and other multi-attachment framebuffers keep the previous paths. The single-attachment tile programs are unchanged; their Ioto program tail and reload sampler move into helpers the multi-target programs share.

2/2 asahi: give a resident M5 multi-target epilog its tile partitions. The compiler orders a fragment epilog's tile stores and picks their pixel classes from the framebuffer's tile partitions in the epilog key (agx_compile_nir_tile). Only the multisample epilog builder passed that key. That works while the epilog stores the attachment at byte 0 of the tile, but on M5 a masked attachment keeps its contents through a tile load/store pair (preserve_zero_mask), and when the byte-0 attachment is not stored (for example a clear through a quad of another attachment) the ordering pass declined and the packer refused the whole fragment program. Indexed draw-buffer conformance tests with mixed integer formats then dropped their draws (4 of 76 failed with 1/2 alone). The single-sample M5 epilog now gets the key too; the attachment-0-only epilog (rt0_resident) has a single partition and is unchanged, as are the other chips.

Tests (no-op DRM shim, asahi suite). asahi-{g17s,g17s-kernel}-m5-mrt-resident:

  • four RGBA8 attachments on G17S: the resident layout and offsets, a single draw into one batch, all background / end-of-tile / partial-render programs build, and the end of tile is the native multi-target store;
  • eight slots of mixed integer and normalized formats with two empty slots: a clear through a quad of each attachment (one channel and all channels) and draws under partial and full colour masks must all link (refused without 2/2);
  • g17s-kernel passes every submission through the M5 kernel's checks and fails on a refused one.

No runtime switches, environment variables or new chip gates; admission uses the existing agx_chip_g17_m5().

Evidence
  • Commits on aurora-wip 387af5e6a02 (Merge agx,borealis: share SSBO vectorization, bounded CSE, loop spill room, and canonical minmax across chips #941):
    • 644036a4928 asahi: keep every M5 colour attachment in the tilebuffer (clean cherry-pick)
    • c9396a6f5c02dc9b180921eac8f168880279d68f asahi: give a resident M5 multi-target epilog its tile partitions
  • Rebase note: aurora-wip moved the compile_samples block of agx_build_meta_shader_internal() into agx_prepare_meta_nir(). 2/2 keeps that and adds only its epilog-key selection, passed to agx_compile_nir_tile(). git range-diff against the tested commits shows context-only differences in both commits; the added code is identical.
  • Mirror CI (DjDeveloperr/mesa, temporary branch, exact commit c9396a6f5c0):
    • asahi (build plus the asahi test suite): run 45404046369 success, 269 OK / 0 fail, including asahi-g17s-m5-mrt-resident and asahi-g17s-kernel-m5-mrt-resident
    • aurora-agent-policy: run 45404046168 success
  • On the current aurora-wip tip: these commits rebase onto 0e7919d41cf (Merge borealis,asahi: enable hardware indirect index bounds on G17P #760) without conflicts (git range-diff: all =) as 60bbebbe707, and merge cleanly into the newer f9b9a5435cf. asahi there: run 45416655413, 277 OK / 1 fail. The one failure, asahi-agx-chip-caps (2 of 366 checks, AGX_CAP_NATIVE_PREAMBLE on G16G and AGX_CAP_VDM_INDIRECT_INDEX_BOUNDS on G17P), fails identically on 0e7919d41cf alone (run 45418268129); no file of this PR is involved.

Hardware: Apple M5 Pro (J714s, G17S B1, AGX3C)

GLES3 CTS (deqp-runner, deqp-gles3, -j 4, pbuffer 256×256, rgba8888d24s8ms0):

Suite Total Before 1/2 only This PR GPU/MMU faults
dEQP-GLES3.functional.draw_buffers* 76 76 / 0 72 / 4 76 / 0 0
dEQP-GLES3.functional.fbo.color.* 302 302 / 0 302 / 0 302 / 0 0

Four RGBA8 render targets at 2560×1440 (bandwidth microbenchmark, MESA_SHADER_CACHE_DISABLE=1, status ok, 0 stderr errors):

Queue depth Before This PR Speedup
1 706.21 µs 388.80 µs 1.82×
4 564.33 µs 261.78 µs (≈620 GB/s) 2.16×

A 70-row GL microbenchmark suite on the same build: 70/70 ok, 0 Mesa stderr lines, 0 kernel faults or warnings.

The M5 profile drew a framebuffer with more than one colour attachment
either an attachment at a time, each pass a render of its own that
reloads and stores the depth attachment, or in one pass that keeps
attachment 0 in the tilebuffer and has every fragment load and store the
other attachments as images. Both cost far more than the draw: a render
of four RGBA8 attachments ran at a third of the speed Borealis reaches on
the same M5 for the same work.

Borealis keeps all of them in the tilebuffer: one background program
clears or reloads each attachment and one end-of-tile program stores
each through its own PBE (hk_build_m5_mrt_bg_eot). Both drivers take
those shaders from agx_bg_eot.c, so Gallium only needs their admission
and argument layout:

 - agx_g17g_mrt_resident_layout admits what hk_m5_mrt_layout_supported
   does for a single-sample layout: two or more attachments that all fit
   in the tilebuffer, each with a multi-target end-of-tile store class,
   in a layout agx_g17p_classify_mrt names. It reads only the formats and
   the sample count, so the batch's layout, its epilogs and the
   framebuffer fetches compiled for it agree.
 - agx_build_native_g17g_mrt_bg_eot passes the dense PBE table and the
   per-target tile offsets to the end of tile, and the per-attachment
   clear colours and reload textures to the background, as Borealis does.
 - Such a batch lays every attachment out in the tilebuffer, and its
   draws and clears run once. The native draw records only see whether
   there is colour, so the draw profile admits the batch.

Multisampled, layered and other multi-attachment framebuffers keep the
previous paths. The single-attachment tile programs are unchanged; their
Ioto program tail and reload sampler move into helpers the multi-target
programs share.

A no-op DRM shim test draws into four RGBA8 attachments on G17S and
checks the layout, the single draw, the multi-target end of tile and that
the M5 submission gate accepts the render.

Signed-off-by: Diljit Singh <hey@djdev.me>
A batch that keeps every M5 colour attachment in the tile
(agx_g17g_mrt_resident) gives its fragment epilog one tile store per
attachment. The compiler orders those stores and selects their pixel
classes by the framebuffer's tile partitions, which it takes from the
epilog key (agx_compile_nir_tile). Only the multisample epilog builder
passed that key, so a single-sample one was compiled without partitions.

That works while the epilog stores the attachment at byte 0 of the tile,
but not otherwise: on M5 a masked attachment keeps its contents through a
tile load/store pair (preserve_zero_mask), and when the attachment at
byte 0 is not stored, for example in a clear through a quad of another
attachment, the ordering pass declines and the packer refuses the whole
fragment program. Indexed draw buffer conformance tests with mixed integer
formats then dropped their draws.

Pass the epilog key for a single-sample M5 epilog too. The epilog that
keeps only attachment 0 in the tile (rt0_resident) has a single partition
and is unchanged, as are the other chips.

The no-op DRM shim test of the resident layout now also draws into eight
slots of mixed formats with two empty ones: a clear through a quad of each
attachment and a draw under partial colour masks. Without this change
those fragment programs are refused.

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

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

APPROVED

Blockers

None

Checked

  • Audited agx_g17g_mrt_resident_layout(), agx_g17g_fb_mrt_resident(), agx_compile_variant(), agx_update_fs(), agx_build_meta_shader_internal(), and agx_build_native_g17g_mrt_bg_eot() in src/gallium/drivers/asahi/agx_state.c, agx_clear() in agx_pipe.c, agx_batch_init() in agx_batch.c, and the new tests in src/gallium/drivers/asahi/tests/test-agx-m5-mrt-resident.c.
  • Verified layout admission (active >= 2, single-sample, single-layer, non-spilling 32x32 tile, valid agx_g17p_mrt_eot_selector per attachment) matches agx_bg_eot.c's multi-target background (textures[2 * rt], clear_base + 8 * rt, clear_base = loads ? 8 : 4) and EOT (active_count >= 2 dense PBE table at u0, per-target tilebyte offsets at u4 + 4i) argument layouts, and confirmed agx_nir_fs_epilog receives tile partitions when !rt0_resident.
  • Built and ran the non-layout asahi test suite (254/254 PASS, including asahi-g17s-m5-mrt-resident and asahi-g17s-kernel-m5-mrt-resident with 0 refused programs at the M5 gate) plus live Gallium Asahi GLES3 FBO/MRT/blend/clear CTS (351/351 PASS) and Borealis Vulkan compute smoke on Apple M5 Max (G17C B1), Linux 7.3 with MESA_SHADER_CACHE_DISABLE=1 and 0 GPU faults in dmesg.
  • Untested scope: Full GLES3/KHR-GL30 draw-buffers CTS sweep and asahi_layout_tests (pre-existing GCC C++20 designator-order error in src/asahi/layout/tests/test-layout.cpp:374).
Evidence
  • meson test --suite asahi (non-layout): 254/254 PASS (0 FAIL)
    • asahi-g17s-m5-mrt-resident: OK
    • asahi-g17s-kernel-m5-mrt-resident: OK (shim: M5 gate: 15 submits, 15 renders, 0 computes, 45 render programs, 0 compute programs; 0 refused)
  • Live Gallium Asahi GLES3 + Borealis Vulkan CTS on Apple M5 Max (G17C B1), Linux 7.3 (MESA_SHADER_CACHE_DISABLE=1, GL_RENDERER = Apple M5 Max (G17C B1), 0 GPU faults in dmesg):
    • dEQP-GLES3.functional.fbo.color.repeated_clear.*: 108/108 PASS, 0 FAIL
    • dEQP-GLES3.functional.fbo.color.tex2d.*: 36/36 PASS, 0 FAIL
    • dEQP-GLES3.functional.draw_buffers_indexed.*: 76/76 PASS, 0 FAIL
    • dEQP-GLES3.functional.fbo.color.blend.*: 14/14 PASS, 0 FAIL
    • dEQP-GLES3.functional.fbo.color.clear.*: 36/36 PASS, 0 FAIL
    • dEQP-GLES3.functional.fbo.completeness.attachment_combinations.*: 81/81 PASS, 0 FAIL
    • dEQP-VK.compute.pipeline.basic.*: 80/81 PASS, 0 FAIL, 1 NotSupported

@RyanTheTide

Copy link
Copy Markdown

Verdict at c9396a6f5c02: Merge.

Blockers: None. The mainline build repairs described in the PR are now merged as Mesa #944. The current exact review adds the M5 Max row.

Checked: Exact fork build and policy CI passed. On M5 Max G17C, the independent review measured 351/351 Gallium FBO, blend, clears and draw-buffer cases with zero GPU faults. The M5 Pro G17S row carries both changes unchanged through the context-only rebase and passed 76/76 draw buffer and 302/302 FBO cases. Its timings compare whole composed builds.

@RyanTheTide
RyanTheTide merged commit 55b34fa into aurora-wip Nov 24, 2026
@RyanTheTide
RyanTheTide deleted the djdev/asahi-gl-m5-mrt-clear 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.

3 participants