Repository navigation
borealis: keep timestamp work off command-buffer boundaries and pack timed passes - #1145
Conversation
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>
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>
|
J700 (MacBook Neo, A18 Pro Both arms are release Borealis Vulkan overlays, cross-built off the Mac with the same options and loaded from private prefixes through VK CTS on head, gpubench-vk smoke ( Fedora 44 Mesa Asahi CI ( Health: 0 GPU faults, 0 recoveries, 0 driver warnings, 0 AVC denials, |
|
J773g (M4 Mac mini, G16G B0, HAL200, second generation) at Both arms are release Borealis Vulkan overlays loaded from private prefixes through
gpubench-vk ABBA, render rows plus
The GPU health: 0 faults, 0 recoveries and |
|
Verdict at Blockers None. Checked
|
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>
What: Three changes so timestamp-heavy frames stop serializing at command-buffer boundaries, and their timed passes pack (mesa#1124).
vkCmdResetQueryPoolon 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.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:
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 asahion 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 (likeHK_SYNC_STAMP).hk_query_reset_cs()records a timestamp pool's reset afterHK_SYNC_QRESET_SCOPE(every stream kind butHK_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_tsholds the stamp until the next stream is created (hk_sync_stream_created()), andlead_scopeits first scope ashk_sync_src_dep()takes it (HK_SYNC_QRESETalone 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-stampsgains 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.