Repository navigation
asahi/compiler: unpack AGX3B multi-byte payloads in one half op and fold redundant byte masks - #1093
Conversation
…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>
|
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
left a comment
There was a problem hiding this comment.
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), leavingAGX2,AGX3C, andG18Gunchanged. - Both commits (
bd7034494e1a,5c20c081f864) carry human authorship and humanSigned-off-by:DCO with zero AI attribution in commits, PR text, or diff. - Exact-head hardware rows cover two distinct
AGX3BMac generations at5c20c081f864:J700(MacBook Neo A18 ProG17P B1) andJ616s(M4 ProT6040/G16S B1), with ABBA wins, targeted byte-path Vulkan CTS passes, and clean host health. - Mesa CI waiver applies (
aurora-silicon/mesadoes not gate on GitHub CI); hardware rows plus full assertion-enabled DRM-shim test suite (322/322OK with negative control on new tests) are the gate.
Evidence
- Audited full diff (
+359 / -5acrosssrc/asahi/compiler/agx_compile.c,agx_optimizer.c,meson.build,test/test-agx3b-byte-unpack.cpp, andtest/test-optimizer.cpp). - Verified
agx_unpack_integer_8_agx3shares oneagx_g17p_shift_boundary(b, 8)across all odd lanes whennr_channels > 1, skips emitting the shift boundary for single-channel loads, and preserves 32-bit zero-extension and theG18G(emit_agx3d) fallback path. - Verified
agx_optimizer_redundant_andruns insideagx_foreach_instr_global_safedirectly afteragx_optimizer_bitop, checksUTIL_LUT2(a & b), single-channel matching SSA width, noabs/neg/memory/saturate, and(c1 & ~c2 & width) == 0, and updatesdefs[mov->dest[0].value]before removingI. - Verified new unit tests cover
G15G,G16G,G17P,G17C, andG18Gacross global/shared memory and float/int consumers, plus positive and negative redundant-mask cases. - Hardware row 1 (
J700MacBook Neo A18 ProG17P B1,5c20c081f864vs55f33ab11a1e): 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-exactgpubench-vkCRCs;322/322assert DRM-shim CI pass; 0 GPU faults/AVCs/failed units. - Hardware row 2 (
J616sM4 ProG16S B1,5c20c081f864): assert-enabled isolated Borealis overlay,725 Pass / 0 Fail / 6 NotSupportedacrosspack_unpack,8bit_storage,r8g8b8a8_unorm,glsl.loops, andapi.smoke;gpubench-vkOK; 0 assertions/GPU faults/AVCs/failed units.
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 redundantAGX3Bmasked-byteANDs ((y & c1) & c2when(c1 & ~c2 & width) == 0) emitted on packed RGBA8 stores.Tested:
J700(MacBook Neo, Apple A18 Pro /G17P B1,AGX3B, kernel7.3.0-41.fc44.aurora.aarch64) exact-head5c20c081f864vs exact base55f33ab11a1e(origin/aurora-wip):A1/B1/B2/A2ABBA runs,0validation 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 warp162 → 142, Canny303 → 287&378 → 363, Feature Matching733 → 696, Stereo782 → 774).5,977cases × 2 runs):5,529 Pass,448 NotSupported,0 Fail/0recoveries (8bit_storage,workgroup_memory_explicit_layout8-bit,type.vec{2,3,4}.{i8,u8},r8g8b8a8_{u,s}inttile loads, GLSL int8).gpubench-vkcompute (conv2d,edge,stereo): bit-exact CRCs across all legs, neutral (±0.8%).-Dtools=drm-shim -Db_ndebug=false, full rebuild):322/322OK,0warnings in touched files; negative control confirmed new tests fail on base and pass on head.0GPU faults,0AVCs,0failed units, boot ID unchanged, SELinux Enforcing.Risk: two-way · scoped strictly to
AGX_ISA_ENCODING_AGX3B(no chip allowlists;AGX2,AGX3C, andG18Gunchanged); 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
55f33ab11a1e):libvulkan_asahi.soSHA-256331375970863d373bdfc794149f8f8698b32503ca23f07ebfd7d173ebb7186c15c20c081f864):libvulkan_asahi.soSHA-2566228f06d636c19ba3391cafa8b31ddb15094124c750b180ba9704fae8662c57255f33ab11a1→5c20c081f86, mean GPU-busy ms, 20 iters/leg):A1 18.552 / B1 18.315 / B2 18.330 / A2 18.587(18.569 → 18.323 ms,−1.33%)A1 24.013 / B1 23.915 / B2 23.892 / A2 24.067(24.040 → 23.903 ms,−0.57%)A1 20.626 / B1 20.516 / B2 20.528 / A2 20.604(20.615 → 20.522 ms,−0.45%)−0.06%, Gaussian Blur−0.20%, Stereo−0.08%, Particle+0.02%(identical binaries); Background Blur+1.14%from single noisyB2leg (9.831vsB1 9.660/A2 9.657, identical binaries).test-agx3b-byte-unpack.cpp(CompilesOnEveryTarget,OneHalfOperationPerByte) andtest-optimizer.cpp(AGX3BRedundantByteMask,AGX3BRedundantByteMaskNegative).