Repository navigation
asahi: promote loop-weighted M5 select/FMA constants and reuse rodata - #1564
Conversation
Signed-off-by: Erik Bourget <erik@ebourget.net>
The mask searches cover every compare-select operand M5 reads from the uniform file, so the per-source hooks were unreachable there. The FCMPSEL one still promoted a first comparand on G18G, which keeps its own select forms. Remove both hooks. Two constants of one value share a uniform, which could turn an unordered LTN/GTN select into a tied min/max with a different NaN result. Refuse that, using the shared tied min/max predicate. Test every reversed ICMPSEL condition, the G18G comparand, the NaN case, and that late rodata reuse compares the whole word. Signed-off-by: DjDeveloperr <hey@djdev.me>
|
We carry this PR in our unified portable daily Mesa build across J716c (M5 Max, T6050), J713 (M4 Air, T8132), and J313 (M1 Air, T8103). Loop-weighted constant promotion for M5 Verified across J716c, J713, and J313 (desktop + Vulkan CTS smoke, zero GPU errors). |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: FINISH, then merge, at c8e980ef281c. Only hardware rows are missing; no open code finding. We pushed a small fix commit on top of 8bf7dce78d1a, so this still needs an approval from someone other than DjDeveloperr, or an admin merge.
Blockers: rows at this head: J714s (M5 Pro, G17S) CTS plus a perf A/B, and a no-regression run on J773g (M4, G16G) and J700 (A18 Pro, G17P). We are queuing all three on our Macs; nothing for you to do.
Fixed in c8e980ef281c (plain commit, 69 lines out, 7 code lines in, one test):
agx_opt_promote_constants.cconstant_use_accepts_uniform(): the newFCMPSELline has no effect on M5, because the mask search already covers it. It did promote on G18G: 286 GTA V vertex shaders changed on M6, although the description says selects stay off there. Removed, together with theICMPSELline that the mask search also replaces.(x LTN c) ? x : c'with two constants of one value became a tied min/max after promotion, which returnscinstead of the NaN.fmin/fmaxalways arrive tied, so as far as I can see no shader reaches this today. It now uses the existingagx_fcmpsel_is_tied_minmax()for both checks.- One test: every reversed
ICMPSELcondition (the signed pair was not covered), the G18G comparand, the NaN case, and the late round comparing the whole constant and keeping its base. It fails on8bf7dce78d1aand on each of these broken again.
Shader statistics at c8e980ef281c equal 8bf7dce78d1a for all 26,443 GTA V executables on G17S and 4,429 each on G16G, G17P and G13X.
Checked: the encodings each promoted form uses, NaN, signed zero and denormals, 16/32 bit, the retry path, a full uniform file, rodata reuse, loop weights on AGX2/AGX3B. The G18G gate is the emit_agx3d ISA bit. No Apple material, no chip gate, commits and sign-offs fine. I corrected the Risk line: M6 does get the FMA pairs, modifier folding, late rodata reuse and loop weights (328 of 12,720 GTA V executables change, 300 shorter, 6 longer), only the select promotion is off.
Evidence and notes
- x86-64, asserts on,
agx_tests: basee4346bdb3a551,971 passed,8bf7dce78d1a1,973,c8e980ef281c1,974, 1 skipped each. asahi, poly and vulkan suites: 464 ok, 0 failed on base and8bf7dce78d1a; 463 ok and one timeout under load onc8e980ef281c(borealis-sync-runner, passes 3 of 3 on its own). - 400,000 random shaders (M5, G18G, AGX3B, AGX2; push counts up to 512; 81 million evaluations with NaN, ±0, denormals, ±Inf, equal and opposite inputs, retry rewrite included): 0 wrong values apart from item 2, 0 promoted constants copied back to a register. 1.2 million select and 250,000 FMA forms the SSA query admits all pack with random registers, lifetimes and waits.
- Mutations: 35 changes to the new rules at
8bf7dce78d1a. 15 fail your tests; of the 20 that don't, 5 change a value: signed reversal, half-word rodata compare, late base reset, inverted tied select,absof a negative literal. The first three are in the new test, the fourth now goes through the shared helper, the last is still untested. The others are equivalent, or only cost a promotion. - Offline, base against head, GTA V fossils:
| executables | changed | instructions | shorter / longer | other | |
|---|---|---|---|---|---|
| G17S | 26,443 | 13,538 | -0.287 % | 10,626 / 1,246 | threads 247 up, 12 down; spills 22,701 to 22,696; uniforms +0.81 %; immediate loads -13.5 % |
G18G (at c8e980ef281c) |
12,720 | 328 | -0.015 % | 300 / 6 | |
| G17P | 4,429 | 6 | -13 | 4 / 2 | |
| G16G | 4,429 | 1 | -4 | 1 / 0 | |
| G15S | 4,429 | 1 | +12 | 0 / 1 | |
| G13X, G14G | 4,429 | 66 | -46 | 28 / 11 | loop immediates -5.5 % |
- A second G17S set (12,897 executables): -0.318 %, 5,492 shorter, 465 longer, threads 211 up, 18 down.
- Nearly all of the G17S change is the float select (about 25,800 of the 26,676 instructions saved, and most of the longer ones: one fewer instruction before register allocation, then extra copies). FMA pairs -385, left-constant integer select -61, loop weights 21 executables; the literal folding changes none of this set.
- Compile cost, user instructions over 400 graphics and 60 compute pipelines: G17S +0.06 %, G16G and G13X +0.02 %.
- Performance: instruction counts are not a speed claim. The Cyberpunk and replay numbers ran on
e6e80f1b2ca3, which is not published, and the Cyberpunk one is a single run per arm (+0.54 %). The J714s A/B decides whether this is a measured win or a merge without an fps claim. - Your CTS rows: the groups and 15,947 count match CTS 1.4.7.1 (
builtin.function.commonhas 81 there, you list 80). Our rows addfloat_controls,float_controls2andglsl.builtin.precision, which test the NaN, denormal and signed-zero rules of min/max. - Not blocking: the FMA pair replacement is the same 25 lines in both rounds and would fit one helper.
|
J773g (Apple M4 Mac mini,
|
J700 (MacBook Neo, A18 Pro, G17P B1): PASS at
|
| Part | Result |
|---|---|
| CTS, the recipe's 31,771 cases | 31,771 of 31,771 compared: 26,332 Pass and 5,439 NotSupported on both arms, 0 status differences |
| GPUBench, 42 points, 6 ABBA rounds (264 runs) | 0 points outside the base spread. One point was outside after three rounds and not after six, so the extra rounds it earned decided it |
| Compiled code | the PR does change compiled code here: 5,932 shader parts on each arm, 2 only in the base and 2 only in the head |
| Kernel log | 0 GPU-side lines, 0 WARN |
Caveats: the J700 was hot (117 C hottest sensor) with a cooling device active and the CPU frequency caps moving through the run, in both arms. The row compares arms inside that. It says no regression; it isn't a speed claim (the compile-time changes in the recipe's x86 data aren't measured on hardware here).
|
J714s (M5 Pro, T6050, G17S B1, AGX3C, stock |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: clean at c8e980ef281c, merging. A second, independent read of the pushed commit found nothing.
Checked
- The two removed per-operand lines are covered: the integer-select one by the mask search, with the same encoder query; the float-select one is new in this PR and does nothing on M5 that the mask search doesn't. G18G keeps no select promotion, as on base.
agx_fcmpsel_is_tied_minmax()in both rounds, and the equality check before and after promotion: two constants in one uniform can't turn an unordered select into a min/max. While counting uses, every operand probes the same slot, so the check can only refuse a promotion there, not allow a wrong one.- Reversed
ICMPSELconditions, the late round's constant reuse, and the literalabs/negfolding. - None of the files changed on
aurora-wipsince the merge base are in this PR. #1567 and #1568 change shift masks, range bounds and shift packing, not constant promotion or selects.
Merge tree: ae6d93c0a130 (aurora-wip 1d87219a0716, with #1565, + this head). x86-64, asserts on, drm-shim: asahi + poly + vulkan 465 ok, 0 failed, 1 skipped; agx_tests 1,979 passed, 1 skipped (three more than without this PR). Run on our own machine, not hosted CI.
Rows: J773g, J700 and J714s at this head, 31,771 CTS cases each, 0 differences; GPUBench on J714s (45 configs) shows no win and no regression. So this merges without an fps claim from us.
What: Weight constant-promotion priority by loop nesting depth (
1 << (3 * depth)) so hot loop constants win uniform slots over cold outside-loop constants when the uniform file fills, promote M5 (AGX3C) constants directly into native uniform-operandFCMPSEL(including tiedfmin/fmax), canonicalized left-constantICMPSEL, and pairedFFMA(R*U+U/R.neg*U+U) instructions, fold literal modifiers when materializing modified M5 FMA immediates, and let the late M5 float promotion round reuse already-uploadedrodataconstants.Tested: J716c M5 Max (
G17C), J713 M4 Pro (G16G), and J313 M1 (G13G) at8bf7dce78d1a(Borealis vse4346bdb3a55on unified daily kernel7.3.0-daily2+): 15,947 Vulkan CTS cases each (ssbo,glsl.operator.*,glsl.builtin.function.common.*,spirv_assembly.*.opselect.*) — 15,860 pass / 0 fail / 87 not supported, 0 diffs, 0 GPU errors on all three Macs; hostagx_tests1,973/1,973 pass (1 skipped, same as base).Risk: two-way door · all Macs (loop-depth weighting runs on AGX2/AGX3B/AGX3C; new FMA constant promotion, modified-FMA modifier folding and late-round
rodatareuse apply toAGX3C, G18G included; select constant promotion applies to M5 only, notemit_agx3d/ G18G).Not yet: J716c 60,838-case
computeCTS, 4-round Cyberpunk replay screen, and 1+1 Cyberpunk 2.5 T2 A/B ran one6e80f1b2ca3prior to adding the retry-path (!ctx->agx3_reg_float_consts) and FP32 normal-only swap guards in8bf7dce78d1a(normal-path finite-normal shaders are unchanged); G18G hardware was not tested.Details
agx_opt_promote_constants.c): Generalizedbuild_in_loop_map()tobuild_loop_depth_map()(depth capped at 4) and replaced flat per-use counts withuint64_t weighted_usesincremented by1u << (3u * depth)(1,8,64,512,4096), preservingAGX3B's in-loop half-float uniform exclusion and inline-blendg17p_rodata_hintcompatibility.ICMPSELconstant promotion: Exportedagx3_m5_isel_native_uniform()(excludingemit_agx3d) and addedm5_isel_best_mask()soagx_opt_promote_constants()promotes single or multi-constant native 32-bitICMPSELoperands and canonicalizesconst op regtoreg op' uniform(reversingULT/UGTandSLT/SGT) directly during promotion.FCMPSELconstant promotion: Exportedagx3_m5_fcmpsel_native_uniform()(querying the sharedagx3_m5_fcmpsel_gpu1_desc()+agx3_alu_fcmp_select32_gpu1()encoder) so Borealis promotes constants into general 1- and 2-uniformFCMPSELforms as well as tiedfmin/fmax(LTN/GTN). Left-comparand tiedfmin/fmax((C, x, C, x)) is canonicalized to(x, u, x, u)only for finite normal FP32 constants (excluding±0.0, subnormals,±Inf, andNaN) and skipped on theagx3_reg_float_constsretry path so retry'sLE/GErewrite preservesNaNbehavior.FFMApromotion and modifier folding: Exportedagx3_m5_float_native_uniform()and addedm5_constant_fma_pair()in both rounds to promote(multiplicand, addend)constant pairs into nativeR*U+UandR.neg*U+Uforms. Inagx3_lower_m5_modified_fma_immediates(), foldedliteral.absandliteral.negdirectly into the decoded 32-bit float bit pattern (& 0x7fffffffu,^ 0x80000000u) so the late M5 float round can promote unmodified constants such asR*R + (-1.0f).rodatareuse: Inagx_opt_promote_m5_float_constants(), scan already-uploaded aligned entries inctx->rodatabefore allocating new uniform slots (including whenpush_counthas already reached512), and continue past oversized constants instead of stopping early onnew_count > max_uniforms.Evidence
Exact-head host tests (
8bf7dce78d1a)agx_tests: 1,973 passed, 0 failed, 1 skipped (NativeFMA.ExactDyadicOracle, same as basee4346bdb3a55), including new unit testsAGX3UniformALU.M5LoopWeightedConstantPromotionAndRodataReuseandAGX3UniformALU.M5PromoteIselLeftConstantAndFcmpselAndFmaPair(covering loop priority,push_count == 512rodata+ FMA-pair reuse, left-constantICMPSEL+ G18G exclusion, general and tiedFCMPSELwith±0.0/subnormal/NaN/retry guards, pairedFFMA, and modified-FMA literal modifier folding).Exact-head Vulkan CTS A/B (
e4346bdb3a55.so d1f6bd527e89vs8bf7dce78d1a.so 07ad779abf17, kernel7.3.0-daily2+,aurora-cts-ab)Suites:
ssbo(12,225),dEQP-VK.glsl.operator.*(3,630),dEQP-VK.glsl.builtin.function.common.*(80),dEQP-VK.spirv_assembly.instruction.*.opselect.*(12).Additional J716c verification on
e6e80f1b2ca3(.so 8c222f1df107vse4346bdb3a55.so d1f6bd527e89)compute+glslCTS (aurora-cts-ab, 64,548 cases): 32,855 pass, 24 pre-existing fail, 198 pre-existing internal error, 31,471 not supported on both arms — 0 diffs after retry, 0 GPU errors.shaderdbcensus (e4346bdb3a55vse6e80f1b2ca3):-3,629instrs,-3,533ALU,-34,790code bytes,-3,179native ldimm,-587loop immediates,-6loop uniform copies; 19 occupancy gains vs 2 losses.replay-ab.py,7.3.0-daily2+):fragment_ms:8.492±0.046 → 8.437±0.035 ms(-0.65%,t = -2.7)compute_ms:18.533±0.102 → 18.494±0.089 ms(-0.21%,t = -0.8)sum_ms:30.491±0.148 → 30.398±0.112 ms(-0.30%,t = -1.4)replay_fps:24.171±0.132 → 24.207±0.112(+0.15%,t = +0.6), 0 GPU errors.run-ab.py,7.3.0-daily2+,cur-fex-main-vkmain, 1+1 A/B):d1f6bd527e89):55.36 FPS(min46.36,V=2.09 ms F=6.68 ms C=17.37 ms)8c222f1df107):55.66 FPS(min46.99,V=2.09 ms F=6.61 ms C=17.25 ms),+0.30 FPS (+0.54%), 0 GPU faults.