shader: see through SSA aliases when dropping a retained ancillary word #2543
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!2543
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2543"
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?
@Nawid3333 on GitHub · 2026-11-24 11:20 UTC · original
Nawid3333:fix/ancillary-alias-retained→main· +37 −9 · 2 files · 1 commits · openAssassin's Creed Valhalla (#2308) stops with
packed pixel ancillary input has an unsupported live usein PS0x3b1b866a5fbafbbe(Crispy81's log, #2307 comment). The shader reads the sample index from the ancillary VGPR after three nested loops and then overwrites the register under a lane mask:The field read is lowered to
SampleId. What is left of the packed word is the old value of the masked write (SelectU32operand 2), a use the sweep inConstantPropagationPassaccepts, but only when it is a direct user of the word.SsaRewritekeeps each trivial phi it removes as anIdentityalias, and after the loops the word is reached through such an alias, so the sweep found anIdentitywith users and kept the word. The next run of the pass no longer tracks it, and shader info collection stopped.AncillaryRetainedOnlynow followsIdentityusers to the users behind them.Test
shader_cfg_tests,TestPixelAncillaryLayerInput: two nested scalar loops, the sample-index read, a lane-dependent EXEC (v_cmpon FragCoord.x,s_and_saveexec), the overwrite and an export. Current main stops with the game's message (exit 65); with this change the test passes. A variant that exports the raw word through the alias still stops (checked where the test can catch a stop, not on Windows).Game
Crispy81 ran fork build f614890, which is the build that stopped here (734dd0b) plus only this commit: Valhalla no longer stops at this shader, and with Continue it goes in game (#2307 comment). New Game now stops later, at
failed to create image: extent=2576x1456x1 format=97, a different problem. 734dd0b also carried #2539, which edits the same check; f614890 has both changes together.Refs #2308
Written with Claude Code (AI): Claude Code found the cause in the tester's IR log and wrote the change and the test.
🤖 Generated with Claude Code
@coderabbitai[bot] on GitHub · 2026-11-24 11:28 UTC · original
Walkthrough
The ancillary normalization pass now accepts qualifying
Identitychains in addition to the previously accepted uses. Nested-loop shader tests check reflected inputs, SPIR-V validity, and a fatal compilation case.Suggested reviewers:
nmzik,senaxxChange: Bug fix
Merge Risk:
Moderate · up to
bfbe5The change lets shader info collection get past a Valhalla shader that previously stopped it. However, a masked write followed by an export under a wider EXEC could now silently export zero for the packed ancillary word, where it used to fail loudly. This is a narrow edge case that is not covered by the new tests, so it should be addressed or explicitly accepted before merge.
Pre-merge checks:
4
Full details: Title check
Explanation
The title names the specific change: the sweep now follows SSA Identity aliases when deciding whether to drop a retained ancillary word. The raw summary and objectives both describe this change to ConstantPropagation.cpp and the new AncillaryRetainedOnly helper. The title is concise and specific enough for a teammate to understand the primary change.
Full details: Description check
Explanation
The description explains the problem (a packed pixel ancillary input error in Assassin's Creed Valhalla shader 0x3b1b866a5fbafbbe), the root cause (the sweep accepted only direct users of the packed word, while SsaRewrite leaves Identity aliases), and the fix (AncillaryRetainedOnly follows Identity users). It also describes the regression test TestPixelAncillaryLayerInput and game-testing results, which match the test and ConstantPropagation changes in the summary.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Share
@coderabbitai[bot] on GitHub · 2026-11-24 11:28 UTC · original · reviewed
Actionable comments posted: 1
6f4b7f94-1e3a-4bad-86b6-70c25ab8bba4Reviewing files that changed from the base of the PR and between
4e90654506andbfbe595933.src/graphics/shader/recompiler/ir/passes/ConstantPropagation.cpptests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@ -25,0 +30,4 @@}return user.GetOpcode() == ValueOpcode::Phi ||(user.GetOpcode() == ValueOpcode::SelectU32 && use.operand == 2u) ||(user.GetOpcode() == ValueOpcode::Identity && AncillaryRetainedOnly(user));@coderabbitai[bot] on GitHub · 2026-11-24 11:28 UTC · original · edited 2026-11-24 11:42 UTC
Ancillary aliases can carry the packed word into exports, and normalization then replaces it with zero.
The new
Identitybranch inAncillaryRetainedOnlyaccepts a packed ancillary value when an alias reachesSelectU32operand 2. The helper does not check whether that select's result is observed. A masked write keeps the old value on lanes outside its write predicate. If a later export runs under a wider EXEC, such as after the saved EXEC is restored, those lanes export the packed word. Normalization then replaces the source with0, so the export writes zero silently instead of failing withpacked pixel ancillary input has an unsupported live use.The same gap already exists for direct
SelectU32andPhiusers. This change extends it to aliased uses.The correction must establish that the carried value is not observed on lanes outside the write predicate. Checking only the select's downstream users rejects the existing
nested_loopscase, because that export reads the select result. Choose how to prove the export predicate matches the write predicate, or keep the source live when that cannot be proven. Add a regression case in which the export EXEC includes a lane that the overwrite excludes.@ -25,0 +30,4 @@}return user.GetOpcode() == ValueOpcode::Phi ||(user.GetOpcode() == ValueOpcode::SelectU32 && use.operand == 2u) ||(user.GetOpcode() == ValueOpcode::Identity && AncillaryRetainedOnly(user));@Nawid3333 on GitHub · 2026-11-24 11:42 UTC · original
The
Identityis the same value as the word:SsaRewriteleaves it when it removes a trivial phi, andRemoveIdentitiesdrops it later. This change only makes the existing rule give the same answer with or without that alias; it adds no new kind of accepted use.The rule itself, that the word may be replaced when each of its users is a
Phi, a masked write that keeps it as the old value, or an unused instruction without side effects, is main's (ConstantPropagation.cpp:976-991 at4e9065450), as you note. In Valhalla's shader the select result is not observed: v5's only read isV_BFE_U32 v8, v5, 8, 4at 0x40c4, before the masked write at 0x40ec.Proving that the export predicate matches the write predicate would change the direct
PhiandSelectU32cases too, so it belongs in its own change.@ -25,0 +30,4 @@}return user.GetOpcode() == ValueOpcode::Phi ||(user.GetOpcode() == ValueOpcode::SelectU32 && use.operand == 2u) ||(user.GetOpcode() == ValueOpcode::Identity && AncillaryRetainedOnly(user));@coderabbitai[bot] on GitHub · 2026-11-24 11:43 UTC · original
Analysis chain
Script executed:
Length of output: 42405
@Nawid3333You’re right: the directPhiandSelectU32rules predate this PR, andIdentitypreserves the value. I accept your decision to address predicate proof separately.The new traversal can apply the existing rule where an alias previously prevented normalization. I have not verified the wider-EXEC case, so I am not marking the finding as addressed.
You are interacting with an AI system.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.