perf(shader): bound masked-lane work per shader #3550
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3550"
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 boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T13:02:14Z.
What
Fixes #3504. Stray (PPSA02101) takes 146.7 seconds to prepare shader
0x200f780000on currentmain, with nearly all the time inMaskedSelectEliminator::Eliminate. InMaskedSelectEliminator.cpp,MaskedLaneWalk::UnobservedWhereMaskedresets its full program-scaled work limit for every candidate select. The issue's counters show more than 1.2 billion values visited across those repeated walks.Keep the per-walk limit, and add one shared work budget for the entire shader. Charge the budget on both successful and early-failed walks. Once the budget is consumed, later proofs return “not proven”; a select is removed only when the existing proof completes successfully. The pass can leave more selects in the IR, but does not change shader semantics. The result reports the analysis work and budget for regression coverage.
The
agc_masked_selectregressions build a long chain of predicated selects, verify the analysis stops at its per-shader budget and keeps unresolved selects, and verify that a later select is still removed after an earlier masked proof spends part of the budget and conservatively fails.#3391 changes the same pass to prove whole-quad mask implications for GTA V. Its behavior is separate from this per-shader work budget; this PR does not depend on it. The overlap is limited to the shared optimizer and test files, and may require a conflict resolution if either branch merges first.
I could not replay Stray's dumped shaders locally. The reported 146.7-second main result and counters are from the issue report. I asked the issue reporter to compare the two shader requests at 1x, 8x and 32x the per-walk limit, including SPIR-V validity; those title-specific measurements and budget tuning remain pending.
Tested
agc_masked_select_tests.agc_masked_select— passed three consecutive runs.python3 tools/check_conventions.py --base upstream/main— passed.git diff --check— passed.Checklist
main; no open PR implements this per-shader budget behaviorImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T13:27:51Z.
Review: CHANGES_REQUESTED
Thanks for the quick patch. The approach (a shared per-shader budget, charged by failed and successful walks) looks reasonable and the pass stays semantically safe, but the PR doesn't show yet that it fixes #3504:
0x200f780000/0x200f7a0000timings on this head are needed (the issue shows 146.7 s / 406 s onmain). Please post them fromagc_shader_replaywith the counters (walks, values visited, selects removed), or ask @ThatsLeo to run them in #3504.32 × walkLimit, picked without data. Please show how the time and the number of removed selects vary with it on those shaders (the issue reports 4,616 removed afterfda4aa90vs 1,391 before), and that the SPIR-V stays valid. A budget that is spent by the first masks leaves later selects in, so report that cost too.agc_masked_selectonly checks that the budget gets consumed. It can't fail for the wrong reason (it doesn't compile without the change). A case where a select provable within the budget is still removed after earlier walks have spent part of it would pin the "proof completes, select removed" half.Happy to merge once the measurements are in.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T13:42:44Z.
Added commit
b58c0428with the requested follow-up regression. Its first masked proof visits a chain, then conservatively fails when the value reaches an image write observed under a wider exec mask. A later proof under the narrower mask still completes and removes its select. The test also checks that some, but not all, of the shader-wide budget was spent.agc_masked_selectpasses three consecutive Release runs on Linux/GCC 12.2.The two Stray replay request files are not available in this workspace, so I can't provide the timing, select-count or SPIR-V results from here. I asked the issue reporter to run both shaders at 1x, 8x and 32x the per-walk limit, and included the requested output fields in the issue comment. The PR description records this as pending rather than claiming an unverified improvement.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T15:26:47Z.
Review: CHANGES_REQUESTED
Thanks for the follow-up test;
agc_masked_selectpasses here on the PR merged onto currentmain(Linux, scoped build, 404/404 ctest in libSceAgc/libSceAgcDriver), and the new stats make the tests fail to build without the source change.What is still missing is the one measurement the claim rests on, which we can't produce without the Stray requests:
0x200f780000/0x200f7a0000replayed on this head vsmain(time, values visited, selects removed, SPIR-V valid), as requested in #3504. If @ThatsLeo posts it there, it is enough.Once the numbers are in, this is ready to merge from our side.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T23:15:20Z.
Conflicts with main in
MaskedSelectEliminator.cppandtests/MaskedSelect.cppsince #3391; please rebase.ThatsLeo's tables in #3504 cover the numbers (141 s → 1.3 s and 385 s → 2.4 s at 32x, SPIR-V valid). They also show that with this PR alone
0x2013010000stops compiling below 128x:So either this goes in after #4031 (list it under Depends on), or the multiple has to be one that keeps that shader compiling.
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-12T12:23:36Z.
Rebase handoff — this branch was ~800 commits behind
mainand conflicting. I rebased it onto currentmainand verified the result; the authorship of both commits is unchanged.The conflicts were semantic, not mechanical —
mainevolvedMaskedLaneWalk(the guarded first-lane reads and whole-quad work landed in the meantime), while this PR adds the shader-wide work budget. The rebased merge keeps both: main'snesting/uniform-aware constructor andsameIterationhandling, plus this PR'sremaining/allowance/ChargeWorkbudget accounting. The test file keepsmain's new whole-quad tests and this PR's budget tests together.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV):tools/check_conventions.py --base origin/mainpassesmasked-lane implication work stays within a shader-wide budget,a later bounded masked-lane proof can still remove its select) and main's whole-quad masked-select testsTo pick it up (either works):
Or cherry-pick the resolution from
blawesom:rebase/3550(head2289cbeac). Happy to adjust the resolution if you'd merge the two mechanisms differently.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-12T17:08:21Z.
Closing this as superseded by merged #4331. Its backward-pass masked-lane analysis fixes the repeated per-select walk that motivated the shared budget and avoids the budget-dependent selects noted in #3504. The budget implementation is no longer needed on current main; #4331 documents the replay evidence and full-output behavior.
Pull request closed