fix(shader): repeat phi folding until no phi folds #6332
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6332"
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 SleglJan on 2026-10-15T12:04:13Z.
What
ConstantFolder::Foldvisits each instruction once, in block order. A loop header phi whose back-edge value is a later phi that folds to it in the same pass is visited before that phi folds, so it stays a phi of its one definition and itself. An example is an outer loop's header phi whose back-edge value is the header phi of an inner loop in which an S# is copied out and back.PackedAncillarybuiltin still has live uses.Such phis reach resource tracking, which compares descriptor dwords as IR values. So the phi of an S# and the S# itself become two samplers, and the same holds for T#s. Two PPSA11386 (007 First Light) pixel shaders each planned 21 direct samplers for 6 distinct S# values. At two heap slots each they exceed the 32 sampler slots, and the shaders stop at their first draw with:
shader sampler pairs exceed runtime heap capacityAfter its pass over the instructions,
Foldnow folds the phis of its blocks again until a pass folds none. Each fold turns a phi into anIdentity, so the loop ends. Only phis are repeated: a fold that depends on a phi folded this late waits for the nextFold, which follows read-lane and masked-select elimination as before. #4150's restriction stays as it is.#6083 raises the sampler heap to 32 pairs, which would also fit this shader's 21 samplers, duplicates included. This change removes the duplicates: the shader plans one sampler per distinct S#. The two do not conflict. #6176 and #5914 also edit
ConstantFolder::Fold; both merge cleanly with this change.Tested
maina08de6827, then rebased without conflicts ontomainb3f9f89e6, wheretools/check_conventions.py --base upstream/mainandgit diff --checkpass.agc_shader_memory,verifyDescriptorPhis: an S# copied out and back in three nested loops, sampled before and inside them, compiled with and without a masked write. Each now plans one sampler and one sampled pair. Onmainboth plan two of each, and the test fails withdescriptor Phi: an S# copied out and back in three nested loops was planned as more than one sampler. One extra phi pass instead of the loop also plans two of each, so the test needs the fixed point.agc|shader|recompileron lavapipe (Mesa 26.2.4, LLVM 23.1.1; Arch Linux container, GCC 16.2.1): 575 of 580 pass. The five failures (agc_storage_kept_unit_settle,agc_driver_bc_block_copy,agc_driver_depth_compare_copy,agc_driver_native_multisample_depth,agc_driver_storage_write_back_overhang) also fail onmainbuilt the same way. The other descriptor-phi and fold tests pass:agc_constant_phi,agc_masked_select,agc_shader_control_flow,agc_driver_relative_ancillary,agc_shader_bindless,agc_vector_windowand others.agc|shader|recompiler|pm4|draw|position, 583 of 583 pass, two of them skipped as onmain.maincan't read their requests, which come from an older local branch, so they ran on that branch with #4150's restriction restored and this change added:Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:26:19Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ConstantFolder.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ConstantFolder.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp