Repository navigation
asahi,hk: speed up multi-block liveness, NIR opt loop, register demand, and Borealis post-lower - #757
Conversation
|
Non-author review of 9658c0f (all 5 commits, read against base 7248af9). Verdict: no blocker. I didn't do my own build or run; this review is from reading the code. Points below. Checked and holding
Points
|
|
Review at 9658c0f. Commits 1-3 and the opt-loop half of commit 4 look semantically identical to me. Commit 5, and two of commit 4's gates, change the pass pipeline, so "bit-identical" doesn't hold for them:
|
9658c0f to
c7b4d60
Compare
|
Review at c7b4d60. Re-read the six commits and range-diffed them against 9658c0f (same base 7248af9). I didn't build or run anything. Status of the earlier points:
New in c7b4d60: the stats aren't only reorders. g13g gpubench-stress.fault.comp goes from 12 to 14 uniforms, g17s deferredshadows CS goes 12 -> 13 instrs and 23 -> 31 GPRs, and 69/110 g13g DBs reorder. This is a compile-time trade, so please give the commit its own compile-time number (with 53578b1 as the baseline) and say why the GPR/uniform regressions are acceptable, or tighten the condition to avoid them. No chip/board/fw gates, env knobs or agent trailers in any commit. The only trailers are Diljit's own Signed-off-by. Verdict: NITS on the code. Merge waits on rows:
|
|
Tested
|
Bare-Metal M5 Pro (
|
| CTS Group (non-mesh) | Passed | Failed | Not Supported |
|---|---|---|---|
dEQP-VK.subgroups.basic.* (46/46) |
41/46 | 0 | 5 |
dEQP-VK.subgroups.vote.* (182/545) |
132/182 | 0 | 50 |
dEQP-VK.subgroups.ballot.* (15/15) |
14/15 | 0 | 1 |
dEQP-VK.subgroups.shuffle.* (249/6,202) |
177/249 | 0 | 72 |
dEQP-VK.subgroups.quad.* (247/2,215) |
171/247 | 0 | 76 |
dEQP-VK.subgroups.clustered.* (238/2,609) |
169/238 | 0 | 69 |
dEQP-VK.subgroups.arithmetic.* (290/7,827) |
209/290 | 0 | 81 |
Total (non-mesh, -Db_ndebug=false) |
913/1,267 | 0 | 354 |
- Assertions / aborts:
0 - GPU faults (
dmesg):0(delta = 0).
…ness
Precompute per-block dense gen/kill bitsets once in agx_compute_liveness()
when num_blocks * BITSET_WORDS(alloc) <= 262144, solve the fixed-point with
word-wide bitset operations instead of per-iteration sparse bitset dup/merge
and repeated instruction walks, then run a single final backwards pass per
block to mark src.kill and populate block->live_{in,out}.
Verified bit-identical with a debug assert comparing the final backwards pass
against the solved live_in bitset.
Signed-off-by: Diljit Singh <hey@djdev.me>
…er cache liveness Precompute per-block 256-bit register gen/kill summaries once for blocks without fused breaks in postra_liveness() and physical_liveness(), replacing repeated per-iteration reverse instruction walks with word-wide bitset updates while falling back to the per-instruction walk for fused-break blocks or non-unique block indices. Signed-off-by: Diljit Singh <hey@djdev.me>
…gx_calc_register_demand Use compact uint8_t stack arrays (2 KiB total) for widths/classes in agx_calc_register_demand() when ctx->alloc <= 1024 and compute agx_values_read(ctx) lazily only when an AGX_OPCODE_ENTER_QUERY_M5 instruction is actually encountered. Signed-off-by: Diljit Singh <hey@djdev.me>
…ate redundant late CSE/DCE Track pending passes with a dirty-pass bitmask in agx_optimize_loop_nir(), skipping loop-unroll on loop-free shaders and CF/phi passes on single-block shaders, and narrowing DCE's wake set to passes that can react to dead instruction removal. Also gate redundant pre-fusion and post-optimize nir_opt_cse/nir_opt_dce cleanups in agx_optimize_nir() and agx_compile_shader_nir_internal() on upstream pass progress, preserving the original post-fusion late_progress condition. Signed-off-by: Diljit Singh <hey@djdev.me>
Add a lightweight linear scan (m5_has_mergeable_buffer_words) checking for at least two reorderable 32-bit scalar load_global* intrinsics with alignment >= 4 in some basic block before running nir_opt_cse and m5_merge_buffer_words in hk_lower_nir(). This path is gated on global_loads.storage_result_select (agx_chip_g17p_or_m5) and global_loads.soft_fault, so it is unreachable on AGX2 (G13/G14) and G18G. This commit is not codegen-neutral on G17P: when a shader has no block with two mergeable scalar global loads, it skips the nir_opt_cse pass that previously ran immediately after nir_opt_sink and nir_opt_move. Skipping that post-sink/move CSE avoids re-hoisting expressions back across uses when nothing can merge. Measured across 83 gpubench-foz/vk-synth pipelines + 110 shader-db Fossilize DBs (assert build, vs parent 50999a7): - g13g (AGX2): 0 diffs across 88 + 1,311 shaders (unreachable) - g17s (AGX3C/M5): 0 diffs across 91 + 1,083 shaders - g18g (G18G): 0 diffs across 23 + 427 shaders (unreachable) - g17p (AGX3B): 0 diffs across 9,308 Fossilize DB shaders; 3 diffs in 83 pipelines (all ray-query compute shaders where lowered_complex is set): - rt.rays.{coherent,incoherent} (790ddb717d3f6502): 531->532 instrs, 5042->5052 B, 71->63 GPRs - gpubench-stress.rq.comp (dd862e831f1114ee): 368->369 instrs, 3620->3624 B, 71->63 GPRs Release (-Db_ndebug=true) compile-time median vs parent on g17p: - vk-mini (39 foz, 5x interleaved): 1.552s -> 1.487s (-4.17%) - vk-fossils (110 foz, 3x interleaved): 37.844s -> 36.211s (-4.32%) Signed-off-by: Diljit Singh <hey@djdev.me>
c7b4d60 to
d6bf671
Compare
|
@RyanTheTide Thanks for the detailed review at I benchmarked Commit 6 (
Because C6 does not earn its compile-time trade on AGX3 and caused the
This cleanly resolves all remaining items from
Assisted-by: LLM (Antigravity:Gemini 4 Neon) |
|
Review at d6bf671. R3 drops c7b4d60 and rebases the other five onto 2c35ed6. range-diff: 2-4 are identical. 1 only moves the
New code: d6bf671 only gates the existing Verdict: APPROVE on the code. Merge waits on:
|
Bare-Metal M5 Pro (
|
| CTS Group | Passed | Failed | Not Supported |
|---|---|---|---|
dEQP-VK.ubo.* (491 evenly-sampled of 13,240) |
491/491 | 0 | 0 |
dEQP-VK.subgroups.basic.* (non-mesh, 46/46) |
41/46 | 0 | 5 |
dEQP-VK.subgroups.vote.* (non-mesh, 182/545) |
132/182 | 0 | 50 |
dEQP-VK.subgroups.ballot.* (non-mesh, 15/15) |
14/15 | 0 | 1 |
dEQP-VK.subgroups.shuffle.* (non-mesh, 249/6,202) |
177/249 | 0 | 72 |
dEQP-VK.subgroups.quad.* (non-mesh, 247/2,215) |
171/247 | 0 | 76 |
dEQP-VK.subgroups.clustered.* (non-mesh, 238/2,609) |
169/238 | 0 | 69 |
dEQP-VK.subgroups.arithmetic.* (non-mesh, 290/7,827) |
209/290 | 0 | 81 |
| Combined Non-Mesh Subgroups | 913/1,267 | 0 | 354 |
gpubench-vk Graphics UBO / MDI / Shadow Smoke (-Db_ndebug=false)
-
render.bindless_ubo(d=1,d=4):status=ok,valid=true(crc=57e7bedd) -
render.mdi(d=4):status=ok,valid=true(crc=06f8412a) -
render.shadow(d=2):status=ok,valid=true(crc=c0fb9993) -
Assertions / aborts:
0 -
GPU faults (
dmesg):0(delta = 0).
|
Merged into Gates verified at exact head
Assisted-by: LLM (Google:Gemini 4 Neon) |
|
Thanks for the review and approval, @RyanTheTide! Updated the PR body text to match the commit message ( Assisted-by: LLM (Antigravity:Gemini 4 Neon) |
Summary
Rebased cleanly onto
aurora-wip(2c35ed624c3, after#747merged) with the 5 clean Asahi/Borealis compile-time optimization commits (5baf663a0cd..d6bf67186ce):5baf663a0cd—asahi/compiler: use dense block gen/kill bitsets for multi-block liveness(uint64_t)num_blocks * words <= 262144(~4 MiB cap), solving multi-block liveness via word-wide bitset ops after the single-block fast path, then populatingsrc.killand sparse live sets in a single final backwards pass.bf21a1a9cfa—asahi/compiler: precompute 256-bit block gen/kill summaries in register cache livenessagx_opt_register_cache.cso worklist iterations avoid re-walking instructions.9219018d1c6—asahi/compiler: avoid heap allocations and eager agx_values_read in agx_calc_register_demanduint8_tdemand arrays (capped at 1024 withstatic_assertonRA_CLASSES) and skipsagx_values_read()when!remat.50999a7e650—asahi/compiler: use dirty-pass bitmask in agx_optimize_loop_nir and gate redundant late CSE/DCEagx_optimize_loop_nir()(documenting reassociate progress) and gates pre-fusion cleanup viapre_fuse_dirty(includingany_flattened) while keeping the post-fusion block underif (late_progress).d6bf67186ce—hk: pre-filter m5_merge_buffer_words before running pre-merge CSEm5_has_mergeable_buffer_words()before runningnir_opt_cse+m5_merge_buffer_wordsinsidehk_lower_nir().global_loads.storage_result_select(agx_chip_g17p_or_m5) andglobal_loads.soft_fault, so this commit is unreachable on AGX2 (G13/G14) andG18G.G17P: skips post-sink/movenir_opt_csewhen no block has two mergeable scalar global loads, improving 3 ray-query compute shaders (71 -> 63GPRs) with+1 instr, +10 B, -8 GPRson the twort.rays.*shaders and+1 instr, +4 B, -8 GPRsongpubench-stress.rq.compacross all 97,428 tested shaders.(Note: R2's Commit 6
can_post_lowerwidening was dropped in R3 after release-Db_ndebug=truebenchmarking showed it was+2.80%slower ong17p110 fossils and+0.17%ong17swhile causing theg17sdeferredshadowsCS GPR regression andg13gfault.compuniform regression. Dropping it keeps allagx_preprocess_nir_post_lowerandagx_nir_lower_subgroupspaths unchanged and leaves zero regressions.)Per-Commit Exact Output Matrix (
-Db_ndebug=false, exact disassembly / AGX3 binary diff)Rebased verification at exact head
d6bf67186ced3af1dbaa0e66074ac4b8f7ceaee9(baseaurora-wip2c35ed624c3, plus per-commit C1..C4 breakdown previously verified at7248af95852..53578b14549with0 / 97,428diffs at every step):g13g(AGX2) GL / VK-mini / VK-fossilsg17p(AGX3B) GL / VK-mini / VK-fossilsg17s(AGX3C/M5) GL / VK-mini / VK-fossilsg18gGL / VK-mini / VK-fossils2c35ed624c3..50999a7e650(C1–C4 combined)0/21,698·0/88·0/1,3110/21,671·0/139·0/9,3080/21,490·0/91·0/1,0830/20,099·0/23·0/4270 / 97,428real diffs,0base nondet,0new fails50999a7e650..d6bf67186ce(C5m5_has_mergeable_buffer_words)—·0/88·0/1,311—·3/139·0/9,308—·0/91·0/1,083—·0/23·0/427g13g/g18gunreachable (agx_chip_g17p_or_m5);g17p3 diffs all improve71->63GPRs (rt.rays.{coherent,incoherent}531->532instrs5042->5052B,gpubench-stress.rq.comp366->367instrs3612->3616B)Verification
DEFAULT_BRANCH=aurora-wip ./.github/aurora/agent-policy.sh pr HEADclean atd6bf67186ced.-Db_ndebug=false,fedora-mesaciatd6bf67186ced):mesa:agx_tests,mesa:hk_pack, and all compiler/Vulkan/gallium-blit/xfb/submit tests PASS (233/236, only 3 unrelated headless-containerasahi-egl-priority-*tests fail), plus--suite poly --suite nir7/7PASS.-Db_ndebug=true) compile-time delta for C5 (m5_has_mergeable_buffer_words) vs C4 ong17p:vk-mini(39.foz, 5x interleaved median):1.552s -> 1.487s(-4.17%)vk-fossils(110.foz, 3x interleaved median):37.844s -> 36.211s(-4.32%)G17P, AGX3B) exact-head assert-enabled (-Db_ndebug=false) Borealis CTS (d6bf67186ced,MESA_SHADER_CACHE_DISABLE=true,sleep_guard=active,pmu=30 00,kfault_delta=0,avc_delta=0):dEQP-VK.ubo.*:8,944 Pass / 4,296 NotSupported / 0 Fail(13,240/13,240,35s)dEQP-VK.ray_query.builtin.*:516 Pass / 0 Fail(516/516,26s) — exercises C5's ray-query compute shadersdEQP-VK.subgroups.basic.*:70 Pass / 0 Fail(70/70)dEQP-VK.subgroups.ballot.*:23 Pass / 0 Fail(23/23)dEQP-VK.subgroups.quad.*:2,515 Pass / 900 NotSupported / 0 Fail(3,415/3,415)dEQP-VK.subgroups.shuffle.*:7,042 Pass / 2,520 NotSupported / 0 Fail(9,562/9,562)dEQP-VK.subgroups.clustered.*:2,525 Pass / 833 NotSupported / 0 Fail(3,358completed before 180s mesh shard timeout)dEQP-VK.subgroups.ballot_broadcast.ray_tracing.subgroupbroadcast_u64vec4(agx_compile.cstack_size < INT16_MAXassert) reproduces identically (rc=134) on base7248af95852andd6bf67186ced.dEQP-VK.subgroups.vote.frag_helper.*hits the pre-existingagx_compile.c:14282agx_assert_post_lower_invariantsassert on native 1x32nir_intrinsic_ballotalready onaurora-wip; this PR no longer touchesagx_assert_post_lower_invariantsorcan_post_lower, and we will open a separate 1-commit fix PR for that pre-existing assert.)G17S B1, AGX3C) assert-enabled (-Db_ndebug=false) Borealis CTS (previously verified at R2c7b4d6082a9fwith1,472/1,472dEQP-VK.ubo.*,4/4gpubench-vk, and913/1,267Pass /0Fail across non-meshdEQP-VK.subgroups.*,#issuecomment-7090000460&#issuecomment-7090695418; pre-existing M5 empty-mesh metadata bug fixed separately in merged#765; exact-head R3d6bf67186cedtarball handed off for M5 Pro verification).0 / 20,549byte-identical ong18g(GL + VK-mini + VK-fossils), and Commit 5 (m5_has_mergeable_buffer_words) is gated onagx_chip_g17p_or_m5and unreachable onG18G.G13/G14) note: All 5 commits are0 / 23,097byte-identical ong13g(GL + VK-mini + VK-fossils), and Commit 5 is unreachable on AGX2 (agx_chip_g17p_or_m5).Assisted-by: LLM (Antigravity:Gemini 4 Neon)