Skip to content

borealis: classify post-graphics query availability streams as HK_SYNC_STAMP - #1230

Merged
RyanTheTide merged 1 commit into
aurora-wipfrom
perf/oq-avail-stamp-kind
Nov 27, 2026
Merged

RyanTheTide merged 1 commit into
aurora-wipfrom
perf/oq-avail-stamp-kind

Conversation

@DjDeveloperr

Copy link
Copy Markdown

What: Classify pure post-graphics query availability streams (hk_flush_oq_pending() and hk_queue_query_available_write(..., after_gfx=true)) as HK_SYNC_STAMP instead of HK_SYNC_GFX, matching timestamp-only streams so GFX/ALL_COMMANDS pipeline barriers and image layout transitions do not stall subsequent renders or computes behind overflow (>3) or non-stamped query availability stores.

Summary

  • Pure post-graphics query availability streams (LIBAGX_WRITE_U32S) write only query availability memory, never attachments, images, buffers, or the geometry heap. Previously they received HK_SYNC_GFX, so any subsequent GFX -> GFX or ALL_COMMANDS -> ALL_COMMANDS pipeline barrier ordered later renders on VDM behind the CDM availability store (VDM -> CDM -> VDM roundtrip stall), even after #1221 when a render exceeds three occlusion queries (nfree < count) or uses non-stamped query pools.
  • Giving them HK_SYNC_STAMP matches existing timestamp-only streams:
    • Application pipeline barriers and image layout transitions (brl_sync_transition_prepare()) no longer stall subsequent renders or computes behind query availability writes.
    • Query commands (HK_SYNC_QUERY_SCOPE, HK_SYNC_QRESET_SCOPE), events, and timestamps (hk_sync_stamp_scope()) still order after HK_SYNC_STAMP both in-CB and across CBs/submissions.
    • hk_sync_src_dep() materializes inline staged occlusion availability on HK_SYNC_STAMP scopes, and brl_sync_transition_begin() flushes inline availability before setting brl_transition_active so availability streams are never tagged as transition streams.
    • hk_sync_heap_used() promotes an existing HK_SYNC_STAMP post_gfx stream to HK_SYNC_GFX | HK_SYNC_GFX_MEM (and updates sync.last) if a later draw in the same pass appends a geometry-heap reset (hk_heap()).
  • Added unit tests in test-hk-query-oq.c covering HK_SYNC_STAMP barrier isolation, in-CB and cross-CB (hk_sync_resolve_submit()) query ordering, transition isolation, event ordering, and hk_sync_heap_used() promotion.

Tested

Machine Head Build / Suite Result
MacBook Pro M5 Pro (J714s, 7.3.0-m5-cdirect16) 5f170b33409f Assert (-Db_ndebug=false) --suite asahi 215/215 PASS (0 warnings in touched lines)
MacBook Pro M5 Pro (J714s, 7.3.0-m5-cdirect16) 5f170b33409f Release (-Db_ndebug=true) --suite asahi 215/215 PASS
MacBook Pro M5 Pro (J714s, 7.3.0-m5-cdirect16) 5f170b33409f CTS dEQP-VK.query_pool.occlusion_query.* 434/434 PASS (7 NS, 0 Fail, 0 faults)
MacBook Pro M5 Pro (J714s, 7.3.0-m5-cdirect16) 5f170b33409f CTS dEQP-VK.query_pool.statistics_query.* 18,770/18,770 PASS (5 NS, 0 Fail, 0 faults)
MacBook Pro M5 Pro (J714s, 7.3.0-m5-cdirect16) 5f170b33409f CTS dEQP-VK.query_pool.concurrent_queries.* 2/2 PASS (0 Fail, 0 faults)
MacBook Pro M5 Pro (J714s, 7.3.0-m5-cdirect16) 5f170b33409f CTS dEQP-VK.synchronization.op.single_queue.event.* 1,631/1,631 PASS (1 NS, 0 Fail, 0 faults)
MacBook Pro M5 Pro (J714s, 7.3.0-m5-cdirect16) 5f170b33409f GTA V Enhanced 3024x1964 (HK_FRAME_ANATOMY_TS=all) R i=4 (bar=v3,c1 -> bar=v3,c-) and R i=7..13 (bar=v*,c2 -> bar=v*,c-) drop all waits on OQ pre=98 (imm=1 and imm=7); R i=0..13 GPU wall span drops 1,619.0 us -> 1,115.7 us (-503.3 us / -31.1% in TS=all) with R i=1..8 overlapped back-to-back; 0 GPU faults. Clean A/B vs 30df6feb98f: P0=58.15->58.80, P1=52.49->52.55, P2=52.25->52.78, P3=56.44->59.02, P4=55.75->57.30 FPS (note: BASE ran at 1578 MHz median pstate 11-13 vs PR at 1620 MHz median pstate 13, so FPS includes DVFS variance; the anatomy barrier drop is the direct causal proof).

Tested: Assert & Release --suite asahi (215/215 each), 20,837/20,837 CTS (query_pool.* + synchronization.op.single_queue.event.*, 0 fail, 0 GPU faults), and GTA V Enhanced 3024x1964 clean + HK_FRAME_ANATOMY_TS=all on MacBook Pro M5 Pro (J714s, head 5f170b33409f).
Risk: two-way · J714s
Not yet: 2nd-generation hardware verification (J700 / G17P).

…C_STAMP

Post-graphics query availability streams (hk_flush_oq_pending() and
hk_queue_query_available_write() with after_gfx) write only query
availability memory, never attachments, images, buffers, or the geometry
heap. Giving them HK_SYNC_GFX caused every subsequent graphics or
ALL_COMMANDS pipeline barrier to wait for the compute availability store
on the CDM subqueue, introducing avoidable VDM->CDM->VDM stalls on later
renders whenever occlusion queries overflow a render's three retirement
timestamp slots or use non-stamped query pools.

Classify post-graphics query availability streams as HK_SYNC_STAMP,
matching timestamp-only streams:
- Pipeline barriers (including ALL_COMMANDS -> ALL_COMMANDS) and image
  layout transitions no longer order later graphics or compute work
  after pure query availability stores.
- Query commands (HK_SYNC_QUERY_SCOPE / HK_SYNC_QRESET_SCOPE), events,
  and timestamps (hk_sync_stamp_scope()) still order after HK_SYNC_STAMP
  both within a command buffer and across command buffers/submissions.
- Flush inline staged occlusion availability before entering a driver
  layout transition (brl_sync_transition_begin()) so it is never tagged
  as a transition stream.
- Promote an existing HK_SYNC_STAMP post-graphics stream to
  HK_SYNC_GFX | HK_SYNC_GFX_MEM in hk_sync_heap_used() if a later draw
  in the same pass appends a geometry-heap reset to it.

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

Copy link
Copy Markdown
Author

J700 (MacBook Neo, Apple A18 Pro T8140 / G17P B1, second generation) at exact head 5f170b33409f against merge-base 30df6feb98f: PASS — clear oq_bar win (-7.5% submit / -7.7% GPU at d4, -10.0% GPU at d1), no regressions elsewhere.

Both arms are isolated release Borealis Vulkan overlays built with identical options and loaded from private prefixes via VK_DRIVER_FILES / LD_LIBRARY_PATH on stock kernel 7.3.0-41.fc44.aurora.aarch64 with no reboot. System Mesa was untouched (stock.sh identical before and after). Each arm's driver ID confirmed its git SHA (git-30df6feb98 vs git-5f170b3340); libvulkan_asahi.so SHA-256 base bfb78d15…, head e2ccb0fe….

gpubench-vk (gpubench fdf4dd6). 30 s warm-up, then A1 B1 B2 A2 B3 A3 A4 B4 (n = 4 per arm, median us_per_submit and gpu_us; lower is better):

row d base us/sub head us/sub Δ us/sub base gpu_us head gpu_us Δ gpu_us ranges (us/sub)
render.pass_chain kind=oq_bar 1 775.2 766.3 -1.15% 652.5 587.6 -9.95% 773.2–779.2 / 763.4–767.3
render.pass_chain kind=oq_bar 4 853.5 789.5 -7.50% 736.3 679.4 -7.72% 849.9–854.7 / 787.4–789.5
render.pass_chain kind=all_bar 1 513.7 514.6 +0.17% 244.9 246.6 +0.71% overlapping
render.pass_chain kind=all_bar 4 449.1 451.1 +0.45% 403.7 407.8 +1.02% overlapping
render.pass_chain kind=frag_bar 1 514.1 513.7 -0.09% 243.3 245.4 +0.87% overlapping
render.pass_chain kind=frag_bar 4 449.1 447.1 -0.45% 407.5 405.5 -0.49% overlapping
render.pass_chain kind=indep 1 511.9 513.7 +0.34% 248.5 248.5 +0.03% overlapping
render.pass_chain kind=indep 4 420.2 421.4 +0.28% 371.3 369.8 -0.40% overlapping
render.deferred tile msaa4 1080p 1 / 2 862.1 / 684.2 860.8 / 681.1 -0.14% / -0.45% 704.0 / 699.8 703.6 / 699.8 -0.04% / 0.00% overlapping
render.deferred dram msaa4 1080p 1 / 2 3208.6 / 2941.2 3191.5 / 2941.2 -0.53% / 0.00% 2933.4 / 3197.2 2928.7 / 3183.7 -0.16% / -0.42% overlapping
render.postfx msaa4 1080p 1 / 2 730.8 / 583.1 730.8 / 580.3 0.00% / -0.48% 527.6 / 680.1 527.8 / 679.5 +0.04% / -0.09% overlapping
render.postfx msaa1 1080p 1 / 2 716.0 / 570.4 716.0 / 567.7 0.00% / -0.47% 512.9 / 666.7 512.9 / 666.2 +0.01% / -0.07% overlapping
render.light kind=tri 1 / 4 123.1 / 33.8 123.4 / 33.8 +0.21% / +0.16% 9.2 / 7.2 9.2 / 7.3 +0.01% / +1.15% overlapping

CRCs match base identically on all 16 CRC-checked rows (pass_chain 93411763, deferred tile 6dc74b48 / dram 7c09507f, postfx msaa4 668d6f0a / msaa1 a630011d). Both oq_bar d1 and d4 gpu_us and us_per_submit ranges are completely non-overlapping.

Targeted VK CTS on exact head 5f170b33409f (deqp-vk --jobs 6): 27,502 cases — 27,418 Pass, 84 NotSupported, 0 Fail, 0 recoveries (31 s):

  • dEQP-VK.query_pool.occlusion_query.*: 434 Pass, 7 NotSupported, 0 Fail
  • dEQP-VK.query_pool.statistics_query.*: 18,770 Pass, 5 NotSupported, 0 Fail
  • dEQP-VK.query_pool.concurrent_queries.*: 2 Pass, 0 Fail (other query_pool.*: 38 Pass, 20 NotSupported)
  • dEQP-VK.synchronization{,2}.* (basic.* incl. events/fences/semaphores/timeline/barriers, op.single_queue.event.*, implicit.*): 6,974 Pass, 3 NotSupported, 0 Fail
  • dEQP-VK.api.command_buffers.* (131 Pass), dEQP-VK.renderpasses.*(barrier|dependenc)* (69 Pass, 19 NS), dEQP-VK.conditional_rendering.* (1,000 Pass, 30 NS).

Fedora 44 Mesa Asahi CI (--suite asahi): 218/0 (hk_query_oq_test passes 110/110 checks).

Health: 0 GPU faults, 0 recoveries, 0 driver warnings, 0 AVC denials, 0 core dumps, 0 leftover processes, failed 0, SELinux Enforcing, stock.diff=0, state-diff=0.

@RyanTheTide

Copy link
Copy Markdown

5f170b33409f J700 (Neo, Apple A18 Pro / G17P B1, 7.3.0-aurora-fleet89) + J615 (M3 Air, Apple M3 / G15G C0, 7.3.0-aurora-fleet90-airs2) 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); meson test --suite asahi 215/215 PASS; deqp-vk on J700 5,425 PASS / 0 FAIL (api.smoke.* 8/8, query_pool.occlusion_query.* 434/441, pipeline.monolithic.timestamp.* 278/278, query_pool.statistics_query.* 1,5 4386/4386, synchronization.op.single_queue.event.* 1,5 319/319) and on J615 5,135 PASS / 0 FAIL (api.smoke.* 8/8, occlusion_query.* 434/441, timestamp.* 278/278, statistics_query.* 1,5 4386/4386, synchronization.basic.* 29/29); 0 GPU faults/recoveries, Enforcing, 0 failed units, 0 new AVC.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Verdict at 5f170b33409f: ready

Audited hk_cmd_buffer.h, hk_query_pool.c, hk_sync.c, hk_sync.h, hk_event.c, and all post_gfx / AGX_POSTGFX / hk_queue_write() callers:

  • hk_flush_oq_pending() and hk_queue_query_available_write(..., after_gfx=true) save/restore cmd->sync.kind_override = HK_SYNC_STAMP, keeping post-graphics query availability publication out of application pipeline barriers while preserving ordering for query commands (HK_SYNC_QUERY_SCOPE), timestamps (hk_sync_stamp_scope()), and events (hk_event_write() at hk_event.c:116).
  • hk_sync_src_dep() materializes oq_pending_render on HK_SYNC_STAMP and brl_sync_transition_begin() flushes oq_pending_render before asserting !st->kind_override.
  • The only non-query writer to post_gfx (hk_cmd_draw.c:6742 poly_heap::bottom reset) calls hk_sync_heap_used() first, which flushes oq_pending_render, promotes post_gfx->sync.kind |= HK_SYNC_GFX | HK_SYNC_GFX_MEM, calls note_last(), and waits all.
  • Verified at exact head 5f170b33409f across all 3 generations: J714s (G17S, 20,837/0 CTS, GTA V R i=0..13 -31.1%), J700 (G17P, 27,418/0 + 5,425/0 CTS, render.pass_chain oq_bar -7.72%/-9.95%), and J615 (M3, 5,135/0 CTS, 215/215 --suite asahi), 0 faults.

@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: MERGE at 5f170b33409f69d7a81be033a458aa9e7638e3c6

Blockers: none

Checked:
Read the whole diff and every post_gfx / AGX_POSTGFX / hk_queue_write(..., after_gfx) writer. The only things that land in a post-graphics stream are query availability writes and the geometry-heap reset from hk_heap(). The non-ring heap path is covered by the new promotion in hk_sync_heap_used() (kind gains GFX | GFX_MEM, note_last() refreshes sync.last); the heap-ring path orders through last_heap_slot/pass_heap_last in hk_sync_heap_slot_used(), which also updates an already-open post_gfx stream and does not depend on the stream kind, so a STAMP-classified post_gfx carrying a ring reset is still ordered for the next pass on that slot. A post_gfx first created by hk_heap() stays HK_SYNC_GFX (override is only set around availability writes). Query consumers (vkCmdCopyQueryPoolResults, reset, begin), events and timestamps still name HK_SYNC_STAMP; shaders cannot read query pools, so dropping availability from GFX/ALL_COMMANDS barrier scopes is within the spec. kind_override is saved/restored, and brl_sync_transition_begin() now flushes inline availability first so its assert holds. No chip/generation gate added.
Local x86 drm-shim gate (head merged into aurora-wip 7617c835): 337/338, identical to the aurora-wip baseline (the one failure, hk_sync_stamps, fails the same way on aurora-wip itself). Test check: with the non-test hunks reverted, hk_query_oq_test fails 9/110 (e.g. "post_gfx OQ availability carries HK_SYNC_STAMP only", "subsequent render waits on r1, not post_gfx OQ availability", "transition begin flushes inline availability outside the transition"); restored: 110/110.
Rows at this head on the PR: J714s (author), J700 (Dj + ours), J615 (ours).

Evidence
  • merged tree c73b592c4d38 (aurora-wip 7617c835 + 5f170b33409f), meson test --suite asahi --suite poly: Ok 337, Fail 1 (hk_sync_stamps, also failing on plain 7617c835: "bracketed compute with GFX+COMPUTE barriers emits both stamps distinctly", from #1235).
  • aurora-wip has since moved to ba2c9efb; #1237/#1238 touch none of this PR's files and the merge is still clean.
  • revert run: patch -R of the non-test diff in the merged tree, rebuild hk_query_oq_test only: 110 tests, 9 failures; re-apply: 110 tests, 0 failures.

@RyanTheTide
RyanTheTide merged commit ef132f5 into aurora-wip Nov 27, 2026
@RyanTheTide
RyanTheTide deleted the perf/oq-avail-stamp-kind branch November 27, 2026 16:42
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