perf(shader): eliminate quadratic scans in unneeded_edges and PrimMaskUses #240
No reviewers
Labels
No labels
accessibility
bug
claimed
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
tester report
urgent
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LakshanSivakumar--Native-Victory-macOS!240
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@Sheffy007 on GitHub · 2026-11-27 03:14 UTC · original
Sheffy007:perf/shader-pixel-translation-blowups→main· +275 −117 · 4 files · 1 commits · merged 2026-11-27 03:56 UTCAddresses 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 policye89f17dc9bto88ec6f4b22@LakshanSivakumar on GitHub · 2026-11-27 03:23 UTC · original · requested changes
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.@LakshanSivakumar on GitHub · 2026-11-27 03:56 UTC · original · approved these changes
Reviewed and tested together with the other open PRs on main (macOS x86_64 workspace tests, the setup shell tests, and Windows clippy). Thanks!