fix(shader): let the SRT walker decide a branch through an invariant phi, and resolve control-flow identities after every fold #23343
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/23343"
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 chitters2004 on 2026-11-18T22:08:19Z.
What
Two small fixes that run for every shader. Neither needs a switch.
1. SRT walker (
SrtEvaluator::MayDecide). It decided aLogicalAnd/LogicalOrwhen one side was decidable but stopped at aPhi. When a block is split and joined again (the constant-buffer NaN guard does this today), a branch condition computed before the split reaches the old terminator through a phi whose incoming values are copies of each other. The plan then dropped the condition, the walker visited both successors, and descriptor sources that the branch rules out failed to evaluate. That aborted the recompile.MayDecidenow resolves an invariant phi and decides its value. It seeds its memo before recursing, so a phi that reaches itself is undecided.Test:
verifyMayDecideSharedConditions(inagc_shader_memory_coherent_atomic_loads) gains phi-of-copies, lanes and looped cases. It fails without the fix ("MayDecide did not decide a branch on a phi of two copies of a condition with a uniform conjunct").2.
ConstantFolder::Fold(IrProgram&)resolves control-flow identities itself.ResolveControlFlowIdentitieswas called by hand after four of the five folds inPrepareResourceProgram/prepareInterfaceand after two inDeserialize. The fold after the vector window index narrower had no call, so a later pass could read a branch condition that the fold had replaced.Foldnow ends with the call and the explicit ones are gone.Test:
agc_constant_phifolds a branch conditionLogicalAnd(compare, true)and checks the metadata names the compare. It fails without the change.Effect on every shader. Both changes can alter what a shader compiles to (item 1 only where a branch is decided through a phi; item 2 only where a stale condition was read). On the 319 replay requests (316 compile; 3 fail on main for an unrelated reason) the
agc_shader_replay --spvoutput is byte-identical to main's with default settings.Disk cache: entries from before this change are invalidated, as for any recompiler source change.
Tested
agc_shader_memory_coherent_atomic_loads,agc_constant_phi: both fail first.11a60f8aa5(linux-gate and windows,^agc_constant_phi|^agc_shader_memory): run 44394091057, green. Linux and Windows ranagc_constant_phi,agc_shader_memoryandagc_shader_memory_coherent_atomic_loads, all passing, with 0 validation-layer VUIDs and nothing failing on the head that passes on main.Checklist
main; no other open PR implements the same functions🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T05:37:05Z.
Review: COMMENTED
Reviewed — no blocking findings
The review found no verified blocking defect;
ShaderMemory.cppwas not read in full, so the evidence is incomplete and does not support approval.What I ran
Reviewed head
11a60f8aa5160fa61421f269e8804f17dbde3718using the prepared diff and pinned repository reader. No tests or builds were run.Results
Findings
Blocking
None verified in the code read.
Non-blocking
None.
Sources
Reviewed the prepared diff and targeted source at the pinned head, including the changes to
MayDecideandConstantFolder::Fold.Not verified
core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppwas excluded from the review folder and not read through the repository reader. Tests, builds, replay comparisons, and author-reported CI or GPU results were not independently run or confirmed. The other changed files were read;Deserialize.cppandRecompiler.cppwere read in the changed regions.To get this to a good state
Nothing is required. The optional point is to inspect
ShaderMemory.cppbefore treating this review as complete.