Skip to content

borealis: extend AGX3 direct-draw fast path to depth bias, continued passes, and dynamic UBOs - #1433

Merged
DjDeveloperr merged 2 commits into
aurora-silicon:aurora-wipfrom
AxxzyWasTaken:pr/agx3-fast-direct-draw-ext
Dec 1, 2026
Merged

DjDeveloperr merged 2 commits into
aurora-silicon:aurora-wipfrom
AxxzyWasTaken:pr/agx3-fast-direct-draw-ext

Conversation

@AxxzyWasTaken

Copy link
Copy Markdown

What: Extend Borealis's AGX3 direct-draw fast path to cover dynamic depth bias, continued render passes, and dynamic UBO offsets (preserving #1306's inline-immediate push-constant path and #1354's reset invariants), with drm-shim unit tests covering all three extensions.

Tested:

  • Host x86-64 (-Db_ndebug=false, rebased on aurora-wip 8b59f2b0a70, head 038c2b08c3b8): meson test --suite asahi 362/362 PASS (0 fail, 0 skip), including the new drm-shim direct-draw fast-path extension tests.
  • J616C (Apple M4 Max, G17P, 7.3.0-j616c-parity5+, Release ARM64 libvulkan_asahi.so) at exact head 038c2b08c3b8:
    • ASAHI_MESA_DEBUG=verify gpubench-vk --test render.bindless_ubo --depths 2: exact CRC 57e7bedd, 0 faults.
    • Targeted deqp-vk dEQP-VK.dynamic_state.monolithic.rs_state.depth_bias*: 4/4 PASS (0 fail).
    • 3-round interleaved A/B vs aurora-wip (8b59f2b0a70, depth=2, no regression on standard non-dynubo draws): render.light 60.11 -> 59.98 us (-0.22%), render.deferred 109.41 -> 109.23 us (-0.16%, CRC 2cfe9a54), render.bindless_ubo 163.13 -> 163.00 us (-0.08%, CRC 57e7bedd), render.shadow GPU 208.96 -> 208.96 us (+0.00%, CRC c0fb9993).
    • dmesg: 0 GPU/DART faults or recoveries.

Risk: two-way door · extends Borealis's AGX3 direct-draw fast path; falls back cleanly to the general draw path when bypass preconditions are not met, and dynbuf_* state is zeroed on command buffer reset.

Not yet: Second Apple Silicon generation hardware row and a dedicated dynamic-UBO / depth-bias direct-draw microbenchmark in gpubench-vk.

@AxxzyWasTaken
AxxzyWasTaken requested review from a team and DjDeveloperr as code owners November 30, 2026 21:23

@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: CHANGES_REQUESTED at 038c2b08

Blockers:

  • Silent stale-address corruption on alternating push-only and dynamic-UBO-only draws (src/asahi/vulkan/hk_cmd_draw.c:17758-17990):
    • When a pipeline uses both push constants and a dynamic UBO (fast->push_bypass_ready && fast->dynbuf_bypass_ready), hk_agx3_push_bypass_ioto_prepare() bakes fast->ioto_bytes once from the initial snapshot (push=P0, dynbuf=D0).
    • In hk_agx3_fast_direct_draw_begin(), every Ioto emission copies from the unmodified initial template hk_copy_small_inline(ioto_cpu, fast->ioto_bytes, ioto_len) and then only patches push_relocs if patch_push is true ((dirty_mask & HK_ROOT_DIRTY_PUSH) != 0) and only patches dynbuf_relocs if patch_dynbuf is true ((dirty_mask & HK_ROOT_DIRTY_DYNBUF) != 0), without updating fast->ioto_bytes or re-patching the non-dirty side from cached->loader_ranges.
    • Concrete failure sequence:
      1. Draw 1 (slow path) snapshots fast->ioto_bytes with (P0, D0).
      2. Draw 2 updates only the dynamic UBO offset (D0 -> D1, patch_push=false, patch_dynbuf=true): emits (P0, D1) and updates cached->loader_ranges, while fast->ioto_bytes still holds D0.
      3. Draw 3 updates only push constants (P0 -> P1, patch_push=true, patch_dynbuf=false): copies fast->ioto_bytes (restoring stale D0!) and patches only P1 -> Draw 3 silently executes with (P1, D0) instead of (P1, D1).
      4. The symmetric sequence (Draw 2 updates push P0 -> P1, Draw 3 updates dynbuf D0 -> D1) copies stale P0 from fast->ioto_bytes and executes Draw 3 with (P0, D1) instead of (P1, D1).
    • Fix by keeping fast->ioto_bytes synchronized with every committed patch (e.g., copying the patched ioto_cpu back to fast->ioto_bytes — or patching fast->ioto_bytes in place only after all fallible return false checks succeed — or re-patching both relocation sets from cached->loader_ranges on every emission), and add a drm-shim + hardware regression test covering alternating push-only -> dynbuf-only -> push-only draws on the same pipeline.
  • Second GPU-generation hardware row missing: Once the stale-template bug is fixed, please re-run meson test --suite asahi + J616C exact-head verification and add a second Apple Silicon generation hardware row (e.g. M5 G17S / AGX3C, which is also enabled in hk_agx3_push_bypass_ioto_prepare() and hk-g17s-kernel-fast-direct-draw-ext).

Checked:

  • Audited hk_cmd_buffer.c, hk_cmd_buffer.h, hk_cmd_draw.c, and meson.build (+1770/-179 across 7 files):
    • Verified hk_agx3_push_bypass_ioto_prepare() zeroes all fast->dynbuf_*, fast->push_*, and fast->vs_* fields on entry, and verifies short_mask and bump uploader bounds before advancing cursors in hk_agx3_fast_direct_draw_begin().
    • Verified cs->m5_ordered remains excluded while non-ordered cs->m5_continued_pass is admitted.
    • Verified fast->push_inline_imm cannot run with patch_dynbuf (fast->dynbuf_range_count == 0).
Evidence
  • Head commit: 038c2b08c3b8896802dd6300406fd993e08a4bfa (MERGEABLE into aurora-wip).
  • Stale template copy site: src/asahi/vulkan/hk_cmd_draw.c (hk_agx3_fast_direct_draw_begin()), copying fast->ioto_bytes into ioto_cpu followed by guarded if (patch_push) and if (patch_dynbuf) loops with no writeback to fast->ioto_bytes.

@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.

The stale-address finding is addressed in source at 15d906c. The code now patches the last committed Ioto template after the validation exits and copies that template into the new draw. The shim assertions cover preservation across alternating updates and lack of mutation on invalid dynamic-buffer fallback. The posted suite and J616C results identify the previous head. Please post current-head shim results and exercise alternating push-only and dynamic-UBO-only draws on J616C and a second enabled GPU generation before merge.

…passes, and dynamic UBOs

Extend the cached AGX3 direct-draw emitter (hk_agx3_direct_draw_fast)
across three additional steady-state workloads while preserving every
correctness invariant of hk_draw_impl():

1. Static depth_bias.enable shadow passes: remove the
   dyn->rs.depth_bias.enable arming exclusion. hk_flush_gfx_state()
   validates cs->cr.dbias_is_int and emits depth-bias PPP state on the
   first draw before arming, and any change to depth-bias enable,
   factors, or representation mutates dyn->generation and dyn->dirty,
   which already declines the fast path.

2. Non-ordered merged/continued passes (cs->m5_continued_pass): remove
   the cs->m5_continued_pass exclusion from arming and admission while
   keeping cs->m5_ordered excluded so ordered continuations still run
   hk_m5_ordered_draw_hazard() on every draw. Drop direct_draw_fast in
   hk_cmd_buffer_end_graphics() so the first draw of a merged pass
   always enters hk_flush_gfx_state() (verifying sample locations and
   depth-bias state) before re-arming for subsequent draws in that pass.

3. Dynamic UBO offset updates (HK_ROOT_DIRTY_DYNBUF) and combined
   push-constant + dynamic-UBO bypass:
   - Snapshot desc->non_dynbuf_generation and FS/VS root read masks
     (agx3_root_reads, agx3_dynbuf_reads, agx3_push_read_dwords).
   - Extend hk_agx3_push_bypass_ioto_prepare() to collect root-set
     HK_G17P_RANGE_SOURCE_BUFFER ranges and relocations, enforcing
     lockstep cluster sharing per dynamic-buffer descriptor in
     l->plan.shared.
   - In hk_agx3_fast_direct_draw_begin(), admit
     (dirty_mask & ~(HK_ROOT_DIRTY_PUSH | HK_ROOT_DIRTY_DYNBUF)) == 0
     when FS and (when launch->has_general_root) VS ignore the dirty
     root fields. Validate every tracked dynamic-buffer descriptor
     (non-zero base_addr, 4B alignment, bounds and uint64 overflow
     guards) along with short-LDIMM and uploader/Ioto bounds before
     advancing any cursor or emitting bytes.
   - Patch both push and dynamic-UBO relocations in one Ioto program
     copy and one 28B VDM State Update, update cached->loader_ranges,
     and mark bypass_launched without clearing dirty_mask so the lazy
     full-root upload invariant stays intact.

Extend hk_cpu_upload_bench with unit tests for static depth bias,
non-ordered vs ordered continued passes, dynamic UBO bypass matching
hk_agx3_try_push_only_vs_program() byte-for-byte, FS/VS read-mask
fallbacks, invalid/OOB/misaligned/overflow descriptor fallbacks, and
combined push-constant + dynamic-UBO sequences on G17P and G17S.

Signed-off-by: AxxzyWasTaken <axxzytte@gmail.com>
…nsions

Add agx3_vulkan_fast_direct_draw_ext and wire it into the g17p, t6041,
and g17s-kernel drm-shim suites with ASAHI_MESA_DEBUG=verify and strict
stream validation. Exercises static depth_bias.enable direct and
indexed draws, non-ordered and ordered merged dynamic rendering passes,
VS dynamic-UBO offset sweeps with FS-disjoint and FS-dirty slots, and
combined push-constant + dynamic-UBO updates.

Signed-off-by: AxxzyWasTaken <axxzytte@gmail.com>
@AxxzyWasTaken
AxxzyWasTaken force-pushed the pr/agx3-fast-direct-draw-ext branch from 15d906c to 915c288 Compare November 30, 2026 22:00
@AxxzyWasTaken

Copy link
Copy Markdown
Author

Fixed the stale fast->ioto_bytes template bug in c390b64a552 + 915c288f90c:

  • hk_agx3_fast_direct_draw_begin() now patches fast->ioto_bytes in place (after all fallible return false checks succeed) before copying to ioto_cpu, keeping fast->ioto_bytes and cached->loader_ranges synchronized across alternating push-only and dynbuf-only draws.
  • Added an alternating dynbuf-only -> push-only -> dynbuf-only -> push-only sequence on the combined pipeline to agx3_vulkan_fast_direct_draw_ext.c.
  • Re-verified:
    • Host drm-shim (-Db_ndebug=false): hk-g17p-fast-direct-draw-ext, hk-t6041-fast-direct-draw-ext, and hk-g17s-kernel-fast-direct-draw-ext 3/3 PASS.
    • J616C (M4 Max, G17P, 7.3.0-j616c-parity6+) at exact head 915c288f90c: ASAHI_MESA_DEBUG=verify render.bindless_ubo d2 exact CRC 57e7bedd, dEQP-VK.dynamic_state.monolithic.rs_state.depth_bias* 4/4 PASS, 0 GPU/DART faults.

@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.

The updated head retains the committed-template fix. The posted 3/3 shim pass covers alternating dynamic-UBO and push-constant updates, and the reported current-head J616C run passes the bindless UBO output and depth-bias checks. Please confirm the alternating sequence itself on hardware and post the second enabled GPU-generation row, especially AGX3C. The J616C benchmark and CTS results are useful coverage for their exercised paths.

@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 915c288.

Checked: The committed Ioto template retains both relocation classes across alternating updates. The current-head shim rows cover the alternating sequence on three profiles, and the current-head J616C UBO and depth-bias checks passed without faults. An additional GPU-generation hardware row can follow separately. This resolves my earlier hold.

@m0d16l14n1

Copy link
Copy Markdown

Base M5 row (MacBook Air 15" M5, J815, G17G), kernel 7.3.0-aurora-j815-dev, PR head 915c288 vs aurora-wip 8b59f2b, release builds, dEQP-VK 1.4.7.1 (+ KhronosGroup/VK-GL-CTS@c2c05e95f97f):

  • every mustpass dynamic_state / draw / dynamic-offset case (46,003): 38,614 = 38,614 Pass, 0 diffs.
  • dEQP gate (15,958): 11,297 = 11,297 Pass, 0 diffs. 0 GPU faults.
  • gpubench-vk render.light / render.heavy / render.tvb (depth 2, 3 rounds): GPU time 4.75 / 260.4 / 19,790 us vs 4.75 / 260.6 / 19,811 us on the base; us per submit 57.4 / 260.4 / 20,833 vs 60.9 / 260.4 / 20,833: neutral.

@RyanTheTide

Copy link
Copy Markdown

@DjDeveloperr, code-owner heads-up: App approval at 915c288f90c0 from a different lane. This PR goes into the merge train's next combined A/B (batch 23, stacked on batch 22: #631 #664 #673 #1422 #1423 #1429 #1431 #1432 #1433 #1434 #1436) on M1 Pro G13S + M4 G16G. If that row is clean, I plan to land it via --admin under the 6-point rule no earlier than one hour from now, unless you post a hold.

@github-actions github-actions Bot added area:borealis Area from CODEOWNERS (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Merge readiness at 915c288f: ready to merge

Check Detail
CI at head ok no CI for this change (the hardware row is the gate)
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok comment at 915c288f
Conflicts ok none
PR text ok Risk: two-way · extends Borealis's AGX3 direct-draw fast path; falls back cleanly to the general draw path when bypass preconditions are not met, and dynbuf state is zeroed on command buffer reset.

Areas: area:borealis
Merge: gh pr merge 1433 --merge (Owners and Core through the bypass: add --admin).

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@DjDeveloperr DjDeveloperr 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.

Reviewed 915c288f90c0 against the earlier direct-draw revision and the tested correction. Both relocation classes now update the retained template after the final fallible check, before its single copy to the arena. The current driver delta from the tested correction is comments and whitespace. The added Vulkan sequences alternate valid dynamic offsets and push constants on one pipeline. Three shim profiles passed, and J616C passed its bindless UBO CRC and four depth-bias cases. The remaining evidence is alternating-draw readback on hardware, then J773g and a post-P0 J700 comparison.

@github-actions github-actions Bot removed the needs-review No approving review from Core or Omarchy Mac yet (bot) label Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:borealis Area from CODEOWNERS (bot) door:two-way Revertible or not, from Merge risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants