Skip to content

asahi/compiler: unpack AGX3B multi-byte payloads in one half op and fold redundant byte masks - #1093

Merged
DjDeveloperr merged 2 commits into
aurora-wipfrom
neo/agx3b-gb6-perf-20261125
Nov 25, 2026
Merged

DjDeveloperr merged 2 commits into
aurora-wipfrom
neo/agx3b-gb6-perf-20261125

Conversation

@DjDeveloperr

Copy link
Copy Markdown

What: Bring AGX3C's one-16-bit-op-per-byte unpack of multi-component 8-bit loads to AGX3B (M3, M4, A18 Pro) using the existing half-register shift boundary count (agx_g17p_shift_boundary), and fold redundant AGX3B masked-byte ANDs ((y & c1) & c2 when (c1 & ~c2 & width) == 0) emitted on packed RGBA8 stores.

Tested: J700 (MacBook Neo, Apple A18 Pro / G17P B1, AGX3B, kernel 7.3.0-41.fc44.aurora.aarch64) exact-head 5c20c081f864 vs exact base 55f33ab11a1e (origin/aurora-wip):

  • Geekbench 6.7.1 Vulkan (two independent same-boot A1/B1/B2/A2 ABBA runs, 0 validation errors): Edge Detection −1.33% (18.569 → 18.323 ms; ABBA agx: introduce agx3b support & HAL200 #1 −1.22%), Horizon Detection −0.57% (−0.67%), Feature Matching −0.45% (−0.33%), all byte-identical siblings flat (kernel sizes: Horizon warp 162 → 142, Canny 303 → 287 & 378 → 363, Feature Matching 733 → 696, Stereo 782 → 774).
  • Targeted byte-path Vulkan CTS (5,977 cases × 2 runs): 5,529 Pass, 448 NotSupported, 0 Fail / 0 recoveries (8bit_storage, workgroup_memory_explicit_layout 8-bit, type.vec{2,3,4}.{i8,u8}, r8g8b8a8_{u,s}int tile loads, GLSL int8).
  • gpubench-vk compute (conv2d, edge, stereo): bit-exact CRCs across all legs, neutral (±0.8%).
  • Fedora CI (-Dtools=drm-shim -Db_ndebug=false, full rebuild): 322/322 OK, 0 warnings in touched files; negative control confirmed new tests fail on base and pass on head.
  • Health: 0 GPU faults, 0 AVCs, 0 failed units, boot ID unchanged, SELinux Enforcing.

Risk: two-way · scoped strictly to AGX_ISA_ENCODING_AGX3B (no chip allowlists; AGX2, AGX3C, and G18G unchanged); easily reverted if any byte-unpack or bitmask edge case arises.

Not yet: Second-generation AGX3B (M3 / M4) hardware row and mirror CI run on this PR.

Exact ABBA timings, CTS breakdown & artifact hashes
  • Base (55f33ab11a1e): libvulkan_asahi.so SHA-256 331375970863d373bdfc794149f8f8698b32503ca23f07ebfd7d173ebb7186c1
  • Head (5c20c081f864): libvulkan_asahi.so SHA-256 6228f06d636c19ba3391cafa8b31ddb15094124c750b180ba9704fae8662c572
  • ABBA agx: fix the -Werror build of the AGX drivers #2 (55f33ab11a1 → 5c20c081f86, mean GPU-busy ms, 20 iters/leg):
    • Edge Detection: A1 18.552 / B1 18.315 / B2 18.330 / A2 18.587 (18.569 → 18.323 ms, −1.33%)
    • Horizon Detection: A1 24.013 / B1 23.915 / B2 23.892 / A2 24.067 (24.040 → 23.903 ms, −0.57%)
    • Feature Matching: A1 20.626 / B1 20.516 / B2 20.528 / A2 20.604 (20.615 → 20.522 ms, −0.45%)
    • Face Detection −0.06%, Gaussian Blur −0.20%, Stereo −0.08%, Particle +0.02% (identical binaries); Background Blur +1.14% from single noisy B2 leg (9.831 vs B1 9.660 / A2 9.657, identical binaries).
  • New unit tests: test-agx3b-byte-unpack.cpp (CompilesOnEveryTarget, OneHalfOperationPerByte) and test-optimizer.cpp (AGX3BRedundantByteMask, AGX3BRedundantByteMaskNegative).

…n per byte

AGX3 loads of two to four 8-bit components (device, shared and tile
memory) return their bytes packed two to a half register, and
agx_unpack_integer_8_agx3 gives each byte its own half. AGX3C does that in
one 16-bit operation per byte: the even byte is masked with 0xff and the
odd byte is shifted right by 8, which clears the upper byte. AGX3B instead
widened each half to a word, shifted it as a word, narrowed it back and
masked it, for every byte.

AGX3B has the same half-register shift. It takes its count from a register,
as for a NIR 16-bit ushr (agx_g17p_shift_boundary), and one count serves
every odd byte of a payload. Use the one-operation unpack on AGX3B too. G18G
keeps the 32-bit form.

On a MacBook Neo (G17P B1), Geekbench 6.7.1 Vulkan kernels that read packed
RGBA8 or byte rows shrink, e.g. Horizon Detection's bilinear warp 162 -> 142
instructions, the Canny chain 303 -> 287 and 378 -> 363, Feature Matching
733 -> 696, Stereo Matching 782 -> 774.

Signed-off-by: Diljit Singh <hey@djdev.me>
x & c2, where x = y & c1, is x itself when c1 sets no bit that c2 clears.
AGX3B meets it whenever a byte that u2u8 has already masked is masked
again: agx_pack_integer_8_agx3 masks every even channel of a packed 8-bit
store, as an RGBA8 pixel is written after f2u32 and u2u8. Replace the second
AND with a move of the first. The mask may be an immediate or a mov_imm.

Signed-off-by: Diljit Singh <hey@djdev.me>
@DjDeveloperr
DjDeveloperr requested a review from a team as a code owner November 25, 2026 21:34
@RyanTheTide

Copy link
Copy Markdown

5c20c08 J616s (M4 Pro T6040, Apple M4 Pro G16S B1, AGX3B, stock 7.3.0-aurora-fleet89) PASS: isolated assert-enabled (-Db_ndebug=false, MESA_SHADER_CACHE_DISABLE=1, libvulkan_asahi.so sha256 10b1a34ab6f9ca26) Borealis overlay; dEQP-VK.glsl.builtin.function.pack_unpack.* 52/52 Pass / 0 Fail, dEQP-VK.spirv_assembly.instruction.compute.8bit_storage.* 29/29 Pass / 0 Fail, dEQP-VK.texture.filtering.2d.formats.r8g8b8a8_unorm.* 12/18 Pass / 0 Fail / 6 NS, dEQP-VK.glsl.loops.* 624/624 Pass / 0 Fail, dEQP-VK.api.smoke.* 8/8 Pass / 0 Fail (725 Pass / 0 Fail / 6 NS); Borealis gpubench-vk (render.light 134.78 us, compute.light 118.48 us) ok; 0 assertions, 0 GPU faults, 0 failed units, Enforcing + 0 AVC, 0 kernel errors; overlay dropped and stock Borealis default verified.

@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: MERGE at 5c20c081f864

Blockers: none

Checked:

  • Clean-room diff with no copyrighted Apple material; compiler lowering, forward-optimizer fold, and compiler unit tests are original code.
  • No chip, board, or firmware gates, no new parameters or hacks, and no hardcoded hardware-safety limits; both changes key strictly on the ISA encoding capability (AGX_ISA_ENCODING_AGX3B), leaving AGX2, AGX3C, and G18G unchanged.
  • Both commits (bd7034494e1a, 5c20c081f864) carry human authorship and human Signed-off-by: DCO with zero AI attribution in commits, PR text, or diff.
  • Exact-head hardware rows cover two distinct AGX3B Mac generations at 5c20c081f864: J700 (MacBook Neo A18 Pro G17P B1) and J616s (M4 Pro T6040 / G16S B1), with ABBA wins, targeted byte-path Vulkan CTS passes, and clean host health.
  • Mesa CI waiver applies (aurora-silicon/mesa does not gate on GitHub CI); hardware rows plus full assertion-enabled DRM-shim test suite (322/322 OK with negative control on new tests) are the gate.
Evidence
  • Audited full diff (+359 / -5 across src/asahi/compiler/agx_compile.c, agx_optimizer.c, meson.build, test/test-agx3b-byte-unpack.cpp, and test/test-optimizer.cpp).
  • Verified agx_unpack_integer_8_agx3 shares one agx_g17p_shift_boundary(b, 8) across all odd lanes when nr_channels > 1, skips emitting the shift boundary for single-channel loads, and preserves 32-bit zero-extension and the G18G (emit_agx3d) fallback path.
  • Verified agx_optimizer_redundant_and runs inside agx_foreach_instr_global_safe directly after agx_optimizer_bitop, checks UTIL_LUT2(a & b), single-channel matching SSA width, no abs/neg/memory/saturate, and (c1 & ~c2 & width) == 0, and updates defs[mov->dest[0].value] before removing I.
  • Verified new unit tests cover G15G, G16G, G17P, G17C, and G18G across global/shared memory and float/int consumers, plus positive and negative redundant-mask cases.
  • Hardware row 1 (J700 MacBook Neo A18 Pro G17P B1, 5c20c081f864 vs 55f33ab11a1e): two same-boot Geekbench 6.7.1 Vulkan ABBA runs (Edge -1.33% / -1.22%, Horizon -0.57% / -0.67%, Feature Matching -0.45% / -0.33%, siblings flat); 5,529 Pass / 448 NotSupported / 0 Fail × 2 runs on byte-path Vulkan CTS; bit-exact gpubench-vk CRCs; 322/322 assert DRM-shim CI pass; 0 GPU faults/AVCs/failed units.
  • Hardware row 2 (J616s M4 Pro G16S B1, 5c20c081f864): assert-enabled isolated Borealis overlay, 725 Pass / 0 Fail / 6 NotSupported across pack_unpack, 8bit_storage, r8g8b8a8_unorm, glsl.loops, and api.smoke; gpubench-vk OK; 0 assertions/GPU faults/AVCs/failed units.

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.

3 participants