Skip to content

borealis: keep timestamp work off command-buffer boundaries and pack timed passes - #1145

Merged
DjDeveloperr merged 8 commits into
aurora-wipfrom
perf/borealis-cb-boundary-sync
Nov 27, 2026
Merged

DjDeveloperr merged 8 commits into
aurora-wipfrom
perf/borealis-cb-boundary-sync

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 26, 2026 •

Copy link
Copy Markdown

What: Three changes so timestamp-heavy frames stop serializing at command-buffer boundaries, and their timed passes pack (mesa#1124).

  1. Timestamp query resets (vkCmdResetQueryPool on a timestamp pool) are ordered only against the commands that use timestamp queries: timestamp writes and query commands. They no longer wait for each other or gate draws and dispatches. A reset waits for every earlier stream except other timestamp resets, which write the same values. Resets of the other query types keep ordering everything after them.
  2. A leading timestamp, recorded before any stream of a command buffer (and any later one before that stream, as a copy of it), rides on the first stream's first end stamp (a render's vertex end, a compute stream's end) instead of a timestamp-only compute command of its own. The stream waits for the stamp's first scope, as that command did: the earlier work of its stages for an ALL_COMMANDS stamp, nothing but the timestamp resets for a top-of-pipe one. Every later timestamp waited for the old command, so a render ending in a timestamp waited for a compute hop after the previous command buffer's render. GTA V (D3D12 through vkd3d-proton) starts each shadow-cascade command list with an ALL_COMMANDS stamp, about four per frame.
  3. Render-pack members with vertex-end or end timestamps: a command buffer whose render carries such a stamp (2.'s leading stamp, or an end-of-pass stamp) now packs. The packet carries the stamp on the same stamp of the merged render, which latches no earlier. A run holds at most one member stamp of each kind; start stamps still refuse.
    Tested: J714s (MacBook Pro 14" M5 Pro, G17S), kernel 7.3.0-m5-cdirect16, isolated Mesa kits, GTA V Enhanced native benchmark (3024x1964, ResScalingType=0, muted, settings restored), one boot per block:
block head / base P4 base P4 this PR change (mean)
r11 86cbf78 / aurora-wip 41fe336 57.18 57.46, 58.93 +1.8 %
r10 859e47b / aurora-wip 58e636c 53.09, 53.46 54.66, 54.91 +2.8 %

FPS. In r10 both runs of this PR beat both base runs on every pass (P0 +2.6 %, P3 +3.1 %); the base moved +0.7 % across the bracket. r11 has one valid base run: the first, on a freshly built kit, recompiled its pipelines past the harness's no-window limit. 0 GPU faults, no new kernel errors. Frame anatomy (r10): timestamp-only compute commands per run 101/110 -> 46/31, and 122/49 renders carry a leading stamp on their vertex end; 86cbf78 also folds the second leading stamp of a command buffer into a copy (the source of most of the rest). VK CTS at 86cbf78 against 41fe336 on the same kernel, query_pool, pipeline.*.timestamp, synchronization{,2} single_queue/implicit/basic/none_set_reset (43,719 cases, 8 jobs): this PR 43,668 pass, 51 not supported, 0 other; base identical. BeamNG.drive (West Coast USA, 3024x1964, 5 x 170 s windows) A S S A: 36.46 / 36.48 / 36.25 / 36.57 FPS, flat (-0.4 %, inside the 0.9 % run spread), 0 GPU faults, settings restored. --suite asahi on the M5 332/332; mirror CI asahi 334/334. An earlier screen without the ALL_COMMANDS part of 2. (b587acb) was neutral (+0.2 %), so most of the gain is 2.
J700 (MacBook Neo, G17P, HAL200) at 86cbf78 against 41fe336, stock 7.3.0-41, isolated overlays (row: #1145 (comment)): VK CTS both lists, 156,600 cases: 120,388 pass, 36,212 not supported, 0 fail, 0 recoveries; Fedora CI 215/0; gpubench render.pass_split, deferred, postfx, msaa_merge, render.heavy and sync.signal CRCs equal to base, timings between the two base runs; 0 GPU faults.
J773g (Mac mini M4, G16G, HAL200) at 86cbf78 against 41fe336, stock kernel, isolated overlays (M4 mini row lane, row comment on this PR): --suite asahi (host) 212/0; VK CTS at 1 worker, list 1 (136,374 cases) 99,946 pass / 36,426 not supported / 2 fail and list 2 (43,719) 43,675 / 43 / 1, the same on base: each fail a different synchronization{,2}.op.single_queue.*buffer_262144 case per arm, all passing when rerun alone (one at 1/5, which also fails 1/20 on base); gpubench render rows and render.pass_split A B B A with CRCs equal to base and every row flat; 0 GPU faults or recoveries.
Risk: two-way door · Borealis sync shared by every generation: (1) runs everywhere, (2) on G17P and M5, whose start stamps latch before barriers. A command buffer that starts with a lone ALL_COMMANDS stamp and then independent work: that work now waits for the earlier command buffers' work, which only the stamp's command waited for before. With begin/end stamp pairs the work already waited for the begin stamp's command through the end stamp.
Not yet: none.

Details

Resets (hk_query_pool.c, hk_sync.c, hk_sync.h): a new stream kind, HK_SYNC_QRESET, never named by an application dependency (like HK_SYNC_STAMP). hk_query_reset_cs() records a timestamp pool's reset after HK_SYNC_QRESET_SCOPE (every stream kind but HK_SYNC_QRESET); the stream is marked with the kind (hk_sync_query_reset_done()), and nothing raises a requirement on it. Its second scope is reached through the first scopes of its users: HK_SYNC_QUERY_SCOPE (query commands) includes the kind, and every timestamp write names it whatever its stage, on each path a stamp can take (in-pass, riding on the tail, a copy of an earlier end stamp, an ordered start stamp, a command of its own). An unordered leading start stamp is checked against earlier resets at submission as before (last_query_reset_point).

Leading stamp (hk_sync.c, hk_queue.c, hk_query_oq.c, hk_cmd_buffer.h): hk_sync_state::lead_ts holds the stamp until the next stream is created (hk_sync_stream_created()), and lead_scope its first scope as hk_sync_src_dep() takes it (HK_SYNC_QRESET alone for a top-of-pipe stamp). A render takes the stamp on a new vertex-end slot, hk_cs::timestamp.vtx_end (ts_vtx.end, which the kernel latches after the vertex half's barriers), and both halves wait for the scope; the occlusion-availability slot allocator skips that slot. A compute stream takes it on its end. Nothing is recorded between the stamp and that stream, so the scope names the same earlier work. If no stream follows, or a query command comes first, the stamp gets the command of its own it had before, after the same scope (hk_sync_flush_pending_timestamp()).

Tests: test-hk-sync-stamps gains the reset ordering (within a command buffer, reset-only command buffers of one submission, a stamped render after them, the render's vertex half free) and the leading stamp: render vertex end, compute end, no stream, the vertex half after an earlier command buffer's reset, a top-of-pipe stamp adding no wait on earlier work, and an ALL_COMMANDS stamp on a render (vertex half after an earlier dispatch), on a dispatch (after an earlier render) and before a query command (a command of its own after an earlier render). All on G17S/G17C/G17G/G17P with exact and legacy priors.

vkCmdResetQueryPool is ordered only against the commands that reference
the same queries (Vulkan 1.4, 17.2). The reset was recorded as a stream
of every class that every later stream waited for, and that itself waited
for every earlier stream, so reset-only command buffers ahead of a frame
ran one after another and gated all later work of the submission.

Timestamp queries are referenced only by timestamp writes and query
commands. A timestamp pool's reset now gets a stream kind of its own,
HK_SYNC_QRESET: timestamp writes (whatever their stage) and query
commands name it in their first scope, application dependencies never do,
and a reset waits for every earlier stream except other timestamp resets,
which write the same values. Resets of the other query types, which draws
and dispatches write, keep ordering everything after them.

Signed-off-by: DjDeveloperr <hey@djdev.me>
On G17P and M5 start stamps latch before a command's barriers resolve, so
a top-of-pipe timestamp recorded before any stream of a command buffer
that already holds a dependency got a timestamp-only compute command of
its own. Every later timestamp waits for such a command, so a render
ending in a timestamp waited for a compute command that waited for the
previous command buffer's render: an extra compute hop between
consecutive renders.

Such a stamp now rides on the first stream's first end stamp, latched after
that stream's barriers: the vertex end of a render (a new timestamp slot,
hk_cs::timestamp.vtx_end) or the end of a compute stream. Its first scope
is empty, so that later point is a valid value; the stream only waits for
the resets of timestamp queries. A command buffer that records no stream
after it keeps the command of its own.

Signed-off-by: DjDeveloperr <hey@djdev.me>
A command buffer whose render carries a leading top-of-pipe timestamp on
its vertex end, or an end-of-pass timestamp on its fragment end, was no
render-pack member, so a timed pass split across command buffers never
packed. The packet carries such a stamp on the same stamp of the merged
render: its vertex half ends after every member's vertex work and its
fragment half after every member's fragment work, and it waits for
everything each member waited for, so the stamp latches no earlier than
it would have. A run holds at most one member stamp of each kind; start
stamps, which latch before the barriers resolve, still refuse.

Signed-off-by: DjDeveloperr <hey@djdev.me>
The new stamp case replaced the packet the vertex-half image assertion reads; run it after that assertion.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr DjDeveloperr changed the title borealis: keep timestamp resets and leading timestamps off the command-buffer boundary borealis: keep timestamp work off command-buffer boundaries and pack timed passes Nov 26, 2026
A timestamp recorded before any stream of a command buffer rode on the
first stream's first end stamp only when it was top-of-pipe. Any other
stage, such as the ALL_COMMANDS stamps a D3D12 translation layer writes
at the start of each command list, still got a timestamp-only compute
command of its own. That command waits for the earlier command buffers'
work. The render after it, when it ends in a timestamp of its own, waits
for that command, so consecutive renders take a render, compute, render
hop. GTA V's shadow cascades do this about four times per frame on M5.

The leading stamp now keeps its first scope (hk_sync_state::lead_scope),
and the first stream waits for it when it takes the stamp. That is the
same wait the timestamp-only command had. A top-of-pipe stamp still
waits only for the resets of timestamp queries. A command buffer that
records no stream after the stamp, or a query command first, still gets
the command of its own, now ordered after the stamp's scope.

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

A command buffer that writes two timestamps before its first stream,
such as GTA V's shadow-cascade lists (two ALL_COMMANDS stamps at the
start), still got a timestamp-only compute command. The second stamp
flushed the waiting leading stamp into a command of its own and then
copied it. The render after that command waited for it through its own
end stamp: the render, compute, render hop the leading stamp was meant to
remove. On J714s about 40 such commands per GTA V run were left.

The later stamp is now a copy of the leading one. The first stream
carries the leading stamp after the first scopes of both stamps, which
is a valid later latch for the earlier one, and the copies launch after
that stream as other stamp copies do. Copies flushed while no stream has
taken the leading stamp yet (vkEndCommandBuffer flushes copies first)
give the leading stamp its command first, so they read it after it is
written.

Signed-off-by: DjDeveloperr <hey@djdev.me>
aurora-wip was rebuilt from 9ca2b09, so its new tip (41fe336)
no longer descends from 58e636c, the tip this branch merged last,
although it holds the same render-pack code. The conflicts were resolved
against 58e636c: this branch's changes over it, applied onto the new
tip.

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

Copy link
Copy Markdown
Author

J700 (MacBook Neo, A18 Pro G17P B1) at exact head 86cbf78e6506, against base 41fe336dffae: PASS, no regression.

Both arms are release Borealis Vulkan overlays, cross-built off the Mac with the same options and loaded from private prefixes through VK_DRIVER_FILES, on the stock kernel 7.3.0-41.fc44.aurora.aarch64 with no reboot. System Mesa wasn't touched. Each arm's driver id shows its git SHA. Head libvulkan_asahi.so SHA-256 38d5c7e1…, base 0a304f30….

VK CTS on head, deqp-vk --jobs 6: 156,600 cases: the same set as #1144 plus query_pool, pipeline.*.timestamp and synchronization{,2} single-queue/implicit/basic/none_set_reset. Results: 120,388 Pass, 36,212 NotSupported, 0 Fail, 0 recoveries. The 20,226 query_pool/pipeline.*.timestamp cases give 20,194 Pass and 32 NotSupported.

gpubench-vk smoke (A1 B1 B2 A2, same boot): CRCs match base on every row (render.pass_split d1/d4 18acb8e1, render.deferred tile/dram msaa4, render.postfx msaa1/msaa4, render.msaa_merge 4x rgba16f/rgba8). render.pass_split timing is identical (4347.8 / 3846.2 µs per submit at d1 / d4 on both arms). sync.signal latency is flat at 145.5–147.8 µs. Thermals rose through the sequence, and every head run on all 17 rows falls between the two base runs. This was a smoke check, not a perf measurement.

Fedora 44 Mesa Asahi CI (fedora-mesaci.sh): 215/0, and --suite poly passes 5/5.

Health: 0 GPU faults, 0 recoveries, 0 driver warnings, 0 AVC denials, failed 0, SELinux Enforcing. stock.sh is the same before and after.

@DjDeveloperr
DjDeveloperr marked this pull request as ready for review November 27, 2026 09:22
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 27, 2026 09:22
@DjDeveloperr

Copy link
Copy Markdown
Author

J773g (M4 Mac mini, G16G B0, HAL200, second generation) at 86cbf78e6506, against aurora-wip 41fe336dffae: PASS, no regression. No case fails on the head only.

Both arms are release Borealis Vulkan overlays loaded from private prefixes through VK_DRIVER_FILES, on the stock kernel 7.3.0-ARCH-m4mainefed1ae3. System Mesa wasn't touched. Each arm's vulkaninfo shows its git SHA.

  • meson test --suite asahi (host build) at base and head: 212 Ok, 0 Fail on both.
  • VK CTS at 1 worker (render-heavy lists stay at 1 worker on this Mac's stock kernel), resumable in ≤8 min pieces:
    • List 1 is the same 136,374 cases. Base and head each give 99,946 Pass, 36,426 NotSupported and 2 Fail.
    • List 2 is 43,719 cases: query_pool.*, pipeline.*.timestamp.* and synchronization{,2}.{op.single_queue,implicit,basic,none_set_reset}.*. Base and head each give 43,675 Pass, 43 NotSupported and 1 Fail.
    • All fails are different synchronization{,2}.op.single_queue.*buffer_262144* cases on each arm.
    • Rerun alone, every differing case passes on both arms, apart from synchronization2.op.single_queue.timeline_semaphore.write_ssbo_tess_control_read_ssbo_vertex.buffer_262144, which failed once in 5 runs on the head.
    • That case and its _specialized_access_flag variant were then run 20 times alone on each arm. The head passed 40 of 40; the base failed the _specialized_access_flag variant once in 20. This flake is in the base too.

gpubench-vk ABBA, render rows plus render.pass_split (us_per_submit, head/base; lower is better; CRCs equal on all four runs of every row):

row A1 / B1 / B2 / A2 head/base
render.deferred, d1 486.22 / 476.19 / 478.47 / 480.00 0.988
render.deferred, d2 235.11 / 234.74 / 234.93 / 235.66 0.998
render.deferred mode=tile msaa=4 res=1080p, d2 348.03 / 348.03 / 349.24 / 348.84 1.001
render.light, d16 58.57 / 58.87 / 58.79 / 58.86 1.002
render.mdi, d4 160.09 / 159.83 / 159.66 / 159.15 1.001
render.msaa_merge fmt=rgba16f samples=4, d4 590.55 / 591.72 / 595.24 / 589.39 1.006
render.pass_split gap=decay, d1 2189.78 / 2189.78 / 2189.78 / 2189.78 1.000
render.pass_split gap=uav, d1 2173.91 / 2173.91 / 2173.91 / 2173.91 1.000
render.pass_split mode=multi_cb splits=1, d1 2112.68 / 2097.90 / 2112.68 / 2097.90 1.000
render.pass_split mode=multi_cb splits=22, d1 2290.08 / 2290.08 / 2307.69 / 2307.69 1.000
render.pass_split mode=multi_cb splits=8, d1 2173.91 / 2173.91 / 2173.91 / 2173.91 1.000
render.pass_split mode=one_cb splits=8, d1 2112.68 / 2127.66 / 2112.68 / 2112.68 1.004
render.postfx, d1 887.57 / 882.35 / 937.50 / 890.21 1.024
render.postfx, d2 771.21 / 769.23 / 783.29 / 767.26 1.009

The render.postfx d1 ratio comes from one outlier run (B2 937.50); the other three runs agree within 1 %.

GPU health: 0 faults, 0 recoveries and failed 0 errno 0 degraded 0 across every CTS piece and the ABBA.

@DjDeveloperr

Copy link
Copy Markdown
Author

Verdict at 86cbf78e6506: ready

Blockers

None.

Checked

  • Timestamp query resets.
    • HK_SYNC_QRESET is never named by an application dependency. A timestamp pool's reset waits for every earlier stream except other timestamp resets (HK_SYNC_QRESET_SCOPE), which write the same values.
    • Timestamp writes of any stage, and query commands, name it in their first scope. Draws and dispatches don't touch timestamp queries, so they no longer wait for it. That matches Vulkan's rule that a reset is ordered only against commands using the same queries.
    • Resets of other query types still order everything.
  • Leading timestamp.
    • A stamp recorded before a command buffer's first stream is now carried on that stream's first end stamp: the render's new vtx_end slot, or the compute stream's end.
    • hk_sync_stream_created() makes the stream wait for lead_scope, the stamp's own first scope, which the stamp-only command used to wait for. So the stamp still latches after everything its stage asks for; it may only latch later, which Vulkan allows.
    • A top-of-pipe stamp waits only for timestamp resets.
    • A second stamp before the first stream becomes a copy of the leading one, launched after that stream like other stamp copies. If copies are flushed first, the leading stamp gets its own command before them.
  • Render packing with stamps. A member may carry a vertex-end or end stamp. A run holds at most one of each (hk_render_pack_stamp_slots()), and start stamps, which latch before barriers resolve, still refuse. The packet's vertex and fragment ends come after every member's and wait for what each waited for, so no stamp latches earlier than it would have.
  • With borealis: order whole-tile load hazards in the fragment half only #1144. No conflict in any merge order. A command buffer that begins with an ALL_COMMANDS stamp makes its first render's vertex half wait for that scope, so it gets none of borealis: order whole-tile load hazards in the fragment half only #1144's tiling overlap. That only limits the win in that case; it isn't a correctness issue.
  • Merge and build.
  • Mutations.
    • Dropping the leading stamp's wait on its scope fails "leading stamp's render follows the reset" and "leading ALL_COMMANDS stamp's vertex half follows earlier work".
    • Letting timestamp resets wait on each other fails "resets of separate command buffers do not chain".
  • Policy. agent-policy.sh pr HEAD: PR is clean. The code commits are signed off; the merge commit from aurora-wip carries no sign-off, which the policy accepts. No attribution lines, no new environment options.
  • Rows. J714s (body), J700 (#issuecomment-7214045424) and J773g (#issuecomment-7214919451) are all at this head, including the J714s pipeline.*.timestamp and query_pool CTS.

@DjDeveloperr
DjDeveloperr merged commit 5ab97d0 into aurora-wip Nov 27, 2026
@RyanTheTide
RyanTheTide deleted the perf/borealis-cb-boundary-sync branch November 27, 2026 13:20
RyanTheTide pushed a commit to oreater/mesa that referenced this pull request Nov 28, 2026
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 aurora-silicon#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>
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.

1 participant