Skip to content

borealis: fold clear-only passes into deferred clears, drop dead clears, and extend dead Z/S store kill to D32S8 - #1171

Merged
RyanTheTide merged 1 commit into
aurora-silicon:aurora-wipfrom
oreater:pr/borealis-clear-folding-d32s8-zstore-kill
Nov 27, 2026
Merged

RyanTheTide merged 1 commit into
aurora-silicon:aurora-wipfrom
oreater:pr/borealis-clear-folding-d32s8-zstore-kill

Conversation

@oreater

@oreater oreater commented Nov 26, 2026 •

Copy link
Copy Markdown

What: Fold eligible single-sample whole-image clear-only render passes into deferred clears (hk_optimize_empty_vdm), drop dead deferred clears overwritten by a subsequent whole-image LOAD_OP_CLEAR render pass, and extend pending_z_store dead-store elimination from depth-only attachments to per-aspect depth and/or stencil stores including D32_SFLOAT_S8_UINT / D24_UNORM_S8_UINT.

Tested: J716c Apple M5 Max at 1eece864031: 334/334 local Clang debug CI tests (--suite asahi --suite poly, without drm-shim; 337/337 with drm-shim) PASS, 2K clear-only pass fold -57.3% (2.34x), 2K dead clear drop -60.3% (2.52x), 2K D32S8 dead-store pass -6.2%, 367/440 Vulkan CTS PASS across dynamic rendering, clear_depth_stencil_image, api.image_clearing.core, synchronization.op.single_queue.barrier, and renderpasses.renderpass2 (0 fail, 0 diffs), 0 kernel errors.

Risk: two-way door · M4, M5 — A plain revert restores eager compute-fill lowering for clear-only passes and depth-only pending_z_store elision. Folded clear-only passes preserve HK_SYNC_GFX ordering and cs->sync.dep if flushed later to compute fills, only fold single-sample whole-image non-suspending/non-resuming passes with no pending transfer sync, and track per-aspect empty_tiles_other / empty_tiles_z / empty_tiles_s so ZLS store elision never drops live stencil or color clears.

Not yet: Upstream CI run at 1eece864031, second-generation native AGX3 hardware row (J700 / G16 M4 or J773g / G17P A18 Pro) with A/B readback + wider CTS, and dEQP-VK.renderpasses.renderpass1.* coverage. (Scope note: multisampled, layered, and partial-area clear-only passes stay on the existing compute-fill path.)

Details and verification evidence

Summary

  1. Clear-only render pass folding (src/asahi/vulkan/hk_cmd_buffer.c, hk_sync.c, hk_sync.h):
    • Fold eligible single-sample whole-image clear-only render passes in hk_optimize_empty_vdm() into deferred clears (preserving HK_SYNC_GFX ordering and cs->sync.dep if later flushed to compute fills) so a subsequent pass that loads or re-clears the attachment absorbs the clear directly as a tilebuffer load-op clear without an extra compute fill kick.
  2. Dead deferred clear dropping (src/asahi/vulkan/hk_cmd_buffer.c, hk_cmd_buffer.h):
    • Drop dead deferred clears in hk_take_deferred_clears() when the next render pass covers the whole image with LOAD_OP_CLEAR in a strict attachment layout (preserving the pass's own clear value).
  3. Per-aspect D32S8 / D24S8 dead Z/S store elimination (src/asahi/vulkan/hk_cmd_buffer.c, hk_cmd_buffer.h, hk_cmd_draw.c):
    • Extend pending_z_store from depth-only images to per-aspect depth and/or stencil stores including combined D32S8 / D24S8, updating z_store, s_store, and per-aspect process_empty_tiles (empty_tiles_other, empty_tiles_z, empty_tiles_s) after ZLS store elision.

Build & Artifacts

  • Host: J716c Apple M5 Max (G17C B1), Fedora Remix 44, kernel 7.3.0-40.j716c19.fc44.aurora.aarch64
  • Base (origin/aurora-wip 0b8e9b836cc): libvulkan_asahi.so SHA-256 dfeef6f446046502ef9ed398f89657d523b6762fa230798828523f16a85548ad
  • Head (1eece864031): libvulkan_asahi.so SHA-256 75abf5b06944f65aa7aa94f9b56cff01a58dfadddd9c209ba311a45ddccf7459

Verification

  • CI-matching Clang 22.1.8 debugoptimized (--suite asahi --suite poly, Gallium + Vulkan + drm-shim, assertions enabled): 334/334 PASS, 0 FAIL.
  • Live M5 Max A/B (strict 3-round ABBA = 6 runs per arm, MESA_SHADER_CACHE_DISABLE=1, pixel-exact readback 0xff1a33cc on every run):
Workload (60 passes × 2048×2048 RGBA8 + D32S8) Base median Head median Delta
Clear-only render pass → LOAD_OP_LOAD draw pass 6.537 ms 2.792 ms -57.3% (2.34x)
vkCmdClearColor/DepthStencil → LOAD_OP_CLEAR draw pass 4.968 ms 1.975 ms -60.3% (2.52x)
D32S8 STORE_OP_STORE → next pass LOAD_OP_CLEAR 2.085 ms 1.955 ms -6.2% (1.07x)
  • Vulkan CTS (deqp-vk, base vs head, MESA_SHADER_CACHE_DISABLE=1):
    • 220-case dEQP-VK.renderpasses.dynamic_rendering.primary_cmd_buff.* + dEQP-VK.api.image_clearing.core.clear_depth_stencil_image.*: 167/220 PASS, 0 FAIL, 53 NotSupported (0 status diffs vs base).
  • Host health: SELinux=Enforcing, 0 DRM/asahi/GPU kernel errors.

…rs, and extend dead Z/S store kill to D32S8

Three frame-time and tile-memory bandwidth optimizations for native AGX3
and M5:

1. Fold eligible single-sample whole-image clear-only render passes in
   hk_optimize_empty_vdm() into deferred clears (preserving HK_SYNC_GFX
   ordering and cs->sync.dep if later flushed to a compute fill) so a
   subsequent pass loading or re-clearing the attachment absorbs the
   clear as a tilebuffer load-op clear without an extra compute fill kick.
2. Drop dead deferred clears in hk_take_deferred_clears() when the next
   render pass covers the whole image with LOAD_OP_CLEAR in a strict
   attachment layout (preserving the pass's own clear value).
3. Extend pending_z_store dead-store elimination from depth-only images
   to per-aspect depth and/or stencil stores including combined D32S8 /
   D24S8, updating z_store, s_store, and per-aspect process_empty_tiles
   after ZLS store elision.

Signed-off-by: oreater <145754695+oreater@users.noreply.github.com>
@oreater
oreater requested review from a team and DjDeveloperr as code owners November 26, 2026 23:30

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

Verdict at 1eece864031a: no code blockers found. Not approving yet, because no CI has run on this PR and hardware coverage on a second GPU generation is still owed (see below).

Blockers: none in the code.

Checked:

  • Clear-only pass folding (hk_try_defer_empty_render_clears()).
    • It is reached only where the existing code would have replaced the pass with compute fills: after the continuation, timestamp, MS-resolve-through-EOT and HAL300 multisample-clear early returns, and only for cs->stats.cmds == 0.
    • A pass is folded only when all of these hold:
      • a native AGX3 or M5 GPU;
      • not in meta, and no view mask;
      • exactly 1 layer;
      • not suspending, resuming or using secondary command buffers;
      • no pending transfer sync;
      • no resolve on any attachment;
      • every cleared attachment is STOREd;
      • each view is 2D at the image's own format, over an image that is 2D, single-mip, single-layer, single-sample, optimally tiled and not alias or sparse;
      • the render area equals the image extent;
      • depth and stencil views of the same image match;
      • there is room in the deferred-clear table, with no duplicate images.
    • Otherwise it returns false and the existing fills run.
    • The clear values are right: colour reuses the raw VkClearValue bits, depth uses uif(clear_colour[0]), and stencil uses clear_colour[1], which is where hk_begin_rendering() stores it.
  • Sync for a folded clear.
    • Flushed as a fill, it runs as HK_SYNC_GFX work, gets the pass's saved cs->sync.dep (hk_sync_apply_dep()), and is followed by a GFX-to-all barrier.
    • Taken or overwritten by the next pass, that pass already waits on the GFX requirement, which only grows, so it covers what the folded pass waited for.
    • hk_sync_forget_stream() moves the folded render's references to the previous stream, as the existing fill replacement does.
    • Events, queries, secondaries and the end of the command buffer already flush deferred clears.
  • Dead deferred clears. A clear is dropped only when the next pass's attachment is LOAD_OP_CLEAR in a strict layout (HK_DEFERRED_CLEAR_LOAD, so no feedback flag and no load-and-fill) over the whole image, with the pass not resuming, no view mask and one layer. A depth/stencil clear is dropped only if every aspect it cleared is overwritten or taken; otherwise it stays and is flushed. The pass keeps its own clear value.
  • Per-aspect dead Z/S store.
    • The mask needs STORE, no resolve, a precise ZLS word and a layout for each aspect.
    • Recording needs a single-stream pass with draws (stats.cmds > 0, so it never names a stream that hk_optimize_empty_vdm() destroys). It also needs no view mask, suspend or secondaries, and a 2D single-mip single-layer image, with G17P-elided aspects excluded.
    • A meta resolve after the pass clears the pending store.
    • The kill unpacks the stream's ZLS word and clears only z_store/s_store. That matches hk_pack_zls_control_final(), whose other fields don't depend on the store op, and the same unpack/repack is already done in hk_g17p_zls_*. It then recomputes process_empty_tiles from the per-aspect flags.
    • The next pass kills an aspect only with CLEAR/DONT_CARE and no feedback flags on the same image over the whole area, without resuming or a view mask. vkCmdClearDepthStencilImage kills only whole-image D+S clears.
  • Unit tests. At this head, with the CI job's options (-Dgallium-drivers=asahi -Dvulkan-drivers=asahi -Dplatforms=wayland,x11 -Dbuild-tests=true -Dtools=drm-shim, ccache clang), meson test --suite asahi --suite poly passes 337/337. The compiler warnings in the touched files are on lines this PR doesn't change.
  • Merge. The PR merges into current aurora-wip (41fe336dffae) without conflicts. Nothing has changed in these five files since its base 0b8e9b836ccf.

Owed before approval:

  • CI. No checks have run on this PR (asahi.yml didn't trigger for the fork branch). A run at this head is needed.
  • A row on a second GPU generation. Both the fold and the per-aspect store kill are gated on agx_chip_native_or_m5(), so they run on native AGX3 too (G16 M4, G17P A18 Pro), not only M5. That path has its own end-of-tile and ZLS-elide handling. The PR's rows are all on J716c (G17C). A J700 or J773g row at this head is needed: the three A/B workloads with pixel readback, plus the CTS below.
  • Wider CTS on both generations. The 220 cases ran on dynamic_rendering.primary_cmd_buff and clear_depth_stencil_image only. Legacy render passes (dEQP-VK.renderpasses.renderpass1/2.*, which reach the same begin/end path), dEQP-VK.api.image_clearing.* (colour too) and dEQP-VK.synchronization* cover the folding, the dropped clears and the sync handoff.
  • PR text. "Not yet" lists cases the PR doesn't handle, not the rows still owed. Please list the owed rows there. The test count in Tested (334) also differs from my 337 at the same head.
Evidence

Head 1eece864031a6b1214790d7ec48936860293c28d, base aurora-wip 0b8e9b836ccf. Linux aarch64 host, clang + ccache, Meson 1.12.1.

Check Result
meson setup … -Dgallium-drivers=asahi -Dvulkan-drivers=asahi -Dplatforms=wayland,x11 -Dbuild-tests=true -Dtools=drm-shim + ninja builds; no new warnings in hk_cmd_buffer.{c,h}, hk_cmd_draw.c, hk_sync.{c,h}
meson test --suite asahi --suite poly Ok: 337, Fail: 0
git merge-tree origin/aurora-wip (41fe336dffae) clean; no commits since the base touch the five files
gh pr checks no checks reported

Code paths read at this head: hk_optimize_empty_vdm() and its caller (cs->stats.cmds == 0), hk_deferred_clear_image_whole() (single sample, single mip and layer, 2D, optimal tiling), hk_deferred_clear_for() / hk_take_deferred_clears(), hk_flush_deferred_clears_why(), hk_sync_barrier() / hk_sync_stream_created() / hk_sync_forget_stream(), hk_begin_rendering() (clear values and the pending mask), hk_CmdEndRendering2KHR(), and hk_pack_zls_control_final() / agx_pack_zls_control().

@oreater

oreater commented Nov 27, 2026

Copy link
Copy Markdown
Author

Thanks for the review at 1eece864031.

Updated the PR description and ran the requested wider Vulkan CTS groups A/B against base on J716c (Apple M5 Max) at 1eece864031:

  • dEQP-VK.api.image_clearing.core.* (80 cases): 64/80 PASS, 16 NotSupported, 0 FAIL, 0 status diffs vs base.
  • dEQP-VK.synchronization.op.single_queue.barrier.* (80 cases): 80/80 PASS, 0 FAIL, 0 status diffs vs base.
  • dEQP-VK.renderpasses.renderpass2.suballocation.* (60 cases): 56/60 PASS, 4 NotSupported, 0 FAIL, 0 status diffs vs base.

Combined with the original dynamic_rendering.primary_cmd_buff + clear_depth_stencil_image slice (167/220 PASS), that is 367/440 PASS, 0 FAIL, 0 diffs on J716c.

Also clarified the 334 vs 337 local test count (our local Clang debug build omits drm-shim) and updated **Not yet:** to explicitly list the owed upstream CI run, J700/J773g native AGX3 hardware row, and renderpasses.renderpass1.* slice. (I only have J716c locally, so the J700/J773g row and upstream fork-PR CI trigger will need to be run by a maintainer or lab machine.)

@RyanTheTide RyanTheTide 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 1eece864031a

Blockers: none

Checked: Read the diff. Folded passes keep their sync dependency, and every later recording flushes deferred clears first (hk_cmd_buffer_get_cs_general() flushes whenever deferred_clear_count is non-zero, as do events, queries and the end of the command buffer), so a copy or draw that reads a folded clear sees it. A dead clear is dropped only when the next pass fully clears every aspect it covered. The per-aspect ZLS store kill only clears z_store/s_store in the unpacked word. Selected by agx_chip_native_or_m5(). Gate green. Dj's list of owed rows stands (renderpass1/2, image_clearing, synchronization on a second generation); we will run them on J700 (G17P) and J713 (G16G).

Evidence

Local Mesa gate (stands in for CI; buildbox x86 docker aurora/hk6356-mesa-x86-tests:local, clang release with asserts, -Dbuild-tests=true -Dtools=asahi,drm-shim, meson test --suite asahi --suite poly):

@AxxzyWasTaken

Copy link
Copy Markdown

Two small edge-case findings at 1eece864031a while auditing this for G17P:

  1. Mid-pass empty-render splits enter hk_try_defer_empty_render_clears() while the API pass is still open:

    • hk_CmdPipelineBarrier2() (src/asahi/vulkan/hk_cmd_buffer.c:1635, cmd->sync.in_pass == true) calls hk_cmd_buffer_end_graphics(cmd) when an in-pass barrier forces a split. If that split happens before any draw (cs->stats.cmds == 0), hk_optimize_empty_vdm() calls hk_try_defer_empty_render_clears(cmd, cs), which defers the attachment clears and calls hk_sync_forget_stream(cmd, cs) (clearing pass_vdm, pass_tile_first, pass_tile_last) without ending the API pass.
    • hk_sync_pass_barrier() then runs with no physical clear stream recorded, and the next draw in the same pass triggers hk_flush_deferred_clears() inside hk_cmd_buffer_get_cs_general() while cmd->sync.in_pass == true — emitting a compute fill and calling outside-pass hk_sync_barrier(cmd, HK_SYNC_GFX, HK_SYNC_ALL) mid-pass (and because pass_vdm was nulled, the continuation stream also re-applies the clear instead of folding it).
    • Restricting hk_try_defer_empty_render_clears() to pass end (e.g. passing bool ending_pass from hk_CmdEndRendering2KHR(), or skipping deferral on mid-pass splits) avoids this cleanly.
  2. Untracked raw struct hk_cs * in deferred_clear[].gfx_dep[].cut (latent hk_sync pointer invariant):

    • hk_try_defer_empty_render_clears() copies cs->sync.dep[sq].cut into cmd->state.deferred_clear[i].gfx_dep[sq].cut, which is not updated by hk_sync_forget_stream() or hk_sync_merge() (src/asahi/vulkan/hk_sync.c:1565,1640).
    • Current callers happen not to forget a predecessor stream while a deferred clear is live, so this is latent today, but walking cmd->state.deferred_clear in hk_sync_forget_stream() / hk_sync_merge() (or flushing deferred clears before forgetting/merging) keeps the hk_sync pointer invariant intact.

@RyanTheTide
RyanTheTide merged commit 9affaed into aurora-silicon:aurora-wip Nov 27, 2026
@RyanTheTide

Copy link
Copy Markdown

1eece864031a Neo (J700, Apple A18 Pro / G17P B1, 7.3.0-aurora-fleet89, default cmdline) PASS: Borealis overlay ICD (-Dbuildtype=release -Db_ndebug=false, sha256: 6e8a388b0fc7..., combined disjoint overlay on aurora-wip@e1b5658fe695 with this PR's touched files verified 0-byte diff vs merge(aurora-wip, head)), meson test --suite asahi 214/214 PASS; live VK CTS (J=1, MemoryMax=3G): dEQP-VK.renderpasses.renderpass1.* (--deqp-fraction=1,40) 358/522 PASS / 0 FAIL (164 NotSupported), dEQP-VK.renderpasses.renderpass2.* (--deqp-fraction=1,60) 327/602 PASS / 0 FAIL (275 NotSupported), dEQP-VK.api.image_clearing.* (--deqp-fraction=1,80) 1,017/2,499 PASS / 0 FAIL (1,482 NotSupported), dEQP-VK.renderpasses.dynamic_rendering.primary_cmd_buff.* (--deqp-fraction=1,30) 169/590 PASS / 0 FAIL (421 NotSupported), dEQP-VK.synchronization2.op.single_queue.* (--deqp-fraction=1,30) 475/476 PASS / 0 FAIL (1 NotSupported); 0 GPU faults/recoveries, 0 failed units, SELinux Enforcing, 0 new AVC denials, stock /usr/lib64/libvulkan_asahi.so untouched.

@RyanTheTide

Copy link
Copy Markdown

1eece86 J713 M4 Air (G16G B0, 7.3.0-aurora-fleet85) PASS (no change from aurora-wip; aurora-wip itself has a G16G regression on this kernel, see below): renderpasses.renderpass1.* 14,665 pass / 3,862 not supported / 1,271 fail, renderpasses.renderpass2.* 13,046 / 18,021 / 1,613, api.image_clearing.* 23,394 / 22,122 / 120, renderpasses.dynamic_rendering.primary_cmd_buff.* 8,386 / 5,835 / 716, synchronization2.op.single_queue.* 14,851 / 215 / 24 (128,141 cases, every listed case ran). The same 3,744 cases fail the same way on aurora-wip 90211df, and all of them pass on the packaged Mesa. 0 GPU faults, Enforcing, 0 failed, 0 AVC; system Mesa untouched

Details
  • Build: exact head 1eece86 (git archive of the PR head, no merge), release with assertions on (-Dbuildtype=release -Db_ndebug=false -Dvulkan-drivers=asahi), built natively on aarch64 Fedora 45 in a container. vulkaninfo with the overlay: Apple M4 (G16G B0), Mesa 26.3.0-devel (git-1eece86403), Borealis. Loaded through VK_DRIVER_FILES only. /usr/lib64/libvulkan_asahi.so sha256 9b40d2912963... before and after. Shader cache off.

  • CTS: deqp-vk 1.4.7.1 (3fd4ea318fe2), all five globs in full, 4 parallel processes. After a lost device the runner starts a new process at the next case, so every case ran.

  • Fails: 3,732 DeviceLost plus 12 crashes (dynamic_rendering...low_resolution_z.*). The crashes are aborts right after a lost device. They are all depth/stencil attachment cases (depth_stencil_resolve, *.formats with D/S formats, clear_depth_stencil_attachment, and so on). The kernel answers each one with aurora-g16 ...: IOCTL: submit failed! (... err: EINVAL). That gives 3,739 rejected submits and no GPU fault or firmware error.

  • Same 3,744 cases, run again:

    • packaged Mesa 26.3.0-30 (git-d4ad4a4dce): 3,712 pass / 32 not supported / 0 fail.
    • aurora-wip 90211df: the same 3,732 DeviceLost + 12 crashes as this head.

    So borealis: fold clear-only passes into deferred clears, drop dead clears, and extend dead Z/S store kill to D32S8 #1171 adds nothing here. The fails come from aurora-wip.

  • First-parent bisect on the J713 with api.image_clearing.core.clear_depth_stencil_attachment.multiple_layers.d16_unorm as the probe, from cedf248 (good) to 6917974 (bad). The first bad merge is 5269d58, "Merge pull request borealis: enable HAL200 lossless compression on G16G #1050 (perf/m4-hal200-compress)", which enables HAL200 lossless compression on G16G. Its first parent e736b5f is good. The J713 runs the 7.3.0-aurora-fleet85 kernel. A kernel with matching G16 support may accept these submits. On fleet85, every depth/stencil attachment submit from aurora-wip Mesa is rejected.

  • Kernel log otherwise clean: 0 GPU faults or recoveries, 0 AVC, 0 failed units, Enforcing.

DjDeveloperr added a commit that referenced this pull request Nov 27, 2026
Update hk_m5_pass_merge_begin() for #1171's pending depth/stencil store
fields:
- set render->empty_tiles_other = true (replacing removed
  process_empty_tiles_without_z) when adding a direct colour resolve
- clear render->pending_zs_store_mask (replacing removed no_z_store_ok)
  when depth/stencil store ops change on STORE -> DONT_CARE.

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.

4 participants