Skip to content

agx: take the long AGX3B SMP form for coordinate banks past 60 - #1223

Merged
RyanTheTide merged 1 commit into
aurora-wipfrom
fix/agx3-shadow-texpack
Nov 27, 2026
Merged

RyanTheTide merged 1 commit into
aurora-wipfrom
fix/agx3-shadow-texpack

Conversation

@DjDeveloperr

Copy link
Copy Markdown

What: On AGX3B (G17P), a run of 2D-array shadow samples whose staging bank goes past 60 no longer fails the whole shader. The packer now uses the 20-byte SMP form when the 14-byte form cannot name the bank. This fixes gpubench-gl render.shadow, whose 3x3 PCF fragment had every draw dropped.

Tested: On J700 (Neo, stock 7.3.0-41, isolated Mesa kits, no reboot): render.shadow --verify fails 6/6 on the base and passes 6/6 with the fix. The VK and GL shadow CTS runs on the fix had no new failures. Unit tests fail before and pass after. Fedora CI passes 217/0. There were 0 GPU faults and 0 AVC denials.

Risk: two-way; blast: neo (AGX3B only). The new path runs only where the old code refused to encode, so shaders that already compiled get the same bytes.

Not yet: none.

Details

Root cause

render.shadow's receiver shader samples a sampler2DArrayShadow nine times (3x3 PCF, implicit LOD, constant reference). It uses immediate texture and sampler indices. Each 2D-array comparison claims its own eight-half sampler-private bank (X/Y at +0/+2, reference at +4, layer at +6), so the taps land on banks 0, 8, ..., 64.

On AGX3B, agx3_tex_encode_sample() picks endpoint 3, the 14-byte form, for immediate descriptors. That form's coordinate-bank field only reaches 60. For the ninth tap, agx3_bind_compose() refuses it. agx3_emit_texture_sample() then returns false without naming a gate, so the refusal shows up only as the caller's line (texture_sample ... lod=0 dim=3, dim 3 = 2d_array). The whole fragment program is marked unusable and its draws are skipped (lit_cells_bad=200/200).

Sweeping the encoder over banks 0..252 shows:

  • AGX3B, 14-byte form: banks 0..60, for 2D, 2D-array, shadow and shadow-array alike.
  • AGX3B, 20-byte form (ep4): every bank.
  • AGX3C: every bank already.

Fix

  • agx3_tex_core.c: on AGX3B, if the ep3 compose fails, try ep4. AGX3C's compact comparison, gather and query forms already step up to a longer form the same way. The 20-byte form is grounded:
    • Apple's linked pipelines stage at banks 84..152 with it (test_linked_staging_witnesses).
    • Sparse samples already use it with immediate descriptors.
    • The binder documents Apple's choice as the smallest form that encodes.
  • agx3_pack_binary.c: when the SMP encoding itself refuses, report no SMP form for coord=halfN slot=S, so this class of refusal names itself.

Tests

  • test-agx3-tex-core.c test_sample_upper_coordinate_banks: for 2D, array, shadow and shadow-array samples, bank 60 stays 14 bytes. Banks 64..252 encode in 20 bytes, decode back to the same bank, and keep the other fields unchanged.
  • test-agx3-pack-binary.cpp TextureSample2DArrayShadowPcfReachesBank64: nine G17P fragment 2D-array shadow taps pack. Staging is 72 halves, the last reference is staged at bank 68, and a 20-byte SMP names bank 64.
  • Without the fix, both fail. The packer test reports texture_sample at line 5233, no SMP form for coord=half64 slot=4. With the fix, both pass.
  • Off hardware, before the J700 row: the real GLSL from render.shadow, compiled through gallium on the G17P drm-shim, reproduced the J700 refusal on the base (same s0=reg48.discard x3, s5=reg4.discard). With the fix it links and draws with no refusal.
Evidence

Hardware: J700 MacBook Neo (G17P B1, AGX3B), Fedora 44, stock kernel 7.3.0-41.fc44.aurora.aarch64 (stock.sh identical before and after), SELinux enforcing, system Mesa untouched. The arms ran in the same boot as isolated overlays (LD_LIBRARY_PATH + EGL/VK ICD JSONs) under neohw.

  • Base fd2cb725134 (aurora-wip): kit sha256 342522da...
  • Fix 8f620bc2aea: kit sha256 f3546b26...
  • Both built on fedora with rig/fedora-mbuild.sh, cross, neo-gl-vk.opts.
  • gpubench-gl: the gl_wave2 build from aurora-silicon/gpubench that the Neo GL-gaps rows use.

gpubench-gl --test render.shadow --verify --depths 1

config base fix
depth_only d32f 2048 FAIL lit_cells_bad=200/200 (PCF FS refused) ok, crc c0fb9993 = expected
depth_only d16 2048 FAIL 200/200 ok, c0fb9993
alpha_test d32f 2048 FAIL 200/200 ok, 7be9463a
alpha_test d16 2048 FAIL 200/200 ok, 7be9463a
depth_only d32f 1024 FAIL 200/200 ok, e2fedee4
alpha_test d16 4096 FAIL 200/200 ok, 7be9463a
  • Fix arm stderr: empty.
  • ASAHI_MESA_DEBUG=verify with alpha_test on the fix: ok, crc 7be9463a = expected, no driver messages.

Timing, render.shadow mode=depth_only, ABBA, 3x250 ms runs, us/submit (median):

depth base A1 / A2 fix B1 / B2
1 515.5 / 516.5 899.3 / 899.3
4 382.3 / 382.3 731.0 / 728.9

The base is not doing the same work: it skips the PCF receiver draw because the program could not be encoded. The fix's number is the first real measurement of this workload. Shaders that compiled before are not affected: the long form is tried only after the short one is refused.

CTS on the fix arm

  • VK, dEQP-VK.texture.shadow.{2d,2d_array}.* plus dEQP-VK.glsl.texture_functions.{texture,texturelod,textureoffset}.sampler2d[array]shadow*: 1546 cases, 394 Pass, 1152 NotSupported, 0 Fail, 0 recoveries.
  • GL, KHR-GL46.ext_texture_shadow_lod.* (glcts 1.4.7.1, pbuffer): 15/16 on both arms. The one failure, texture.sampler2darrayshadow_vertex, is already on the base: identical image difference 0.124546 on both arms, 3/3 runs each, no packer refusal on either. It is a separate vertex-stage issue and this change does not touch it.

Health over every slot: 0 kernel GPU-side lines, 0 driver warnings, 0 AVC denials, 0 failed units, no leftover processes, staging removed.

Fedora CI (rig/fedora-mesaci.sh 8f620bc2aea, asahi suite): 217/0.

The PR merges cleanly onto the current aurora-wip tip (only one unrelated hunk in agx3_pack_binary.c changed there).

AGX3B's 14-byte immediate-descriptor SMP form can only name coordinate
staging banks 0..60. Each 2D-array comparison sample claims its own
eight-half bank, so the ninth tap of a 3x3 PCF kernel on a
sampler2DArrayShadow relocates to bank 64, agx3_bind_compose() refuses
the short form, and the whole fragment shader fails closed. That is
gpubench-gl render.shadow on G17P: every draw with the PCF program was
dropped (lit_cells_bad=200/200).

The 20-byte ep4 form carries the full bank field. Apple's linked
pipelines stage at banks 84..152 with it, and sparse samples already use
it with immediate descriptors. When the short form cannot encode the
operands, take the long one, as AGX3C's compact comparison, gather and
query forms already escalate.

Also name the SMP encoding when it is what refuses: the refusal used to
surface only as the caller's line, which reads like an operand-shape gate.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 27, 2026 10:52
@DjDeveloperr

Copy link
Copy Markdown
Author

J773g (M4 Mac mini, G16G B0, AGX3B, second generation) at 8f620bc2aea6, against its parent fd2cb7251346: PASS. The fix restores the dropped shadow draws on G16G, with no regression.

All arms are release overlays built natively on the Mac, on the stock kernel 7.3.0-ARCH-m4mainefed1ae3, with nothing installed and system Mesa untouched. Gallium asahi is loaded through EGL/glvnd vendor JSON; Borealis through VK_DRIVER_FILES.

GL, gpubench-gl --test render.shadow --verify (suite ae90a40, d1):

mode base head
default fail: output check failed, lit_cells_bad=200/200 ok, valid, CRC c0fb9993
alpha_test d32f 2048 fail: output check failed ok, valid, CRC 7be9463a
depth_only d32f 2048 fail: output check failed ok, valid, CRC c0fb9993

On base, Mesa reports: asahi: the AGX backend cannot encode this FS shader … for G16G … AGX3 binary packer refused texture_sample … and then dropping work: the fragment program is unusable. On the head, neither message appears.

VK CTS at 2 workers, 6,253 shadow cases: texture.shadow.*, the glsl.texture_functions.*shadow* cases and the pipeline.*.sampler.* compare/shadow cases.

  • Both arms give 2,221 Pass, 4,031 NotSupported and 1 Fail, with 0 cases that differ.
  • The fail is the same case on both: glsl.texture_functions.texture.samplercubearrayshadow_compute.

VK control, gpubench-vk render.shadow ABBA (us_per_submit, head/base; CRCs equal on all four runs):

row A1 / B1 / B2 / A2 head/base
alpha_test d32f 2048, d1 / d2 1388.89 / 1388.89 / 1395.35 / 1395.35 · 1016.95 / 1016.95 / 1016.95 / 1013.51 1.000 / 1.002
depth_only d32f 2048, d1 / d2 757.58 / 757.58 / 753.77 / 755.67 · 433.53 / 452.49 / 437.32 / 436.05 0.999 / 1.023

The depth_only d2 ratio comes from one outlier run (B1 452.49); the other three agree within 1 %.

GPU health: 0 faults, 0 recoveries and failed 0 errno 0 degraded 0 at start and end.

@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 8f620bc2aea6039a8016e03bafb93a93144e01c8

Blockers: none

Checked:

  • Fallback shape. agx3_tex_encode_sample() only tries ep4 after ep3 has refused, and only on AGX3B with an immediate-descriptor (ep3) sample. Shaders that encoded before get the same bytes. The binder refuses a form that leaves an override field unconsumed or fails a predicate (agx3_bind_compose() -> agx3_compose_known()), so the 20-byte form cannot silently drop the shadow, layer, LOD, offset or wait operands that the 14-byte form carried. A refusal still fails closed.
  • Bank edges, from agx3b_tables.txt form smp 3 14 / form smp 4 20. Field 19 has bit 0 pinned to 0 in both forms. ep3 deposits bits 1..5, so it holds even banks 0..62. ep4 adds bits 6..12. Banks 61 and 63 are refused by both forms, as they were before, so no odd bank can now encode. Bank 62 still takes the short form, and 64 is the first bank to take the long one. (Non-blocking nit: the comment says "0..60". 62 also fits the short form. A test row at 62 asserting 14 bytes would pin the edge.)
  • Length handling. SMP bytes are appended to the emission dynarray as returned, and nothing in the packer assumes a fixed 14-byte SMP size.
  • Decode coverage. Both new tests decode the long form back through agx3_decode(&agx3b_table, ...) and check field 19 and the other operand fields.
  • Tests fail without the fix. I reverted the agx3_tex_core.c hunk on the merged tree and rebuilt. agx3_tex_core then fails at line 1390 (the encode of bank 64), and AGX3PackBinary.TextureSample2DArrayShadowPcfReachesBank64 fails. With the hunk restored, both pass.
  • NO-GATES. The new condition keys on the ISA encoding (AGX_ISA_ENCODING_AGX3B, which selects the encoding table), not on a chip id. AGX3C and AGX3D paths are untouched.
  • Merge and local gate. The head merges cleanly onto aurora-wip a97571c6b2839. The drm-shim build of that merge (x86, -Dbuild-tests=true, asahi + poly suites) passes 338/338, the same as the tip at a97571c6.
  • Hardware rows at this exact head: J700 (G17P, AGX3B) in the body, and J773g (G16G, AGX3B, other generation) in the comment. The change only reaches AGX3B.
Evidence
  • Merged tree 42e4479b = a97571c6 + 8f620bc2: meson test --suite asahi --suite poly, Ok 338, Fail 0.
  • Mutation (ep4 fallback reverted): FAIL line 1390: agx3_tex_encode_sample(AGX_ISA_ENCODING_AGX3B, &d, long_form, &long_len). gtest: [ FAILED ] AGX3PackBinary.TextureSample2DArrayShadowPcfReachesBank64, other bank tests OK.
  • Table rows: form smp 3 14 ... 19[0+1]=0 19[6+4]=0 19[10+3]=0 ... 19[1+3]>0.8 19[4+2]>1.8; form smp 4 20 ... 19[0+1]=0 ... 19[1+3]>0.8 19[4+2]>1.8 19[6+7]>8.0.

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