Repository navigation
asahi: coalesce multi-pass batches and emit fragment barriers and few-primitives hints - #822
Conversation
RyanTheTide
left a comment
There was a problem hiding this comment.
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.
G17S B1 (
|
Exact-head Apple M4 (
|
| 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)
|
Reply to the 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 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), Also: G16 doesn't advertise 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) |
|
Reply to the Environment & Exact-Head Identity
Live Output Results — 700/700 bit-exact PASS (100% coalesced
|
| 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:
0GPU faults,0recoveries,0hang kills,dmesgdelta+0(+1,026jobs /+1,826commands,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>
442f2fc to
c1dddbc
Compare
|
Rebased cleanly onto |
satchlj
left a comment
There was a problem hiding this comment.
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 acrossagx_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, andagx_flush. - Threaded context & sync ownership: Verified
agx_publish_batch_query_state()underctx->query_lockkeeps queued batchessubmitted = falseuntilagx_submit_pending()submits them (preservingagx_get_query_result_flushed()semantics),agx_get_in_sync()returns a borrowed handle without leaking on submit or error, andlast_batch->syncobjfromDRM_IOCTL_ASAHI_SUBMITout_syncscovers 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_BARRIERSUAPI contract (asahi_drm.h) that render barriers move to the fragment half while compute (cdm_barrier) dependencies still order the vertex half, sorsrc->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-headerSET_FRAGMENT_ATTACHMENTS/SET_COMPUTE_RESOURCESresets between heterogeneous coalesced commands and thesync_capacityupper 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 (includingasahi-{g13g,g17p,t6041}-gallium-submitandasahi-{g13g,g16g,g17p}-threaded-context).- Live GLES3 / GLES31 CTS on
Apple M5 Max (G17C B1)(--deqp-surface-type=fbo):dEQP-GLES3.info.*: 6/6 PASSdEQP-GLES3.functional.fbo.color.repeated_clear.*: 108/108 PASSdEQP-GLES3.functional.fbo.render.shared_colorbuffer.*: 84/84 PASSdEQP-GLES3.functional.texture.vertex.2d.filtering.*: 36/36 PASSdEQP-GLES3.functional.occlusion_query.*: 66/66 PASSdEQP-GLES3.functional.fence_sync.*: 11/11 PASSdEQP-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, andt6041drm-shim unit tests and liveG17C B1silicon). - Full GLES3/GLES31/GL46 CTS suites and Wayland/compositor multi-context fence-sharing stress tests beyond the targeted suites above.
|
Merged into
|
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>
…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>
…fix the build" This reverts commit 3432e67. Signed-off-by: Dj <43033058+DjDeveloperr@users.noreply.github.com>
…rf/asahi-multipass-coalesce-frag-barriers" This reverts commit 241e852. Signed-off-by: Dj <43033058+DjDeveloperr@users.noreply.github.com>
Summary
Closes the multi-pass OpenGL submission and barrier gap vs Borealis on Apple Silicon:
asahi: coalesce hazard-flushed batches into multi-command submits(e59614516ff)ctx->pendingcommand queue so hazard-flushed intermediate passes (e.g. post-processing chains and shadow passes) encode intoctx->pendingviaagx_batch_queue_or_submit()and drain together in a singleDRM_IOCTL_ASAHI_SUBMITon explicit flush, CPU sync/map, fence creation/server wait, query availability checks, shared resource export, batch slot pressure, ormax_commands_per_submissionoverflow.vdm_barrier/cdm_barrierindices, size-0SET_FRAGMENT_ATTACHMENTS/SET_COMPUTE_RESOURCESstate resets between heterogeneous commands, and group retirement viabatch->submit_seqwhile preserving per-batch syncobjs and written-BO tracking.src/gallium/drivers/asahi/tests/test-agx-submit.ccovering multi-batch render/compute coalescing, attachment-state resets,max_commands_per_submissionsplitting,fence_server_syncdraining, and failed-submit retirement.asahi: emit fragment barriers and few-primitives hints on renders(442f2fc3490)rsrc->render_written) and conservatively setsbatch->vs_needs_render_barrierwhenever 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.DRM_ASAHI_RENDER_FRAGMENT_BARRIERSwhenDRM_ASAHI_FEATURE_FRAGMENT_BARRIERSis 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.prims_unknownon indirect, primitive restart, patch, GS, tess, or high-instance draws) and emitsDRM_ASAHI_RENDER_FEW_PRIMITIVESon native/M5 chips whenDRM_ASAHI_FEATURE_FEW_PRIMITIVESis advertised andknown_prims <= 4, matching Borealis.test-agx-submit.cto verify both flags and all suppression cases.Verification
Offline CI (
fedora-mesaciat exact head442f2fc3490b)--suite asahi: 164/164 PASS--suite poly: 5/5 PASSASAHI_SHIM_VALIDATE_G17P_STREAM=1withlibasahi_noop_drm_shim.so: 233/233 runnable tests PASS (includingasahi-{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: cleanMacBook Neo (
Apple A18 Pro/G17P B1) — Exact Head442f2fc3490bvs Baseefabab38502d1. Custom 8-test GL hardware verifier (
test_multipass_submit)base(git-efabab3850) andcand(git-442f2fc349): 8/8 PASS with identical CRC (0x7e130dde):0x7e130dde)texelFetchfrom render-written texture (20 iters — verifiesvs_needs_render_barriersuppressesFRAGMENT_BARRIERS)glMemoryBarrier-> Pass 1 VS SSBO overwrite (20 iters)max_commands_per_submission(64) andAGX_MAX_BATCHES(32)GL_ANY_SAMPLES_PASSED,GL_TIME_ELAPSED,GL_TIMESTAMP) withoutglFlush()glFenceSync/glWaitSyncinter-batch orderingFEW_PRIMITIVESboundary (1, 2, 4, 5, 20 triangles +glMultiDrawArrays2+2 vs 2+3)2. 6-round cool-down ABBA (
gpubench-gl --verify, 3s cool-down between legs)efabab3850)442f2fc349)us)rec+sub,us)render.postfx(1080p,msaa=1)fps2133faaa)render.postfx(1440p,msaa=1)fpsrender.postfx(1080p,msaa=4)fpsrender.postfx(1080p,msaa=1)fps2133faaa)render.postfx(1440p,msaa=1)fpsrender.postfx(1080p,msaa=4)fpsrender.shadow(fmt=d16)mtri_srender.shadow(fmt=d16)mtri_srender.shadow(fmt=d32f)mtri_srender.shadow(fmt=d32f)mtri_scompress.bw(mrt4,1440p)us/subcompress.bw(mrt4,1440p)us/subcompress.bw(storage,1440p)us/subcompress.bw(storage,1440p)us/subcompute.uber(control)us/subcompute.uber(control)us/subsync.finish(control)us/sub*Note on
render.postfx 1080p depth=1(-4.63%,+43 us): with synchronousglFinish()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 usidle-start latency for2.30xlower total CPU:300.0 -> 130.3 us). Under standard pipelined double buffering (depth=2), the GPU stays busy and everyrender.postfxconfiguration wins+4.47%to+8.42%across all 6 rounds, whilerender.shadowwins up to+7.50%even atdepth=1with4.35xless 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=0dEQP-GLES3.functional.transform_feedback.*: 882/882 Pass on both,diffs=0dEQP-GLES3.functional.texture.vertex.*: 174/174 Pass on both,diffs=0dEQP-GLES3.functional.occlusion_query.*: 62/62 Pass on both,diffs=0dEQP-GLES31.functional.draw_indirect.*: 207 cases (193 Pass / 14 NotSupported on both),diffs=0dEQP-GLES31.functional.synchronization.*: 104/104 Pass on both,diffs=0diffs=04. Kernel health
kfault_delta=0,avc_delta=0Assisted-by: LLM (Antigravity:Gemini 4 Neon)