perf(shader): eliminate quadratic scans in unneeded_edges and PrimMaskUses #240
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/240"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-27T03:14:31Z.
Addresses the recent 46–48 KB pixel shader translation slowdown noted on #180 (tracked under #15):
Lower::unneeded_edges(crates/victory-shader/src/emit/lower.rs):Once guessed wave32 pixel shaders began reaching
Lower::fill_phis(df21edf), a 46–48 KB pixel shader with hundreds of sequential per-lane merge blocks and dozens of live SGPRs (descriptors, root constants, loop counters) startsunneeded_edgeswith thousands of intermediateReg::S(_)SSA phis that have no direct instruction reads in their block. Iterating blocks top-down (0..p.blocks.len()) while invalidity propagates backward from the final consumers removed one block layer per outer pass, runningO(B^2 * S)bools.meetevaluations andVecallocations.dead_relay(b, n, e)per(block, pred, succ)CFG triple sost.bools.meetruns at most once per CFG step rather than once per SGPR phi per iteration.O(B * S)time.io::PrimMaskUses(crates/victory-shader/src/io.rs,graphics.rs,lower.rs):Since
dc5223b,graphics::inferprobes every live entry SGPR instart..32foris_prim_mask_only(in addition toio::ps_prim_maskandLower::inputs). When entry SGPRs are spilled viav_writelane_b32into a shared VGPR carried across hundreds of blocks and phis, each popped(vv, lane)scanned every block, phi, and instruction in the program (plus full-program scans forsccandm0consumers).PrograminPrimMaskUsesand reuse it across entry SGPR checks ingraphics::infer,io::ps_prim_mask, andLower::inputs.Tests & Verification
emit::lower::tests::unneeded_edges_propagates_across_deep_sgpr_phi_chains_without_quadratic_scans(160 sequential per-lane diamonds carrying 32 SGPRs + anunneeded_edgesmask).io::tests::prim_mask_uses_visits_spills_and_phis_linearly.cargo test -p victory-shader -p victory-gpu -p victory-metal -p victory-hle -p victory -p xtaskcargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warningscargo clippy --workspace --all-targets --all-features --target x86_64-pc-windows-gnullvm -- -D warningscargo xtask policyImported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T03:23:33Z.
Review: CHANGES_REQUESTED
Thanks for the speed-up. It conflicts with main, though:
2fa17f16(landed just before this) changed the same per-read test inunneeded_edges. It now also acceptss_andn2/s_orn2by EXEC (keeps_exec), and it reads EXEC in another block only when neither block is on a cycle (bb == b || !self.on_cycle(b) && !self.on_cycle(bb)). Your version of that closure keeps onlyinst.read(Reg::S(EXEC)), so a plain merge would drop both rules. It also conflicts in docs/native-host.md.Could you merge main and rebuild the indexing on top of the new closure, keeping
by_exec/keeps_execand theon_cyclefilter as they are? Please also confirm the dumped-corpus translate counts are unchanged before and after (main reports 7,879 pixel shaders and 24 lane-mask join refusals), since this is meant to be a pure speed-up.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T03:56:45Z.
Review: APPROVED
Reviewed and tested together with the other open PRs on main (macOS x86_64 workspace tests, the setup shell tests, and Windows clippy). Thanks!