Skip to content

asahi/compiler: zero-extend 16-bit FFS sources on AGX3C instead of undef-padding - #1158

Merged
RyanTheTide merged 1 commit into
aurora-silicon:aurora-wipfrom
oreater:pr/agx-ffs16-zext
Nov 27, 2026
Merged

RyanTheTide merged 1 commit into
aurora-silicon:aurora-wipfrom
oreater:pr/agx-ffs16-zext

Conversation

@oreater

@oreater oreater commented Nov 26, 2026 •

Copy link
Copy Markdown

What: Fix a 16-bit AGX_OPCODE_FFS miscompilation in agx_lower_m5_alu_operands() that causes 4 Vulkan CTS tessellation invariance failures on M5 (AGX3C):

  • src/asahi/compiler/agx_compile.c & agx_compiler.h:
    • agx_supports_zext() folds u2u32 into AGX_OPCODE_FFS, leaving a 16-bit source whose upper 16 bits are defined to be zero.
    • agx_lower_m5_alu_operands() previously widened that 16-bit source back to 32-bit for AGX3's 32-bit FFS encoding via agx_pad_to_32() (collect with undef high half), leaving uninitialized garbage in bits 16..31 and corrupting MSB / clz results (e.g. RemoveMSB() in libagx_tess_tri).
    • Widen 16-bit AGX_OPCODE_FFS sources with a zero-extending agx_mov_to (matching AGX_OPCODE_BITREV).
  • src/asahi/compiler/test/test-native-form-regressions.cpp: Add NativeForms.AGX3CFfsHalfSourceZeroExtends regression test.

Tested: J716c Apple M5 Max (G17C B1, 40 GPU cores), Fedora Remix 44 (7.3.0-40.j716c19.fc44.aurora.aarch64, GCC 16.2.1, --buildtype=release -Db_ndebug=true), at 31f4cf41f65 vs base aurora-wip 822cf58723a:

  • meson test --suite asahi: 212/212 PASS (0 fail; NativeForms.AGX3CFfsHalfSourceZeroExtends passes).
  • Vulkan CTS (deqp-vk, MESA_SHADER_CACHE_DISABLE=1, dEQP-VK.tessellation.invariance.{outer_edge_index_independence,inner_triangle_set}.* + dEQP-VK.glsl.builtin.function.integer.findmsb.*, 30 cases):
    • Base (822cf58723a): 26/30 PASS, 4/30 FAIL (outer_edge_index_independence.triangles_fractional_even_spacing_*)
    • Head (31f4cf41f65): 30/30 PASS, 0/30 FAIL (+4 CTS fixes, 0 regressions).
  • Host health: SELinux=Enforcing, 0 failed systemd units, 0 kernel GPU/DRM/AVC errors.

Risk: two-way door · AGX3C (M5). A plain revert restores agx_pad_to_32(). Non-AGX3C encodings are untouched.

Not yet: Full vk-default mustpass sweep.

Frozen binary hashes
  • Base (822cf58723a04967a1b99653f9de72e3d2982487): libvulkan_asahi.so SHA-256 d5b7e4582e1b034642e804f6477b070504ad077c2f0a3212989f6ad785228d68
  • Head (31f4cf41f658e37d7ff809815bb82d5b2d6189c6): libvulkan_asahi.so SHA-256 4f3934239f6b7b547e51e2af5635ef0f6bf91f329e0587e426d3721cb9ed385f

…def-padding

agx_supports_zext folds u2u32 into AGX_OPCODE_FFS, leaving a 16-bit
source whose upper 16 bits are defined to be zero. In
agx_lower_m5_alu_operands, widening that 16-bit source back to 32-bit for
AGX3's 32-bit FFS encoding called agx_pad_to_32() (collect with undef
high half), leaving uninitialized garbage in bits 16..31 and corrupting
MSB / clz results.

This miscompiled RemoveMSB() in libagx_tess_tri, breaking
dEQP-VK.tessellation.invariance.outer_edge_index_independence.triangles_fractional_even_spacing_*.

Widen 16-bit FFS sources with a zero-extending agx_mov_to (matching
AGX_OPCODE_BITREV) and add NativeForms.AGX3CFfsHalfSourceZeroExtends.

Signed-off-by: oreater <145754695+oreater@users.noreply.github.com>

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: MERGE at 31f4cf41f658

Blockers: none

Checked: Read the diff. agx_supports_zext() folds u2u32 into FFS, so the 16-bit source has defined-zero upper bits; widening with a zero-extending move (as BITREV already does) instead of an undef-padded collect is the right fix, and findMSB of the zero-extended value equals the original semantics. AGX3C only, selected by encoding. The new AGX3CFfsHalfSourceZeroExtends test passes in the gate; your CTS A/B shows the 4 tessellation invariance failures fixed. M5-only, so the J716c row is the hardware row.

Evidence

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

@RyanTheTide
RyanTheTide merged commit f50ca54 into aurora-silicon:aurora-wip Nov 27, 2026
RyanTheTide added a commit that referenced this pull request Nov 27, 2026
…bases

aurora-wip gained #1158's AGX3CFfsHalfSourceZeroExtends test next to this
branch's AGX3CCompilePlacesPreambleLoadBasesLow in
test-native-form-regressions.cpp. Keep both tests; no code conflict.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
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.

2 participants