shader: drop the packed ancillary word when a high-word write keeps only unread bits #2539

Open
github-bot wants to merge 1 commit from github-bot/gh-2539 into main AGit
Owner

@⁠Nawid3333 on GitHub · 2026-11-24 07:17 UTC · original
Nawid3333:fix/ancillary-high-word-write → main · +98 −0 · 2 files · 1 commits · open

Assassin's Creed Black Flag Resynced (#2307) stops with shader info collection failed: packed pixel ancillary input has an unsupported live use on the official KytyPS5-2026-11-23-4e90654. The pixel shader is 0xb5c241e9c8678b97. It reads the ancillary VGPR v7 once (V_BFE_U32 v2, v7, 8, 4, the sample index, already lowered) and then reuses v7 as 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:

%659   = BitFieldInsert %22, %658, 0x00000010, 0x00000010 (U32; uses=1)
%660   = SelectU32 %605, %659, %22 (U32; uses=4)
%696   = BitFieldUExtract %660, 0x00000010, 0x00000010 (U32; uses=1)
%700   = BitFieldUExtract %660, 0x00000010, 0x00000010 (U32; uses=1)
%725   = BitFieldUExtract %660, 0x00000010, 0x00000010 (U32; uses=1)
%732   = SelectU32 %605, %731, %660 (U32; uses=3)

The three extracts read only the high half, and %732 takes %731 in the lanes where the write ran. So the kept low bits are never read there. In the other lanes %660 is the unchanged word, taken as its operand 2, which the existing rule already accepts. Besides dead users, the retained-only rule in ConstantPropagationPass accepts the ancillary word only as a Phi or as SelectU32 operand 2, so the BitFieldInsert use stops the shader.

Change

The retained-only rule also accepts a BitFieldInsert whose base is the ancillary word when no lane can read the bits the insert keeps (AncillaryBitsUnread):

  • an insert that overwrites the whole word is accepted at once;
  • otherwise users may be dead instructions, Identity, extracts that read none of the kept bits, further inserts into the value, or SelectU32 operand 1 or 2;
  • SelectU32 operand 2 under the condition of the select that first carried the value as operand 1 drops it (those lanes take operand 1);
  • anything else (Phi, arithmetic, export, ...) still stops, and the walk is limited to 16 levels.

Shaders without such an insert are unchanged.

Test

TestPixelAncillaryLayerInput gets 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. With upstream/main src and this test, shader_cfg_tests exits with packed pixel ancillary input has an unsupported live use. With the change it passes: the program has a SampleId input and no PackedAncillary input, and the SPIR-V validates. Two new ExpectFatal cases (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 on 0xb5c241e9c8678b97 and 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

**@⁠Nawid3333** on GitHub · 2026-11-24 07:17 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2539) `Nawid3333:fix/ancillary-high-word-write` → `main` · +98 −0 · 2 files · 1 commits · open Assassin's Creed Black Flag Resynced (#2307) stops with `shader info collection failed: packed pixel ancillary input has an unsupported live use` on the official `KytyPS5-2026-11-23-4e90654`. The pixel shader is `0xb5c241e9c8678b97`. It reads the ancillary VGPR `v7` once (`V_BFE_U32 v2, v7, 8, 4`, the sample index, already lowered) and then reuses `v7` as 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: ``` %659 = BitFieldInsert %22, %658, 0x00000010, 0x00000010 (U32; uses=1) %660 = SelectU32 %605, %659, %22 (U32; uses=4) %696 = BitFieldUExtract %660, 0x00000010, 0x00000010 (U32; uses=1) %700 = BitFieldUExtract %660, 0x00000010, 0x00000010 (U32; uses=1) %725 = BitFieldUExtract %660, 0x00000010, 0x00000010 (U32; uses=1) %732 = SelectU32 %605, %731, %660 (U32; uses=3) ``` The three extracts read only the high half, and `%732` takes `%731` in the lanes where the write ran. So the kept low bits are never read there. In the other lanes `%660` is the unchanged word, taken as its operand 2, which the existing rule already accepts. Besides dead users, the retained-only rule in `ConstantPropagationPass` accepts the ancillary word only as a `Phi` or as `SelectU32` operand 2, so the `BitFieldInsert` use stops the shader. ## Change The retained-only rule also accepts a `BitFieldInsert` whose base is the ancillary word when no lane can read the bits the insert keeps (`AncillaryBitsUnread`): - an insert that overwrites the whole word is accepted at once; - otherwise users may be dead instructions, `Identity`, extracts that read none of the kept bits, further inserts into the value, or `SelectU32` operand 1 or 2; - `SelectU32` operand 2 under the condition of the select that first carried the value as operand 1 drops it (those lanes take operand 1); - anything else (`Phi`, arithmetic, export, ...) still stops, and the walk is limited to 16 levels. Shaders without such an insert are unchanged. ## Test `TestPixelAncillaryLayerInput` gets 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. With `upstream/main` src and this test, `shader_cfg_tests` exits with `packed pixel ancillary input has an unsupported live use`. With the change it passes: the program has a `SampleId` input and no `PackedAncillary` input, and the SPIR-V validates. Two new `ExpectFatal` cases (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 on `0xb5c241e9c8678b97` and got into the game in a tester's run (https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/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](https://claude.com/claude-code)
A pixel shader may reuse the ancillary VGPR for 16-bit values after reading
its sample index. An SDWA write of the high word keeps the low ancillary bits
in the register, so the word stayed live and shader info collection stopped.
Track which bits of such a write still hold ancillary data and accept it when
no later read touches them; reads of the kept bits still stop.

Refs #2307

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:22:26 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-24 07:24 UTC · original

Explain Change →

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 BitFieldInsert base uses. Shader tests cover ancillary input retention, SPIR-V validation, and fatal ancillary export cases.

Suggested reviewers: nmzik, senaxx

Change: Bug fix

Merge Risk: Minimal · up to 3a3f5

This 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: Passed 4

Check name Status Explanation
Title check Passed 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 ConstantPropag…
Description check Passed 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 ch…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
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.

Warning

Some tools did not complete. Review the errors below.

Cppcheck (2.22.0)

Cppcheck (2.22.0) exceeded its 180-second time budget. Findings from completed work are retained; remaining checks are incomplete.

tests/shaderCfgTests.cpp

Cppcheck interrupted; analysis of this file is incomplete

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4e90654506 and 3a3f52a4f9.

Files selected for processing: 2

  • src/graphics/shader/recompiler/ir/passes/ConstantPropagation.cpp
  • tests/shaderCfgTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-11-24 07:24 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2539#issuecomment-7124952904) <!-- coderabbit-ai-generated:v1 --> <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/2539?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg" alt="Explain Change →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- recent_review_status_start --> No actionable comments were generated in the recent review. <!-- recent_review_status_end --> <!-- walkthrough_start --> <details> <summary><strong>Walkthrough</strong></summary> <dl> <dd> <br> The compiler now performs bounded analysis to determine whether bits in an ancillary value remain observable. Retained-value normalization uses this analysis for eligible `BitFieldInsert` base uses. Shader tests cover ancillary input retention, SPIR-V validation, and fatal ancillary export cases. **Suggested reviewers:** `nmzik`, `senaxx` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> <!-- change_assessment_commit:"3a3f52a4f901539065df92fc55fe1fa48e532050" --> <!-- change_assessment_priority:{"version":1,"urgency":"p2","manual":false} --> **Change:** Bug fix <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/risk-unassessed-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minimal</strong> · up to <code>3a3f5</code></summary> <dl> <dd> <br> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `3a3f5` --> <!-- final_review_risk_coverage:{"sourceCommitId":"3a3f52a4f901539065df92fc55fe1fa48e532050","coveredCommitId":"3a3f52a4f901539065df92fc55fe1fa48e532050","kind":"reviewed"} --> This 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. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4</strong></summary> <dl> <dd> <br> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | 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 ConstantPropag… | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | 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 ch… | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | <details> <summary><strong>Full details: Title check</strong></summary> <dl> <dd> <br> **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. </dd> </dl> </details> <details> <summary><strong>Full details: Description check</strong></summary> <dl> <dd> <br> **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. </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- operational_warnings_start --> <!-- This is an auto-generated comment: all tool run failures by coderabbit.ai --> > [!WARNING] > Some tools did not complete. Review the errors below. > > <details> > <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/wrench-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/wrench.svg" width="16" height="16" align="absmiddle" alt=""></picture> Cppcheck (2.22.0)</strong></summary> > <dl> > <dd> > <br> > > Cppcheck (2.22.0) exceeded its 180-second time budget. Findings from completed work are retained; remaining checks are incomplete. > > <details> > <summary><strong>tests/shaderCfgTests.cpp</strong></summary> > <dl> > <dd> > <br> > > Cppcheck interrupted; analysis of this file is incomplete > > </dd> > </dl> > </details> > > </dd> > </dl> > </details> <!-- end of auto-generated comment: all tool run failures by coderabbit.ai --> <!-- operational_warnings_end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=2539)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>Share</strong></summary> <dl> <dd> <br> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </dd> </dl> </details> <!-- tips_end --> <!-- recent_review_start --> <h6> <details> <summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Recent review info</strong></summary> <dl> <dd> <br> <!-- review_info_content --> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</strong></summary> <dl> <dd> <br> - **Source mode**: Auto - **Repository**: [KytyPS5/KytyPS5](<https://github.com/KytyPS5/KytyPS5>) - **Branch**: [main](<https://github.com/KytyPS5/KytyPS5/tree/main>) - **File**: [.coderabbit.yaml](<https://github.com/KytyPS5/KytyPS5/blob/4e90654506c8078649e2c1d22c763164406497da/.coderabbit.yaml>) - **Commit**: [4e90654](<https://github.com/KytyPS5/KytyPS5/commit/4e90654506c8078649e2c1d22c763164406497da>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `4cc33060-e110-46c8-a86b-b1f7752ad22f` </dd> </dl> </details> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</strong></summary> <dl> <dd> <br> Reviewing files that changed from the base of the PR and between 4e90654506c8078649e2c1d22c763164406497da and 3a3f52a4f901539065df92fc55fe1fa48e532050. </dd> </dl> </details> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 2</strong></summary> <dl> <dd> <br> * `src/graphics/shader/recompiler/ir/passes/ConstantPropagation.cpp` * `tests/shaderCfgTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review. </dd> </dl> </details> </h6> <!-- recent_review_end -->
Author
Owner

@⁠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.

**@⁠Nawid3333** on GitHub · 2026-11-24 07:37 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2539#issuecomment-7125196943) @⁠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.
Author
Owner

@⁠Crispy81 on GitHub · 2026-11-24 08:16 UTC · original

Confirmed, made it in game. But is unplayable 1 frame per second.

image
**@⁠Crispy81** on GitHub · 2026-11-24 08:16 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2539#issuecomment-7125933716) Confirmed, made it in game. But is unplayable 1 frame per second. <img width="1921" height="1111" alt="image" src="https://github.com/user-attachments/assets/f3a06954-aaa8-45d0-b9ac-d37c21c34f89" />
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2539/head:github-bot/gh-2539'
git switch 'github-bot/gh-2539'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2539'
git switch 'github-bot/gh-2539'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2539'
git switch 'github-bot/gh-2539'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2539'
git switch 'main'
git merge --squash 'github-bot/gh-2539'
git switch 'main'
git merge --ff-only 'github-bot/gh-2539'
git switch 'main'
git merge 'github-bot/gh-2539'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.