fix(shader): carry a packed pixel ancillary through phis when every reader extracts a modelled field #1934

Merged
fisherjoey merged 1 commit from upstream-pr/1934 into main 2026-10-10 07:05:48 +00:00
fisherjoey commented 2026-10-09 00:46:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-09T00:46:54Z.


Related: #1933. This PR covers only the phi case. The whole-word case from #1933 moved to a separate issue, #2548.

What

Since #1179, lowerPackedAncillary rebuilds the packed pixel ancillary word when it is passed through a move (Identity) or the data operand of a SelectU32, as long as every reader of the result extracts a range inside one modelled field (sample index or render target index). It does not follow a Phi. When the old value of the ancillary VGPR reaches a block merge, the phi counts as a reader, and shader info collection throws packed pixel ancillary input has an unsupported live use (used by Phi ...) even when every value read after the phi is an in-field extract.

This change treats a Phi operand the same way as a select data operand: the word is forwarded through it, and the rule from #1179 is unchanged. Every reader past the phi must still be an extract inside one modelled field, or nothing is lowered and the shader is refused as before. The reader walk keeps a visited list, so a phi on a loop back edge ends the walk. The TechnicalDebt entry from #1179 now says "select, move or phi".

The earlier version of this PR also let the word reach whole-word readers (float math, outputs) with the unmodelled bits read as 0. That part is dropped: it guesses those bits, which #1179's rule and #182 rule out. Stray's 26 shaders need that case, so this PR no longer fixes them. They are described in #2548.

Tested

Linux (Nobara 44, GCC), RTX 5070 Ti, NVIDIA 595.91.07.

New checks in core/libs/tests/PixelAncillary.cpp: MergedValues builds a diamond where a Phi merges the ancillary word with other data, and a loop where the phi's back edge goes through a SelectU32 that reads the phi. Each case evaluates the extract against the packed word for every row. MergedRefused checks that a phi into BitwiseOr32 or into an extract outside the modelled fields still throws.

ctest -R pixel_ancillary
main 87be9489 + the test only fails: shader info collection failed: packed pixel ancillary input has an unsupported live use (used by Phi 1513922071)
this branch (79653e00) passes

ctest -R 'agc_|pixel_ancillary' -j1 on this branch: 290 of 291 pass. The one failure, agc_driver_dcc_keys_first_write, also fails on main on this NVIDIA setup.

Rebased onto main after #1904, which touches the same function. Its masked-copy extract rewrite is kept as is.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (whole-word readers still do)
  • No notes, investigation .md files or images added to the repository
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4794540360 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1934). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-09T00:46:54Z. --- Related: #1933. This PR covers only the phi case. The whole-word case from #1933 moved to a separate issue, #2548. ### What Since #1179, `lowerPackedAncillary` rebuilds the packed pixel ancillary word when it is passed through a move (`Identity`) or the data operand of a `SelectU32`, as long as every reader of the result extracts a range inside one modelled field (sample index or render target index). It does not follow a `Phi`. When the old value of the ancillary VGPR reaches a block merge, the phi counts as a reader, and shader info collection throws `packed pixel ancillary input has an unsupported live use (used by Phi ...)` even when every value read after the phi is an in-field extract. This change treats a `Phi` operand the same way as a select data operand: the word is forwarded through it, and the rule from #1179 is unchanged. Every reader past the phi must still be an extract inside one modelled field, or nothing is lowered and the shader is refused as before. The reader walk keeps a visited list, so a phi on a loop back edge ends the walk. The TechnicalDebt entry from #1179 now says "select, move or phi". The earlier version of this PR also let the word reach whole-word readers (float math, outputs) with the unmodelled bits read as 0. That part is dropped: it guesses those bits, which #1179's rule and #182 rule out. Stray's 26 shaders need that case, so this PR no longer fixes them. They are described in #2548. ### Tested Linux (Nobara 44, GCC), RTX 5070 Ti, NVIDIA 595.91.07. New checks in `core/libs/tests/PixelAncillary.cpp`: `MergedValues` builds a diamond where a `Phi` merges the ancillary word with other data, and a loop where the phi's back edge goes through a `SelectU32` that reads the phi. Each case evaluates the extract against the packed word for every row. `MergedRefused` checks that a phi into `BitwiseOr32` or into an extract outside the modelled fields still throws. | | `ctest -R pixel_ancillary` | |---|---| | `main` 87be9489 + the test only | fails: `shader info collection failed: packed pixel ancillary input has an unsupported live use (used by Phi 1513922071)` | | this branch (79653e00) | passes | `ctest -R 'agc_|pixel_ancillary' -j1` on this branch: 290 of 291 pass. The one failure, `agc_driver_dcc_keys_first_write`, also fails on `main` on this NVIDIA setup. Rebased onto `main` after #1904, which touches the same function. Its masked-copy extract rewrite is kept as is. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (whole-word readers still do) - [x] No notes, investigation `.md` files or images added to the repository - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
fisherjoey commented 2026-10-09 14:31:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-09T14:31:37Z.


Overlap note: #1179 (open since 10-07) handles extracts reached through moves and selects. It refuses a word that reaches a phi or a whole-word reader by design, so it doesn't cover this PR's case: Stray's 26 pixel shaders where v4's old value, still the raw word, flows through Phi into float math. This PR rebuilds the word from SampleId and Layer for those uses, with the other bits read as 0 (recorded in TechnicalDebt).

Stray, with #1179 in place of this PR: 0 of the 26 compile (21 refused as used by BitFieldUExtract 16 11, SelectU32 ? ?, 5 as ... SelectU32 0 ?), and this PR's test fails with used by SelectU32 0 ?. With this PR, 26 of 26 compile. Details on #1179: https://github.com/boykopovar/AnyPS5/pull/1179#issuecomment-6082989392.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6082992471 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1934#issuecomment-6082992471). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-09T14:31:37Z. --- Overlap note: #1179 (open since 10-07) handles extracts reached through moves and selects. It refuses a word that reaches a phi or a whole-word reader by design, so it doesn't cover this PR's case: Stray's 26 pixel shaders where v4's old value, still the raw word, flows through `Phi` into float math. This PR rebuilds the word from `SampleId` and `Layer` for those uses, with the other bits read as 0 (recorded in TechnicalDebt). Stray, with #1179 in place of this PR: 0 of the 26 compile (21 refused as `used by BitFieldUExtract 16 11, SelectU32 ? ?`, 5 as `... SelectU32 0 ?`), and this PR's test fails with `used by SelectU32 0 ?`. With this PR, 26 of 26 compile. Details on #1179: https://github.com/boykopovar/AnyPS5/pull/1179#issuecomment-6082989392. AI-assisted: yes
popcoder565 commented 2026-10-09 15:23:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T15:23:27Z.


Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head 9cf81e62, merged onto main d70b8998 in one build with 33 other AGC/shader PRs that had no Windows run.

  • This PR's tests pass: pixel_ancillary. None of them reported skipping a case.
  • Full ctest in that build: 514 of 515. The one failure is #2257's new test, which is registered without the Windows PATH setup.

No title was run.

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6083890458 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1934#issuecomment-6083890458). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-09T15:23:27Z. --- Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head `9cf81e62`, merged onto `main` d70b8998 in one build with 33 other AGC/shader PRs that had no Windows run. - This PR's tests pass: `pixel_ancillary`. None of them reported skipping a case. - Full ctest in that build: 514 of 515. The one failure is #2257's new test, which is registered without the Windows `PATH` setup. No title was run. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
fisherjoey commented 2026-10-10 04:29:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-10T04:29:15Z.


I narrowed this PR to fit #1179's rule. It now only lets the word pass through a Phi into readers that each extract a range inside one modelled field, the same rule #1179 applies to selects and moves. The reader walk stops at phis it has already visited, so loop back edges terminate. Any other reader still throws. I dropped the earlier path that let whole-word readers see the unmodelled bits as 0. That case, Stray's 26 shaders, is now #2548.

New head: 7918aa11, on main afb8cd22. The new MergedValues/MergedRefused checks in pixel_ancillary fail on main with the test alone (unsupported live use (used by Phi 1513922071)) and pass on this branch. ctest -R 'agc_|pixel_ancillary' -j1 passes 271 of 272. The one failure, agc_driver_dcc_keys_first_write, also fails on main on NVIDIA. It merges cleanly with #1904.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6093774097 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1934#issuecomment-6093774097). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-10T04:29:15Z. --- I narrowed this PR to fit #1179's rule. It now only lets the word pass through a `Phi` into readers that each extract a range inside one modelled field, the same rule #1179 applies to selects and moves. The reader walk stops at phis it has already visited, so loop back edges terminate. Any other reader still throws. I dropped the earlier path that let whole-word readers see the unmodelled bits as 0. That case, Stray's 26 shaders, is now #2548. New head: 7918aa11, on main afb8cd22. The new `MergedValues`/`MergedRefused` checks in `pixel_ancillary` fail on main with the test alone (`unsupported live use (used by Phi 1513922071)`) and pass on this branch. `ctest -R 'agc_|pixel_ancillary' -j1` passes 271 of 272. The one failure, `agc_driver_dcc_keys_first_write`, also fails on main on NVIDIA. It merges cleanly with #1904. AI-assisted: yes
adriadam10 commented 2026-10-10 07:05:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T07:05:44Z.


Re-checked on the rebased head 79653e00 (merged onto current main): scoped build + ctest 334/334 green; pixel_ancillary fails without the ConstantFolder.cpp change and passes with it. The word only passes through a phi when every reader is an extract inside one modelled field, other readers still throw, and the visited list terminates loop back edges. No conflicts with main. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094945482 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1934#issuecomment-6094945482). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T07:05:44Z. --- Re-checked on the rebased head 79653e00 (merged onto current main): scoped build + ctest 334/334 green; `pixel_ancillary` fails without the `ConstantFolder.cpp` change and passes with it. The word only passes through a phi when every reader is an extract inside one modelled field, other readers still throw, and the visited list terminates loop back edges. No conflicts with main. Merging.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!1934
No description provided.