Skip to content

borealis: prune retired exact priors and prefer fragment barriers - #1216

Merged
RyanTheTide merged 2 commits into
aurora-wipfrom
perf/prune-retired-exact-priors
Nov 27, 2026
Merged

RyanTheTide merged 2 commits into
aurora-wipfrom
perf/prune-retired-exact-priors

Conversation

@DjDeveloperr

Copy link
Copy Markdown

What: Prune already-retired exact VDM/CDM ordinals from hk_sync_queue using a 64-entry timeline-to-ordinal ring, and prefer DRM_ASAHI_RENDER_FRAGMENT_BARRIERS over DRM_ASAHI_RENDER_STAGE_PREFIXES when the vertex half has no render prefix and an unchanged compute prefix.

Why

On queues using exact historical ordinals (M5 and HAL200), last_absolute and tail ordinals remain nonzero indefinitely after the referenced submission retires on the GPU. A single earlier HK_SYNC_GFX_MEM render leaves a stale prior_ta[VDM] ordinal on thousands of subsequent renders (measured up to 27,710 renders behind, median 6,268 in GTA V), preventing DRM_ASAHI_RENDER_FRAGMENT_BARRIERS and forcing M5 renders onto the staged render path instead of direct kernel publication.

Summary of changes

  • Retired ordinal ring (hk_sync.h, hk_sync.c): Record each submission's (timeline_point, submitted[VDM], submitted[CDM]) in a 64-entry ring on hk_sync_queue (zeroed automatically by hk_queue_restart_sync()). When completed advances, raise retired_ord[sq] monotonically and prune retired ordinals (<= retired_ord[sq]) to 0 in last_absolute, tail, and resolved prior/prior_ta fields before computing ta_split.
  • Progress refresh (hk_queue.c): Start completed from queue->drm.signalled_value and refresh via drmSyncobjQuery() when hk_sync_submit_has_unretired_priors(queue) holds.
  • Prefer FRAGMENT_BARRIERS (hk_queue.c): When DRM_ASAHI_FEATURE_FRAGMENT_BARRIERS is available and the vertex half has no render prefix (barrier_ta[VDM] == NONE, prior_ta[VDM] == 0, ta_command_prior[VDM] == 0) with an unchanged compute prefix, emit DRM_ASAHI_RENDER_FRAGMENT_BARRIERS instead of DRM_ASAHI_RENDER_STAGE_PREFIXES.
  • Unit tests (test-hk-sync-prior.c): Added retired-prior pruning tests covering unretired HK_SYNC_GFX_MEM, partial retirement (prior_ta[VDM] pruned while live fragment prior[VDM] keeps ta_split), and full retirement clearing both priors and ta_split.

Testing

All hardware tests run on J714s (Apple M5 Pro, G17S, kernel 7.3.0-m5-cdirect16, base aurora-wip fa8970cda14f, isolated Mesa kits, 0 GPU faults, 0 kernel errors):

  • Unit tests (--suite asahi):
    • Assert build (-Db_ndebug=false, GCC 16.1.1): 214/214 PASS (0 warnings in touched files)
    • Release build (-Db_ndebug=true): 214/214 PASS
  • Targeted Vulkan CTS (cts1471/deqp-vk):
    • dEQP-VK.synchronization.op.single_queue.barrier.*vertex*: 258/258 PASS (0 failed)
    • dEQP-VK.synchronization2.op.single_queue.barrier.*vertex*: 509/509 PASS (0 failed)
    • dEQP-VK.query_pool.occlusion_query.*: 434/434 PASS (0 failed, 7 not supported)
  • gpubench-vk render.pass_chain (passes=14, res=tiny 60x33, RGBA16F, all CRCs valid=True):
    • kind=all_bar, depth=4: 40.89 -> 20.53 us/pass (2.00x, -49.8%); depth=1 gpu_us: 206.9 -> 125.5 us (-39.3%)
    • kind=indep, depth=4: 40.58 -> 18.67 us/pass (2.17x, -54.0%); depth=1 gpu_us: 196.7 -> 125.6 us (-36.1%)
    • kind=frag_bar, depth=4: 40.89 -> 31.24 us/pass (-23.6%)
  • GTA V Enhanced native benchmark (3024x1964, ResScalingType=0, HK_FRAME_ANATOMY_TS=none):
    • Eliminated 100% of stale prior_ta[VDM] lag (median 6,268 / max 27,710 -> median 0 / max 56, same-frame live only).
    • Base: P0=55.68 P1=51.33 P2=51.91 P3=57.09 P4=54.48 FPS
    • Stacked with OQ-stamp PR: P0=55.76 P1=51.71 P2=51.84 P3=56.87 P4=55.11 FPS (+1.2% P4, +0.7% P1, 0 GPU faults)

Not yet

  • Second-generation HAL200 (J700 / G17P) targeted synchronization CTS row, since exact-prior retirement pruning also runs on HAL200 queues.

Risk: two-way door · shared Borealis sync path; retired_ord[sq] only advances for timeline points confirmed complete (point <= completed) via the queue's monotonic syncobj timeline, so live dependencies are never dropped.

On queues using exact historical ordinals (M5 and HAL200), last_absolute
and tail ordinals remain nonzero indefinitely after the referenced
submission has retired on the GPU. For example, a single earlier
HK_SYNC_GFX_MEM render leaves a stale prior_ta[VDM] ordinal on thousands of
subsequent renders, preventing DRM_ASAHI_RENDER_FRAGMENT_BARRIERS and
forcing M5 renders onto the staged render path.

- Record a 64-entry ring on hk_sync_queue mapping each submission's
  timeline point to its submitted VDM/CDM ordinals, and advance
  retired_ord[sq] whenever completed advances from drmSyncobjQuery() or
  the cached queue signalled_value.
- Prune retired ordinals (<= retired_ord[sq]) to 0 in last_absolute,
  tail, and resolved prior/prior_ta fields before computing ta_split.
- Prefer DRM_ASAHI_RENDER_FRAGMENT_BARRIERS over
  DRM_ASAHI_RENDER_STAGE_PREFIXES when the vertex half has no render
  prefix and an unchanged compute prefix, preserving identical ordering
  with a smaller render command eligible for direct kernel publication.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 27, 2026 08:15
@DjDeveloperr

Copy link
Copy Markdown
Author

Verdict at c01fe0c8628f: ready

Blockers

None.

Checked

  • Retirement is only recorded for work that has finished.
    • sync_record_retired() runs after submitted[] has been raised and stores queue->drm.timeline_value. queue_submit_recordings() raises that value by the submission's point_count before resolving, so the stored point is this submission's last signal point (its last chunk with chunked timelines).
    • retired_ord[sq] only moves when completed >= point, from the cached signalled_value or a fresh drmSyncobjQuery(). So every ordinal it covers belongs to work the queue has finished on both subqueues.
    • Ordinals are 64-bit and per queue, so there is no wraparound and no cross-queue mixing. A ring entry overwritten before its point is seen only delays pruning. A submission that fails after resolving leaves a point that never signals, so nothing is pruned for it.
  • Pruning.
    • last_absolute, tail and each stream's prior/prior_ta drop to 0 only when they are at or below retired_ord, and that happens before ta_split is worked out.
    • This covers the borealis: narrow HK_SYNC_GFX_IMG vertex waits by attachment image bloom #1206 bloom path too: resolve_exact_vdm_ta_bloom() reads the pruned last_absolute, and an exact prior_ta it picks from the attachment ring is pruned in the same pass if it has already retired.
    • hk_sync_merge_rendering() and att_bloom are untouched.
  • FRAGMENT_BARRIERS instead of staged prefixes on M5.
    • It is used only when the vertex half has no render wait (barrier_ta/prior_ta/ta_command_prior on VDM empty), the compute prefix is identical for both halves, and the fragment half has a render wait.
    • Under the UAPI, render dependencies then wait in the fragment half and cdm_barrier still orders the vertex half, so the ordering matches the staged form. A render with m5_vertex_tps keeps its render wait in the vertex half, so it never takes this path.
  • Merge and build.
  • Mutations. Recording retirement before the point completes is caught (2 failures). Dropping the per-stream prior_ta prune is not caught. A cross-submit case where the attachment ring hands back an already-retired ordinal would cover it.
  • Policy. No new environment options. agent-policy.sh pr HEAD: PR is clean. Signed off, no attribution lines.

Still owed before merge

  • A J714s row on kits built from this head. The Tested section uses kits built on fa8970cda14f and a GTA V run stacked with another PR.
  • The J700 (HAL200) synchronization CTS row listed under Not yet, since the pruning runs on HAL200 queues too.

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

Verdict: FINISH, then merge at c01fe0c8628f9ab301606dab62c0e89a6f79c546

Blockers: none in the code.

To finish:

  1. Merge aurora-wip. The PR conflicts in src/asahi/vulkan/hk_sync.c. #1144 (load_hazard_frag(), the new recent_conflict(..., frag_only) signature) added functions right after hk_sync_submit_needs_completed(), where this PR adds hk_sync_submit_has_unretired_priors(), sync_advance_retired() and sync_record_retired(). Keep both sides, with this PR's three functions first so the load_hazard_frag() block stays directly above recent_conflict(). I gated that resolution locally (numbers below).
  2. A J714s row at the new head. The Tested section's kits were built on fa8970cda14f, which is an older ancestor (the head's parent is b200715b4841), and the GTA V numbers are stacked with another PR. The conflict is in a touched file, so the post-merge head needs its own row.
  3. The J700 (HAL200) synchronization CTS row listed under Not yet. Pruning runs on every exact_prior queue, not only M5.

Checked:

  • Retirement bookkeeping. sync_record_retired() runs after submitted[] is raised and stores queue->drm.timeline_value, which queue_submit_recordings() has already raised by point_count for this submission. retired_ord only moves for entries with point <= completed, and completed is the cached signalled_value or a fresh drmSyncobjQuery(), so it is a real lower bound. The host-flush ordinal (hk_sync_host_flush_prefix() does submitted[CDM]++ after resolve) falls into the next ring entry, which only delays pruning. hk_queue_restart_sync() memsets the whole hk_sync_queue, so the ring and retired_ord reset with a new kernel queue. All of it, including the per-stream prune, sits inside exact_prior blocks, so legacy queues are untouched. Empty submissions pass completed = 0 and record nothing.
  • Pruning only drops waits on work that has finished. last_absolute/tail at or below retired_ord go to 0 before resolving, and the per-stream prior/prior_ta prune runs before ta_split. Ordinals of the current submission are above submitted and are never pruned.
  • FRAGMENT_BARRIERS selection. m5_frag_barriers_only only turns off the two M5 staged forms. The existing generic FRAGMENT_BARRIERS branch then fires, since its conditions are a superset. On HAL200 nothing changes: g17p_staged already requires the compute halves to differ, and the new flag requires them to be equal. The flag is selected by DRM_ASAHI_FEATURE_FRAGMENT_BARRIERS, a kernel capability, so no new gate. Nit: the m5_ prefix is misleading for a capability-selected flag.
  • Non-blocking: hk_sync_submit_has_unretired_priors() is true after almost every submission on an exact queue (submitted > retired_ord as soon as anything is in flight), so this adds a drmSyncobjQuery() ioctl to nearly every submit there. The GTA V numbers show no cost, but a cheaper test (any nonzero last_absolute/tail above retired_ord) would skip it when nothing is left to prune.
  • Non-blocking test gaps (mutations below): removing the per-stream prior/prior_ta prune, or changing the queue-level <= ret to < ret, is not caught. A cross-submit case where the attachment ring hands back an already-retired exact prior_ta, plus a boundary case at exactly retired_ord, would cover both.
Evidence
  • Local x86 drm-shim gate (stands in for CI): head merged into aurora-wip 5ab97d0f2c60 with the resolution above (local merge 792dfbcc2c00, not pushed). meson test --suite asahi --suite poly: 338 Ok / 0 Fail, the same as the aurora-wip tip (338 / 0). hk_sync_prior_test: 3574 checks / 0 failures (tip 3566, plus the 8 new checks).
  • Mutations on the merged tree: dropping the sync_advance_retired() call gives 2 failures (caught). Dropping the per-stream prior/prior_ta prune gives 0 failures (not caught). <= changed to < in the last_absolute/tail prune gives 0 failures (not caught).
  • Rows: J714s M5 Pro (G17S) on kits from base fa8970cda14f, not this head and not the post-merge head: missing at head. J700 G17P: missing.

@DjDeveloperr

Copy link
Copy Markdown
Author

J700 (MacBook Neo, G17P B1, HAL200) at c01fe0c8628f, against merge-base b200715b4841: PASS. render.pass_chain is 6–8 % faster at depth 4 and flat at depth 1, CRCs are clean, and the sync, barrier and renderpass CTS shows 0 Fail.

  • Setup:

    • Stock kernel 7.3.0-41 with no reboot. One isolated Mesa build per SHA, both from fedora-mbuild with the same options.
    • vulkaninfo showed each build's own driver id (git-b200715b48 and git-c01fe0c862) on the Apple A18 Pro.
    • Shader cache off, MAX_RECOVERIES=0.
    • gpubench-vk is gpubench fdf4dd6, the build with render.pass_chain.
  • gpubench-vk:

    • After a 30 s warm-up, same boot, in the order b h h b h b b h (ABBA+BAAB).
    • Median us per submit, lower is better.
    • All 96 results ok, with every output check valid.
    row d1 base → head d4 base → head
    render.pass_chain kind=all_bar 520.3 → 518.4 (−0.4 %) 457.9 → 423.6 (−7.5 %)
    render.pass_chain kind=frag_bar 520.3 → 517.1 (−0.6 %) 461.3 → 425.2 (−7.8 %)
    render.pass_chain kind=indep 514.9 → 518.9 (+0.8 %) 429.2 → 401.8 (−6.4 %)
    render.pass_chain kind=oq_bar 791.1 → 798.1 (+0.9 %) 862.1 → 867.3 (+0.6 %)
    render.deferred 603.9 → 608.6 (+0.8 %) 505.1 → 502.8 (−0.5 %)
    render.postfx 1078 → 1081 (+0.3 %) 984.3 → 978.5 (−0.6 %)

    pass_chain uses its defaults: res tiny, 14 passes. Spreads are 0.2–3.6 % per arm.

  • Vulkan CTS on the head, 25,932 cases:

    • synchronization(2).basic, op.single_queue.barrier and op.single_queue.event (10,010);
    • every renderpasses.*self_dep* case (renderpass1, renderpass2, dynamic_rendering: 15,738);
    • memory.pipeline_barrier (184).

    Results: 24,559 Pass, 1,373 NotSupported, 0 Fail, 0 recoveries.

  • Health: 0 GPU faults, 0 driver warnings, 0 AVC denials, 0 failed units and 0 core dumps. stock.sh was identical before and after.

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

Copy link
Copy Markdown
Author

Exact-head J714s verification (c01fe0c8628f on b200715b484)

Verified exact head c01fe0c8628f9ab301606dab62c0e89a6f79c546 on MacBook Pro M5 Pro (J714s, kernel 7.3.0-m5-cdirect16, isolated Mesa kit):

Check Target Result
meson test --suite asahi (Assert, -Db_ndebug=false) J714s (7.3.0-m5-cdirect16) 214/214 PASS (0 warnings in touched files)
meson test --suite asahi (Release, -Db_ndebug=true) J714s (7.3.0-m5-cdirect16) 214/214 PASS
VK CTS dEQP-VK.synchronization.op.single_queue.barrier.*vertex* J714s (7.3.0-m5-cdirect16) 258/258 PASS (0 failed)
VK CTS dEQP-VK.synchronization2.op.single_queue.barrier.*vertex* J714s (7.3.0-m5-cdirect16) 509/509 PASS (0 failed)
gpubench-vk render.pass_chain (passes=14, res=tiny) J714s (7.3.0-m5-cdirect16) indep d=4: 39.46 -> 17.83 us/pass (2.21x / -54.8%, gpu_us 489.4 -> 237.2 -51.5%); indep d=1: gpu_us 216.3 -> 123.8 (-42.8%); all_bar d=4: 39.79 -> 29.33 us/pass (-26.3%), valid=True, status=ok
GPU health J714s (7.3.0-m5-cdirect16) 0 GPU faults, online=1, crashed=0, quarantined=0

Note: the merge conflict against current aurora-wip (5ab97d0) is a single adjacent-function placement in src/asahi/vulkan/hk_sync.c (load_hazard_frag() from #1144 next to exact_prior_completed(), zero logic overlap).

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

Verdict: FINISH, then merge at 12a93c9c17c07ca4db02034125dc576500bf0eab

Blockers: none in the code. Rows are owed at this head: J700 (G17P) and J714s (M5). The rows at c01fe0c8628f were run on base b200715b4841, before #1144. The merge hand-resolves hk_sync.c, which this PR touches, and it brings #1144's fragment-only tile-hazard path (load_hazard_frag(), vf[]) into the same submit code where this PR prunes priors and prefers fragment barriers. That combination has not run on hardware. A short repeat of the render.pass_chain d4 rows and the sync/barrier/self_dep CTS subset on both Macs is enough.

Checked: this is a resolution review of the aurora-wip merge 12a93c9c17c0 (git show --remerge-diff) and of how the two sides combine.

  • The conflict. It is a placement conflict only. hk_sync_submit_has_unretired_priors(), sync_advance_retired() and sync_record_retired() from this PR sit before aurora-wip's load_hazard_frag() and the recent_conflict() comment. No logic changed on either side.
  • Pruning against #1144. The prune in the submit loop zeroes prior[sq]/prior_ta[sq] only when they are <= retired_ord[sq]. retired_ord only advances in sync_advance_retired() from timeline points <= completed. So it drops waits only on work that has already finished, whether #1144 routed the hazard to the fragment-only vf[] or to the full v[]. The ta_split recompute after it still keeps the vertex half at least as strict as the fragment half.
  • Merge. The head merges cleanly into aurora-wip fffdc5c7c634.
Evidence

Local drm-shim gate (x86 clang, release + asserts, meson test --suite asahi --suite poly):

  • aurora-wip fffdc5c7c634: Ok 338, Fail 0
  • aurora-wip fffdc5c7c634 + 12a93c9c17c0 (clean merge, tree 2cf7ec712d17): Ok 338, Fail 0; test-hk-sync-prior passes

@RyanTheTide

Copy link
Copy Markdown

12a93c9c17c0 J700 (Neo, Apple A18 Pro / G17P B1, 7.3.0-aurora-fleet89) PASS: Borealis exact-head overlay ICD (VK_DRIVER_FILES, -Dbuildtype=release -Db_ndebug=false, stock /usr/lib64/libvulkan_asahi.so verified byte-identical before/after); meson test --suite asahi 215/215 PASS; deqp-vk 1,516 PASS / 0 FAIL (api.smoke.* 8/8, synchronization.basic.* 29/29, synchronization.op.single_queue.barrier.*vertex* 258/258, synchronization2.op.single_queue.barrier.*vertex* 509/509, pipeline.monolithic.timestamp.* 278/278, query_pool.occlusion_query.* 434/441); 0 GPU faults/recoveries, Enforcing, 0 failed units, 0 new AVC.

@RyanTheTide

Copy link
Copy Markdown

12a93c9c17c0 J615 (M3 Air, Apple M3 / G15G C0, 7.3.0-aurora-fleet90-airs2) + J316s (M1 Pro, Apple M1 Pro / G13S C0, 7.3.0-aurora-fleet89) PASS: Borealis exact-head overlay ICD (VK_DRIVER_FILES, -Dbuildtype=release -Db_ndebug=false, stock /usr/lib64/libvulkan_asahi.so verified byte-identical before/after on both Macs); deqp-vk on J615 api.smoke.* 8/8, synchronization.basic.* 29/29, pipeline.monolithic.timestamp.* 278/278, query_pool.occlusion_query.* 434/441, 2D barrier.*vertex* 12/12 PASS (the 3D image_64x64x8_r32_sfloat VK_ERROR_DEVICE_LOST / fw recovery on 7.3.0-aurora-fleet90-airs2 reproduced identically 0/1 in same-boot stock Mesa A/B control on both synchronization and synchronization2); deqp-vk on J316s 715 PASS / 0 FAIL (api.smoke.* 8/8, synchronization.basic.* 21/29, pipeline.monolithic.timestamp.* 252/278, query_pool.occlusion_query.* 434/441; barrier.*vertex* NotSupported on G13S, 0 GPU faults); Enforcing, 0 failed units, 0 new AVC on both.

@RyanTheTide
RyanTheTide merged commit 743fa0d into aurora-wip Nov 27, 2026
@RyanTheTide
RyanTheTide deleted the perf/prune-retired-exact-priors branch November 27, 2026 14:59
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