Skip to content

borealis: batch adjacent stores in large image clears - #462

Closed
erikwb wants to merge 8 commits into
aurora-wipfrom
j716c/t2-tile-clear
Closed

erikwb wants to merge 8 commits into
aurora-wipfrom
j716c/t2-tile-clear

Conversation

@erikwb

@erikwb erikwb commented Nov 19, 2026 •

Copy link
Copy Markdown

What: Batch adjacent 16-byte stores in Borealis uncompressed image clears via libagx_fill_uint4_blocks (src/asahi/libagx/copy.cl, src/asahi/clc/asahi_clc.c, src/asahi/vulkan/hk_cmd_clear.c) using 32-bit uint indexing across all GPU generations when the clear covers at least max(128, 4 * agx_get_num_cores()) 4 KiB blocks (512 KiB minimum, scaling up to 640 KiB on 40-core GPUs). Adds vulkan-image-clear-bench (src/asahi/vulkan/tests/vulkan_image_clear_bench.c).
Tested: Host x86_64 at de451b95c0a7 (poly 5/5, asahi 347/347, agx_tests 1,812 passed / 1 skipped, vulkan-image-clear-bench builds cleanly). Exact-head de451b95c0a7 vs 46f3a68e60d9: J716c M5 Max (dEQP-VK.api.image_clearing.* 45,636 cases 0 diffs; vulkan-image-clear-bench neutral on post-#1270 KERNEL(256) base, readbacks verified; boot/smoke clean, 0 GPU faults) and J713 M4 Air (dEQP-VK.api.image_clearing.* 45,636 cases 0 diffs; vulkan-image-clear-bench 16 ABBA runs 0 readback mismatches, per-size medians pending raw reduction; default-boot baseline smoke clean, 0 new dmesg error lines during this PR's Mesa run window); J313 M1 Air exact-head row pending. Prior-merge-base 86abe1d53d54 vs a0164c9101c1 (pre-#1270 KERNEL(32)) rows across J716c, J713 (>= 512 KiB through 16 MiB -24.00% at 1 MiB to -1.64% at 16 MiB), and J313 are in Evidence.
Risk: two-way door · all Macs (M1–M6 / G18G, Neo)
Revert: git revert -m 1 <merge-sha> on aurora-wip; no persistent on-disk, shader-cache (hk_cache_identity() hashes build_sha), UAPI, or firmware state is changed.
Not yet: Reduction of per-size vulkan-image-clear-bench medians from the raw timing file on J713 (M4 Air, G16G B0, currently awaiting human recovery); exact-head paired A/B vs origin/aurora-wip (46f3a68e60d9, post-#1270 KERNEL(256) libagx_fill_uint4) at de451b95c0a7 on local lab Mac J313 (M1 Air, G13G B1: vulkan-image-clear-bench ABBA across the 512 KiB floor, dEQP-VK.api.image_clearing.*, and boot/smoke checks with kernel/Stage 2 hashes and dmesg excerpt); plus external J413 (M2 Air, G14G B0), G15 (M3), G17P (A18 Pro Neo / M4 Pro J616s), G17S, and G18G (M6) rows (no external hardware in lab).

Details

Change

  • src/asahi/libagx/copy.cl (libagx_fill_uint4_blocks): Each 32-lane group fills one 4 KiB block in eight rounds of adjacent 16-byte stores, sharing address setup across eight stores. Indexing in 32-bit uint (cl_global_id.y * layer_stride_uint4 + cl_group_id.x * 256 + cl_local_id.x), matching libagx_fill_uint4, eliminates the 140-byte preamble and seven 64-bit iadd chains on AGX2 (201 -> 66 uint32s on g13g) and the 16-bit split carry chains on AGX3 (276 -> 80 uint32s on g17p/g15s/g15g/g16g, 247 -> 74 on g17g, 217 -> 62 on g18g).
  • src/asahi/clc/asahi_clc.c: Build libagx_fill_uint4_blocks for every libagx target.
  • src/asahi/vulkan/hk_cmd_clear.c (hk_clear_use_block_fill() / hk_clear_image()): Select libagx_fill_uint4_blocks on all generations when size % 4096 == 0 and total blocks (uint64_t)(size / 4096) * layer_count >= max(128, 4 * agx_get_num_cores(&dev->dev)) (HK_CLEAR_BLOCK_FILL_MIN_GROUPS = 128, HK_CLEAR_BLOCK_FILL_GROUPS_PER_CORE = 4), where size is the tile-aligned padded level size rather than the unaligned logical image size (width * height * bpp). For example, a 176×176 R32G32B32A32_UINT layer has a 484 KiB logical size (176 × 176 × 16 B), while its padded tile-aligned level size is >= 512 KiB (>= 128 blocks), so the cutoff calculation (padded level size / 4096 * layer_count) selects libagx_fill_uint4_blocks. After aurora-silicon/mesa#1270 (0df1e19b9174) moved libagx_fill_uint4 from KERNEL(32) to KERNEL(256), both kernels launch one 4 KiB block per workgroup (size / 4096 groups per layer), with libagx_fill_uint4_blocks launching an eighth of the threads per group (32 lanes × 8 stores vs 256 lanes × 1 store). Requiring at least 128 blocks (512 KiB) keeps small clears (144–256 KiB, where 36–64 eight-store workgroups left narrower 8-core G13G paying +0.26 µs store-latency overhead against KERNEL(32) libagx_fill_uint4) on libagx_fill_uint4, while scaling the floor with 4 * agx_get_num_cores() (640 KiB on 40-core G17C) so wide GPUs stay saturated. Partial blocks and compressed levels keep their existing paths.
  • Branch history: Merged origin/aurora-wip (cedf24806bcb) in 523f52be9f12, added c1f8d2f816dc on top, merged origin/aurora-wip (a0164c9101c1) in 23e513cde215 to resolve the src/asahi/vulkan/meson.build test-executable conflict without rewriting public history, raised HK_CLEAR_BLOCK_FILL_MIN_GROUPS to 128 in 86abe1d53d54, merged origin/aurora-wip (46f3a68e60d9, including #1270 0df1e19b9174) in 93e1fe96a14f, and updated the hk_cmd_clear.c block-fill comment in de451b95c0a7 for 256-lane libagx_fill_uint4.

Benchmark (vulkan-image-clear-bench)

src/asahi/vulkan/tests/vulkan_image_clear_bench.c builds with -Dbuild-tests=true (manual test, outside meson test) and only needs -lvulkan (cc -O2 -o vulkan-image-clear-bench vulkan_image_clear_bench.c -lvulkan).

Per side S (default 16 128 512 1024, i.e. 4 KiB, 256 KiB, 4 MiB, 16 MiB per layer):

  • Creates a 3-layer R32G32B32A32_UINT optimal-tiling image with transfer and storage usage (storage usage keeps the image uncompressed on every generation).
  • Clears all 3 layers once, then runs 8 warm-up clears and 32 timed clears of layer 1 with a transfer barrier between clears.
  • Copies all 3 layers to a host-visible buffer and verifies every word (layer 1 holds the final colour; layers 0 and 2 hold the initial colour), printing clear_us and exiting non-zero on any mismatch.

Credits

Tested-by: satchlj (J716c M5 Max & aarch64 Meson suite at c1f8d2f816dc)
Tested-by: RyanTheTide (J413 M2 Air at c1f8d2f816dc)

Evidence
  • Exact-head J716c (M5 Max, T6050, 2026-11-28): native release base-plus-patch builds (aurora-wip 46f3a68e60d9 incremental tree plus head patch, sharing git-97742505d8 in driverInfo and identified by source SHA and libvulkan_asahi.so SHA-256: 8e738aeae25de9f4a7870f081ccce9ff2693997e2a2dfb378b543b075ac330e6 for head de451b95c0a7 vs 291c55d4954f28aa2fcfc362db21decf1aeb7d0a65ed154c9aba12b047dbe595 for base 46f3a68e60d9); default kernel image SHA-256 bf2582ab357573db64031f39e7bc9d617eb574c6b221364ff417810bbddf4c87, default Stage 2 SHA-256 21edee972e1ff1718c6f41c32b91ee151afdc58cbb69f16f2f6a4d8d4c722170, AC power. CTS runs used tools/cts/aurora-cts-ab.py (6 workers, shader cache on, chunk 300, CTS 7ba03cdac7ae) with its case-list expansion patched locally to keep only TEST: lines (the repository copy mis-parses this CTS build's export); Borealis arms are selected through VK_DRIVER_FILES.
    • dEQP-VK.api.image_clearing.*: 45,636 cases, 24,418 Pass / 21,218 NotSupported on both arms, 0 diffs, 0 GPU-error lines.
    • vulkan-image-clear-bench (built from the PR tree's tests/vulkan_image_clear_bench.c), VK_DRIVER_FILES per arm, 7 rounds in A B / B A order, median clear_us (image side, bytes per layer): 16 (4 KiB) 2.065 -> 2.141 (+3.66%); 128 (256 KiB) 1.818 -> 1.810 (-0.43%); 181 (512 KiB) 2.581 -> 2.578 (-0.10%); 192 (576 KiB) 2.574 -> 2.572 (-0.10%); 202 (638 KiB) 3.030 -> 3.038 (+0.26%); 256 (1 MiB) 3.630 -> 3.646 (+0.43%); 512 (4 MiB) 10.961 -> 11.053 (+0.84%); 1024 (16 MiB) 37.445 -> 37.276 (-0.45%). Every word of the three layers verified. On J716c the post-#1270 KERNEL(256) base leaves no measurable difference around the 512 / 640 KiB floor.
    • boot/smoke on the default boot: eDP-1 3456x2234@120 enabled; Apple MTP keyboard, trackpad and SMC lid devices enumerated (not exercised remotely); wlan0 connected, 0% loss over 3 pings; AppleJ716 card present with speakerguardd v2 active (no playback in this row); Borealis Apple M5 Max (G17C B1) with vkcube --c 240 --wsi wayland clean; 0 failed units (system and user); 0 LSM denials (no SELinux/AppArmor loaded); 0 GPU fault, MMU fault, SError or Oops lines. Redacted dmesg excerpt (default boot, unchanged by the runs): aurora 2302600000.gpu: GPU firmware: 27.2 (26B123), G17C; 0 GPU fault / MMU fault / DeviceLost lines after all runs; the err+ set is the boot's usual 55 lines (apple-dcp ... unable to match service ... and systemd-gpt-auto-generator), unchanged.
  • Exact-head J713 (M4 MacBook Air, T8132, G16G B0, AGX3B, 2026-11-28): native release base-plus-patch builds (aurora-wip 46f3a68e60d9 plus head patch SHA-256 verified byte-identical to git diff 46f3a68e60d9 de451b95c0a7, built on the aarch64 lab sibling Mac, sharing git-97742505d8 in driverInfo and identified by source SHA and libvulkan_asahi.so SHA-256: 8e738aeae25de9f4a7870f081ccce9ff2693997e2a2dfb378b543b075ac330e6 for head de451b95c0a7 vs 291c55d4954f28aa2fcfc362db21decf1aeb7d0a65ed154c9aba12b047dbe595 for base 46f3a68e60d9), selected via VK_DRIVER_FILES on battery; default Linux 7.3.0 (default J713 7.3.0 kernel) kernel image SHA-256 592f7bc8834d8796d5bdb086091e90ac96fc6a17a83769cbadc92b3268604c49, default Stage 2 SHA-256 3b2d2f059858d1891b225910864c02d68afb1b42893667e0afa8666491651071.
    • dEQP-VK.api.image_clearing.* (CTS 7ba03cdac7ae, 3 workers, aurora-cts-ab 1.0, all 45,636 cases): 23,514 Pass / 22,122 NotSupported / 0 Fail on both arms, 0 diffs.
    • vulkan-image-clear-bench (sides 16 128 160 192 256 512 1024, 4 KiB to 16 MiB per layer, 16 runs / 8 per arm ABBA): every run verified all words (0 readback mismatches, rc 0). Observed single-run values (not reduced medians): <= 400 KiB/layer equal within noise (1.2 / 2.1 / 2.6 us), 1 MiB 4.8 us both, 4 MiB 29.8–30.1 us PR vs 31.1–31.4 us base, 16 MiB 199–247 us PR vs 199–203 us base (single outliers up to 247 µs recorded on both arms; thermal state varied across the pass). Per-size medians have not been reduced yet because the raw timing file remains on J713 (currently awaiting human recovery).
    • Default-boot baseline smoke (default J713 7.3.0 kernel): eDP-1 2560x1664@60 enabled, input enumerated, wlan0 3/3 gateway ping (0% loss), speakerguardd-v2 active with protected-sink sgv2.voicing tone rc 0, Borealis Apple M4 (G16G B0) Vulkan 1.4.363 (glmark2 5,047), 0 failed units (system and user), 0 AppArmor denials (no SELinux), 4 pre-existing baseline err+ boot lines (AFK[ep:20], unsupported DFB layout, apple_sep matching, brcmfmac ring 4). Per-arm Mesa vulkaninfo --summary / vkcube smoke passed with 0 new dmesg error lines during this PR's Mesa run window.

Host build and unit tests at de451b95c0a7

  • Build config (x86_64): -Doptimization=2 -Ddebug=false -Db_ndebug=false -Dbuild-tests=true -Dtools=drm-shim -Dvulkan-drivers=asahi -Dgallium-drivers=asahi -Dplatforms=wayland -Dglx=disabled
  • ninja -C _build: clean build including src/asahi/vulkan/vulkan-image-clear-bench; _build/src/asahi/lib/libagx_shaders.h emits LIBAGX_FILL_UINT4 = 36 and LIBAGX_FILL_UINT4_BLOCKS = 37.
  • meson test -C _build --suite poly: 5/5 pass (0 fail).
  • meson test -C _build --suite asahi: 347/347 pass (0 fail).
  • _build/src/asahi/compiler/agx_tests --gtest_brief=1: 1,812 pass, 1 pre-existing skip (NativeFMA.ExactDyadicOracle, 1,813 total).

Prior-merge-base host tests, codegen, and drm-shim at 86abe1d53d54

  • Build config (x86_64): -Doptimization=2 -Ddebug=false -Db_ndebug=false -Dbuild-tests=true -Dtools=drm-shim -Dvulkan-drivers=asahi -Dgallium-drivers=asahi -Dplatforms=wayland -Dglx=disabled
  • meson test --suite poly: 5/5 pass (0 fail).
  • agx_tests --gtest_brief=1: 1,726 pass, 1 pre-existing skip (NativeFMA.ExactDyadicOracle, 1,727 total).
  • meson test --suite asahi: 326/337 pass, 11 fail; all 11 failures were unrelated pre-existing/headless-environment failures on origin/aurora-wip (a0164c9101c1), now resolved on 46f3a68e60d9.
  • Generated libagx_shaders.c binary word counts for libagx_fill_uint4_blocks: g13g 66, g17p/g15s/g15g/g16g 80, g17g 74, g18g 62 uint32s; vulkan-image-clear-bench built cleanly.
  • drm-shim (vulkan-image-clear-bench under gdb breaking on agx_get_precompiled, checking both the 3-layer initial clear and 1-layer timed clears):
    • g13g (8 cores, floor max(128, 32) = 128 blocks = 512 KiB): side=96 (144 KiB/layer, 432 KiB 3-layer) -> LIBAGX_FILL_UINT4 (36) for both 3-layer and 1-layer; side=128 (256 KiB/layer), side=144 (324 KiB/layer), side=160 (400 KiB/layer) -> 3-layer LIBAGX_FILL_UINT4_BLOCKS (37), 1-layer LIBAGX_FILL_UINT4 (36); side=176 (484 KiB logical, tile-aligned level >= 512 KiB), side=192 (576 KiB/layer), side=256 (1 MiB/layer) -> LIBAGX_FILL_UINT4_BLOCKS (37) for both.
    • g14g, g16g (10 cores, floor max(128, 40) = 128 blocks), g17p (5-core shim, floor max(128, 20) = 128 blocks), and g17s (20 cores, floor max(128, 80) = 128 blocks): identical switchover — side=96 -> LIBAGX_FILL_UINT4 (36) for 3-layer and 1-layer; side=128 (144/160 checked on g17p) -> 3-layer (37), 1-layer (36); side=176/192/256 -> LIBAGX_FILL_UINT4_BLOCKS (37).

Prior-merge-base hardware A/B at 86abe1d53d54 vs aurora-wip a0164c9101c1 (pre-#1270 KERNEL(32) libagx_fill_uint4)

Cross-built aarch64 release Borealis ICDs (-Doptimization=2 -Ddebug=false -Db_ndebug=false -Dvulkan-drivers=asahi, libvulkan_asahi.so sha256: base a0164c9101c1 61a02818ab44113440360aed455d208158fd2e66414f1b3580d3501d195103d0, head 86abe1d53d54 8b911b07cdcb438619571c5a973c594e8125cb9a4814545dd508acb5fc721f45; vulkan-image-clear-bench sha256 d94634a37d43b8cb438fa8a4b1d2693ef9556e226a3f3a976d324470dec29224), selected per process via VK_DRIVER_FILES, Linux 7.3.0, default command line, AC online, 0 readback mismatches across all invocations.

J716c (M5 Max, G17C B1) at 86abe1d53d54 vs a0164c9101c1

  • vulkan-image-clear-bench (25 ABBA rounds = 50 samples/arm/size, µs):
Side Layer size base median (IQR) 462 median (IQR) Median Δ Min Δ
64 64 KiB 2.406 (2.251–2.729) 2.414 (2.265–2.835) +0.3% +0.3%
96 144 KiB 3.425 (2.516–3.910) 3.275 (2.425–3.619) -4.4% -1.4%
128 256 KiB 3.877 (3.678–4.363) 4.030 (3.630–4.358) +3.9% -1.8%
181 511.9 KiB 5.333 (5.147–5.724) 5.523 (5.171–5.735) +3.6% -1.1%
202 637.6 KiB 6.197 (6.047–6.516) 6.223 (5.784–6.353) +0.4% -9.9%
256 1 MiB 7.590 (7.562–7.845) 7.033 (7.006–7.355) -7.3% -8.1%
512 4 MiB 27.249 (27.166–27.551) 23.882 (23.778–24.092) -12.4% -23.0%
1024 16 MiB 101.247 (99.856–102.446) 96.732 (94.840–97.944) -4.5% -12.7%

Sizes <= 637.6 KiB stay below the 40-core 640 KiB floor (noise at µs scale).

  • dEQP-VK.api.image_clearing.* (45,636 cases, NIR_DEBUG=novalidate identically on both arms because base a0164c9101c1 trips NIR validation in vk-meta-copy-buffer-to-image-frag under -Db_ndebug=false): 24,418 Pass / 21,218 NotSupported / 0 Fail both arms, 0 diffs (.res sha256 3358e861a4c0e422...), 0 GPU faults / 0 new dmesg lines (1,203 before/after), 0 new failed systemd units.

J713 (M4 MacBook Air, G16G B0) at 86abe1d53d54 vs a0164c9101c1

  • vulkan-image-clear-bench (40 interleaved ABBA rounds = 80 samples/arm/size, 1,280 invocations, µs): below the 512 KiB floor flat (-0.45% to +0.09%); padded level >= 512 KiB through 16 MiB -24.00% (at 1 MiB) to -1.64% (at 16 MiB):
Side Logical layer size base median (IQR) 462 median (IQR) Median Δ Mean per-round Δ 462 faster
16 4 KiB 1.546 (1.521–1.559) 1.539 (1.512–1.559) -0.42% -0.34% 22/40
96 144 KiB 2.742 (2.709–2.759) 2.744 (2.724–2.764) +0.09% +0.20% 17/40
128 256 KiB 3.800 (3.772–3.816) 3.783 (3.754–3.809) -0.45% -0.13% 24/40
176 484 KiB (padded >= 512 KiB) 6.348 (6.296–6.378) 5.055 (5.023–5.113) -20.37% -20.21% 40/40
192 576 KiB 6.358 (6.317–6.397) 5.068 (5.047–5.110) -20.29% -20.29% 40/40
256 1 MiB 9.296 (9.273–9.330) 7.065 (6.995–7.084) -24.00% -24.26% 40/40
512 4 MiB 31.820 (31.784–31.858) 29.236 (29.165–29.403) -8.12% -8.01% 40/40
1024 16 MiB 169.116 (168.302–169.895) 166.350 (165.457–167.343) -1.64% -1.50% 38/40

144 KiB and 256 KiB stay on libagx_fill_uint4 and are flat (replacing the earlier-head c1f8d2f816dc -5% block-path speedup at 256 KiB). Side 176 (484 KiB logical image size) enters libagx_fill_uint4_blocks because the cutoff multiplies the padded tile-aligned level size by layer count (>= 512 KiB / >= 128 blocks).

  • dEQP-VK.api.image_clearing.* (45,636 cases, Vulkan CTS 7ba03cdac7ae, 2 workers): raw batch base 23,469 Pass / 22,122 NotSupported / 24 Fail / 21 Crash vs head 23,454 / 22,122 / 23 Fail / 37 Crash (85 bidirectional diffs from base a0164c9101c1's vk-meta-copy-buffer-to-image-frag / agx_compile.c:20037 NIR validation abort under -Db_ndebug=false). Solo reruns across all 95 non-Pass cases (2 passes/arm, plus 8 more on the 23 remaining cases; crash rates base 55/190 + 121/230 vs head 54/190 + 128/230) passed every case on both arms (all batch Fails passed solo) -> 0 deterministic diffs. 0 GPU faults/hangs/OOMs, 0 failed systemd units.

J313 (M1 MacBook Air, G13G B1) at 86abe1d53d54 vs a0164c9101c1

  • vulkan-image-clear-bench (40–60 samples/arm ABBA, cache off, µs):
Side Layer size base median (µs) 462 median (µs) 462/base median n / arm
64 64 KiB 5.14 5.37 1.044 40
96 144 KiB 6.70 6.70 1.000 40
112 196 KiB 8.76 8.78 1.002 40
128 256 KiB 8.76 8.78 1.002 40
160 400 KiB 11.39 11.42 1.003 40
181 511.9 KiB 14.78 14.86 1.005 60
182 517.6 KiB 14.77 / 14.73 14.82 / 14.81 1.003 / 1.005 60 / 40
192 576 KiB 14.76 14.85 1.006 40
256 1 MiB 23.10 23.02 0.997 60
362 ~2 MiB 43.15 43.34 1.004 40
512 4 MiB 70.81 / 70.58 71.56 / 71.59 1.011 / 1.014 60 / 40
1024 16 MiB 258.71 260.60 1.007 40
2048 64 MiB 1,125.14 1,013.23 0.901 60

The prior c1f8d2f816dc 144–256 KiB regression (+2.8% to +3.5%) is eliminated (1.000x–1.002x). At 64 MiB, #462 holds steady at 1,013 µs while base is bimodal (~1,030 µs in 10/60 samples, ~1,127 µs in 50/60).

  • dEQP-VK.api.image_clearing.* (45,636 cases, Vulkan CTS 1.4.6.2-4-gcbe875d1aa08, 2 workers): 19,144 Pass / 26,492 NotSupported / 0 Fail both arms, 0 diffs, 0 crashes, 0 GPU faults/OOMs, 0 failed systemd units.

Host unit tests, codegen, and drm-shim path selection at prior head c1f8d2f816dc

  • Build config (x86_64): -Doptimization=2 -Ddebug=false -Db_ndebug=false -Dbuild-tests=true -Dtools=drm-shim -Dvulkan-drivers=asahi -Dgallium-drivers= -Dplatforms=wayland
  • meson test --suite asahi: 225/225 pass (0 fail).
  • agx_tests: 1,459 pass, 1 pre-existing skip (NativeFMA.ExactDyadicOracle, 1,460 total).
  • asahi_clc binary word counts for libagx_fill_uint4_blocks (64-bit ulong -> 32-bit uint indexing):
    • g13g: 201 -> 66 uint32s (0 B preamble, zero 64-bit iadds)
    • g17p / g15s / g15g / g16g: 276 -> 80 uint32s (0 B preamble, zero 64-bit carry chains)
    • g17g: 247 -> 74 uint32s
    • g18g: 217 -> 62 uint32s

Prior head c1f8d2f816dc aarch64 & J716c (M5 Max, G17C) verification (satchlj)

  • Build config (Linux 7.3 aarch64): -Dbuildtype=debugoptimized -Db_ndebug=false -Dvulkan-drivers=asahi -Dgallium-drivers=asahi -Dbuild-tests=true -Dtools=drm-shim
  • meson test --suite asahi: 288/288 OK (0 fail); meson test --suite poly: 5/5 OK (0 fail).
  • Live J716c vulkan-image-clear-bench 16 128 256 512 1024 (interior layer 1 cleared, all 3 layers verified, 0 mismatches, 0 GPU faults in dmesg):
    • side=16 (4 KiB/layer, below floor): verified_words=3072, clear_us=9.5430
    • side=128 (256 KiB/layer, below 40-core 640 KiB floor): verified_words=196608, clear_us=13.3685
    • side=256 (1 MiB/layer, above floor -> libagx_fill_uint4_blocks): verified_words=786432, clear_us=14.4062
    • side=512 (4 MiB/layer, libagx_fill_uint4_blocks): verified_words=3145728, clear_us=31.3854
    • side=1024 (16 MiB/layer, libagx_fill_uint4_blocks): verified_words=12582912, clear_us=84.1042
  • Live J716c CTS dEQP-VK.api.image_clearing.core.clear_color_image.2d.* (290 cases): 215 Pass / 75 NotSupported / 0 Fail, 0 GPU faults in dmesg.

Paired J716c (M5 Max, G17C B1) A/B at prior head c1f8d2f816dc vs merge-base cedf24806bcb

AArch64 release cross-builds (-Doptimization=2 -Ddebug=false -Db_ndebug=false, libvulkan_asahi.so sha256 6270200a2c9f768498755ca610e1b812ee7dc0ac144c3de679ab9f73df928303 base vs c4f02b6b7d66a3c0198c7db0761a57aab289136b864d74ce3bc2db367ba07426 PR, VK_DRIVER_FILES, Linux 7.3.0, GPU firmware 27.2):

  • vulkan-image-clear-bench (same executable sha256 b915e2e36cbf5f0b7aa4ac0b6ab56b62726b6f56da60817cba327c3897aa91a2 across both ICDs, 41 interleaved rounds A B / B A, 0 readback failures):
Side Layer bytes base cedf24806bcb (µs) PR c1f8d2f816dc (µs) Delta
16 4,096 2.216 2.207 -0.42% (below 640 KiB floor)
128 262,144 1.717 1.751 +1.97% (range 1.686–2.236 vs 1.676–2.380, below floor)
192 589,824 2.415 2.422 +0.27% (below floor)
256 1,048,576 3.466 2.724 -21.41%
384 2,359,296 6.372 4.342 -31.86%
512 4,194,304 10.462 6.789 -35.11%
1024 16,777,216 30.549 20.077 -34.28%
  • dEQP-VK.api.image_clearing.* (all 45,636 mustpass cases, 6 shards): 24,418 Pass / 21,218 NotSupported / 0 Fail both arms, 0 diffs, 0 GPU-error lines, 0 AVC lines (SELinux not built).

Paired J713 (M4 Air, G16G B0) A/B at prior head c1f8d2f816dc vs merge-base cedf24806bcb

AArch64 release cross-builds (libvulkan_asahi.so sha256 629a758c222b700db61ca1767ca2a930deeab63f039bd30bf51a19161e8c923a base vs 76b39400704337b75a64a8ee6e9d7a9df57b8f64b16bf5d584061d2f4420ddae PR, VK_DRIVER_FILES, Linux 7.3.0, Vulkan CTS 1.4.6.2-4-gcbe875d1aa087da57474a0b1dea3cd6d41dc0366):

  • vulkan-image-clear-bench (same executable sha256 b915e2e36cbf5f0b7aa4ac0b6ab56b62726b6f56da60817cba327c3897aa91a2, MESA_SHADER_CACHE_DISABLE=true, 0 readback mismatches across all 120 processes; Run 1 = 20 interleaved rounds, Run 2 = 40 interleaved rounds):
    • Run 1 (20 rounds):
Side Layer bytes base median µs (IQR) PR median µs (IQR) B/A of medians median per-round B/A rounds B<A
16 4,096 8.216 (7.813–8.938) 7.851 (7.774–8.739) 0.956 0.997 12/20
96 147,456 9.243 (9.069–9.737) 9.402 (9.168–9.688) 1.017 1.018 7/20
128 262,144 10.459 (10.300–10.545) 9.952 (9.782–10.216) 0.952 0.959 15/20
256 1,048,576 16.161 (15.606–16.271) 13.350 (13.114–14.062) 0.826 0.841 18/20
512 4,194,304 38.616 (38.093–39.268) 36.582 (35.985–36.892) 0.947 0.940 19/20
1024 16,777,216 162.879 (162.678–163.797) 161.132 (160.851–161.479) 0.989 0.988 20/20
  • Run 2 (40 rounds):
Side Layer bytes base median µs (IQR) PR median µs (IQR) B/A of medians median per-round B/A rounds B<A
16 4,096 8.454 (8.120–9.032) 8.081 (8.026–8.906) 0.956 0.977 25/40
96 147,456 9.887 (9.817–9.966) 9.860 (9.753–9.951) 0.997 0.995 24/40
128 262,144 10.704 (10.562–11.250) 10.210 (10.025–10.896) 0.954 0.948 32/40
256 1,048,576 16.331 (16.188–16.818) 14.021 (13.935–14.308) 0.859 0.859 35/40
512 4,194,304 39.156 (39.041–39.368) 36.434 (36.293–36.789) 0.931 0.927 39/40
1024 16,777,216 164.195 (163.932–164.423) 161.288 (160.973–161.505) 0.982 0.981 40/40
  • dEQP-VK.api.image_clearing.* (all 45,636 mustpass cases, 6 shards, fresh per-arm shader cache): 23,514 Pass / 22,122 NotSupported / 0 Fail both arms, 0 diffs, 0 crashes (0 new kernel errors / GPU faults / OOM kills / failed units / AppArmor denials; SELinux not installed).
  • Earlier sampled dEQP-VK.api.copy_and_blit.core.image_to_image.* (stride 40, 1,318 cases, Vulkan CTS 7ba03cdac7ae): 846 Pass / 472 NotSupported / 0 Fail, identical to base (0 diffs, 0 crashes).

Paired J413 (M2 Air, G14G B0) A/B at prior head c1f8d2f816dc vs merge-base cedf24806bcb (RyanTheTide)

Native aarch64 Fedora 45 release builds (-Dbuildtype=release -Db_ndebug=false -Dvulkan-drivers=asahi, VK_DRIVER_FILES, shader cache off, Linux 7.3.0-aurora-fleet89, deqp-vk 1.4.7.1 3fd4ea318fe2, system Mesa untouched):

  • vulkan-image-clear-bench (20 interleaved alternating rounds, 0 readback mismatches):
Side Layer bytes base median (µs) PR c1f8d2f816dc (µs) Delta head faster
16 4,096 2.176 2.134 -1.9% 15/20
64 65,536 2.601 2.545 -2.2% 11/20
96 147,456 3.751 3.818 +1.8% (below 160 KiB floor) 5/20
128 262,144 5.789 5.738 -0.9% 10/20
192 589,824 10.215 10.193 -0.2% 9/20
256 1,048,576 17.042 17.351 +1.8% 10/20
512 4,194,304 55.134 55.483 +0.6% 8/20
1024 16,777,216 197.279 202.016 +2.4% 3/20
  • dEQP-VK.api.image_clearing.* (all 45,636 cases, 4 parallel processes): 19,144 Pass / 26,492 NotSupported / 0 Fail both arms, 0 diffs, 0 GPU faults/recoveries/timeouts/rejected submits, 0 AVC, 0 failed units, Enforcing.

Paired J313 (M1 Air, G13G B1) A/B at prior head c1f8d2f816dc vs merge-base cedf24806bcb

AArch64 release cross-builds (libvulkan_asahi.so sha256 cc9098300cf4ae2e6dd7ef251ca15cc15e44dcd99e79fb1e080204417accaedd base vs aabbdcc18a38636d5a7babe02ebd2d330a237a2bc49a1ab22e3db35e51a9ac49 PR, VK_DRIVER_FILES, Linux 7.3.0, Vulkan CTS 1.4.6.2-4-gcbe875d1aa087da57474a0b1dea3cd6d41dc0366):

  • vulkan-image-clear-bench (same executable sha256 b915e2e36cbf5f0b7aa4ac0b6ab56b62726b6f56da60817cba327c3897aa91a2, MESA_SHADER_CACHE_DISABLE=true, 0 readback mismatches across all 120 processes):
    • Run 1 (20 rounds):
Side Layer bytes base median µs (IQR) PR median µs (IQR) B/A of medians median per-round B/A rounds head<base
16 4,096 5.326 (5.025–5.388) 5.117 (4.850–5.431) 0.961 0.962 12/20
64 65,536 6.104 (6.042–6.122) 6.111 (5.994–6.115) 1.001 0.999 11/20
96 147,456 7.419 (7.331–7.434) 7.677 (7.591–7.688) 1.035 1.035 3/20
128 262,144 9.455 (9.419–9.488) 9.722 (9.609–9.750) 1.028 1.027 1/20
256 1,048,576 21.495 (21.421–21.737) 21.662 (21.605–21.754) 1.008 1.007 6/20
512 4,194,304 70.481 (70.333–76.897) 71.262 (71.021–76.749) 1.011 1.012 7/20
1024 16,777,216 257.546 (256.943–263.413) 258.825 (256.941–271.237) 1.005 1.001 9/20
  • Run 2 (40 rounds):
Side Layer bytes base median µs (IQR) PR median µs (IQR) B/A of medians median per-round B/A rounds head<base
16 4,096 5.202 (5.009–5.389) 5.148 (4.969–5.385) 0.990 0.998 20/40
64 65,536 6.104 (6.025–6.116) 6.102 (5.940–6.113) 1.000 0.999 22/40
96 147,456 7.422 (7.363–7.432) 7.680 (7.603–7.703) 1.035 1.035 3/40
128 262,144 9.468 (9.374–9.531) 9.734 (9.661–9.800) 1.028 1.029 4/40
256 1,048,576 21.548 (21.434–21.712) 21.627 (21.470–21.707) 1.004 1.003 16/40
512 4,194,304 70.354 (70.257–71.807) 71.519 (71.197–71.905) 1.017 1.012 12/40
1024 16,777,216 257.135 (256.602–258.535) 257.225 (256.780–260.203) 1.000 1.002 17/40
  • dEQP-VK.api.image_clearing.* (all 45,636 mustpass cases, 6 shards, fresh per-arm shader cache): 19,144 Pass / 26,492 NotSupported / 0 Fail both arms, 0 diffs, 0 new kernel error lines, 0 GPU fault/recovery/OOM/AppArmor denials (SELinux not installed). Side 1024 clears 16 MiB in ~257 µs (~65 GB/s, bandwidth-bound on M1), while sides 96 and 128 (first two sizes on the block path) paid a consistent +0.26 µs overhead under the prior 128 KiB floor.

Prior-head hardware runs (superseded by c1f8d2f816dc, kept for reference)

  • A18 Pro (G17P B1, MacBook Neo) at 43ac3c8a326a vs afcc08b7106, Linux 7.3.0-41.fc44.aurora.aarch64, 8 alternating rounds of vulkan-image-clear-bench (MESA_SHADER_CACHE_DISABLE=true, all words verified), 0 GPU faults / 0 AVC denials: -2.14% at 256 KiB, -3.26% at 400 KiB, -4.65% at 484 KiB, -6.05% at 576 KiB, -3.06% at 1 MiB, -0.89% at 2.25 MiB, -0.47% at 4 MiB, -0.20% at 16 MiB. dEQP-VK.api.image_clearing.*: 23,514 Pass, 22,122 NotSupported, 0 Fail, 0 diffs vs base.
  • M4 (G16G) at 43ac3c8a326a: dEQP-VK.api.image_clearing.* (45,636 cases, 1,274 on the new path): same results as base; 4 MiB/layer clear 3.7% faster, 16 MiB/layer unchanged.
  • M2 (G14G, MacBook Air J413) on main bc937edc540 + 43ac3c8a overlay (with the prior ulong kernel): dEQP-VK.api.image_clearing.*: 18,842 Pass, 26,794 NotSupported, 0 Fail, 0 diffs vs base; vulkan-image-clear-bench (n=16 rounds) regressed near 256 KiB (+14.4% all-round median, +14.8% slow-mode 9.04–9.31 vs 10.35–10.65 µs), which prompted the 32-bit indexing fix in c1f8d2f816dc.
  • M5 Max (G17C) at 43ac3c8a326a vs afcc08b71067 (previous transfer-only benchmark revision; 3-layer image is uncompressed on M5): 4 KiB (below cutoff) 2.58 -> 2.30 µs (n=4); 256 KiB 1.96/2.78 -> 2.04/2.74 µs (+3.8%/-1.6%, n=4+8); 400 KiB 2.42 -> 2.43 µs (+0.4%, n=8); 576 KiB 3.00 -> 2.84 µs (-5.6%, n=8); 1 MiB 4.51 -> 3.88 µs (-13.9%, n=8); 2.25 MiB 8.77 -> 6.94 µs (-20.8%, n=8); 4 MiB 14.76 -> 11.22 µs (-23.9%, n=4); 16 MiB 44.84 -> 37.45 µs (-16.5%, n=4).
  • Short Cyberpunk 2077 2.5 replay on M5 Max (J716c, 128 GB) on an earlier G17C-only head (3840×2160 High, FSR2 Balanced, 22 frames with GFXReconstruct 1.0.5-dev ccbbb1c, borealis: expose single-texel buffer offsets on every M5 part #450/agx: respect destination register limits when coalescing AGX3C splits #451/agx: apply single-sample coverage before in-tile MRT stores #452 on 57df4db849a in both arms): Replay FPS 12.029 -> 12.067 (+0.31%), Vertex 4.388 -> 4.391 ms/frame, Fragment 12.711 -> 12.700 ms/frame, Compute 25.281 -> 25.218 ms/frame.

@RyanTheTide

Copy link
Copy Markdown

Thanks for the clear kernel.

We select behaviour by a hardware property rather than by the chip a change was measured on. The block fill is used on one chip:

  • src/asahi/vulkan/hk_cmd_clear.c:162 } else if (hk_cmd_buffer_device(cmd)->dev.chip == AGX_CHIP_G17C &&

Amortizing address generation over eight adjacent 16-byte stores is generic, so libagx_fill_uint4_blocks should help, or at least not hurt, any GPU that runs these clears. Could it be the path for every chip when size % 4096 == 0, with a code comment naming the hardware reason for any generation that must keep the old fill? The +0.3 % in the short replay is within the run-to-run spread, so an isolated clear benchmark would also show the effect better.

If you make it the default, we can supply rows on our M1 Pro, M2, M4 Pro and A18 Pro.

@erikwb

erikwb commented Nov 19, 2026 •

Copy link
Copy Markdown
Author

The isolated GPU test shows a gain for large uncompressed clears. Median time per 4 MiB layer fell from 14.72 to 11.23 µs (24%) and per 16 MiB layer from 44.38 to 37.09 µs (16%). Both sizes improved in every round. At 4 KiB the median went from 2.39 to 2.55 µs, with overlapping ranges.

We used two blocks of full Cyberpunk T2 runs in opposite orders on the M5 Max, native 2560×1600 High, with the fans fixed. The control was Mesa e59727e7a4fc with #460, #461, #466 and #468 removed. Each delta uses the mean of two control runs in its block. For this PR we also built the control without #462 to isolate its effect.

We alternated drivers for four rounds each, timed 32 clears per size after eight warmups, and checked every pixel in the target and both untouched array layers. The individual full-game T2 deltas were +0.11 and −0.21 FPS. Batching adjacent stores earns its keep on large fills here. The results leave the size cutoff and behavior on other chips open.

In the separate eight-run test, #460, #461, #466 and #468 together gained 1.35 FPS (29.99 to 31.33). #462 was present on both sides of that comparison.

@RyanTheTide

Copy link
Copy Markdown

Thanks for the isolated clear benchmark; 24 % and 16 % per-layer gains on large clears, with every pixel checked, is a convincing result.

The remaining point is scope: hk_cmd_clear.c:162 still selects the block fill by AGX_CHIP_G17C. Amortizing address generation over adjacent stores is not specific to one GPU, so could it be the path on every chip for large, 4 KiB-aligned uncompressed clears, perhaps with a size cutoff given your 4 KiB result? If a generation has a hardware reason to keep the old fill, a code comment naming it is enough. We can run your benchmark on our M1 Pro, M2, M4 Pro and A18 Pro if you share it.

@DjDeveloperr

Copy link
Copy Markdown

Merge train: independent review (code only, Opus 5.5 xhigh)

Verdict: CLEAN WITH NITS. No blocker or major. The block fill writes exactly the same bytes as before.

  • Reach: behaviour changes on G17C only. The new libagx kernel also ships in the shared g17g library that G17G/G17S load, but it is never dispatched there.
  • Widening: to G17G/G17S, safe as written. To G15, G16, G17P or G18G, it first needs the kernel qualified in asahi_clc.c; otherwise those chips get no kernel and the clear is silently dropped.
  • NIT: the 4 KiB cutoff showed no gain in your own benchmark (2.39 -> 2.55 µs median at 4 KiB); a higher cutoff may be better.

Train: held only on the open property-gate request (owner decision pending).

@RyanTheTide RyanTheTide changed the title hk: batch adjacent stores in G17C image clears borealis: batch adjacent stores in G17C image clears Nov 20, 2026
@erikwb
erikwb force-pushed the j716c/t2-tile-clear branch from 0c9338f to d1b398c Compare November 21, 2026 00:09
@erikwb erikwb changed the title borealis: batch adjacent stores in G17C image clears borealis: batch adjacent stores in large image clears Nov 21, 2026
@erikwb

erikwb commented Nov 21, 2026 •

Copy link
Copy Markdown
Author

The block fill is now the path on every chip for uncompressed clears of at least 256 KiB per layer whose size is a multiple of 4 KiB (72360cd).

  • @DjDeveloperr: libagx_fill_uint4_blocks is now built for every libagx target, so no chip is left without the kernel.
  • The cutoff moved from 4 KiB to 256 KiB, because 4 KiB showed no gain (2.39 to 2.55 µs median, overlapping ranges).
  • M4 (G16G): dEQP-VK api.image_clearing.* (45,636 cases, 1,274 on the new path) gives the same results as the base. A 4 MiB-per-layer clear is 3.7% faster and 16 MiB is unchanged, with every word checked.
  • Not tested on AGX2, G15, G17P or G18G. The benchmark is a small standalone Vulkan program that times 32 clears per size and checks every pixel. I can add it to the PR if you want to run it on your M1 Pro, M2, M4 Pro and A18 Pro.

@erikwb
erikwb force-pushed the j716c/t2-tile-clear branch from d1b398c to 72360cd Compare November 21, 2026 00:13

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

No blockers. Re-review of 72360cd: the block fill is now used on every chip with a 256 KiB cutoff, and the kernel is built for every libagx target, so no chip is left with a NULL program. Both earlier points are resolved. The indexing is right: a 32-lane group covers 256 uint4 (4 KiB), and the grid is size / 128 threads.

The only gap is evidence on the chips this newly reaches. Please add the benchmark to the PR (or link it) and we will run it.

HW rows we can run: M1 Pro, M2, J616s (M4 Pro) and A18 Pro: dEQP-VK.api.image_clearing.*, base vs head, no new failures; plus your clear benchmark at 4 KiB, 256 KiB, 4 MiB and 16 MiB per layer, every word checked. Pass = identical CTS results and no size at or above the cutoff slower than the base.

Nit: the body says 4 KiB clears were "no faster" and the commit message says "slower". Pick one wording.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown

Looks good; approve once the attribution and naming below are fixed and the cross-generation rows from the earlier review are in.

  1. Commit 72360cd has "Developed with Claude Code." in its message. A commit should carry only the human author and the Signed-off-by. Please drop that line from the commit and end the PR body with Assisted-by: LLM (<Vendor>:<Model>). The body has no such line today.
  2. The PR body (replay section) names the Vulkan driver by its old upstream name. It is Borealis here; please reword that line.

I re-checked the kernel and the dispatch at head. agx_2d(size / 128, layer_count) with KERNEL(32) gives size / 4096 groups per layer, and each group writes 256 uint4 at group * 256 + lane + 32 * i (src/asahi/libagx/copy.cl:309-317). The writes don't overlap and leave no gap. size % 4096 == 0 keeps the grid an exact multiple of the group (src/asahi/vulkan/hk_cmd_clear.c:169-172). The kernel is now built for every libagx target (src/asahi/clc/asahi_clc.c:359), so no chip can reach a NULL program. I found no correctness issue.

The 256 KiB cutoff (hk_cmd_clear.c:29) was measured on G17C and G16G only. Gen-1 (G13/G14) has a different number of cores per cluster and different store paths, so the AGX2 rows are the ones that could move it.

HW row: M1 Pro (G13), M2 (G14) and A18 Pro (G17P) on head 72360cd. Run dEQP-VK.api.image_clearing.*, base vs head: identical results. Run the clear benchmark at 4 KiB, 256 KiB, 4 MiB and 16 MiB per layer with every word checked: no size at or above 256 KiB slower than the base. Regression: 0 GPU faults and no new kernel errors.

Assisted-by: LLM (Claude:Opus 5.5)

Uncompressed image clears launch libagx_fill_uint4, one 16-byte store per
invocation, so every store pays its own address generation. Add
libagx_fill_uint4_blocks, where each 32-lane group fills a 4 KiB block in
eight rounds of adjacent stores and shares the address generation across
them, and build it for every libagx target.

Use it on every chip for uncompressed levels of at least 256 KiB per
layer whose size is a multiple of 4 KiB. The block fill launches an
eighth of the groups, so small clears keep the per-store fill: at 4 KiB
per layer the block fill showed no gain (median 2.55 us against 2.39 us,
with overlapping ranges); from 256 KiB to 400 KiB it came out even,
and larger clears were faster.
Partial blocks and compressed levels keep their existing paths.

vulkan-image-clear-bench (built with the other manual Vulkan tests)
times clears of one layer at 4 KiB to 16 MiB and checks every word of
the image afterwards. Its image has storage usage, which keeps it
uncompressed on every generation, so the clears take the fill paths
rather than a metadata clear.

Signed-off-by: Erik Bourget <erik@ebourget.net>
@erikwb
erikwb force-pushed the j716c/t2-tile-clear branch from 72360cd to 43ac3c8 Compare November 21, 2026 17:18
@erikwb

erikwb commented Nov 21, 2026 •

Copy link
Copy Markdown
Author

The benchmark is in the PR (43ac3c8), and the 4 KiB wording now matches in the commit message, the code comment and the body: the block fill showed no gain there (median 2.55 µs against 2.39 µs, overlapping ranges).

Benchmark. src/asahi/vulkan/tests/vulkan_image_clear_bench.c builds as vulkan-image-clear-bench with the other manual Vulkan tests (-Dbuild-tests=true), outside meson test. It needs only the Vulkan loader, so cc -O2 -o vulkan-image-clear-bench vulkan_image_clear_bench.c -lvulkan works on its own too.

Per side S on the command line (default 16 128 512 1024, which is 4 KiB, 256 KiB, 4 MiB and 16 MiB per layer), it:

  • creates a 3-layer R32G32B32A32_UINT optimal-tiling image with transfer and storage usage,
  • clears all three layers, then layer 1 eight times as warm-up and 32 times between GPU timestamps,
  • reads all three layers back and checks every word,
  • prints clear_us per size, and exits non-zero on a mismatch.

For an A/B, run one process per sample with VK_DRIVER_FILES naming each driver in turn, alternate which goes first each round, and compare the medians.

Please use this revision on the M1 Pro and M2. AGX2 compresses a transfer-only image of this format, and a compressed level takes the metadata clear, not either fill. Storage usage keeps the image uncompressed on every generation. I checked which clear runs under drm-shim, breaking on the libagx dispatch at 4 KiB, 256 KiB, 400 KiB, 576 KiB, 4 MiB and 16 MiB per layer:

  • with this revision, 4 KiB runs libagx_fill_uint4 and every size from 256 KiB runs libagx_fill_uint4_blocks, on the G13G, G14G, G15G, G16G, G17P, G17S and G18G identities;
  • the transfer-only image ran the metadata clear at every size on G13G and G14G, and the same fills as above on the others.

M5 Max rows, base afcc08b71067, median µs per clear, every word checked. They were measured with the transfer-only image, which is uncompressed on M5 too (M5 compresses colour images only with one layer), so the image layout and clear path match this revision:

Per layer Rounds Base This PR Change
256 KiB 4 + 8 1.96 / 2.78 2.04 / 2.74 +3.8% / -1.6%
400 KiB 8 2.42 2.43 +0.4%
576 KiB 8 3.00 2.84 -5.6%
1 MiB 8 4.51 3.88 -13.9%
2.25 MiB 8 8.77 6.94 -20.8%
4 MiB 4 14.76 11.22 -23.9%
16 MiB 4 44.84 37.45 -16.5%

From 576 KiB up, every run with this PR beats every base run. At 256 KiB and 400 KiB the two come out even within noise; the two 256 KiB sets disagree in sign. That is close to your pass line at the cutoff. If your M1 Pro, M2, J616s or A18 Pro rows show 256 KiB slower, I'll raise the cutoff to 512 KiB.

@erikwb
erikwb marked this pull request as draft November 21, 2026 17:18
@RyanTheTide

Copy link
Copy Markdown

Thanks, both points are fixed: the commit carries only your Signed-off-by, the body ends with Assisted-by, and the driver is named Borealis. The benchmark is a good addition, and the note that AGX2 needs storage usage to keep the image off the metadata clear would otherwise have spoiled our rows.

We will run vulkan-image-clear-bench (one process per sample, alternating order) on 43ac3c8 against the base on our M1 Pro, M2 and A18 Pro, plus dEQP-VK.api.image_clearing.*, and post the medians here. If 256 KiB comes out slower on any of them, raising the cutoff to 512 KiB as you propose is fine. Please take it out of draft when you consider it done.

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr

Copy link
Copy Markdown

A18 Pro (G17P B1, MacBook Neo, Linux 7.3.0-41.fc44.aurora.aarch64, sleep_guard=active, pmu=30 00) rows at exact PR head 43ac3c8a326a against base afcc08b7106:

  • Base libvulkan_asahi.so SHA-256: eb94cdeda8fdb2d86dbf4fd5ec7f321c0a423910879fa3adce068394ab098eb9
  • Head libvulkan_asahi.so SHA-256: 172d37582311f4a3def06396a4ae11661d759ea6879b3c07e62e44b592cc48c8

vulkan-image-clear-bench (8 alternating rounds, one process per sample, MESA_SHADER_CACHE_DISABLE=true, all readback words verified):

Side Per layer Rounds Base median (µs) PR 43ac3c8a median (µs) Change
16 4 KiB 8 7.678 8.062 +5.00% (noise; both < 256 KiB per-store path, means 7.856 vs 7.842 µs)
128 256 KiB 8 7.227 7.072 -2.14%
144 324 KiB 8 8.366 8.344 -0.26%
160 400 KiB 8 7.674 7.424 -3.26%
176 484 KiB 8 8.312 7.925 -4.65%
192 576 KiB 8 8.387 7.879 -6.05%
256 1 MiB 8 16.126 15.633 -3.06%
384 2.25 MiB 8 36.803 36.476 -0.89%
512 4 MiB 8 62.398 62.104 -0.47%
1024 16 MiB 8 133.718 133.444 -0.20%

On A18 Pro (G17P), every size from 256 KiB through 16 MiB is faster (or even within noise at 324 KiB / 16 MiB) — never slower at 256 KiB (-2.14%), peaking at -6.05% at 576 KiB. From the G17P side, the 256 KiB cutoff is good as-is and does not need to be raised to 512 KiB.

CTS (dEQP-VK.api.image_clearing.*, 45,636 cases):

Build Pass NotSupported Fail Diffs vs base GPU faults (kfault_delta / avc_delta)
Base afcc08b7106 23,514 22,122 0 — 0 / 0
Head 43ac3c8a326a 23,514 22,122 0 0 0 / 0

Assisted-by: LLM (Antigravity:Gemini 4 Neon)

@erikwb
erikwb marked this pull request as ready for review November 22, 2026 07:42
@erikwb

erikwb commented Nov 22, 2026 •

Copy link
Copy Markdown
Author

Marked ready for review — keeping the 256 KiB cutoff as-is pending the M1 Pro / M2 (AGX2) rows.

On A18 Pro (G17P) at 43ac3c8a326a, every size from 256 KiB through 16 MiB is faster (-2.14% at 256 KiB, peaking at -6.05% at 576 KiB) with 0 diffs across all 45,636 dEQP-VK.api.image_clearing.* cases and 0 GPU faults. Added the A18 Pro results to the PR description.

@RyanTheTide

Copy link
Copy Markdown

AGX2 row (M2 MacBook Air J413, G14G, fleet82 kernel, user-space Mesa overlays, base = main bc937ed, head = main + this PR 43ac3c8).

CTS: dEQP-VK.api.image_clearing.*: base and head both 18842 Pass / 26794 NotSupported, 0 status differences.

Perf: slower on AGX2 near the crossover. vulkan-image-clear-bench, 16 alternating base/head rounds. The bench is bimodal per process, so I split the rounds by mode:

layer slow mode: base -> head (us, median) delta fast mode delta
256 KiB 9.15 -> 10.51 +14.8 % +4.2 %
400 KiB 11.71 -> 13.32 +13.8 % +3.8 %
576 KiB 15.09 -> 16.38 +8.5 % +2.8 %
1 MiB 23.52 -> 25.08 +6.6 % -0.4 %
2.25 MiB 47.08 -> 48.13 +2.2 % -0.7 %
16 MiB 204.62 -> 206.13 +0.7 % +1.3 %

In slow mode the min-max ranges do not overlap (256 KiB: base 9.04-9.31, head 10.35-10.65). So the 256 KiB crossover that was measured on G17P makes clears from 256 KiB to about 1-2 MiB slower on G14G. Correctness is fine on AGX2. The threshold would need to come from something the device reports, or be set where the batched path is not slower on every generation we test, before this can land as a fleet-wide win.

Full table and method
| per layer | all: base | all: head | all Δ | fast-mode: base | fast: head | fast Δ | slow-mode: base | slow: head | slow Δ |
|---|---|---|---|---|---|---|---|---|---|
| 4 KiB | 3.55 [1.79-4.53] n=16 | 3.56 [2.11-5.12] n=16 | +0.5% | 2.11 [1.79-3.00] n=6 | 2.26 [2.11-2.52] n=7 | +7.1% | 3.59 [3.54-4.53] n=10 | 3.66 [3.56-5.12] n=9 | +2.1% |
| 256 KiB | 9.06 [5.58-9.31] n=16 | 10.36 [6.04-10.65] n=16 | +14.4% | 5.94 [5.58-6.51] n=6 | 6.19 [6.04-7.06] n=7 | +4.2% | 9.15 [9.04-9.31] n=10 | 10.51 [10.35-10.65] n=9 | +14.8% |
| 400 KiB | 11.67 [7.44-11.98] n=16 | 13.12 [8.05-13.48] n=16 | +12.4% | 7.92 [7.44-8.68] n=6 | 8.22 [8.05-9.32] n=7 | +3.8% | 11.71 [11.62-11.98] n=10 | 13.32 [13.11-13.48] n=9 | +13.8% |
| 484 KiB | 14.91 [9.99-15.26] n=16 | 16.27 [10.36-16.63] n=16 | +9.1% | 10.35 [9.99-11.88] n=6 | 10.63 [10.36-11.83] n=7 | +2.8% | 15.06 [14.87-15.26] n=10 | 16.44 [16.22-16.63] n=9 | +9.1% |
| 576 KiB | 14.95 [10.00-15.34] n=16 | 16.31 [10.39-16.71] n=16 | +9.1% | 10.33 [10.00-11.85] n=6 | 10.62 [10.39-11.82] n=7 | +2.8% | 15.09 [14.81-15.34] n=10 | 16.38 [16.30-16.71] n=9 | +8.5% |
| 1024 KiB | 23.35 [16.11-26.86] n=16 | 24.94 [16.59-28.29] n=16 | +6.8% | 17.03 [16.11-18.72] n=6 | 16.96 [16.59-19.64] n=7 | -0.4% | 23.52 [23.17-26.86] n=10 | 25.08 [24.89-28.29] n=9 | +6.6% |
| 2304 KiB | 46.49 [32.93-47.75] n=16 | 46.32 [33.23-49.61] n=16 | -0.4% | 35.65 [32.93-37.66] n=6 | 35.41 [33.23-35.80] n=7 | -0.7% | 47.08 [44.13-47.75] n=10 | 48.13 [46.26-49.61] n=9 | +2.2% |
| 4096 KiB | 66.95 [53.98-68.17] n=16 | 67.91 [54.33-69.84] n=16 | +1.4% | 56.07 [53.98-58.15] n=6 | 55.98 [54.33-58.86] n=7 | -0.2% | 67.46 [65.32-68.17] n=10 | 69.22 [67.88-69.84] n=9 | +2.6% |
| 16384 KiB | 202.86 [196.03-209.85] n=16 | 205.37 [200.76-211.82] n=16 | +1.2% | 198.99 [196.03-206.44] n=6 | 201.60 [200.76-209.14] n=7 | +1.3% | 204.62 [198.36-209.85] n=10 | 206.13 [204.18-211.82] n=9 | +0.7% |
{('base', 'slow'): 10, ('h462', 'fast'): 7, ('h462', 'slow'): 9, ('base', 'fast'): 6}

Overlays: x86 cross builds, VK_DRIVER_FILES per arm, deqp-vk J=8, no reboot, no install.

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

Review at 43ac3c8. Please exercise exact-head G14G image readback for an interior array layer and verify its untouched neighbors. The small/large fill split also needs paired GPU timing on both sides of the cutoff. The shim confirms path selection, while hardware verifies the writes.

On AGX2 (M2 G14G), vulkan-image-clear-bench (main bc937ed +
43ac3c8) showed slower slow-mode clears with libagx_fill_uint4_blocks
across 256 KiB to 16 MiB (+14.8% at 256 KiB, +0.7% at 16 MiB; all-round
n=16 medians +14.4% at 256 KiB, +6.8% at 1 MiB, -0.4% at 2.25 MiB, +1.2%
at 16 MiB), whereas tested AGX3 parts (G16G, G17P, G17C) are faster or
even from 256 KiB upward.

Gate libagx_fill_uint4_blocks directly on the kernel-reported
dev.params.usc_generation == AGX_ISA_AGX3 so AGX2 keeps libagx_fill_uint4.

Signed-off-by: Erik Bourget <erik@ebourget.net>

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

Formal §1–§6 pre-PR checklist review at live head 43ac3c8a326a (base: aurora-wip, 223 commits behind efabab38502d; not superseded; aurora-silicon/mesa Actions disabled / 0 check runs).

Technical & Checklist Summary

  • Kernel & dispatch correctness: libagx_fill_uint4_blocks (src/asahi/libagx/copy.cl:309-317) and dispatch (src/asahi/vulkan/hk_cmd_clear.c:170-173) are sound: KERNEL(32) with agx_2d(size / 128, layer_count) and size % 4096 == 0 yields size / 4096 groups covering 256 * uint4 (4 KiB) each with 64-bit ulong byte indexing, no overlap/gaps, and built for all libagx targets in src/asahi/clc/asahi_clc.c:359.
  • §1 (No model gating): No chip gate; applies globally across all generations.
  • §3 (Safety): Pass (N/A).
  • §4 (Clean-room & attribution): Pass — commit 43ac3c8a326a carries human author/committer and human Signed-off-by: only (zero AI trailers); PR body has Assisted-by:.
  • §6 (Naming): Pass — Borealis naming and neutral vulkan-image-clear-bench target.

Blockers

  1. §5 / §2 — Measured AGX2 (G14G M2) performance regression with hardcoded 256 KiB cutoff:
    HK_CLEAR_BLOCK_FILL_MIN_B (256 * 1024) (hk_cmd_clear.c:30) is a hardcoded threshold tuned on G17C/G17P/G16G. On M2 (J413 / G14G / AGX2, 16 alternating rounds of vulkan-image-clear-bench at 43ac3c8a), the batched path is slower across the cutoff and beyond, with non-overlapping slow-mode ranges:
    • 256 KiB: +14.8% slow mode (9.04–9.31 vs 10.35–10.65 µs), +4.2% fast mode
    • 400 KiB: +13.8% slow, +3.8% fast
    • 484–576 KiB: +8.5% to +9.1% slow, +2.8% fast
    • 1 MiB: +6.6% slow (-0.4% fast); 2.25–16 MiB: +0.7% to +2.6% slow (+1.3% fast at 16 MiB)
      Under §5 ("Performance claims: a same-machine A/B with conformance unchanged on every GPU generation the change applies to"), a fleet-wide change cannot land with a confirmed regression on AGX2. Either derive enablement/cutoff from a real hardware property (e.g., ISA/store capability or core/cluster occupancy, with documented hardware rationale per §1) or rework the threshold/kernel so no affected generation regresses.
  2. §5 — Stale PR body & remaining cross-generation rows:
    Update the PR description to reflect the M2 (G14G) measurements (it still lists M2 as unrun in Still to run and states no regression from 256 KiB up), and complete the requested exact-head verification rows (M1 Pro / M2 readback + paired timing across the cutoff, M4 Pro) after updating the cutoff/gating and rebasing onto current aurora-wip.

Assisted-by: LLM (Gemini 4 Neon)

@erikwb

erikwb commented Nov 23, 2026 •

Copy link
Copy Markdown
Author

Gated libagx_fill_uint4_blocks in src/asahi/vulkan/hk_cmd_clear.c directly on dev.params.usc_generation == AGX_ISA_AGX3 (61459d5e73f4), keeping AGX2 (usc_generation == 2) on libagx_fill_uint4 while leaving the AGX3 kernel and dispatch unchanged.

  • AGX2 (G14G) regression: Your M2 (G14G) run (user-space Mesa overlay of 43ac3c8a onto main bc937edc540 against main bc937edc540) passed all 18,842 dEQP-VK.api.image_clearing.* cases with 0 diffs, and on vulkan-image-clear-bench (n=16 rounds) the largest slowdown was near the 256 KiB cutoff (+14.4% all-round median; +14.8% in the slow-mode n=10/9 split with non-overlapping ranges 9.04–9.31 vs 10.35–10.65 µs). Across the full size sweep, all-round n=16 medians included a -0.4% improvement at 2.25 MiB (+14.4% at 256 KiB, +6.8% at 1 MiB, +1.4% at 4 MiB, +1.2% at 16 MiB); in the bimodal splits, slow-mode (n=10/9) was slower across 256 KiB–16 MiB (+14.8% down to +0.7%), while fast-mode (n=6/7) was slower near the cutoff (+4.2% at 256 KiB, +3.8% at 400 KiB, +2.8% at 484–576 KiB) and flat at 1–4 MiB (-0.4% at 1 MiB, -0.7% at 2.25 MiB, -0.2% at 4 MiB; +1.3% at 16 MiB). Raising the byte cutoff alone would still leave slow-mode (+2.6% at 4 MiB, +0.7% at 16 MiB) and all-round 4–16 MiB medians (+1.4%, +1.2%) slower on G14G while dropping the G17P and G17C wins (-2.14% to -6.05% on A18 Pro; -5.6% to -23.9% on M5 Max), so hk_clear_image() now selects libagx_fill_uint4_blocks directly from the kernel-reported dev.params.usc_generation == AGX_ISA_AGX3.
  • Provisional hypothesis (copy.cl, unverified): Inspection of asahi_clc output shows libagx_fill_uint4_blocks declares ulong base (unlike libagx_fill_uint4's 32-bit uint offs), which prevents agx_nir_lower_address from folding + 32 * i into u2u64 base+index addressing (g13g emits a 226-byte preamble and 7 64-bit iadds, 201 uint32s vs 33 for libagx_fill_uint4; g17p/g17g emit 64-bit carry chains instead of byte_offset). This explanation remains provisional until a controlled comparison establishes whether that address lowering causes the G14G slowdown. Leaving copy.cl unchanged here preserves the exact AGX3 kernel binary already measured on A18 Pro, M4, and M5 Max; switching base to uint is a clean follow-up to test against G14G or AGX3.
  • Pending G14G verification on 61459d5e73f4: Your earlier G14G run used a main bc937edc540 + 43ac3c8a user-space overlay and exercised the old libagx_fill_uint4_blocks dispatch. With 61459d5e73f4, G14G stays on libagx_fill_uint4; paired G14G timing and three-layer readback on 61459d5e73f4 remain pending (holding merge until G14G hardware verifies the new dispatch), and 61459d5e73f4 currently has host drm-shim path-selection evidence only for AGX2.
  • Verification on 61459d5e73f4 (x86_64 host): meson test --suite asahi passed 159/159, agx_tests passed 1,205/1,206 (NativeFMA.ExactDyadicOracle pre-existing skip), and drm-shim (vulkan-image-clear-bench under gdb breaking on agx_get_precompiled) confirmed G13G/G14G dispatch libagx_fill_uint4 at both 4 KiB and 256 KiB while G15G/G16G/G17P/G17S dispatch libagx_fill_uint4 at 4 KiB and libagx_fill_uint4_blocks at 256 KiB.

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

Formal §1–§6 pre-PR re-review at live head 61459d5e73f4 (base aurora-wip; the branch is still 230 commits behind, merge base afcc08b71067; previous Dj review at 43ac3c8a326a).

What changed since 43ac3c8a326a

One new commit, 61459d5e73f4 "borealis: restrict block-fill image clears to AGX3". It adds dev.params.usc_generation == AGX_ISA_AGX3 to the libagx_fill_uint4_blocks branch in hk_clear_image() and extends the comment above HK_CLEAR_BLOCK_FILL_MIN_B. There is no rebase and copy.cl is unchanged.

Cleared

  • AGX2 regression (measured): AGX2 no longer takes the block fill, so @RyanTheTide's G14G slowdown (+14.8% at 256 KiB slow mode, non-overlapping ranges) cannot occur on this head. Correctness is unchanged; the kernel and its indexing were already LGTM.
  • §4: Pass. Both commits have a human author/committer and a human Signed-off-by: only; zero AI trailers.

Blockers (REQUEST_CHANGES)

  1. §1: the new generation gate is avoidable, and the PR itself names the likely cause. usc_generation == AGX_ISA_AGX3 is a GPU-generation gate chosen because one generation measured slower. It is not a property that explains why. Your own hypothesis in the 11-23 comment points at the kernel: libagx_fill_uint4_blocks computes ulong base, which stops agx_nir_lower_address from folding + 32 * i into base+index addressing. On G13G that costs a 226-byte preamble and seven 64-bit iadds (201 vs 33 uint32s); on G17P/G17G it costs 64-bit carry chains instead of byte_offset. That is a codegen defect on every generation, and it is the cheaper fix. Please:
    • index with a 32-bit uint offset, as libagx_fill_uint4 does (layer stride × layer plus block offset fits in 32 bits for the uint4 units used here, or split the layer term out the way the existing kernel does);
    • check the asahi_clc output on G13G and G17P, where the 64-bit adds should go;
    • re-run the G14G sweep. If AGX2 is then even or faster at and above the cutoff, drop the gate. If it is still slower, the commit message has to say why AGX2 is slower with folded addressing, using a hardware property (for example per-store issue or the core count), and the gate should test that property, not the generation.
  2. §2: HK_CLEAR_BLOCK_FILL_MIN_B (256 * 1024) is still a tuned cutoff. The code comment says the cutoff exists because the block fill launches 1/8 of the groups, which makes it a parallelism floor. Derive it from what the device reports (for example enough 4 KiB blocks to give every core N groups, from the core count in dev.params), or show the same 256 KiB holds on every generation the path runs on. After blocker 1, that includes AGX2.
  3. Commit hygiene. Commit 1 says "Use it on every chip" and commit 2 contradicts it. Please squash them into one commit whose message describes the final behaviour and evidence. Rebase onto current aurora-wip while you're at it: the branch is 230 commits behind.
  4. §5: exact-head rows. These are still open from the previous round: G14G readback of an interior array layer with its neighbours untouched, plus paired timing on both sides of the cutoff, on the final head. After blocker 1, add a G17C or G17P sweep showing the 32-bit-offset kernel keeps the AGX3 wins (−2.1% to −6.1% on A18 Pro, −5.6% to −23.9% on M5 Max).

Checklist

  • §1: Blocked (1).
  • §2: Blocked (2).
  • §3: N/A.
  • §4: Pass.
  • §5: Blocked (4).
  • §6: Pass. borealis: subject, neutral vulkan-image-clear-bench.

Assisted-by: LLM (Claude Opus 5.5)

Signed-off-by: Erik Bourget <erik@ebourget.net>
… core count

libagx_fill_uint4_blocks declared a 64-bit ulong base offset, which prevented agx_nir_lower_address from keeping the offset calculation in 32-bit registers and forced a 140-byte preamble plus seven 64-bit iadd chains on AGX2 (201 uint32s on g13g) and 16-bit carry chains on AGX3 (276 uint32s on g17p, 247 on g17g, 217 on g18g). Match libagx_fill_uint4 by computing the uint4 index in 32-bit uint arithmetic; this eliminates the preamble and 64-bit adds across all targets (66 uint32s on g13g, 80 on g17p/g15s/g15g/g16g, 74 on g17g, 62 on g18g).

Drop the AGX_ISA_AGX3 generation gate in hk_clear_image() and replace the fixed 256 KiB cutoff with a parallelism floor derived from agx_get_num_cores(): require at least four 4 KiB blocks per GPU core across the cleared layers ((size / 4096) * layer_count >= 4 * num_cores).

Signed-off-by: Erik Bourget <erik@ebourget.net>
@erikwb
erikwb requested review from a team as code owners November 24, 2026 21:28
@erikwb
erikwb requested a review from Acelogic November 24, 2026 21:28
@erikwb

erikwb commented Nov 24, 2026 •

Copy link
Copy Markdown
Author

Updated the branch to c1f8d2f816dc (merged origin/aurora-wip cedf24806bcb in 523f52be9f12 and added c1f8d2f816dc on top) to address the codegen, gate, and threshold findings:

  1. 32-bit uint offset in libagx_fill_uint4_blocks (src/asahi/libagx/copy.cl:431-434): Replaced ulong base with uint base = cl_global_id.y * layer_stride_uint4 + cl_group_id.x * 256 + cl_local_id.x;, matching libagx_fill_uint4. Inspecting asahi_clc output confirms the 140-byte preamble and seven 64-bit iadds on g13g and the 16-bit split carry chains on g17p/g17g/g18g are gone (0-byte preamble across all targets; binary word counts dropped 201 -> 66 on g13g, 276 -> 80 on g17p/g15s/g15g/g16g, 247 -> 74 on g17g, and 217 -> 62 on g18g).
  2. Removed the AGX_ISA_AGX3 gate and derived the parallelism floor from agx_get_num_cores() (src/asahi/vulkan/hk_cmd_clear.c:29,143-179): Dropped dev.params.usc_generation == AGX_ISA_AGX3 and replaced HK_CLEAR_BLOCK_FILL_MIN_B with HK_CLEAR_BLOCK_FILL_GROUPS_PER_CORE (4), requiring (uint64_t)(size / 4096) * layer_count >= 4 * MAX2(1u, agx_get_num_cores(&hk_cmd_buffer_device(cmd)->dev)). For single-layer clears this scales the block-fill floor with device core count (128 KiB on 8-core G13G, 160 KiB on 10-core G14G/G16G, 80–96 KiB on 5–6-core G17P, 320 KiB on 20-core G17S/M4 Pro, and a conservative 640 KiB floor on 40-core G17C—above the prior-head 576 KiB point that already improved over 400 KiB; the new sweep will measure both sides of 640 KiB).
  3. Branch hygiene: Merged origin/aurora-wip (cedf24806bcb) cleanly and added c1f8d2f816dc as a new commit rather than squashing and force-pushing an open PR branch.
  4. Host verification at c1f8d2f816dc: meson test --suite asahi passed 225/225, agx_tests passed 1,459/1,460 (1 pre-existing skip: NativeFMA.ExactDyadicOracle), and drm-shim (vulkan-image-clear-bench under gdb breaking on agx_get_precompiled) confirmed the exact per-core switchover between LIBAGX_FILL_UINT4 (35) and LIBAGX_FILL_UINT4_BLOCKS (36) across g13g (32 blocks), g14g/g16g (40 blocks), g17p (20 blocks), and g17s (80 blocks).

Pending at c1f8d2f816dc: exact-head dEQP-VK.api.image_clearing.* and paired vulkan-image-clear-bench A/B sweeps with interior-layer readback on AGX2 (J313 M1 G13G, J413 M2 G14G) and AGX3 (J713 M4 G16G, J716c M5 Max G17C, MacBook Neo A18 Pro G17P). If G14G still regresses with the 32-bit-indexed kernel, we can isolate why and gate on the underlying hardware property instead of generation.

@erikwb
erikwb requested a review from maralcbr November 24, 2026 21:28

@satchlj satchlj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict at c1f8d2f816dc

APPROVE — commit c1f8d2f816dc resolves the prior generation-gate and tuned-cutoff blockers cleanly by switching libagx_fill_uint4_blocks to 32-bit uint indexing across all GPU generations and deriving the dispatch floor from agx_get_num_cores(), passing -Db_ndebug=false Meson suites, live Apple M5 Max vulkan-image-clear-bench readback verification on both sides of the floor, and live dEQP-VK.api.image_clearing CTS with 0 GPU faults.

Blockers

None.

Checked

  • Changed files (5): src/asahi/clc/asahi_clc.c, src/asahi/libagx/copy.cl, src/asahi/vulkan/hk_cmd_clear.c, src/asahi/vulkan/meson.build, src/asahi/vulkan/tests/vulkan_image_clear_bench.c.
  • Kernel & dispatch math audit (copy.cl, hk_cmd_clear.c, asahi_clc.c):
    • KERNEL(32) libagx_fill_uint4_blocks builds for every libagx target (asahi_clc.c) and uses 32-bit uint indexing (cl_global_id.y * layer_stride_uint4 + cl_group_id.x * 256 + cl_local_id.x + 32 * i for i = 0..7), covering exactly 256 * 16 = 4096 bytes per workgroup with zero overlap or gaps.
    • hk_clear_image() dispatches agx_2d(size / 128, layer_count) ((size / 128) / 32 = size / 4096 workgroups per layer) when size % 4096 == 0 and (uint64_t)(size / 4096) * layer_count >= 4 * agx_get_num_cores(&dev->dev), replacing both the AGX3 generation gate and the hardcoded 256 KiB threshold.
    • Commits carry human Signed-off-by:.
  • Build & host tests (-Db_ndebug=false, Linux 7.3 aarch64):
    • meson test --suite asahi: 288/288 OK (0 fail).
    • meson test --suite poly: 5/5 OK (0 fail).
  • Live Apple M5 Max Vulkan verification (Linux 7.3, 0 GPU faults in dmesg):
    • vulkan-image-clear-bench 16 128 256 512 1024 (clears interior layer 1 and verifies all words of all 3 layers — cleared interior + untouched neighbors 0 and 2):
      • side=16 (4 KiB/layer, below floor): verified_words=3072, clear_us=9.5430
      • side=128 (256 KiB/layer, below 40-core 640 KiB floor): verified_words=196608, clear_us=13.3685
      • side=256 (1 MiB/layer, above floor -> libagx_fill_uint4_blocks): verified_words=786432, clear_us=14.4062
      • side=512 (4 MiB/layer, libagx_fill_uint4_blocks): verified_words=3145728, clear_us=31.3854
      • side=1024 (16 MiB/layer, libagx_fill_uint4_blocks): verified_words=12582912, clear_us=84.1042
    • dEQP-VK.api.image_clearing.core.clear_color_image.2d.* (290 cases across r8g8b8a8_unorm, r16g16b16a16_sfloat, r32g32b32a32_sfloat, r32_uint linear/optimal multi-layer): 215 Pass, 75 NotSupported, 0 Fail.
  • Untested scope: Live AGX2 (M1/M2) and M3/M4 hardware sweeps after the 32-bit indexing change (particularly re-measuring M2 at/above its core-scaled floor).
Evidence
  • Built c1f8d2f816dc with -Dbuildtype=debugoptimized -Db_ndebug=false -Dvulkan-drivers=asahi -Dgallium-drivers=asahi -Dbuild-tests=true -Dtools=drm-shim.
  • meson test --suite asahi: 288/288 OK; --suite poly: 5/5 OK.
  • Live Apple M5 Max vulkan-image-clear-bench 16 128 256 512 1024: all 5 sizes verified (3072, 196608, 786432, 3145728, 12582912 words, 0 mismatches).
  • Live Apple M5 Max CTS (290 dEQP-VK.api.image_clearing.core.clear_color_image.2d.* cases): 215 Pass / 75 NotSupported / 0 Fail, 0 GPU faults in dmesg.

@erikwb

erikwb commented Nov 24, 2026 •

Copy link
Copy Markdown
Author

Added exact-head J713 (M4 Air, G16G) sampled Borealis Vulkan CTS A/B results at c1f8d2f816dc vs merge-base cedf24806bcb (Linux 7.3.0, Vulkan CTS 7ba03cdac7ae, same boot back-to-back):

  • dEQP-VK.api.image_clearing.* (stride 6, 7,606 cases): 3,948 Pass / 3,658 NotSupported / 0 Fail, identical to base (0 diffs, 0 crashes).
  • dEQP-VK.api.copy_and_blit.core.image_to_image.* (stride 40, 1,318 cases): 846 Pass / 472 NotSupported / 0 Fail, identical to base (0 diffs, 0 crashes).

Updated the PR body's Tested, Not yet, and Evidence sections (vulkan-image-clear-bench A/B, unsampled image_clearing.*, and other Macs remain under Not yet). Head c1f8d2f816dc is unchanged.

@erikwb

erikwb commented Nov 26, 2026 •

Copy link
Copy Markdown
Author

@DjDeveloperr — updated the PR body with M6 (G18G) in **Risk:** and exact-head (c1f8d2f816dc vs cedf24806bcb) paired vulkan-image-clear-bench A/B and full unsampled dEQP-VK.api.image_clearing.* (45,636 cases, 0 diffs on every Mac) across all three local test machines (same vulkan-image-clear-bench executable across both ICDs, 0 readback mismatches, 0 GPU-error lines):

  • J716c (M5 Max / G17C B1): 41 interleaved rounds: -21.41% at 1 MiB/layer (3.466 -> 2.724 µs), -31.86% at 2.25 MiB (6.372 -> 4.342 µs), -35.11% at 4 MiB (10.462 -> 6.789 µs), and -34.28% at 16 MiB (30.549 -> 20.077 µs); sizes below the 40-core 640 KiB floor are unchanged (4 KiB -0.42%, 256 KiB +1.97% noise, 576 KiB +0.27%). dEQP-VK.api.image_clearing.*: 45,636 cases (24,418 Pass / 21,218 NotSupported / 0 Fail), 0 diffs.
  • J713 (M4 Air / G16G B0): Two independent interleaved runs (20 and 40 rounds): -5% at 256 KiB/layer (10.459 -> 9.952 µs / 10.704 -> 10.210 µs), -14% at 1 MiB (16.161 -> 13.350 µs / 16.331 -> 14.021 µs), -5.3% to -6.9% at 4 MiB (38.616 -> 36.582 µs / 39.156 -> 36.434 µs), and -1.1% to -1.8% at 16 MiB (162.879 -> 161.132 µs / 164.195 -> 161.288 µs, PR faster in 60/60 rounds); sizes below the 160 KiB floor (4 KiB, 144 KiB) are within noise. dEQP-VK.api.image_clearing.*: 45,636 cases (23,514 Pass / 22,122 NotSupported / 0 Fail), 0 diffs.
  • J313 (M1 Air / G13G B1): No gain on G13G — in two independent interleaved runs (20 and 40 rounds), the first two sizes on the block path are slightly slower by +0.26 µs with non-overlapping IQRs: side 96 (144 KiB/layer) +3.5% (7.419 -> 7.677 µs, head faster 3/20; 7.422 -> 7.680 µs, 3/40) and side 128 (256 KiB/layer) +2.8% (9.455 -> 9.722 µs, 1/20; 9.468 -> 9.734 µs, 4/40); sides 256–1024 (1–16 MiB/layer) are +0.0% to +1.7% (bandwidth-bound), and below-128 KiB floor sizes (4 KiB, 64 KiB) are within noise. dEQP-VK.api.image_clearing.*: 45,636 cases (19,144 Pass / 26,492 NotSupported / 0 Fail), 0 diffs.

Still open in **Not yet:**: external G14G (M2) crossover retest requested in review (after the c1f8d2f816dc 32-bit indexing fix), external G15 / G17P / G17S / G18G (M6) rows, and whether the small-size G13G +2.8%–3.5% crossover at sides 96–128 merits tuning the floor (or excluding G13G) or is acceptable.

@RyanTheTide

Copy link
Copy Markdown

Re-check of the items in Dj's 11-24 review, at c1f8d2f (still merges cleanly onto aurora-wip e1b5658):

  1. Gate: fixed in c1f8d2f (checked in the code). libagx_fill_uint4_blocks (libagx/copy.cl) indexes with a 32-bit uint base, as libagx_fill_uint4 does, and the usc_generation == AGX_ISA_AGX3 gate is gone from hk_cmd_clear.c.
  2. Cutoff: fixed in c1f8d2f. The floor is now four 4 KiB blocks per core from agx_get_num_cores() (HK_CLEAR_BLOCK_FILL_GROUPS_PER_CORE) instead of a fixed 256 KiB.
  3. Commit hygiene: the commits are not squashed (the author avoided a force push). A squash merge covers this.
  4. Rows at c1f8d2f against cedf248 are posted for J716c (G17C), J713 (G16G) and J313 (G13G): clear bench plus the full dEQP-VK.api.image_clearing.*, 0 diffs.

Still open: the G14G interior-layer readback and crossover timing (we have M2s and will queue it). Item 1 also needs a decision on the J313 result, which is +2.8 % to +3.5 % at 144 and 256 KiB per layer, the first two sizes above G13G's 128 KiB floor: accept it, or raise the floor from a hardware property.

@RyanTheTide

Copy link
Copy Markdown

c1f8d2f J413 M2 Air (G14G B0, 7.3.0-aurora-fleet89) PASS: api.image_clearing.* 19,144 pass / 26,492 not supported / 0 fail on head and on merge-base cedf248, 0 cases differ; vulkan-image-clear-bench 20 interleaved rounds, 0 readback mismatches, no slowdown at 256 KiB any more (-0.9 %); 0 GPU faults, Enforcing, 0 failed, 0 AVC; system Mesa untouched

Details

This is the G14G crossover retest asked for in review.

  • Builds: exact head c1f8d2f and its merge-base cedf248 (git archive, no merge), release with assertions on (-Dbuildtype=release -Db_ndebug=false -Dvulkan-drivers=asahi), native aarch64 Fedora 45. vulkaninfo shows git-c1f8d2f816 and git-cedf24806b. Both loaded through VK_DRIVER_FILES; /usr/lib64/libvulkan_asahi.so sha256 82e6d1112e5e... before and after. Shader cache off.
  • Bench: vulkan-image-clear-bench built from the PR's src/asahi/vulkan/tests/vulkan_image_clear_bench.c (cc -O2 ... -lvulkan), the same binary for both arms. 20 rounds, arm order alternating (base first in odd rounds, head first in even rounds). Every process exited 0, so all 3 layers matched on every run. Medians of clear_us:
side bytes per layer base head change head faster
16 4,096 2.176 2.134 -1.9 % 15/20
64 65,536 2.601 2.545 -2.2 % 11/20
96 147,456 3.751 3.818 +1.8 % 5/20
128 262,144 5.789 5.738 -0.9 % 10/20
192 589,824 10.215 10.193 -0.2 % 9/20
256 1,048,576 17.042 17.351 +1.8 % 10/20
512 4,194,304 55.134 55.483 +0.6 % 8/20
1024 16,777,216 197.279 202.016 +2.4 % 3/20
  • On this M2 the block path is neither faster nor slower within about 2 %. The old ulong build's +14 % at 256 KiB is gone. Side 96 (144 KiB) is below the 160 KiB floor for the timed one-layer clears, so it runs the old path in both arms. The only steady change is 16 MiB at +2.4 % (head faster in 3 of 20 rounds). That is small, but it is not a gain on G14G.
  • CTS: deqp-vk 1.4.7.1 (3fd4ea318fe2), dEQP-VK.api.image_clearing.* in full (45,636 cases) on both arms, 4 parallel processes. Every case has the same result on both arms.
  • Kernel log over the bench and both CTS runs: 0 GPU faults, recoveries, timeouts or rejected submits. 0 AVC, 0 failed units, Enforcing.

@erikwb

erikwb commented Nov 27, 2026

Copy link
Copy Markdown
Author

Updated the PR body at unchanged head c1f8d2f816dc to record your J413 (M2 Air, G14G B0) paired A/B row (dEQP-VK.api.image_clearing.* 19,144 Pass / 26,492 NotSupported / 0 Fail, 0 diffs; vulkan-image-clear-bench 20 rounds, 0 readback mismatches, 256 KiB -0.9% confirming the prior ulong +14% slowdown is gone, and 0 GPU faults) and move G14G out of **Not yet:**.

We are holding merge on c1f8d2f816dc to diagnose the repeatable J313 (G13G B1) 144–256 KiB (+2.8% to +3.5% / +0.26 µs, head faster in only 1/20–4/40 rounds) and J413 (G14G B0) 16 MiB (+2.4%, head faster in only 3/20 rounds) regressions and validate a fix with paired A/B runs before merging:

  • Simply raising HK_CLEAR_BLOCK_FILL_GROUPS_PER_CORE (src/asahi/vulkan/hk_cmd_clear.c:29,143-179) past 8 (to >= 9 groups/core, since 256 KiB on 8-core G13G is 64 groups = 8 groups/core and is still +2.8%) is not a clean fix by itself: at 9 groups/core, the single-layer floor moves to 360 KiB on 10-core G16G (J713, dropping its -5% win at 256 KiB) and to 1.40625 MiB (360 4 KiB groups) on 40-core G17C (J716c, dropping its -21.41% win at 1 MiB while retaining the -31.86% win at 2.25 MiB), while leaving G13G 1–16 MiB (+0.0% to +1.7%) and G14G 16 MiB (+2.4%) unchanged.
  • struct agx_device / drm_asahi_params_global expose core count (agx_get_num_cores()) but no store-coalescing capability bit separating AGX2 from AGX3 without usc_generation / ISA gating.

Next step: investigate why libagx_fill_uint4_blocks regresses at 144–256 KiB on G13G and 16 MiB on G14G, land a proper fix, and re-run paired A/B checks at the new head before merging.

…lear

Signed-off-by: Erik Bourget <erik@ebourget.net>
Keep small uncompressed clears on libagx_fill_uint4 until the clear reaches at least 128 4 KiB blocks (512 KiB) as well as four blocks per GPU core (agx_get_num_cores()). On narrower GPUs (such as 8-core G13G, where 4 * num_cores was only 32 blocks / 128 KiB), launching 36 to 64 workgroups with eight stores per thread showed a repeatable +0.26 us (+2.8% to +3.5%) slowdown at 144 KiB and 256 KiB compared to libagx_fill_uint4, while 1 MiB (256 blocks) and wider GPUs (40-core G17C at 160 blocks / 640 KiB) keep their existing thresholds.

Signed-off-by: Erik Bourget <erik@ebourget.net>
@erikwb

erikwb commented Nov 28, 2026

Copy link
Copy Markdown
Author

Updated the branch to 86abe1d53d54 (merged origin/aurora-wip a0164c9101c1 in 23e513cde215 to resolve the src/asahi/vulkan/meson.build conflict, then raised the minimum block-fill threshold in src/asahi/vulkan/hk_cmd_clear.c in 86abe1d53d54), completed exact-head hardware A/B and CTS runs across J716c, J713, and J313, and updated the PR body.

  • Conflict resolution (23e513cde215): Kept both the PR's vulkan-image-clear-bench executable and upstream vulkan-compute-store-visibility in src/asahi/vulkan/meson.build.
  • Crossover threshold fix (86abe1d53d54): hk_clear_use_block_fill() now requires at least max(128, 4 * agx_get_num_cores()) 4 KiB blocks (HK_CLEAR_BLOCK_FILL_MIN_GROUPS = 128, 512 KiB minimum; 640 KiB on 40-core G17C). On 8-core G13G, 144–256 KiB single-layer clears (36–64 workgroups, which previously regressed by +0.26 µs / +2.8% to +3.5% at c1f8d2f816dc) now stay on libagx_fill_uint4, while large clears (>= 484 KiB tile-aligned / 1–16 MiB on G16G and G17C) keep the block path.
  • Host checks at 86abe1d53d54 (x86_64): meson test --suite poly 5/5 pass, agx_tests --gtest_brief=1 1,726/1,727 pass (NativeFMA.ExactDyadicOracle pre-existing skip), vulkan-image-clear-bench built cleanly, asahi_clc emitted libagx_fill_uint4_blocks across all targets, and drm-shim confirmed side=96–160 1-layer clears select libagx_fill_uint4 while >= 512 KiB clears select libagx_fill_uint4_blocks across g13g, g14g, g16g, g17p, and g17s. meson test --suite asahi passed 326/337 (all 11 failures are unrelated pre-existing/headless failures on origin/aurora-wip a0164c9101c1).
  • Exact-head hardware A/B (86abe1d53d54 vs a0164c9101c1, cross-built aarch64 release Borealis ICDs, -Db_ndebug=false, Linux 7.3.0, 0 readback mismatches, 0 GPU faults):
    • J716c (M5 Max / G17C B1): dEQP-VK.api.image_clearing.* 45,636/45,636 identical (24,418 Pass / 21,218 NotSupported, 0 diffs; NIR_DEBUG=novalidate on both arms for base a0164c9101c1's vk-meta-copy-buffer-to-image-frag validation error). vulkan-image-clear-bench (50 samples/arm/size ABBA): <= 637.6 KiB noise at µs scale; 1 MiB -7.3%, 4 MiB -12.4% (-23.0% min), 16 MiB -4.5% (-12.7% min).
    • J713 (M4 MacBook Air / G16G B0): vulkan-image-clear-bench (40 ABBA rounds = 80 samples/arm/size): 144 KiB (+0.09%) and 256 KiB (-0.45%) flat (confirming the >= 512 KiB floor; the earlier -5% at 256 KiB was from prior head c1f8d2f816dc), while 484 KiB -20.37% (40/40), 576 KiB -20.29% (40/40), 1 MiB -24.00% (40/40), 4 MiB -8.12% (40/40), and 16 MiB -1.64% (38/40) win cleanly. dEQP-VK.api.image_clearing.* (45,636 cases): 0 deterministic diffs after solo flake resolution of base a0164c9101c1's NIR-validation aborts.
    • J313 (M1 MacBook Air / G13G B1): vulkan-image-clear-bench (40–60 samples/arm ABBA): prior 144–256 KiB regression is gone (144 KiB 1.000x, 196–256 KiB 1.002x, 400 KiB 1.003x, 511.9–517.6 KiB 1.003–1.005x, 1 MiB 0.997x, 4 MiB 1.011–1.014x, 16 MiB 1.007x, 64 MiB 0.901x / 1,125 -> 1,013 µs). dEQP-VK.api.image_clearing.* 45,636/45,636 identical (19,144 Pass / 26,492 NotSupported, 0 diffs, 0 crashes).
  • Remaining under **Not yet:**: External J413 (M2 Air, G14G B0, re-measurement at 86abe1d53d54 including the prior 16 MiB +2.4% result) plus external G15, G17P, G17S, and G18G rows.

@erikwb
erikwb requested a review from a team as a code owner November 28, 2026 02:28

@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 86abe1d5

Blockers: none (ready for multi-family lab regression overlay and merge).

Checked:

  • src/asahi/libagx/copy.cl, asahi_clc.c, hk_cmd_clear.c: 32-bit uint indexing in libagx_fill_uint4_blocks works across all GPU generations without generation gates; 86abe1d5 raises the crossover floor to max(128, 4 * agx_get_num_cores()) 4 KiB blocks (512 KiB min, 640 KiB on 40-core GPUs), eliminating the earlier small-clear regression on 8-core G13G while retaining large-clear wins on G16G/G17C.
  • Conflict resolution at 23e513cd (src/asahi/vulkan/meson.build) cleanly preserves both vulkan-image-clear-bench and upstream vulkan-compute-store-visibility.
  • Exact-head host tests (poly 5/5, agx_tests 1,726/1,727, asahi_clc all targets, drm-shim path selection) and exact-head hardware A/B + CTS PASS across J716c (45,636/45,636 image_clearing CTS 0 diffs), J713, and J313, with 0 readback mismatches and 0 GPU faults.
  • Checked for Apple material, tool attribution, private serials, and Borealis naming: clean; human Signed-off-by present; MERGEABLE on aurora-wip.
Evidence
  • Head: 86abe1d53d54 (base: aurora-wip, mergeable: MERGEABLE, +386/-0).

Signed-off-by: Erik Bourget <erik@ebourget.net>
After libagx_fill_uint4 moved to 256-thread workgroups, both libagx_fill_uint4 and libagx_fill_uint4_blocks fill one 4 KiB block per workgroup; libagx_fill_uint4_blocks launches an eighth of the threads rather than an eighth of the groups.

Signed-off-by: Erik Bourget <erik@ebourget.net>
@erikwb

erikwb commented Nov 28, 2026

Copy link
Copy Markdown
Author

Updated the branch to de451b95c0a7 (merged origin/aurora-wip 46f3a68e60d9 in 93e1fe96a14f and updated the src/asahi/vulkan/hk_cmd_clear.c block-fill comment in de451b95c0a7):

  • Overlapping aurora-wip change (aurora-silicon/mesa#1270 / 0df1e19b9174): libagx_fill_uint4 now uses KERNEL(256) on aurora-wip, so both libagx_fill_uint4 and libagx_fill_uint4_blocks fill one 4 KiB block per workgroup (size / 4096 groups per layer) and libagx_fill_uint4_blocks launches an eighth of the threads rather than an eighth of the groups. Updated the comment above HK_CLEAR_BLOCK_FILL_MIN_GROUPS in src/asahi/vulkan/hk_cmd_clear.c to match.
  • Host verification at de451b95c0a7 (x86_64, -Doptimization=2 -Ddebug=false -Db_ndebug=false): meson test --suite poly 5/5 pass, meson test --suite asahi 347/347 pass, agx_tests --gtest_brief=1 1,812 pass / 1 pre-existing skip (NativeFMA.ExactDyadicOracle), and vulkan-image-clear-bench built cleanly (libagx_shaders.h emits LIBAGX_FILL_UINT4 and LIBAGX_FILL_UINT4_BLOCKS).
  • PR body & hardware baseline: Added **Revert:** and labeled the 86abe1d53d54 vs a0164c9101c1 A/B numbers as prior-merge-base (pre-#1270 KERNEL(32) libagx_fill_uint4) pending exact-head de451b95c0a7 vs 46f3a68e60d9 paired vulkan-image-clear-bench ABBA, dEQP-VK.api.image_clearing.*, and boot/smoke runs across J716c, J713, and J313.
  • Exact-head J716c & J713 (2026-11-28): de451b95c0a7 vs 46f3a68e60d9 (native release base-plus-patch builds identified by source SHA and libvulkan_asahi.so SHA-256, sharing git-97742505d8 in driverInfo):
    • J716c (M5 Max / G17C B1): dEQP-VK.api.image_clearing.* 45,636 cases 0 diffs; vulkan-image-clear-bench 7 rounds alternating order is neutral on this base (-0.45% to +0.84% from 256 KiB to 16 MiB, +3.66% at 4 KiB which is microsecond noise); boot/smoke clean.
    • J713 (M4 Air / G16G B0): dEQP-VK.api.image_clearing.* all 45,636 cases (23,514 Pass / 22,122 NotSupported, 0 diffs) and vulkan-image-clear-bench 16 runs (8 per arm ABBA, 4 KiB to 16 MiB/layer) passed with 0 readback mismatches (rc 0); default-boot baseline smoke clean (0 new dmesg error lines during this PR's Mesa run window). Per-size J713 timing medians are not yet reduced because the raw timing file is on J713 (currently awaiting human recovery); outside single 247 µs outliers recorded on both arms, observed 16 MiB runs were 199–203 µs on base (and 199–247 µs on PR). J313 exact-head row remains pending under **Not yet:**.

@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: FINISH, then merge at de451b95

Blockers:

  1. Post-#1270 performance justification still open: Since aurora-silicon/mesa#1270 (0df1e19b) widened libagx_fill_uint4 from KERNEL(32) to KERNEL(256) (matching one 4 KiB block per workgroup), the exact-head de451b95 vs 46f3a68e vulkan-image-clear-bench row on J716c (M5 Max) is now neutral (-0.45% to +0.84% across 256 KiB–16 MiB), J713 (M4 Air) per-size medians are not yet reduced from the raw file, and J313 (M1 Air) exact-head A/B is still pending. Please confirm a measurable post-#1270 win on J713/J313 before landing a second clear kernel (or close as superseded by #1270 if post-#1270 stays neutral across families).

Checked: Merge onto aurora-wip 46f3a68e (93e1fe96), comment update de451b95 (src/asahi/vulkan/hk_cmd_clear.c), full 5-file diff (+388/-0), host test results, and exact-head J716c/J713 CTS + readback rows.

Evidence
  • Correctness (0 code bugs): libagx_fill_uint4_blocks (copy.cl, asahi_clc.c, hk_cmd_clear.c) remains clean with 32-bit uint indexing, no generation gates, and max(128, 4 * agx_get_num_cores()) floor; de451b95 accurately updates the HK_CLEAR_BLOCK_FILL_MIN_GROUPS comment for the 256-lane libagx_fill_uint4 baseline.
  • Verification at exact head de451b95: Host x86_64 (poly 5/5, asahi 347/347, agx_tests 1,812 passed / 1 skipped) and exact-head dEQP-VK.api.image_clearing.* (45,636 cases, 0 diffs) + vulkan-image-clear-bench readback pass on both J716c (M5 Max) and J713 (M4 Air) with 0 GPU faults / 0 new kernel errors.

@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: HOLD at de451b9

Keep the comparative performance gate from the current review. J716c is neutral after #1270, while the exact-head J713 medians and J313 A/B are still outstanding. The correctness results pass. A reproducible improvement against the landed #1270 baseline is needed to justify adding a second clear kernel.

@RyanTheTide

Copy link
Copy Markdown

J316s / M1 Pro (G13S C0), post-#1270 paired A/B. Compared de451b95c0a7 with 46f3a68e60d9 using the same assertion-enabled release options, Vulkan clear benchmark and 7.3.0-aurora-edge boot. Each driver completed 144 size/process checks covering 287,874,048 readback words across two independent eight-pair alternating-order runs. The 26 sampled dEQP-VK.api.image_clearing.* cases matched in both runs (11 Pass, 15 NotSupported), with no GPU faults or boot changes.

At 16 MiB/layer, the median paired delta was +4.87% in the first run (arm medians 178.62 and 191.13 µs) and +10.00% on repeat (174.81 and 190.50 µs). The candidate was slower in 15 of 16 pairs. Smaller-size timings varied across runs. This is the G13S peer result. The post-#1270 G13G J313 comparison and J713 medians will determine whether a hardware-supported scope retains a reproducible win.

@RyanTheTide

Copy link
Copy Markdown

J713 M4 Air (G16G B0), post-#1270 paired A/B. Fresh measurements at de451b95c0a7 vs 46f3a68e60d9 on saved 7.3.0-aurora-fleet85, using the same release options, fixture and alternating order in two runs of eight pairs each. Both ICDs verified 287,874,048 words across 144 size checks per arm. The 26 sampled image-clearing CTS cases matched in each run (16 Pass, 10 NotSupported), with no GPU faults or boot change.

Size per layer Run 1 median paired change Run 2 median paired change Candidate faster
1 MiB −2.57% −3.11% 11/16
4 MiB −0.97% −2.95% 14/16
16 MiB −0.47% −0.31% 10/16

The 4 MiB improvement repeats on G16G. At 16 MiB the same pair slowed down on the G13S peer, and the existing J716c result was neutral. The J313 G13G post-#1270 row remains useful for deciding the scope of the second clear path.

@erikwb

erikwb commented Nov 29, 2026

Copy link
Copy Markdown
Author

Closing this as superseded by #1270. The post-#1270 rows show the second kernel no longer pays its way.

Mac GPU (cores) 1 MiB 4 MiB 16 MiB
J716c G17C (40) +0.43% +0.84% -0.45%
J713 G16G (10) -2.57% / -3.11% -0.97% / -2.95% -0.47% / -0.31%
J316s G13S (16) varies varies +4.87% / +10.00% (15/16 pairs slower)

Before #1270, J713 was -24% at 1 MiB and J716c -12% at 4 MiB. #1270 gives the base fill one 4 KiB block per workgroup, the same group count as libagx_fill_uint4_blocks, so it already delivers almost all of that gain for every fill on every generation. Against that base, the only difference left is 32 threads issuing 8 stores each instead of 256 threads issuing 1. That saves a little fixed cost on mid-size clears (about 0.2 µs at 1 MiB on G16G). It also cuts the threads resident per core 8x, and the 16 MiB results on G13S, which is bandwidth-bound, point to that costing stores in flight. AGX2 already leaned that way at 16 MiB before #1270 (J413 +2.4%).

We looked at keeping a window, with a ceiling in groups per core added to the existing floor. It would fit the rows so far, but it is a second tuned constant standing in for memory bandwidth per core, which the driver doesn't report. It would also rest on a gain of about 3% on one family, with no workload gain behind it: the full Cyberpunk T2 runs were inside noise. That isn't enough to justify a second clear kernel.

Thanks for the J316s and J713 pairs. They settled it. If the clear benchmark (src/asahi/vulkan/tests/vulkan_image_clear_bench.c) is useful for future fill or clear work, I can put it up as a test-only PR.

@erikwb erikwb closed this Nov 29, 2026
@RyanTheTide

Copy link
Copy Markdown

Thanks for closing this out and documenting the post-#1270 comparison. The J713 and J316s data made the remaining tradeoff clear. I’ve withdrawn the pending J313 run for this PR.

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