Skip to content

borealis: flush leading timestamps before opening a compute stream - #1235

Merged
DjDeveloperr merged 1 commit into
aurora-wipfrom
fix/borealis-lead-ts-compute-sync
Nov 27, 2026
Merged

DjDeveloperr merged 1 commit into
aurora-wipfrom
fix/borealis-lead-ts-compute-sync

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 27, 2026 •

Copy link
Copy Markdown

Fixes two regressions introduced by #1145 (5ab97d0f2c60) on chips where start_stamps_ordered() is false (G17P and M5):

What:

  • Flush hk_sync_state::lead_ts into a preceding timestamp-only compute carrier in hk_cmd_buffer_get_cs_general() before creating any compute stream, instead of attaching lead_ts to the compute stream's timestamp.end in hk_sync_stream_created().
  • Keep lead_ts riding on timestamp.vtx_end when the first stream is a render stream (HK_CS_VDM), preserving borealis: keep timestamp work off command-buffer boundaries and pack timed passes #1145's cross-engine hop elimination and render packing.
  • Save/restore brl_transition_active and xfer_depth around hk_sync_flush_lead_timestamp() so a flushed carrier stays pure HK_SYNC_STAMP.
  • End any open timestamped compute stream before falling through to timestamp_only_stream() in hk_sync_write_timestamp() and assert !cs->timestamp.end.handle before writing cs->timestamp.end.
  • Update and expand test-hk-sync-stamps.c with regression coverage for both the 0 us compute timestamp collapse and the bracketed compute + GFX|COMPUTE barrier overwrite/deadlock sequence (plus test-hk-host-flush.c, test-hk-query-reset.c, and test-hk-tess-batch.c stubs).

Root cause:

  1. 0 us compute timestamps: Attaching a leading timestamp (Q0) to a compute stream's timestamp.end latched Q0 after the compute work finished and left current_cs.cs open with timestamp.end already set. A trailing timestamp (Q1) then hit stamp_covered() and copied Q0 -> Q1, collapsing GPU time to 0 us on compute and compute-transfer workloads.
  2. D3D12 compute.conv2d ETIMEDOUT deadlock: When an interleaved GFX|COMPUTE barrier (such as D3D12 UAV <-> NON_PIXEL_SHADER_RESOURCE) recorded HK_SYNC_GFX_MEM into req[HK_SYNC_GFX][VDM].prior before Q1, stamp_covered() returned false while current_cs.cs was still open with timestamp.end = Q0. The fallback timestamp_only_stream() path reused the open compute stream and overwrote timestamp.end with Q1, leaving Q0 permanently UINT64_MAX so vkCmdCopyQueryPoolResults(..., VK_QUERY_RESULT_WAIT_BIT) spun until the G17 watchdog returned ETIMEDOUT.

Tested:

  • Fedora 44 Mesa CI (./rig/fedora-mesaci.sh c454b390fe62): 218/0 PASS, 0 warnings in touched lines (hk_sync_stamps: 896 tests, 0 failures; mutation reverting the fix fails 56/896 assertions across all 8 chip/exact-prior variants).
  • MacBook Neo (J700, G17P B1, stock 7.3.0-41.fc44.aurora.aarch64, isolated overlay c454b390fe62, stock.diff 0, 0 GPU faults, 0 AVCs, 0 recoveries):
    • gpubench-d3d12 --verify compute.conv2d gaussian 1080p d=1: PASS (1282.05 us/submit, gpu_us 976.08 us, CRC 2d55a14d), anatomy confirms [CB0 reset] -> [CB1 Q0 carrier bar=c1] -> [CB1 H+V dispatches + Q1] -> [CB1 copy_query_g17p bar=c3].
    • gpubench-d3d12 --verify full sweep: 47/47 PASS, gpu_us==0: 2/47 (restored to pre-borealis: keep timestamp work off command-buffer boundaries and pack timed passes #1145 4b87e99be586 baseline; was 8/38 + 1 ETIMEDOUT).
    • gpubench-d3d11 --verify full sweep: 45/45 PASS, gpu_us==0: 4/45 (restored to pre-borealis: keep timestamp work off command-buffer boundaries and pack timed passes #1145 baseline; was 15/45).
    • gpubench-vk --verify full sweep: 37/37 PASS, gpu_us==0: 0/37.
    • Vulkan CTS: full query-pool.txt mustpass (dEQP-VK.query_pool.statistics_query.* 18770/18775 PASS + 5 Not supported; all remaining 501 dEQP-VK.query_pool.* including timestamp/occlusion/copy/reset/concurrent 474/501 PASS + 27 Not supported -> 19244 PASS / 0 FAIL / 32 Not supported total) and dEQP-VK.api.command_buffers.* (131/131 PASS).

Risk: two-way · M3, M4, Neo, M5

Not yet:

  • Hardware run on M5 (G17S/G17C/G17G) and M3/M4 (start_stamps_ordered() is true on M3/M4 so lead_ts is inactive there; M5 shares the !start_stamps_ordered() path covered by the unit tests across G17S/G17C/G17G/G17P).

When start_stamps_ordered() is false (G17P and M5), a leading timestamp
recorded before the command buffer's first stream is deferred in
hk_sync_state::lead_ts so a first render stream can carry it on
timestamp.vtx_end without inserting a cross-engine compute carrier ahead
of the render.

Attaching lead_ts to a first compute stream's timestamp.end instead
caused two regressions from #1145:

1. Compute streams have no separate start-side end stamp, so latching a
   leading start timestamp on the compute stream's end moved the start
   timestamp past the dispatch and left current_cs.cs open with
   timestamp.end already populated. A trailing timestamp after the
   dispatch then hit stamp_covered() and copied the start stamp,
   collapsing measured GPU time to 0 us on compute workloads.

2. If an interleaved graphics+compute barrier recorded HK_SYNC_GFX_MEM
   into req[HK_SYNC_GFX][VDM].prior before the trailing timestamp (as
   in D3D12 compute.conv2d UAV <-> NON_PIXEL_SHADER_RESOURCE barriers),
   stamp_covered() returned false while current_cs.cs was still open
   with timestamp.end set. The fallback timestamp_only_stream() path
   reused the open compute stream and overwrote timestamp.end with the
   second query, leaving the first timestamp query permanently
   unavailable (UINT64_MAX) so a subsequent vkCmdCopyQueryPoolResults
   with VK_QUERY_RESULT_WAIT_BIT spun until the GPU watchdog hit
   ETIMEDOUT.

Flush lead_ts into a preceding timestamp-only compute carrier in
hk_cmd_buffer_get_cs_general() before creating any compute stream,
keeping lead_ts on timestamp.vtx_end for first render streams. Also
end any open timestamped compute stream before falling through to
timestamp_only_stream() in hk_sync_write_timestamp() and assert that
timestamp.end is never overwritten.

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

Copy link
Copy Markdown

c454b390fe62 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 1,307 PASS / 0 FAIL (api.smoke.* 8/8, pipeline.monolithic.timestamp.* 278/278, compute.pipeline.basic.* 80/81, synchronization.basic.* 29/29, synchronization2.op.single_queue.barrier.*compute* 912/913) and on J615 395 PASS / 0 FAIL (api.smoke.* 8/8, timestamp.* 278/278, compute.pipeline.basic.* 80/81, synchronization.basic.* 29/29); 0 GPU faults/recoveries, Enforcing, 0 failed units, 0 new AVC.

@DjDeveloperr

Copy link
Copy Markdown
Author

J714s (MacBook Pro M5 Pro, G17S, kernel 7.3.0-m5-cdirect16, second generation) at exact head c454b390fe6285f25136639d23ff8d9b63371915 against 30df6feb98f: PASS

  • Build & unit tests: Clang 22.1.8 assert (-Db_ndebug=false, 0 warnings in PR diff) and GCC release (-Db_ndebug=true) --suite asahi: 215/215 PASS each (hk_sync_stamps PASS).
  • Vulkan CTS (cts1471):
    • dEQP-VK.query_pool.*: 19,236/19,276 PASS, 0 Fail (40 Not supported).
    • dEQP-VK.api.command_buffers.*: 131/131 PASS, 0 Fail.
  • gpubench-vk ABBA vs 30df6feb98f (32/32 rows valid=True, status=ok, non-zero compute timestamps, 0 timeouts):
    • compute.conv2d 1080p: d=1 202.9 -> 202.6 us (-0.1%, submit 10.7 -> 10.4 us), d=4 202.5 -> 202.3 us (-0.1%, submit 12.7 -> 12.4 us).
    • render.deferred 1080p: d=1 109.1 -> 109.1 us (0.0%), d=4 85.6 -> 85.6 us (0.0%).
    • render.pass_chain 14-pass tiny: all_bar d=1 201.4 -> 201.7 us (+0.1%), indep d=4 500.2 -> 509.7 us (+1.9%).
  • Health: boot=same, online=1, crashed=0, quarantined=0, 0 kernel errors, 0 GPU faults.

@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 c454b390fe62: ready

Audited hk_cmd_buffer.h, hk_sync.c, hk_sync.h, test-hk-sync-stamps.c, and all callers of hk_sync_stream_created() / hk_cs_create*() / hk_sync_write_timestamp():

  • hk_cmd_buffer_get_cs_general() flushes lead_ts into a pure HK_SYNC_STAMP carrier before hk_cs_create() for compute streams (checking vk_command_buffer_has_error()), preserving the #1145 render vtx_end path. The only other compute hk_sync_stream_created() site (hk_cmd_buffer.c:5266 G18 indirect launch) is preceded by libagx_g18_indirect_launch() via hk_cmd_buffer_get_cs_general(), so assert(cs->type == HK_CS_VDM) holds.
  • hk_sync_flush_lead_timestamp() clears st->lead_ts before timestamp_only_stream() (no recursion), saves/restores brl_transition_active and xfer_depth, updates stamp_copy_after[HK_SYNC_CDM], asserts !cs->timestamp.end.handle, and ends the carrier compute stream.
  • hk_sync_write_timestamp() closes any open timestamped compute stream via hk_sync_end_cs_if_timestamped() before timestamp_only_stream() and asserts !cs->timestamp.end.handle, preventing silent overwrite.
  • Verified at exact head c454b390fe62 on J700 (G17P B1), J615 (M3), and J714s (G17S B1) with 0 CTS failures, 0 faults, and #1145 render perf preserved.

@RyanTheTide

Copy link
Copy Markdown

aurora-wip has failed hk_sync_stamps since this PR merged (7617c83). It is a semantic clash with #1213, not a bug in this PR on its own:

#1213 orders work after a compute barrier that follows earlier compute, so the dispatch after the GFX+COMPUTE barrier probably no longer shares the first dispatch's stream. The test asserts d0 == d1 and is_end(d1, 1).

Please decide which is right: update the test's expected stream layout for #1213's rule, or fix the sync code if the trailing stamp now lands on the wrong stream. Until then every mesa PR's local gate baseline is 337/338 (only this check failing), and we compare against that. Commands: meson test --suite asahi hk_sync_stamps on aurora-wip ef132f59.

RyanTheTide pushed a commit to oreater/mesa that referenced this pull request Nov 28, 2026
…x check

Commit 088f203 (aurora-silicon#1213) changed cs_reusable() so a self-cut compute
barrier keeps an open compute stream only when that stream already waits
for its predecessor on the compute subqueue. Commit c454b39 (aurora-silicon#1235)
then flushed leading timestamps into a preceding pure HK_SYNC_STAMP
carrier before opening a compute stream.

When an application compute stream follows a pure HK_SYNC_STAMP or
HK_SYNC_QRESET stream (such as a leading timestamp carrier, timestamp
copy stream, post-graphics query availability stream, or timestamp reset),
an application barrier never names those query-memory streams, so the
open compute stream does not wait on them. Treating them as unwaited
predecessors in cs_reusable() caused hk_sync_check_cs() to split the
compute stream on the first compute barrier, breaking
test-hk-sync-stamps.c:1237 and gratuitously splitting compute chains.

Scope cdm_waits_for_prefix() by the required producer kinds:
- For application work in cs_reusable(), walk back to the latest earlier
  HK_SYNC_ALL compute stream, ignoring pure HK_SYNC_STAMP and
  HK_SYNC_QRESET streams while still splitting whenever an unwaited
  application compute stream sits behind them.
- For hk_sync_get_cs_after() and non-application callers (query commands,
  events, and timestamp streams), keep checking HK_SYNC_STREAM_KINDS so
  dependencies on earlier stamp or reset streams are never dropped.

Signed-off-by: DjDeveloperr <hey@djdev.me>
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