Repository navigation
agx: keep range bounds per implementation in two late passes - #1567
Conversation
nir_unsigned_upper_bound() caches by SSA index, and every implementation numbers its defs from zero. agx_nir_opt_bitfield_slices() used one table for the whole shader, so a bound found in the main shader could be used for an unrelated value of the preamble: ushr(ishl(x, a), c), and the imadshl_agx form of the shift, lost the truncation of x << a, which gives a wrong value. Start every implementation with an empty table, like agx_nir_lower_address() and agx_nir_lower_bitfield_u2f(). Fixes: 408af60 ("hk,agx: prove uniform compute loop bounds and fold AGX3 bitfield slices") Signed-off-by: DjDeveloperr <hey@djdev.me>
agx_nir_opt_redundant_shift_masks() used one range table for the main shader and the preamble, but nir_unsigned_upper_bound() caches by SSA index and every implementation numbers its defs from zero. A bound found in the main shader, such as that of a local invocation index, could answer for an unrelated value of the preamble. Its & 15 or & 31 was then removed, whether it masked a shift count or decoded a field of a uniform. Give every implementation a table of its own, and declare the pass in agx_nir.h so it can be tested with two implementations. Fixes: fc22daf ("agx: fold constant-XOR shuffles, enable 16-bit shuffle_xor, and strip redundant late shift masks") Signed-off-by: DjDeveloperr <hey@djdev.me>
RyanTheTide
left a comment
There was a problem hiding this comment.
Reviewed b7fe9e7. Both passes isolate range entries by implementation, so matching SSA indices in the main shader and preamble cannot share a cached bound. The reported two regressions fail against base, and the rest of the host suites retain their outcomes. Hardware coverage is pending.
|
J773g (Apple M4 Mac mini, Verdict: PASS.
1.
|
J700 (MacBook Neo, A18 Pro, G17P B1): PASS at
|
| Run | Shaders | Wrong | No pipeline |
|---|---|---|---|
| base (1st) | 600 | 140 | 0 |
| head (1st) | 600 | 0 | 0 |
| head (2nd) | 600 | 0 | 0 |
| base (2nd) | 600 | 140 | 0 |
- The row reaches the bug: the base got the same 140 of the 600 self-checking shaders wrong both times, and the head got all 600 right both times. That is the same base count that the J773g reports.
- CTS: 384 cases on each arm (the recipe's list), 384 Pass on both, 0 differences.
- Health: 0 GPU-side kernel lines, 0 WARN or BUG lines.
Not covered: no performance row (no GTA V or llama binary changes, per the recipe), and the run-time internal shaders.
|
J714s (M5 Pro, T6050, G17S B1, AGX3C, stock |
What:
agx_nir_opt_bitfield_slices()andagx_nir_opt_redundant_shift_masks()each used one range table for the main shader and the preamble.nir_unsigned_upper_bound()caches by SSA index and every implementation numbers from zero, so a bound found in the main shader could answer for an unrelated value of the preamble and give a wrong result. Each implementation now starts with an empty table, as inagx_nir_lower_address()andagx_nir_lower_bitfield_u2f().Examples on
aurora-wip:(p.v[6] & 31u)of a push constant loses its mask in the G16G constant program because the main shader shifts bygl_LocalInvocationIndex & 15u;ushr(ishl(x, 12), 4)of an unboundedxbecomesx << 8.Tested: Local only at
b7fe9e7c2486(base80a0ac5d0cdd), no Mac yet. Assert-enabled x86-64: asahi, poly and vulkan suites 465 ok, 0 failed, 1 skipped, before and after;agx_tests1971 passed before, 1973 after (the two new tests), 1 skipped. Both new tests fail on the base.Risk: two-way door · M1, M2, M4, A18 Pro, M5 (and M3 where the kernel lets a compute shader form a constant program). A shader can only change where the two tables disagree. Borealis forms no preamble on M6, so it is not affected there.
Not yet: hardware rows on M4 (J773g), A18 Pro (J700), M5 Pro (J714s) and M2 Pro (J414s): the self-checking shaders below, base and head, plus
dEQP-VK.glsl.operator.binary_operator.*shifts and masks.Details
fc22dafe903), merged 2026-12-02 02:30 UTC. Bitfield slices since hk,agx: prove uniform compute loop bounds and fold AGX3 bitfield slices #1495 (408af606be8), merged 2026-12-02 13:29 UTC; agx: sink epilogue defs past high-pressure loops and fold imadshl bitfield slices #1496 added theimadshl_agxform.& 15,& 31, a shift count from a local or subgroup invocation index; for the slices a shift left then right), and a preamble value with the same SSA index whose mask or truncation matters. Out of reach without a preamble: G18G, and G15 without a compute constant program. The slices pass runs on AGX3 only; the masks pass runs everywhere.f5ff0023b6ca) without the fusion it was written next to, and the helper text is the same. Merging the two has two conflict hunks inagx_nir_lower_shared_bitsize.c, both "nothing on one side": take agx: fuse disjoint shifted ior and masked shifts into imadshl_agx #1559's side (git merge -X theirs, with agx: fuse disjoint shifted ior and masked shifts into imadshl_agx #1559 as the merged branch). The file is then identical to agx: fuse disjoint shifted ior and masked shifts into imadshl_agx #1559's (blobae3a46f04e30), and the merged tree passesagx_tests(1977 passed, 1 skipped). agx: interleave provably disjoint shared-memory stores before workgroup barriers #1560 merges cleanly.aurora-wiphas the bug today and agx: fuse disjoint shifted ior and masked shifts into imadshl_agx #1559 still owes its rows. If agx: fuse disjoint shifted ior and masked shifts into imadshl_agx #1559 lands first, the same rule applies: keep its side. Nothing in agx: fuse disjoint shifted ior and masked shifts into imadshl_agx #1559's own code changes either way.agx_nir_opt_shared_byte_offsets(),agx_nir_opt_g13x_shared_offsets()andagx_nir_opt_shared_vec2()only ask about shared-memory accesses, which the preamble has none of;agx_nir_opt_iv_divmod()andagx_nir_opt_nonneg_idiv()run before a preamble exists.Evidence
Compiled with each driver's noop shim. A probe build runs both tables side by side, compares every decision, and hashes every compiled binary; the arms differ only in which table is used.
MUL_MATq4_K/q6_KMUL_MATq4_K/q6_KMUL_MATq4_K/q6_KThe unmodified base and head drivers agree as well: 0 of 26,447 GTA V executables change on G17S and 0 of 22,208 on G16G. No compiled GTA V or llama.cpp binary changes; the generated shaders show that ordinary code reaches both bugs. The other 249 of 600 do not compile on G17S and G17D, before or after this change, for another reason: the AGX3C packer refuses a right shift by a 16-bit count.
Failing on
80a0ac5d0cdd, passing atb7fe9e7c2486:SharedByteOffsets.BitfieldSlicesRangesStayInTheirImpl(both theishland theimadshl_agxform):0xffffff00instead of0x0fffff00,0xfffffffcinstead of0x3ffffffc.AGX3SubgroupShuffleXor.ShiftMaskRangesStayInTheirImpl: the preamble'siand(x, 31)is gone.Smallest whole-pipeline example, G16G constant program before and after (
NIR_DEBUG=print_cs):