Repository navigation
asahi: run M5 PBO transfers on the GPU and draw vertex-shader gl_Layer per layer - #953
Conversation
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
left a comment
There was a problem hiding this comment.
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_BLITis enabled only foragx_chip_g17_m5(dev->chip).agx_state.c:agx_swtnl_applies()routes vertex shaders writinggl_Layerinto multi-layer framebuffers (util_framebuffer_get_num_layers(&ctx->framebuffer) > 1) through software TNL while keeping non-M5, nestedswtnl_inner, GPU-tess, and bindful-image guards intact;agx_compile_variant()strips unusedVARYING_BIT_LAYERfrom M5 hardware vertex shaders vianir_remove_outputs()and clearsoutputs_writtenbeforeagx_nir_lower_uvs().- Non-blocking note: commit 2 (
91d632a44221) enablesPIPE_TEXTURE_TRANSFER_BLITbefore commit 3 (9191810055ff) strips hardware VSVARYING_BIT_LAYER, so intermediate commit91d632a44221drops PBO draws (0/54vs16/54at both base0e7919d41cf2and head9191810055ff); flipping commits 2 and 3 or squashing on merge would preserve bisectability.
- Unit & drm-shim tests:
265/266non-layoutasahitests PASS, including all 5 new tests (asahi-{g13g,g17p,g17s}-m5-layer-transfer,asahi-{g17s,g17s-kernel}-m5-pbo-draw,0refused in the M5 submit gate). The single failure (asahi-agx-chip-caps,2 of 366 checks failed) reproduces identically on the untouched base commit0e7919d41cf2and 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/54PASS (0regressions vs16/54on base0e7919d41cf2,0dropped draws; the remaining 38 failures are pre-existing renderbuffer format/readpixelsGL_INVALID_FRAMEBUFFER_OPERATION/GL_INVALID_OPERATIONerrors identical on base).dEQP-GLES3.functional.fbo.color.tex2darray.*:36/36PASS (0fail).dEQP-GLES3.functional.fbo.color.tex3d.*:36/36PASS (0fail).0GPU faults indmesg.
- 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, andasahi_layout_tests(pre-existing GCC 16 C++20 designated-initializer order error insrc/asahi/layout/tests/test-layout.cpp:374).
Evidence
- Unit & drm-shim suite (
-Dtools=drm-shim -Dbuild-tests=true -Dbuildtype=release):- Non-layout
asahisuite:265/266 OK,1 Fail(asahi-agx-chip-caps, verified identical2 of 366 checks failedon untouched base0e7919d41cf2) 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)
- Non-layout
- 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/2PassdEQP-GLES3.functional.pbo.*:16/54Pass (0regressions vs16/54on base0e7919d41cf2;0/54at intermediate91d632a44221, proving commit 3 restores GPU PBO draw admission)dEQP-GLES3.functional.fbo.color.tex2darray.*:36/36Pass (0Fail)dEQP-GLES3.functional.fbo.color.tex3d.*:36/36Pass (0Fail)- Kernel GPU faults (
dmesgdelta):0
|
Merged into |
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_Layerinto 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 unusedgl_Layerexport 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-wipitself currently fails one unrelated capability-table test (under Evidence); an M5 hardware re-run on currentaurora-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 writinggl_Layerput 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 writesgl_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 thePIPE_TEXTURE_TRANSFER_BLITgate. #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_vswritesgl_Layerfrom 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'sgl_Layerinto one takes the CPU vertex stages, and the fragment shader readsgl_Layerfrom the draw uniforms viaagx_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,
asahisuite).asahi-{g13g,g17p,g17s}-m5-layer-transfer: checks thegl_Layerrouting 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 ong17s-kernelthat 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) andtest-agx-m5-layer-transfer.cexpect 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
aurora-wip0e7919d41cf(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):fe7e4d57585asahi: draw a vertex shader's gl_Layer through the M5 layer split91d632a4422asahi: use blit-based texture transfers on the M5 profile9191810055ffe68148ae80e178bb27bc9c3cc2ceasahi: drop an M5 hardware vertex shader's unused gl_Layer exportDjDeveloperr/mesa, temporary branch, exact commit9191810055f):asahi(build plus the asahi test suite): run 45416656627, 280 OK / 1 fail (the base failure below), includingasahi-{g13g,g17p,g17s}-m5-layer-transferandasahi-{g17s,g17s-kernel}-m5-pbo-drawaurora-agent-policy: run 45416656670 successasahi-agx-chip-caps(2 of 366 checks:AGX_CAP_NATIVE_PREAMBLEon G16G,AGX_CAP_VDM_INDIRECT_INDEX_BOUNDSon G17P), fails identically onaurora-wip0e7919d41cfalone (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)
git-dba993db23(OpenGL ES 3.2 Mesa 26.3.0-devel (git-dba993db23)), system Mesa untouched,MESA_LOADER_DRIVER_OVERRIDE=asahi.git-8956dffd84, which has none of the three commits; it differs from the tested build by more than this PR, so the bandwidth ratio is an end-to-end figure for the composed builds.texture_transfer_modesexpression and its test expectation. The resolution keeps asahi,st/mesa: enable blit texture transfers on native AGX3 and invalidate full PBO uploads #754's gate and comment and adds|| agx_chip_g17_m5(dev->chip)with the M5 explanation; the tested build hadAGX2 || agx_chip_g17_m5()instead, which on M5 evaluates the same. 1/3 and 3/3 rebased without conflicts, including over asahi: G17G: fix CW tessellation winding and enable native GS copy draws #670 and asahi: wire TGSI sampler and buffer hooks in agx_swtnl without LLVM #671, which also touch the CPU vertex stages.agx_draw_vbo()waits for it (stages_compiling), but the layer-transfer shim test callsagx_swtnl_applies()directly, so on the G17S case it intermittently readwrites_layerbefore the compile finished and failed in CI. The test now callsagx_shader_wait_ready()on the bound vertex shader first. Driver draws are unaffected.dEQP-GLES3.functional.pbo.*0/54 and the transfer checksum; that is the failure 3/3 fixes.GLES3 CTS (
deqp-runner,deqp-gles3,-j 4, pbuffer 256×256,rgba8888d24s8ms0):dEQP-GLES3.functional.pbo.*dEQP-GLES3.functional.fbo.completeness.layer.*dEQP-GLES3.functional.fbo.color.*Buffer-to-image texture upload microbenchmark (
MESA_SHADER_CACHE_DISABLE=1, checksum of the destination verified against the expected value, 0 stderr errors):0883f778= expected0883f778= expectedThe 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.