shader: drop the packed ancillary word when a high-word write keeps only unread bits #2539
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!2539
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2539"
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 07:17 UTC · original
Nawid3333:fix/ancillary-high-word-write→main· +98 −0 · 2 files · 1 commits · openAssassin's Creed Black Flag Resynced (#2307) stops with
shader info collection failed: packed pixel ancillary input has an unsupported live useon the officialKytyPS5-2026-11-23-4e90654. The pixel shader is0xb5c241e9c8678b97. It reads the ancillary VGPRv7once (V_BFE_U32 v2, v7, 8, 4, the sample index, already lowered) and then reusesv7as a scratch register:V_INTERP_P2_F16 v7.sdwa(sel=5)writes the high 16 bits and keeps the low 16. In the IR before resource tracking:The three extracts read only the high half, and
%732takes%731in the lanes where the write ran. So the kept low bits are never read there. In the other lanes%660is the unchanged word, taken as its operand 2, which the existing rule already accepts. Besides dead users, the retained-only rule inConstantPropagationPassaccepts the ancillary word only as aPhior asSelectU32operand 2, so theBitFieldInsertuse stops the shader.Change
The retained-only rule also accepts a
BitFieldInsertwhose base is the ancillary word when no lane can read the bits the insert keeps (AncillaryBitsUnread):Identity, extracts that read none of the kept bits, further inserts into the value, orSelectU32operand 1 or 2;SelectU32operand 2 under the condition of the select that first carried the value as operand 1 drops it (those lanes take operand 1);Phi, arithmetic, export, ...) still stops, and the walk is limited to 16 levels.Shaders without such an insert are unchanged.
Test
TestPixelAncillaryLayerInputgets a pixel shader with the same pattern: it reads the sample index from the ancillary VGPR, writes the register's high half with SDWA (dst_sel=WORD_1,dst_unused=PRESERVE), reads back only the high half, and then overwrites the register. Withupstream/mainsrc and this test,shader_cfg_testsexits withpacked pixel ancillary input has an unsupported live use. With the change it passes: the program has aSampleIdinput and noPackedAncillaryinput, and the SPIR-V validates. Two newExpectFatalcases (non-Windows builds) keep a read of the kept low half and an export of the whole word fatal.Fork CI (Windows, Linux, macOS): https://github.com/Nawid3333/KytyPS5/actions/runs/45316219439/attempts/1
Game: with a fork build of this commit (
3a3f52a), Black Flag no longer stopped on0xb5c241e9c8678b97and got into the game in a tester's run (#2307). It then stops at a different error:TextureCache: unresolvable equal-address image overlap ... requested_size=0x0000000000020000 cached_size=0x0000000000010000 type=10/10 tile=9/9(textureCache.cpp:857).Refs #2307
Written with Claude Code (AI): Claude Code wrote the change and the test and ran the local tests; the game run is a tester's.
🤖 Generated with Claude Code
@coderabbitai[bot] on GitHub · 2026-11-24 07:24 UTC · original
No actionable comments were generated in the recent review.
Walkthrough
The compiler now performs bounded analysis to determine whether bits in an ancillary value remain observable. Retained-value normalization uses this analysis for eligible
BitFieldInsertbase uses. Shader tests cover ancillary input retention, SPIR-V validation, and fatal ancillary export cases.Suggested reviewers:
nmzik,senaxxChange: Bug fix
Merge Risk:
Minimal · up to
3a3f5This change lets pixel shaders that reuse the ancillary register after reading the sample index compile, instead of stopping with an unsupported-use error. Shaders without such an insert behave as before, and reads of preserved bits or exports of the whole word still stop compilation. No merge-blocking risk was found.
Pre-merge checks:
4
Full details: Title check
Explanation
The title names the specific change: a high-word write that keeps only unread bits lets the packed ancillary word be dropped. The raw summary describes a BitFieldInsert liveness rule in ConstantPropagation.cpp and a new shader test, which matches this title. The title is specific and reflects the main change.
Full details: Description check
Explanation
The description covers the failing shader, the IR pattern, the new BitFieldInsert acceptance rule, the new TestPixelAncillaryLayerInput test, and CI and game-run results. It relates directly to the changeset, so the check passes.
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
4cc33060-e110-46c8-a86b-b1f7752ad22fReviewing files that changed from the base of the PR and between
4e90654506and3a3f52a4f9.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; 7 remain after this review.
@Nawid3333 on GitHub · 2026-11-24 07:37 UTC · original
@Crispy81 This PR is the change in build
3a3f52a, which got Black Flag past the ancillary stop and into the game for you (#2307). Could you confirm that here? No new run needed.@Crispy81 on GitHub · 2026-11-24 08:16 UTC · original
Confirmed, made it in game. But is unplayable 1 frame per second.
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.