Skip to content

asahi: run M5 PBO transfers on the GPU and draw vertex-shader gl_Layer per layer - #953

Merged
DjDeveloperr merged 3 commits into
aurora-wipfrom
djdev/asahi-gl-m5-parity
Nov 24, 2026
Merged

DjDeveloperr merged 3 commits into
aurora-wipfrom
djdev/asahi-gl-m5-parity

Conversation

@DjDeveloperr

Copy link
Copy Markdown

What: The M5 GL profile dropped pixel-buffer uploads and downloads to the CPU and put every primitive of a vertex shader that writes gl_Layer into layer 0. This sends such layered draws through the CPU vertex stages (which already split by layer), adds the M5 profile to the blit-based texture transfer gate that #754 set up for AGX2 and Gen9 AGX3, and drops the unused gl_Layer export that st/mesa's PBO vertex shader writes, so PBO transfers run on the GPU and stay correct.

Tested: J714s M5 Pro (G17S B1) on the composed test build git-dba993db23, which carries these three commits (2/3 since rebased onto #754's transfer gate, below): dEQP-GLES3.functional.pbo.* 54/54 pass, fbo.completeness.layer.* 8/8 pass, fbo.color.* 302/302 pass, 0 GPU/MMU faults. Buffer-to-image texture transfer 4.37× at queue depth 4 (47.45 → 207.50 GB/s) and 2.32× at depth 1 (33.15 → 76.97 GB/s) with a matching checksum. 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.

Not yet: aurora-wip itself currently fails one unrelated capability-table test (under Evidence); an M5 hardware re-run on current aurora-wip: the tested build predates #754, whose full-upload PBO invalidation (invalidate_pbo_upload_destination) now also applies on the M5 profile through this change; no G17G or G17C row.

Details

1/3 asahi: draw a vertex shader's gl_Layer through the M5 layer split. The M5 profile renders a layered framebuffer a layer at a time (agx_g17g_layered_draw()): each attachment's single-layer view is bound and the draw is issued per layer. Only the CPU vertex stages (agx_swtnl.c) split primitives by the layer they select, so a draw whose last pre-rasterization stage is a vertex (or tessellation evaluation) shader writing gl_Layer put everything in layer 0. That covers u_blitter's layered clears (get_vs_layered), ARB_shader_viewport_layer_array, and st/mesa's layered PBO draws (st_pbo_create_vs). The shader now records whether it writes gl_Layer, and such a draw into a layered framebuffer takes the CPU vertex stages on M5 (agx_swtnl_applies). Single-layer draws and other chips are unchanged.

2/3 asahi: use blit-based texture transfers on the M5 profile. With mapped transfers, st/mesa copies every texel on the CPU, through a linear staging resource for a tiled or compressed texture. Every target a blit-based transfer renders into is one the existing staging blits (agx_blit_from_staging / agx_blit_to_staging) already render into on M5: u_blitter blits a layer at a time, layered PBO draws are split by 1/3, the end-of-tile PBE stores sRGB as the linear format the shader encoded, and a level of a mipmapped 2D texture is stored as a one-level image at the level's offset. So the M5 profile (agx_chip_g17_m5()) joins the PIPE_TEXTURE_TRANSFER_BLIT gate. #754 (merged while this was under test) set that gate to AGX2 and Gen9 AGX3 and keeps Gen10 on mapped transfers because the Gen10 PBE refuses sRGB, mipmapped (non-G18) and linear layered (G18) targets. The M5 profile is Gen10, but per the list above it never hands the PBE those targets in that form, so it is added to #754's condition; G18G, the other Gen10 chip, stays on mapped transfers.

3/3 asahi: drop an M5 hardware vertex shader's unused gl_Layer export. st_pbo_create_vs writes gl_Layer from the instance ID for every upload and download, layered or not. On M5 that export lands in the layer/viewport UVS group, which no shape of the M5 draw profile admits, so with 2/3 alone every single-layer PBO transfer was dropped (varyings outside the colour shape) and the destination kept its old contents. Nothing on the M5 profile reads that export (layered framebuffers are split per layer, a vertex shader's gl_Layer into one takes the CPU vertex stages, and the fragment shader reads gl_Layer from the draw uniforms via agx_nir_lower_g17g_fs_layer), so it is removed from the M5 hardware vertex shader the same way the point size is removed where the rasterizer ignores it. The draw is then the position-only shape the profile admits.

The three commits should land together: 2/3 without 3/3 drops every PBO transfer.

Tests (no-op DRM shim, asahi suite).

  • asahi-{g13g,g17p,g17s}-m5-layer-transfer: checks the gl_Layer routing on G13G, G17P and G17S (only G17S takes the CPU vertex stages).
  • asahi-{g17s,g17s-kernel}-m5-pbo-draw: draws the st/mesa upload and download shapes into one layer on G17S, checks that no draw is dropped, and on g17s-kernel that the M5 kernel submission checks accept the renders.
  • test-agx-g17p-blit.c (asahi,st/mesa: enable blit texture transfers on native AGX3 and invalidate full PBO uploads #754's caps check) and test-agx-m5-layer-transfer.c expect blit transfers on AGX2, Gen9 AGX3 and the M5 profile, mapped transfers elsewhere.

No runtime switches, environment variables or new chip gates; the M5 paths use the existing agx_chip_g17_m5().

Evidence
  • Commits on aurora-wip 0e7919d41cf (Merge borealis,asahi: enable hardware indirect index bounds on G17P #760). The driver code of 1/3 and 3/3 is identical to the tested build; 2/3 was resolved against asahi,st/mesa: enable blit texture transfers on native AGX3 and invalidate full PBO uploads #754, and 1/3's new shim test gained a wait (both below):
    • fe7e4d57585 asahi: draw a vertex shader's gl_Layer through the M5 layer split
    • 91d632a4422 asahi: use blit-based texture transfers on the M5 profile
    • 9191810055ffe68148ae80e178bb27bc9c3cc2ce asahi: drop an M5 hardware vertex shader's unused gl_Layer export
  • Mirror CI (DjDeveloperr/mesa, temporary branch, exact commit 9191810055f):
    • asahi (build plus the asahi test suite): run 45416656627, 280 OK / 1 fail (the base failure below), including asahi-{g13g,g17p,g17s}-m5-layer-transfer and asahi-{g17s,g17s-kernel}-m5-pbo-draw
    • aurora-agent-policy: run 45416656670 success
    • The one failing test, asahi-agx-chip-caps (2 of 366 checks: AGX_CAP_NATIVE_PREAMBLE on G16G, AGX_CAP_VDM_INDIRECT_INDEX_BOUNDS on G17P), fails identically on aurora-wip 0e7919d41cf alone (run 45418268129, 275 OK / 1 fail): two merged changes updated those chip predicates without the capability table. 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/3 + 2/3 only This PR GPU/MMU faults
dEQP-GLES3.functional.pbo.* 54 54 / 0 0 / 54 54 / 0 0
dEQP-GLES3.functional.fbo.completeness.layer.* 8 — — 8 / 0 0
dEQP-GLES3.functional.fbo.color.* 302 302 / 0 302 / 0 302 / 0 0

Buffer-to-image texture upload microbenchmark (MESA_SHADER_CACHE_DISABLE=1, checksum of the destination verified against the expected value, 0 stderr errors):

Queue depth Before This PR Ratio Checksum
1 506.07 µs (33.15 GB/s) 217.96 µs (76.97 GB/s) 2.32× 0883f778 = expected
4 353.61 µs (47.45 GB/s) 80.85 µs (207.50 GB/s) 4.37× 0883f778 = expected

The other transfer kinds (4 MiB and 16 MiB clears, mip chain) pass with exact checksums. 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 cannot render a layered framebuffer in one pass, so
agx_g17g_layered_draw() binds each attachment's single-layer view and
draws a layer at a time. Only the CPU vertex stages (agx_swtnl.c) split a
draw's primitives by the layer they select; every other draw is issued
once, against layer 0.

A draw whose last pre-rasterization stage is a vertex shader that writes
gl_Layer therefore put all of its primitives into layer 0. That covers
u_blitter's layered clears (get_vs_layered), application vertex shaders
using ARB_shader_viewport_layer_array and, once blit-based texture
transfers are enabled, st/mesa's layered PBO uploads and downloads
(st_pbo_create_vs).

Record whether a vertex or tessellation evaluation shader writes
gl_Layer, and send a layered-framebuffer draw whose vertex shader does
through the CPU vertex stages on the M5 profile, which already draw each
primitive into the layer its provoking vertex names. Draws into a single
layer, and draws on other chips, are unchanged.

Add a no-op DRM shim test that checks the routing on G13G, G17P and G17S.

Signed-off-by: Diljit Singh <hey@djdev.me>
With mapped texture transfers, st/mesa uploads from a pixel unpack buffer
by mapping the buffer and the texture and copying every texel on the
CPU. A tiled or compressed texture is mapped through a linear staging
resource, so the upload is a CPU copy into staging followed by a
u_blitter blit into the texture (agx_blit_from_staging), and a read is
the reverse (agx_blit_to_staging).

The targets a blit-based transfer renders into on the M5 profile are the
ones those staging blits already render into: u_blitter blits a layer at
a time, a layered st/mesa PBO draw is split into layers by the CPU vertex
stages, the end-of-tile PBE stores sRGB as the linear format the shaders
encoded, and a level of a mipmapped 2D texture is stored as a one-level
image at the level's offset (agx_batch_upload_pbe_internal). Advertise
PIPE_TEXTURE_TRANSFER_BLIT there, as AGX2 and Gen9 AGX3 do, so st/mesa
uploads PBOs and converts formats on the GPU. G18G, the other Gen10
chip, stays on mapped transfers because its PBE refuses some of those
targets; the M5 profile never hands them to the PBE in that form.

Signed-off-by: Diljit Singh <hey@djdev.me>
st/mesa's pixel-buffer vertex shader (st_pbo_create_vs) writes gl_Layer
from the instance ID for every upload and download, layered or not. On
the M5 profile that export lands in the layer/viewport UVS group, which
no shape of the M5 draw profile admits, so with blit-based texture
transfers every pixel-buffer upload and download into a single layer was
dropped ("varyings outside the colour shape") and the texture or buffer
kept its old contents.

Nothing on the M5 profile reads that export: a layered framebuffer is
drawn a layer at a time, a vertex shader's gl_Layer into one takes the
CPU vertex stages (agx_swtnl_applies), and a fragment shader reads
gl_Layer from the draw uniforms (agx_nir_lower_g17g_fs_layer). Remove it
from the M5 hardware vertex shader, as the point size is removed where
the rasterizer ignores it. The draw is then the position-only shape the
profile admits.

A no-op DRM shim test draws the st/mesa upload and download shapes into
one layer on G17S, checks that no draw is dropped, and on g17s-kernel
that the M5 kernel checks accept the renders.

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 9191810055ff

APPROVE — Clean M5-scoped enablement of GPU PBO texture transfers (PIPE_TEXTURE_TRANSFER_BLIT), unused hardware vertex-shader VARYING_BIT_LAYER stripping, and CPU vertex-stage fallback (agx_swtnl_applies()) for vertex-shader gl_Layer into multi-layer framebuffers. All 5 new drm-shim tests pass and live Apple M5 Max Gallium GLES3 PBO and layered-FBO CTS runs pass with zero regressions and zero GPU faults.

Blockers

None.

Checked

  • Code audit (src/gallium/drivers/asahi/agx_pipe.c, agx_state.c, meson.build, tests/test-agx-m5-layer-transfer.c, tests/test-agx-m5-pbo-draw.c):
    • agx_pipe.c: PIPE_TEXTURE_TRANSFER_BLIT is enabled only for agx_chip_g17_m5(dev->chip).
    • agx_state.c: agx_swtnl_applies() routes vertex shaders writing gl_Layer into multi-layer framebuffers (util_framebuffer_get_num_layers(&ctx->framebuffer) > 1) through software TNL while keeping non-M5, nested swtnl_inner, GPU-tess, and bindful-image guards intact; agx_compile_variant() strips unused VARYING_BIT_LAYER from M5 hardware vertex shaders via nir_remove_outputs() and clears outputs_written before agx_nir_lower_uvs().
    • Non-blocking note: commit 2 (91d632a44221) enables PIPE_TEXTURE_TRANSFER_BLIT before commit 3 (9191810055ff) strips hardware VS VARYING_BIT_LAYER, so intermediate commit 91d632a44221 drops PBO draws (0/54 vs 16/54 at both base 0e7919d41cf2 and head 9191810055ff); flipping commits 2 and 3 or squashing on merge would preserve bisectability.
  • Unit & drm-shim tests: 265/266 non-layout asahi tests PASS, including all 5 new tests (asahi-{g13g,g17p,g17s}-m5-layer-transfer, asahi-{g17s,g17s-kernel}-m5-pbo-draw, 0 refused in the M5 submit gate). The single failure (asahi-agx-chip-caps, 2 of 366 checks failed) reproduces identically on the untouched base commit 0e7919d41cf2 and is unrelated to this PR.
  • Live hardware verification (Apple M5 Max G17C B1, Linux 7.3, Gallium Asahi GLES 3.2, MESA_SHADER_CACHE_DISABLE=1):
    • dEQP-GLES3.functional.pbo.*: 16/54 PASS (0 regressions vs 16/54 on base 0e7919d41cf2, 0 dropped draws; the remaining 38 failures are pre-existing renderbuffer format/readpixels GL_INVALID_FRAMEBUFFER_OPERATION/GL_INVALID_OPERATION errors identical on base).
    • dEQP-GLES3.functional.fbo.color.tex2darray.*: 36/36 PASS (0 fail).
    • dEQP-GLES3.functional.fbo.color.tex3d.*: 36/36 PASS (0 fail).
    • 0 GPU faults in dmesg.
  • Untested scope: Live GLES/GL vertex-shader gl_Layer (GL_ARB_shader_viewport_layer_array) layered-FBO draw beyond the drm-shim layer-transfer test, non-M5 live hardware, and asahi_layout_tests (pre-existing GCC 16 C++20 designated-initializer order error in src/asahi/layout/tests/test-layout.cpp:374).
Evidence
  • Unit & drm-shim suite (-Dtools=drm-shim -Dbuild-tests=true -Dbuildtype=release):
    • Non-layout asahi suite: 265/266 OK, 1 Fail (asahi-agx-chip-caps, verified identical 2 of 366 checks failed on untouched base 0e7919d41cf2)
    • asahi-g13g-m5-layer-transfer: OK (0.01s)
    • asahi-g17p-m5-layer-transfer: OK (0.02s)
    • asahi-g17s-m5-layer-transfer: OK (0.02s)
    • asahi-g17s-m5-pbo-draw: OK (0.01s)
    • asahi-g17s-kernel-m5-pbo-draw: OK (0.02s, M5 gate: 2 submits, 2 renders, 0 computes, 6 render programs, 0 compute programs; 0 refused)
  • Live Gallium GLES3 CTS on Apple M5 Max (G17C B1), Linux 7.3 (OpenGL ES 3.2 Mesa 26.3.0-devel (git-9191810055), MESA_SHADER_CACHE_DISABLE=1):
    • dEQP-GLES3.info.renderer / dEQP-GLES3.info.version: 2/2 Pass
    • dEQP-GLES3.functional.pbo.*: 16/54 Pass (0 regressions vs 16/54 on base 0e7919d41cf2; 0/54 at intermediate 91d632a44221, proving commit 3 restores GPU PBO draw admission)
    • dEQP-GLES3.functional.fbo.color.tex2darray.*: 36/36 Pass (0 Fail)
    • dEQP-GLES3.functional.fbo.color.tex3d.*: 36/36 Pass (0 Fail)
    • Kernel GPU faults (dmesg delta): 0

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

Copy link
Copy Markdown
Author

Merged into aurora-wip as 21dfa09fe24e (head 9191810055ff, verified tree e51a5bfe8f01). Verified: exact-head peer approval (265/265 non-chip-caps asahi tests including all 5 new M5 PBO/layer-transfer tests, live M5 Max Gallium GLES 3.2 PBO + 72/72 layered-FBO CTS, 0 GPU faults), M5 Pro live verification, aurora-agent-policy (45416656670), and asahi (45416656627, 280/280 non-chip-caps passing; asahi-agx-chip-caps restored in #955).

@RyanTheTide
RyanTheTide deleted the djdev/asahi-gl-m5-parity 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