Skip to content

borealis: pack consecutive query-reset command buffers - #1254

Merged
DjDeveloperr merged 1 commit into
aurora-wipfrom
perf/pack-query-reset-cbs
Nov 28, 2026
Merged

DjDeveloperr merged 1 commit into
aurora-wipfrom
perf/pack-query-reset-cbs

Conversation

@DjDeveloperr

Copy link
Copy Markdown

Summary

Vulkan applications (including GTA V Enhanced via vkd3d-proton) frequently begin a frame with consecutive single-stream command buffers that each record only vkCmdResetQueryPool (HK_SYNC_QRESET for timestamp pools, HK_SYNC_ALL for non-timestamp pools). Previously hk_pack_run_member() rejected every such stream because cs->stats.calls == 0, cs->query_access is set, and HK_SYNC_QRESET was not admitted, and emit_zero_queries() only tracked query_reset_dispatches / query_reset_queries on the G17P path. Each tiny query-reset command buffer therefore paid a separate CDM submission and firmware turnaround.

This PR:

  • Records query_reset_dispatches and query_reset_queries in emit_zero_queries() (src/asahi/vulkan/hk_query_pool.c) on non-G17P paths as well (M5, G16, G15, AGX2).
  • Admits pure flushed query-reset CDM streams (cs->query_access && !cs->query_reset_pending && calls == 0 && cmds == query_reset_dispatches && query_reset_queries > 0, with kind HK_SYNC_QRESET or HK_SYNC_ALL, ignoring HK_SYNC_GFX_MEM) in hk_pack_run_member(), bounded by query_reset_queries with a conservative 32-instruction-per-query work estimate.
  • Keeps query-reset runs strictly isolated from regular compute command buffers and from differing query-reset kinds (HK_SYNC_QRESET vs HK_SYNC_ALL) in hk_pack_plan(), so regular compute packets retain COMPUTE_NO_QUERY_ACCESS and query-reset kinds never mix.
  • Propagates has_gpu_query_reset in hk_pack_fold_member().
  • Adds unit test coverage in src/asahi/vulkan/tests/test-hk-pack.c for both HK_SYNC_QRESET and HK_SYNC_ALL runs, isolation from regular compute and from each other, pending/mixed-stream rejection, query-count caps, and has_gpu_query_reset propagation.

Verification

Head Hardware / Kernel Result
891b38daea28e90b4e5a42b3f8a324597877baa7 MacBook Pro M5 Pro (J714s, G17S, 7.3.0-m5-cdirect16) PASS: Clang 22.1.8 assert (0 diff warnings) & GCC release --suite asahi 215/215 each (hk_pack: 359/359, random: 3180/30204, history: 4872/36056); dEQP-VK.query_pool.* 19,236/19,276 (0 Fail); dEQP-VK.api.command_buffers.* 126/131 (0 Fail); GTA V Enhanced 3024x1964 (0 GPU faults)

Live GTA V Enhanced (3024x1964, J714s)

  • Frame anatomy (HK_FRAME_ANATOMY_EVERY=151): 48/48 multi-CB pre=92 query-reset bursts collapsed 7 -> 1 (merged=6, dispatches=9..12, flushes=0; 360 pre=92 CDM streams across 360 submits = 1.000 CDM/submit, eliminating 288 CDM kicks in the sampled window).
  • Clean A/B vs aurora-wip (99658583598, both 1620 MHz median):
    • Base: P0=60.98 P1=54.99 P2=54.34 P3=61.61 P4=59.24 (0 GPU faults)
    • PR: P0=60.78 P1=54.83 P2=54.37 P3=61.21 P4=59.12 (0 GPU faults)

Vulkan applications (such as GTA V Enhanced via vkd3d-proton) frequently open a frame with a run of consecutive single-stream command buffers that each record only vkCmdResetQueryPool (timestamp queries with HK_SYNC_QRESET, or non-timestamp queries with HK_SYNC_ALL). Previously hk_pack_run_member() rejected every such stream because cs->stats.calls == 0, cs->query_access is set, and HK_SYNC_QRESET was not admitted, and emit_zero_queries() only recorded query_reset_dispatches / query_reset_queries on the G17P path, forcing each tiny reset command buffer on M5 and other generations to pay a separate CDM submission and firmware turnaround.

Record query_reset_dispatches and query_reset_queries in emit_zero_queries() for non-G17P paths as well, recognize pure flushed query-reset CDM streams (cs->query_access && !cs->query_reset_pending && calls == 0 && cmds == query_reset_dispatches && query_reset_queries > 0, with kind HK_SYNC_QRESET or HK_SYNC_ALL) in hk_pack_run_member(), bound them by query_reset_queries (with a conservative 32-instruction-per-query static work estimate), and keep them strictly isolated from regular compute command buffers and from differing query-reset kinds in hk_pack_plan() so regular compute packets retain COMPUTE_NO_QUERY_ACCESS and HK_SYNC_QRESET packets do not mix with HK_SYNC_ALL.

Also propagate has_gpu_query_reset in hk_pack_fold_member() so packed query-reset packets preserve query-reset tracking on the packet command buffer.

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

Copy link
Copy Markdown

891b38daea28 Borealis 3-gen PASS (GCC 16.2.1 -Db_ndebug=false, isolated VK_DRIVER_FILES, stock Mesa untouched):

  • J700 (MacBook Neo, G17P, 7.3.0-aurora-fleet89): deqp-vk 19,621 PASS / 0 FAIL (api.smoke.* 8/8, query_pool.statistics_query.* 18,770/18,775, query_pool.occlusion_query.* 434/441, pipeline.monolithic.timestamp.* 278/278, api.command_buffers.* 131/131); 0 GPU faults, Enforcing, 0 failed units, 0 new AVC.
  • J413 (M2 Air, G14G B0, 7.3.0-aurora-fleet89): deqp-vk 19,529 PASS / 0 FAIL (api.smoke.* 8/8, query_pool.statistics_query.* 18,770/18,775, query_pool.occlusion_query.* 434/441, pipeline.monolithic.timestamp.* 252/278, api.command_buffers.* 65/131); 0 GPU faults, Enforcing, 0 failed units, 0 new AVC.
  • J316s (M1 Pro, G13S, 7.3.0-aurora-fleet89): hk_pack_test PASS (random: 3,180/30,204, history: 4,872/36,056, 0 failures), hk_query_no_access_test OK, hk_query_stamps_test OK; deqp-vk 19,529 PASS / 0 FAIL; 0 GPU faults, Enforcing, 0 failed units, 0 new AVC.

@aurora-silicon-review aurora-silicon-review Bot 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 891b38da

Blockers: none.

Checked: no Apple material, no AI attribution, no new chip/board/firmware gates (removes the G17P-only restriction in emit_zero_queries() so all generations track query resets uniformly), human Signed-off-by, overflow-safe hk_pack_member_static_work() (__builtin_mul_overflow), strict isolation of query-reset runs from regular compute and between HK_SYNC_QRESET and HK_SYNC_ALL, has_gpu_query_reset propagation, 201 lines of unit tests across G16G/G17P/G17S (test-hk-pack.c), exact-head 3-gen Borealis hardware verification PASS (including J700 G17P deqp-vk 19,621 PASS / 0 FAIL).

Evidence
  • Inspected all 4 files (hk_pack.c, hk_pack.h, hk_query_pool.c, tests/test-hk-pack.c).
  • Verified hk_pack_is_query_reset_stream() admits only pure flushed query-reset CDM streams (query_access && !query_reset_pending && calls == 0 && cmds == query_reset_dispatches && query_reset_queries > 0), rejects non-reset HK_SYNC_QRESET, isolates query-reset runs from plain compute (m->query_reset == run_query_reset) so regular compute keeps NO_QUERY_ACCESS, and keeps HK_SYNC_QRESET and HK_SYNC_ALL runs separate (((m->kinds ^ kinds) & ~HK_SYNC_GFX_MEM) == 0).
  • Verified hk_pack_member_static_work() guards query_reset_queries * 32u with __builtin_mul_overflow, and hk_pack_fold_member() folds packet->sync.has_gpu_query_reset |= source->sync.has_gpu_query_reset.
  • Exact-head 891b38da 3-gen Borealis hardware verification in comments passed with 0 failures (J700 G17P deqp-vk 19,621 PASS / 0 FAIL).

@DjDeveloperr
DjDeveloperr merged commit be78a8f into aurora-wip Nov 28, 2026
@DjDeveloperr
DjDeveloperr deleted the perf/pack-query-reset-cbs branch November 28, 2026 05:01
@RyanTheTide

Copy link
Copy Markdown

Merge-train note: App approval at 891b38daea28 and the exact-head rows are in. I plan to land this no earlier than 06:29Z, after the combined A/B regression row (M1 Pro G13S + M4 G16G). If you'd rather merge it yourself or hold it, say so here.

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