Repository navigation
borealis: fold clear-only passes into deferred clears, drop dead clears, and extend dead Z/S store kill to D32S8 - #1171
Conversation
…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>
DjDeveloperr
left a comment
There was a problem hiding this comment.
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
VkClearValuebits, depth usesuif(clear_colour[0]), and stencil usesclear_colour[1], which is wherehk_begin_rendering()stores it.
- 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
- Sync for a folded clear.
- Flushed as a fill, it runs as
HK_SYNC_GFXwork, gets the pass's savedcs->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.
- Flushed as a fill, it runs as
- Dead deferred clears. A clear is dropped only when the next pass's attachment is
LOAD_OP_CLEARin 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 thathk_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 matcheshk_pack_zls_control_final(), whose other fields don't depend on the store op, and the same unpack/repack is already done inhk_g17p_zls_*. It then recomputesprocess_empty_tilesfrom the per-aspect flags. - The next pass kills an aspect only with
CLEAR/DONT_CAREand no feedback flags on the same image over the whole area, without resuming or a view mask.vkCmdClearDepthStencilImagekills only whole-image D+S clears.
- The mask needs
- 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 polypasses 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 base0b8e9b836ccf.
Owed before approval:
- CI. No checks have run on this PR (
asahi.ymldidn'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_buffandclear_depth_stencil_imageonly. Legacy render passes (dEQP-VK.renderpasses.renderpass1/2.*, which reach the same begin/end path),dEQP-VK.api.image_clearing.*(colour too) anddEQP-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().
|
Thanks for the review at Updated the PR description and ran the requested wider Vulkan CTS groups A/B against base on J716c (Apple M5 Max) at
Combined with the original Also clarified the |
RyanTheTide
left a comment
There was a problem hiding this comment.
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):
- base
aurora-wip90211df6816: 335/335 OK. - batch build:
90211df6816with 22 open PR heads merged on top (#1133 #1137 #1155 #1136 #1140 #1157 #1158 #1160 #1164 #1165 #1167 #1168 #1170 #1171 #1172 #1175 #1182 #1183 #1185 #1187 #1190 #1191; each also merges cleanly alone, and into currentaurora-wipd2e883ab2e3): 335/336 OK. The one failure,agx3_cmat_mixed_mma8, reproduces with #1187 alone on the base (329/330) and is caused by that PR's new test; nothing else in the batch fails.
|
Two small edge-case findings at
|
|
|
|
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
|
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>
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-imageLOAD_OP_CLEARrender pass, and extendpending_z_storedead-store elimination from depth-only attachments to per-aspect depth and/or stencil stores includingD32_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_storeelision. Folded clear-only passes preserveHK_SYNC_GFXordering andcs->sync.depif flushed later to compute fills, only fold single-sample whole-image non-suspending/non-resuming passes with no pending transfer sync, and track per-aspectempty_tiles_other/empty_tiles_z/empty_tiles_sso 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, anddEQP-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
src/asahi/vulkan/hk_cmd_buffer.c,hk_sync.c,hk_sync.h):hk_optimize_empty_vdm()into deferred clears (preservingHK_SYNC_GFXordering andcs->sync.depif 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.src/asahi/vulkan/hk_cmd_buffer.c,hk_cmd_buffer.h):hk_take_deferred_clears()when the next render pass covers the whole image withLOAD_OP_CLEARin a strict attachment layout (preserving the pass's own clear value).src/asahi/vulkan/hk_cmd_buffer.c,hk_cmd_buffer.h,hk_cmd_draw.c):pending_z_storefrom depth-only images to per-aspect depth and/or stencil stores including combinedD32S8/D24S8, updatingz_store,s_store, and per-aspectprocess_empty_tiles(empty_tiles_other,empty_tiles_z,empty_tiles_s) after ZLS store elision.Build & Artifacts
J716c Apple M5 Max (G17C B1), Fedora Remix 44, kernel7.3.0-40.j716c19.fc44.aurora.aarch64origin/aurora-wip0b8e9b836cc):libvulkan_asahi.soSHA-256dfeef6f446046502ef9ed398f89657d523b6762fa230798828523f16a85548ad1eece864031):libvulkan_asahi.soSHA-25675abf5b06944f65aa7aa94f9b56cff01a58dfadddd9c209ba311a45ddccf7459Verification
--suite asahi --suite poly, Gallium + Vulkan +drm-shim, assertions enabled):334/334 PASS, 0 FAIL.MESA_SHADER_CACHE_DISABLE=1, pixel-exact readback0xff1a33ccon every run):LOAD_OP_LOADdraw pass6.537 ms2.792 ms2.34x)vkCmdClearColor/DepthStencil→LOAD_OP_CLEARdraw pass4.968 ms1.975 ms2.52x)STORE_OP_STORE→ next passLOAD_OP_CLEAR2.085 ms1.955 ms1.07x)deqp-vk, base vs head,MESA_SHADER_CACHE_DISABLE=1):220-casedEQP-VK.renderpasses.dynamic_rendering.primary_cmd_buff.*+dEQP-VK.api.image_clearing.core.clear_depth_stencil_image.*:167/220 PASS, 0 FAIL, 53 NotSupported(0status diffs vs base).SELinux=Enforcing,0DRM/asahi/GPU kernel errors.