Skip to content

asahi: coalesce multi-pass batches and emit fragment barriers and few-primitives hints - #822

Merged
DjDeveloperr merged 3 commits into
aurora-wipfrom
perf/asahi-multipass-coalesce-frag-barriers
Nov 24, 2026
Merged

DjDeveloperr merged 3 commits into
aurora-wipfrom
perf/asahi-multipass-coalesce-frag-barriers

Conversation

@DjDeveloperr

Copy link
Copy Markdown

Summary

Closes the multi-pass OpenGL submission and barrier gap vs Borealis on Apple Silicon:

  1. asahi: coalesce hazard-flushed batches into multi-command submits (e59614516ff)

    • Adds a queued batch state and per-context ctx->pending command queue so hazard-flushed intermediate passes (e.g. post-processing chains and shadow passes) encode into ctx->pending via agx_batch_queue_or_submit() and drain together in a single DRM_IOCTL_ASAHI_SUBMIT on explicit flush, CPU sync/map, fence creation/server wait, query availability checks, shared resource export, batch slot pressure, or max_commands_per_submission overflow.
    • Emits exact intra-submission vdm_barrier / cdm_barrier indices, size-0 SET_FRAGMENT_ATTACHMENTS / SET_COMPUTE_RESOURCES state resets between heterogeneous commands, and group retirement via batch->submit_seq while preserving per-batch syncobjs and written-BO tracking.
    • Adds 4 unit tests in src/gallium/drivers/asahi/tests/test-agx-submit.c covering multi-batch render/compute coalescing, attachment-state resets, max_commands_per_submission splitting, fence_server_sync draining, and failed-submit retirement.
  2. asahi: emit fragment barriers and few-primitives hints on renders (442f2fc3490)

    • Tracks render-written resources (rsrc->render_written) and conservatively sets batch->vs_needs_render_barrier whenever any pre-fragment stage reads a render-written, shared, or cross-context resource, writes memory, or uses indirect draws, conditional rendering, geometry shaders, tessellation, or transform feedback.
    • Emits DRM_ASAHI_RENDER_FRAGMENT_BARRIERS when DRM_ASAHI_FEATURE_FRAGMENT_BARRIERS is advertised, vdm_barrier != DRM_ASAHI_BARRIER_NONE, and !batch->vs_needs_render_barrier, allowing the next render's vertex/tiling half to overlap with the prior render's fragment stage while keeping compute and fragment ordering intact.
    • Tracks known primitive counts across direct and multi-draws (marking prims_unknown on indirect, primitive restart, patch, GS, tess, or high-instance draws) and emits DRM_ASAHI_RENDER_FEW_PRIMITIVES on native/M5 chips when DRM_ASAHI_FEATURE_FEW_PRIMITIVES is advertised and known_prims <= 4, matching Borealis.
    • Extends test-agx-submit.c to verify both flags and all suppression cases.

Verification

Offline CI (fedora-mesaci at exact head 442f2fc3490b)

  • --suite asahi: 164/164 PASS
  • --suite poly: 5/5 PASS
  • ASAHI_SHIM_VALIDATE_G17P_STREAM=1 with libasahi_noop_drm_shim.so: 233/233 runnable tests PASS (including asahi-{g13g,g17p,t6041}-gallium-submit, asahi-{g17p,t6041}-gallium-blit, asahi-g17p-submit-retirement-*, asahi-g17p-async-fence)
  • DEFAULT_BRANCH=aurora-wip ./.github/aurora/agent-policy.sh pr HEAD: clean

MacBook Neo (Apple A18 Pro / G17P B1) — Exact Head 442f2fc3490b vs Base efabab38502d

1. Custom 8-test GL hardware verifier (test_multipass_submit)

  • Both base (git-efabab3850) and cand (git-442f2fc349): 8/8 PASS with identical CRC (0x7e130dde):
    • 11-pass postfx chain + CRC parity (0x7e130dde)
    • VS texelFetch from render-written texture (20 iters — verifies vs_needs_render_barrier suppresses FRAGMENT_BARRIERS)
    • FS SSBO store -> indirect draw + VBO read (20 iters)
    • WAR hazard: Pass 0 FS SSBO read -> glMemoryBarrier -> Pass 1 VS SSBO overwrite (20 iters)
    • 70-pass chain overflowing both max_commands_per_submission (64) and AGX_MAX_BATCHES (32)
    • Query availability (GL_ANY_SAMPLES_PASSED, GL_TIME_ELAPSED, GL_TIMESTAMP) without glFlush()
    • glFenceSync / glWaitSync inter-batch ordering
    • FEW_PRIMITIVES boundary (1, 2, 4, 5, 20 triangles + glMultiDrawArrays 2+2 vs 2+3)

2. 6-round cool-down ABBA (gpubench-gl --verify, 3s cool-down between legs)

Benchmark Depth Metric Base (efabab3850) Cand (442f2fc349) Primary Delta Record CPU (us) Total CPU (rec+sub, us) CRC
render.postfx (1080p, msaa=1) 2 fps 1354.00 1468.00 +8.42% 488.0 → 146.9 (-3.3x) 543.0 → 469.5 MATCH (2133faaa)
render.postfx (1440p, msaa=1) 2 fps 756.00 794.00 +5.03% 644.7 → 264.8 (-2.4x) 711.4 → 835.7 MATCH
render.postfx (1080p, msaa=4) 2 fps 626.00 654.00 +4.47% 684.0 → 288.4 (-2.4x) 737.9 → 906.4 MATCH
render.postfx (1080p, msaa=1) 1 fps 1166.00 1112.00 -4.63%* 279.3 → 37.1 (-7.5x) 300.0 → 130.3 (-2.30x) MATCH (2133faaa)
render.postfx (1440p, msaa=1) 1 fps 726.00 720.00 -0.83% 277.1 → 46.4 (-6.0x) 303.2 → 177.6 (-1.71x) MATCH
render.postfx (1080p, msaa=4) 1 fps 582.00 576.00 -1.03% 307.0 → 52.5 (-5.8x) 332.7 → 185.7 (-1.79x) MATCH
render.shadow (fmt=d16) 1 mtri_s 9.18 9.86 +7.50% 362.3 → 27.5 (-13.2x) 455.3 → 104.6 (-4.35x) MATCH
render.shadow (fmt=d16) 2 mtri_s 10.75 11.47 +6.71% 409.0 → 91.1 (-4.5x) 505.1 → 353.9 (-1.43x) MATCH
render.shadow (fmt=d32f) 1 mtri_s 5.18 5.18 +0.00% 372.5 → 90.8 (-4.1x) 452.0 → 332.8 (-1.36x) MATCH
render.shadow (fmt=d32f) 2 mtri_s 5.64 5.83 +3.49% 403.7 → 93.0 (-4.3x) 487.2 → 354.9 (-1.37x) MATCH
compress.bw (mrt4, 1440p) 1 us/sub 1020.43 1022.50 -0.20% 44.4 → 14.6 68.1 → 52.2 n/a
compress.bw (mrt4, 1440p) 2 us/sub 907.47 896.07 +1.26% 132.0 → 51.4 211.4 → 184.5 n/a
compress.bw (storage, 1440p) 1 us/sub 503.55 511.26 -1.53% 25.7 → 7.9 36.4 → 32.7 n/a
compress.bw (storage, 1440p) 2 us/sub 449.68 450.05 -0.08% 77.7 → 32.4 132.6 → 108.4 n/a
compute.uber (control) 1 us/sub 1347.72 1351.35 -0.27% 13.6 → 13.7 76.2 → 76.6 MATCH
compute.uber (control) 2 us/sub 1207.76 1207.73 +0.00% 14.2 → 14.2 79.3 → 79.7 MATCH
sync.finish (control) 1 us/sub 129.07 130.62 -1.20% 3.6 → 3.8 136.1 → 136.6 n/a

*Note on render.postfx 1080p depth=1 (-4.63%, +43 us): with synchronous glFinish() draining the GPU to idle every frame, deferring all 11 passes into a single ioctl delays starting pass 1 until pass 11 is recorded (trading +43 us idle-start latency for 2.30x lower total CPU: 300.0 -> 130.3 us). Under standard pipelined double buffering (depth=2), the GPU stays busy and every render.postfx configuration wins +4.47% to +8.42% across all 6 rounds, while render.shadow wins up to +7.50% even at depth=1 with 4.35x less total CPU.

3. Exact-head GLES3 / GLES31 CTS diff (Wayland pbuffer, 256×256 rgba8888d24s8ms0)

  • dEQP-GLES3.functional.fbo.*: 2,028 cases (1,990 Pass / 37 NotSupported / 1 QualityWarning on both), diffs=0
  • dEQP-GLES3.functional.transform_feedback.*: 882/882 Pass on both, diffs=0
  • dEQP-GLES3.functional.texture.vertex.*: 174/174 Pass on both, diffs=0
  • dEQP-GLES3.functional.occlusion_query.*: 62/62 Pass on both, diffs=0
  • dEQP-GLES31.functional.draw_indirect.*: 207 cases (193 Pass / 14 NotSupported on both), diffs=0
  • dEQP-GLES31.functional.synchronization.*: 104/104 Pass on both, diffs=0
  • Grand total: 3,457 / 3,457 cases, diffs=0

4. Kernel health

  • kfault_delta=0, avc_delta=0

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

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-Up at 442f2fc3490b.

The coalesced path publishes one release fence for shared BOs from the last batch, while the new fragment-only barrier lets part of a later render run ahead. Please show the submit-fence contract that guarantees the last batch fence covers every preceding compute and render in this ioctl. Add an output check across a writer and pre-fragment consumer in separate queued batches plus a shared-BO export/readback. The existing shim flag checks and general GLES rows do not exercise those two contracts together.

Source review. I used the test evidence attached to this PR.

@DjDeveloperr

Copy link
Copy Markdown
Author

G17S B1 (Apple M5 Pro / m5-ssd) Exact-Head Cross-Verification

  • Hardware / Kernel: Apple M5 Pro (G17S B1), Linux 7.3.0-m5-cdirect2 (+ 16-plane SLC)
  • Environment: MESA_SHADER_CACHE_DISABLE=1, no ASAHI_M5_BRINGUP, extracted LIBGL_DRIVERS_PATH / LD_LIBRARY_PATH / __EGL_VENDOR_LIBRARY_FILENAMES (never /usr/lib/dri/asahi_dri.so)
  • HEAD SHA: 442f2fc3490bcfae2ab7e84cdfb4c5a3eff19bc8
  • GL Renderer / Version: Apple M5 Pro (G17S B1) / 4.6 (Core Profile) Mesa 26.3.0-devel (git-442f2fc349) (prebuilt ARM64 tarball mesa-multipass-442f2fc3490b.tar.zst, SHA-256 ce2c809fa1f56b0556bafcdb30b16c0514d42928c43eb4b8fc2b2e2501f366fe)
  • Targeted GLES3 / GLES31 CTS (249/261 passed, 0 failed, 12 not supported):
    • dEQP-GLES3.functional.fbo.color.repeated_clear.*: 108/108 passed (0 failed)
    • dEQP-GLES3.functional.fbo.render.shared_colorbuffer.*: 84/84 passed (0 failed)
    • dEQP-GLES3.functional.fbo.depth.depth_test_clamp.*: 5/5 passed (0 failed)
    • dEQP-GLES3.functional.fbo.blit.depth_stencil.*: 16/28 passed (0 failed, 12 NS)
    • dEQP-GLES31.functional.synchronization.inter_call.without_memory_barrier.*: 36/36 passed (0 failed)
  • gpubench-gl ABBA vs efabab38502d (mesa-base-efabab38502d.tar.zst, base1 -> cand1 -> cand2 -> base2):
    • render.postfx d=1: 517.50 -> 520.00 fps (+0.5%; 1932.5 -> 1923.1 us, record_cpu_us 558.4 -> 60.1 us -89.2%)
    • render.postfx d=2: 570.83 -> 605.83 fps (+6.1%; 1751.8 -> 1650.7 us -5.8%, record_cpu_us 592.2 -> 158.8 us -73.2%)
    • render.shadow d=1: 17.24 -> 18.65 Mtri/s (+8.2%; 950.1 -> 878.5 us -7.5%, record_cpu_us 69.5 -> 13.0 us -81.3%)
    • render.shadow d=2: 20.14 -> 22.46 Mtri/s (+11.5%; 813.6 -> 729.5 us -10.3%, record_cpu_us 196.5 -> 38.9 us -80.2%)
  • Kernel GPU faults: 0 (dmesg delta 0)

@DjDeveloperr

Copy link
Copy Markdown
Author

Exact-head Apple M4 (G16G B0) hardware verification — PASS

Verified exact PR head 442f2fc3490bcfae2ab7e84cdfb4c5a3eff19bc8 (4.6 (Core Profile) Mesa 26.3.0-devel (git-442f2fc349), tarball mesa-multipass-442f2fc3490b.tar.zst, SHA-256 ce2c809fa1f56b0556bafcdb30b16c0514d42928c43eb4b8fc2b2e2501f366fe) against exact parent efabab38502dc32302a058503231b12e815a21f9 (git-efabab3850) on live Apple M4 (G16G B0, J773g Mac mini), Linux 7.3.0-ARCH-m4prod23.

1. Targeted dEQP-GLES3 / dEQP-GLES31 FBO CTS (220 passed, 0 failed, 25 not supported, 245 total, nonzero_rc=0, dmesg_delta=+0)

  • gles3_fbo_msaa: 48/48 PASS (0 fail, 22 NS, dmesg=+0)
  • gles3_fbo_blit: 117/117 PASS (0 fail, 3 NS, dmesg=+0)
  • gles3_fbo_color_clear: 36/36 PASS (0 fail, 0 NS, dmesg=+0)
  • gles3_fbo_depth: 15/15 PASS (0 fail, 0 NS, dmesg=+0)
  • gles31_fb_no_attach: 4/4 PASS (0 fail, 0 NS, dmesg=+0)

2. Symmetric ABBA gpubench-gl (efabab3850 vs 442f2fc349) — wins 8/8 cases

Case d Base sub (us) #822 sub (us) Δsub
render.postfx(msaa=4,res=1080p) 2 3030.3 2631.6 -13.2% (1.15x)
render.postfx(msaa=1,res=1080p) 2 1408.5 1242.3 -11.8% (1.13x)
render.postfx(msaa=1,res=1440p) 2 2010.1 1810.0 -10.0% (1.11x)
render.shadow(fmt=d16,mode=depth_only,res=2048) 2 1000.0 896.9 -10.3% (1.11x)
render.shadow(fmt=d32f,mode=depth_only,res=2048) 2 1785.7 1652.9 -7.4% (1.08x)
render.shadow(fmt=d32f,mode=alpha_test,res=2048) 2 1886.8 1769.9 -6.2% (1.07x)
render.heavy(kind=fill,res=1080p) 2 469.5 451.5 -3.8% (1.04x) (GPU 469.4 -> 450.5 us, -4.0% / 1.04x)
compress.bw(kind=mrt4,res=1440p) 4 1659.8 1639.3 -1.2% (1.01x)

Verdict: PASS on Apple M4 (G16G B0).

Assisted-by: LLM (Gemini:4 Neon)

@DjDeveloperr

Copy link
Copy Markdown
Author

Reply to the 442f2fc3490b follow-up, part 1 (submit-fence contract). Kernel references are integration/aurora at 7d3d1e29dbd2.

One fence per SUBMIT, installed in every output sync, signalled only after every command in the ioctl retires. That holds on all three kernel submit paths that #822 can reach:

On the Mesa side, every coalesced batch's syncobj is an output of the same ioctl (agx_batch.c#L2835). So last_batch->syncobj carries the same aggregate fence as every earlier batch, not the fence of the last command, and the shared-BO release fence exported from it (#L2973) covers every compute and render in the submit. Shared-BO and cross-queue input syncs are job-level scheduler dependencies (g16/job.rs L6), so they gate every command in the ioctl.

The fragment-only barrier doesn't change that. It only moves where a render's VDM dependency attaches; the command is still a member of the same aggregate. Per the uAPI (asahi_drm.h#L1505-L1519), cdm_barrier still orders the vertex half, so compute writers are never overtaken. #822 sets the flag only when the batch has a real VDM barrier and !vs_needs_render_barrier (agx_batch.c#L2905-L2910). agx_batch_note_vs_read() (agx_state.h#L1406-L1426) forces the full barrier for any pre-fragment read of a render-written, shared, or other-queue-written resource. That covers VBOs, index and indirect buffers, and VS/TES/GS textures, images, UBOs and SSBOs. Indirect draws, conditional rendering, GS/tess, XFB and VS memory writes always take the full barrier (agx_state.c#L16007-L16013). A batch with its own compute uses vdm_barrier = NONE, gets no fragment-only flag, and is ordered behind earlier renders through that compute's full VDM barrier.

Also: G16 doesn't advertise FRAGMENT_BARRIERS (early_tiling() is false, g16/params.rs#L52-L54, and the flag is refused at g16/command.rs#L528-L529). On M4 this PR therefore only changes coalescing. The fragment-only path runs on the kernels that advertise it (G15 with early tiling, G17).

Part 2 (output check) is still open. This PR doesn't yet have the writer → pre-fragment-consumer readback across separate queued batches, or the shared-BO export/readback. The current evidence is the shim flag checks and GLES rows, as you said. I'll post exact-head hardware output rows here when they exist. Until then this follow-up stays unresolved.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr

Copy link
Copy Markdown
Author

Reply to the 442f2fc3490b follow-up, part 2 (live hardware output check on Apple M4 G16G B0).

Environment & Exact-Head Identity

  • Hardware / Kernel: Apple Mac mini M4 (Apple M4 (G16G B0)), Linux 7.3.0 (drm/asahi G16)
  • Exact PR Head: 442f2fc3490bcfae2ab7e84cdfb4c5a3eff19bc8 (OpenGL ES 3.2 Mesa 26.3.0-devel (git-442f2fc349), mesa-multipass-442f2fc3490b.tar.zst, SHA-256 ce2c809fa1f56b0556bafcdb30b16c0514d42928c43eb4b8fc2b2e2501f366fe)
  • Runtime: Isolated extraction (MESA_SHADER_CACHE_DISABLE=1, LIBGL_DRIVERS_PATH/LD_LIBRARY_PATH/GBM_BACKENDS_PATH/__EGL_VENDOR_LIBRARY_FILENAMES, system /usr/lib untouched)
  • Calibrated Batch-1 GPU Work: 512×512 non-eliminable ALU loop — render 5.49 ms, compute 5.14 ms, writing unique per-iteration + per-pixel RGBA8 payload V(iter, x, y) verified across 64×64 (4,096 texels spanning all tiles) per iteration.

Live Output Results — 700/700 bit-exact PASS (100% coalesced DRM_IOCTL_ASAHI_SUBMIT verified via ioctl interposer)

Subcase Contract Exercised Bit-Exact Coalesced (hw_cmds >= 2) Observed DRM_IOCTL_ASAHI_SUBMIT Stream Additional Synchronization Evidence
1A Render writer (T1) → VS pre-fragment texelFetch (T2), no flush between draws 100/100 100/100 (max_hw=2) [R(vdm=0,cdm=0,frag=1) -> R(vdm=1,cdm=0,frag=0)] Consumer R1 clears DRM_ASAHI_RENDER_FRAGMENT_BARRIERS (frag=0) and sets vdm=1
1B 3-batch mixed chain: Render (T1) → Frag-only (T2) → VS pre-fragment (T3) 100/100 100/100 (max_hw=3) [R(vdm=0,cdm=0,frag=1) -> R(vdm=1,cdm=0,frag=1) -> R(vdm=2,cdm=0,frag=0)] R1 runs coalesced frag-only barrier (frag=1, vdm=1); R2 upgrades to full pre-frag barrier (frag=0, vdm=2)
1C Compute writer (image2D + SSBO) → VS pre-fragment reader (texelFetch + SSBO) 100/100 100/100 (max_hw=2) [C(vdm=0,cdm=0) -> R(vdm=0,cdm=1,frag=0)] Render consumer waits on cdm=1 with frag=0
2A-ctx2 Slow render (~5.5 ms) to exported linear GBM DMA-BUF + tiny 16×16 private trailing render → glFlush() only → independent DRM fd / GBM / EGLContext ctx2 GPU readback 100/100 100/100 (max_hw=2) [R(vdm=0,cdm=0,frag=1) -> R(vdm=1,cdm=0,frag=1)] (in_sync=1, out_sync=4) Cross-context implicit dma_resv fence covers earlier slow render Batch 1
2A-sync Same slow render + tiny trailing render → glFlush() only → DMA_BUF_IOCTL_EXPORT_SYNC_FILE + poll() + DMA_BUF_IOCTL_SYNC CPU mmap 100/100 100/100 (max_hw=2) [R(vdm=0,cdm=0,frag=1) -> R(vdm=1,cdm=0,frag=1)] (in_sync=1, out_sync=4) sync_file poll() waited avg 5.46 ms (min 5.40 ms, max 7.19 ms), matching slow Batch 1 (5.49 ms)
2B-ctx2 Slow compute (~5.1 ms) to exported immutable EGLImage DMA-BUF + tiny 16×16 private trailing render → glFlush() only → independent ctx2 GPU readback 100/100 100/100 (max_hw=2) [C(vdm=0,cdm=0) -> R(vdm=0,cdm=1,frag=1)] (in_sync=1, out_sync=4) Cross-context implicit dma_resv fence covers earlier slow compute Batch 1
2B-sync Same slow compute + tiny trailing render → glFlush() only → DMA_BUF_IOCTL_EXPORT_SYNC_FILE + poll() + ctx2 readback 100/100 100/100 (max_hw=2) [C(vdm=0,cdm=0) -> R(vdm=0,cdm=1,frag=1)] (in_sync=1, out_sync=4) sync_file poll() waited avg 5.26 ms (min 5.19 ms, max 8.96 ms), matching slow compute Batch 1 (5.14 ms)
  • Kernel / GPU Health: 0 GPU faults, 0 recoveries, 0 hang kills, dmesg delta +0 (+1,026 jobs / +1,826 commands, job_max=3).

Both parts of the follow-up (submit-fence kernel contract + live writer→pre-fragment and shared-BO export/readback output checks) are now closed on exact head 442f2fc3490b.

Assisted-by: LLM (Antigravity)

Multi-pass OpenGL workloads such as post-processing chains and shadow
maps flush intermediate batches on read-after-write hazards (e.g.
binding a prior render target as a sampled texture). Previously each
agx_flush_batch() issued a separate DRM_IOCTL_ASAHI_SUBMIT, incurring
per-pass ioctl, syncobj, and kernel submission overhead even when an
entire frame's passes fit inside one multi-command submission.

Add a queued batch state and per-context pending command queue:
- agx_flush_batch() encodes each batch and appends it via
  agx_batch_queue_or_submit() when the kernel supports multi-command
  submissions and debug/sync flags do not force immediate submission.
- Pending batches drain together in a single DRM_IOCTL_ASAHI_SUBMIT on
  explicit context flush, CPU sync/map, fence creation/server wait,
  query availability checks, shared resource export, batch slot
  pressure, or when adding a batch would exceed
  max_commands_per_submission.
- Within a coalesced submission, compute and render commands carry
  exact intra-submission VDM/CDM barrier indices, emit size-0
  SET_FRAGMENT_ATTACHMENTS / SET_COMPUTE_RESOURCES resets when state
  is no longer present, and share a submission sequence id for group
  retirement while preserving per-batch syncobjs and written-BO
  tracking.
- Add unit tests in test-agx-submit covering multi-batch render and
  compute coalescing, attachment-state clearing, command-limit
  splitting, fence_server_sync draining, and failed submit retirement.

Signed-off-by: Diljit Singh <hey@djdev.me>
Multi-pass OpenGL renders where each pass samples prior render targets
only in the fragment shader previously forced the kernel to wait for
the previous pass's fragment stage before starting the next pass's
vertex/tiling half, and omitted the firmware's few-primitives hint on
fullscreen post-processing passes.

Match Borealis's UAPI flags safely for Gallium renders:
- Track resources written by any render batch in the context
  (rsrc->render_written) and conservatively set
  batch->vs_needs_render_barrier whenever a pre-fragment stage reads a
  render-written, shared, or cross-context resource, writes memory,
  uses indirect draws, conditional rendering, geometry shaders,
  tessellation, or transform feedback.
- When DRM_ASAHI_FEATURE_FRAGMENT_BARRIERS is advertised, vdm_barrier
  is active, and !batch->vs_needs_render_barrier, set
  DRM_ASAHI_RENDER_FRAGMENT_BARRIERS so the kernel overlaps the next
  render's vertex/tiling half with the prior render's fragment stage
  while preserving full compute and fragment ordering.
- Track known primitive counts across direct and multi-draws (marking
  prims_unknown on indirect, primitive restart, patch, GS, tess, or
  high-instance draws) and set DRM_ASAHI_RENDER_FEW_PRIMITIVES on
  native/M5 chips when DRM_ASAHI_FEATURE_FEW_PRIMITIVES is advertised
  and the pass has at most 4 known primitives.
- Extend test-agx-submit to verify both flags and their suppression
  conditions.

Signed-off-by: Diljit Singh <hey@djdev.me>
Coalesced submission was written before the driver enabled
u_threaded_context, and misses three of its contracts:

- agx_get_query_result_flushed() answers a flushed query from the
  frontend thread from the per-batch query_state that agx_batch_submit()
  publishes under query_lock, and expects every writer of a flushed
  query to be published as submitted. Batches submitted together by
  agx_submit_pending(), or quarantined by agx_retire_failed_pending(),
  never published it. Publish it from one helper on every submit and
  quarantine path, and set any_faults atomically on the coalesced
  failure paths as the single-batch paths do.
- agx_resource_get_handle() drains the pending submits of the context
  the frontend passes, which is the u_threaded_context wrapper when TC
  is enabled. Unwrap and sync it before treating it as an agx_context.
- The threaded-context test compares a texture's readback with its
  upload. On G17P that level is compressed and both directions go
  through GPU staging blits, which the no-op shim never executes; the
  comparison passed only while the readback's staging BO was the
  upload's, recycled through the BO cache. With the upload's batch
  still queued, it no longer is. Compare uncompressed levels only.

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

Copy link
Copy Markdown
Author

Rebased cleanly onto aurora-wip after u_threaded_context (#689) at c1dddbc3e666 and added an integration commit (asahi: integrate coalesced submits with u_threaded_context) fixing query-state publication under query_lock + atomic any_faults on coalesced submit/quarantine paths, threaded_context_unwrap_sync() in agx_resource_get_handle(), and compressed-level readback guarding in test-agx-threaded-context.c. Verified clean against aurora-wip (c3fee1a8c89) with full asahi CI passing (250/250) and aurora-agent-policy passing.

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

Reviewed at head c1dddbc3e666c37403b788e696a86e9aad4e6aaa (asahi: coalesce multi-pass batches and emit fragment barriers and few-primitives hints).

Code audit

  • Batch lifecycle (active / queued / submitted) & draining: Verified state transitions (agx_batch_mark_active, agx_batch_mark_queued, agx_batch_mark_submitted, agx_batch_mark_complete) and drain points across agx_flush_all, agx_sync_all, agx_sync_batch, agx_get_batch_for_framebuffer, agx_flush_readers_except_range(sync=true), agx_flush_writer_except(sync=true), agx_fence_snapshot_syncobj, agx_fence_server_sync, agx_resource_get_handle, agx_flush_resource, is_query_busy, agx_destroy_context, and agx_flush.
  • Threaded context & sync ownership: Verified agx_publish_batch_query_state() under ctx->query_lock keeps queued batches submitted = false until agx_submit_pending() submits them (preserving agx_get_query_result_flushed() semantics), agx_get_in_sync() returns a borrowed handle without leaking on submit or error, and last_batch->syncobj from DRM_IOCTL_ASAHI_SUBMIT out_syncs covers all coalesced commands in the submission for shared-BO release fences and timeline transfers.
  • Fragment barriers & coalesced M5 resource encoding: Verified against the DRM_ASAHI_RENDER_FRAGMENT_BARRIERS UAPI contract (asahi_drm.h) that render barriers move to the fragment half while compute (cdm_barrier) dependencies still order the vertex half, so rsrc->render_written + agx_batch_note_vs_read() (covering VBOs, IBOs, indirect buffers, pre-fragment UBOs/SSBOs/textures/images, shared/cross-context BOs, GS/tess/XFB, conditional queries, and VS memory writes) is sound. Empty-header SET_FRAGMENT_ATTACHMENTS / SET_COMPUTE_RESOURCES resets between heterogeneous coalesced commands and the sync_capacity upper bound check out.

Verification

Built in an isolated debugoptimized build (-Dtools=drm-shim, MESA_SHADER_CACHE_DISABLE=1) and tested on J775c (Apple M5 Max, G17C B1, Linux 7.3) (OpenGL ES 3.2 Mesa 26.3.0-devel (git-c1dddbc3e6)):

  • meson test --suite asahi: 245/245 PASS (including asahi-{g13g,g17p,t6041}-gallium-submit and asahi-{g13g,g16g,g17p}-threaded-context).
  • Live GLES3 / GLES31 CTS on Apple M5 Max (G17C B1) (--deqp-surface-type=fbo):
    • dEQP-GLES3.info.*: 6/6 PASS
    • dEQP-GLES3.functional.fbo.color.repeated_clear.*: 108/108 PASS
    • dEQP-GLES3.functional.fbo.render.shared_colorbuffer.*: 84/84 PASS
    • dEQP-GLES3.functional.texture.vertex.2d.filtering.*: 36/36 PASS
    • dEQP-GLES3.functional.occlusion_query.*: 66/66 PASS
    • dEQP-GLES3.functional.fence_sync.*: 11/11 PASS
    • dEQP-GLES31.functional.synchronization.inter_call.without_memory_barrier.*: 36/36 PASS
    • 347/347 PASS, zero GPU faults in dmesg.

Untested scope

  • Live G13/G14/G15/G16/G17P hardware (tested via g13g, g16g, g17p, and t6041 drm-shim unit tests and live G17C B1 silicon).
  • Full GLES3/GLES31/GL46 CTS suites and Wayland/compositor multi-context fence-sharing stress tests beyond the targeted suites above.

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

Copy link
Copy Markdown
Author

Merged into aurora-wip.

  • Exact-head commit c1dddbc3e666 verified with asahi CI (45375420934 / 45367011804, aurora-agent-policy 45375421073) and peer approval from @satchlj.

DjDeveloperr added a commit that referenced this pull request Nov 24, 2026
The revert of #822 kept #896 (inter-submission barrier elision for
disjoint AGX3 batches, merge commit ba9bcc7), but #896 is built on
#822's written-BO list and per-batch submission state, so the driver no
longer compiled. Revert #896 as well, in the order a clean revert takes:
#896 first, then #822.

Two later users of #822 are adapted rather than reverted:

- #802 (HAL200 bind elision for multi-draw indirect) noted the indirect
  buffer as a vertex-stage read for #822's render barrier tracking. That
  tracking is gone; the indirect buffer is still recorded as a batch
  read.
- #745 (fast-clear batches) also checked #822's primitive counters. Its
  draw checks remain.

#754's agx_resource_set_valid() and #745's change to always write the
compute end timestamp are kept.

Two test changes keep later tests meaningful without #822:

- #822's guard in the threaded-context test that skips comparing a
  compressed level is kept. That level uploads and reads back through
  GPU blits, which the no-op drm-shim never runs.
- The #802 multi-draw test checked that a forced flush started a new
  batch by comparing batch pointers. Without #822 the flushed batch is
  submitted at once and its slot can be reused, so it compares the batch
  sequence number instead.

Signed-off-by: Dj <43033058+DjDeveloperr@users.noreply.github.com>
DjDeveloperr added a commit that referenced this pull request Nov 24, 2026
…-submits

Revert #896 and #822: GL coalesced submissions break render ordering on G13/G14
AxxzyWasTaken pushed a commit to AxxzyWasTaken/mesa that referenced this pull request Nov 25, 2026
…f/asahi-multipass-coalesce-frag-barriers"

This reverts merge commit 3fc1b77, reversing changes made to
8315013.

aurora-silicon#822 breaks gpubench-gl render.postfx on M1 Pro (G13X) and M2 Air
(G14G): the output check fails with the centre pixel at (0,249,0,255).
A bisect on a bare-metal M1 Pro found 8315013 as the last good
commit and 3fc1b77 as the first bad one.

On those GPUs the kernel accepts DRM_ASAHI_RENDER_FRAGMENT_BARRIERS and
then adds no wait at all for the earlier render, relying on the order of
the fragment queue. aurora-silicon#822 sets that flag on every render that depends on
an earlier one, and queues the passes of a multi-pass chain into one
submission. Nothing but fragment-queue order then separates a pass from
the output of the pass before it, which is not enough on these GPUs.
Revert it until the ordering is correct on every GPU.

Later commits build on parts of aurora-silicon#822. The conflicts are resolved as
follows:

- aurora-silicon#896 (inter-submission barrier elision) uses the written-BO list and
  the per-batch submitted_has_vdm, submitted_has_cdm and
  barrier_untracked state. That tracking and its single-submission
  barrier test are kept. Its changes to the coalesced submission path
  go with that path.
- aurora-silicon#754 (PBO upload) replaced the valid-level bit with
  agx_resource_set_valid(); that call is kept.
- aurora-silicon#745 (fast-clear batches) also checked the primitive counters aurora-silicon#822
  added. Those counters are gone; its draw checks remain.
- aurora-silicon#745's change to always write the compute end timestamp is kept.
- The flush_resource barrier sequence update from aurora-silicon#896 is kept; the
  pending-submission flush that went with it is removed.

Signed-off-by: Dj <43033058+DjDeveloperr@users.noreply.github.com>
@RyanTheTide
RyanTheTide deleted the perf/asahi-multipass-coalesce-frag-barriers branch November 27, 2026 13:20
AxxzyWasTaken pushed a commit to AxxzyWasTaken/mesa that referenced this pull request Dec 3, 2026
…fix the build"

This reverts commit 3432e67.

Signed-off-by: Dj <43033058+DjDeveloperr@users.noreply.github.com>
AxxzyWasTaken pushed a commit to AxxzyWasTaken/mesa that referenced this pull request Dec 3, 2026
…rf/asahi-multipass-coalesce-frag-barriers"

This reverts commit 241e852.

Signed-off-by: Dj <43033058+DjDeveloperr@users.noreply.github.com>
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