fix(shader): packed pixel ancillary as SampleId and Layer, gl_Layer via Geometry, Z export formats #295

Merged
MichonGoddijn231849 merged 3 commits from upstream-pr/295 into main 2026-10-07 09:06:34 +00:00
MichonGoddijn231849 commented 2026-10-01 21:58:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-01T21:58:17Z.


What

Split out of #167.

  • Packed ancillary: bit-field extracts of the packed pixel ancillary VGPR become gl_SampleID and gl_Layer reads, instead of failing with packed pixel ancillary input has an unsupported live use.
  • gl_Layer: a pixel shader reading it needs the Geometry capability instead of ShaderLayer and SPIR-V 1.5. The Geometry capability is available whenever the geometryShader feature is, and the device enables sampleRateShading, geometryShader and shaderClipDistance when available.
  • Z export: the 32-bit SPI_SHADER_Z_FORMATs and 32_ABGR are accepted together with the depth and sample-mask export enables.

Tested

Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB DDR5-5600, MinGW-w64 GCC 15.2.0.

  • GTA V (PPSA04264): the draws rejected for the packed ancillary use, and for the depth export formats, now run.
  • Dreaming Sarah (PPSA02929): the title menu renders as on main.
  • ctest: all tests pass.

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 (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes. Written with Claude (Anthropic) under my direction; I reviewed and tested it.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4710120805 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/295). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-01T21:58:17Z. --- ### What Split out of #167. - **Packed ancillary:** bit-field extracts of the packed pixel ancillary VGPR become `gl_SampleID` and `gl_Layer` reads, instead of failing with `packed pixel ancillary input has an unsupported live use`. - **`gl_Layer`:** a pixel shader reading it needs the Geometry capability instead of ShaderLayer and SPIR-V 1.5. The Geometry capability is available whenever the geometryShader feature is, and the device enables sampleRateShading, geometryShader and shaderClipDistance when available. - **Z export:** the 32-bit `SPI_SHADER_Z_FORMAT`s and 32_ABGR are accepted together with the depth and sample-mask export enables. ### Tested Windows 11 Pro, AMD Ryzen 5 7600, NVIDIA GeForce RTX 5080 (driver 32.0.16.1074), 32 GB DDR5-5600, MinGW-w64 GCC 15.2.0. - GTA V (PPSA04264): the draws rejected for the packed ancillary use, and for the depth export formats, now run. - Dreaming Sarah (PPSA02929): the title menu renders as on `main`. - `ctest`: all tests pass. ### 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 (`NotImplemented_nid_no_patch`); silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes. Written with Claude (Anthropic) under my direction; I reviewed and tested it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
github-actions[bot] commented 2026-10-03 19:50:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-03T19:50:46Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#426 core/libs/tests/PixelAncillary.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5972881123 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/295#issuecomment-5972881123). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-03T19:50:46Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #426 | | | `core/libs/tests/PixelAncillary.cpp` |
oneandonlydean commented 2026-10-04 05:39:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T05:39:30Z.


Thanks for splitting this out of #167. The sample id and layer fields match what Mesa unpacks (ac_nir_lower_intrinsics_to_args.c: bits 8 to 11 and 16 to 28), and Geometry is the right capability for a fragment Layer input.

One thing I'd change: in lowerPackedAncillary, a use that isn't a bit-field extract inside one of those two fields gets SampleId << 8 | Layer << 16. That reads 0 for the other bits (Mesa takes the VRS rates from bits 2 to 5, for example), where main threw unsupported live use. Could that path keep throwing, so only the extracts that map exactly are lowered? A recompiler test with an extract of each field, plus a whole-register use that is still refused, would cover it.

Also, #375's validator change needs the geometryShader and sampleRateShading enables this PR adds to VulkanDevice (main doesn't enable them), and this PR's Geometry and SampleRateShading modules need #375 to pass validation. I'd land this one first and add Depends on #295 to #375.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5977000336 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/295#issuecomment-5977000336). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T05:39:30Z. --- Thanks for splitting this out of #167. The sample id and layer fields match what Mesa unpacks (`ac_nir_lower_intrinsics_to_args.c`: bits 8 to 11 and 16 to 28), and Geometry is the right capability for a fragment Layer input. One thing I'd change: in `lowerPackedAncillary`, a use that isn't a bit-field extract inside one of those two fields gets `SampleId << 8 | Layer << 16`. That reads 0 for the other bits (Mesa takes the VRS rates from bits 2 to 5, for example), where main threw `unsupported live use`. Could that path keep throwing, so only the extracts that map exactly are lowered? A recompiler test with an extract of each field, plus a whole-register use that is still refused, would cover it. Also, #375's validator change needs the `geometryShader` and `sampleRateShading` enables this PR adds to VulkanDevice (main doesn't enable them), and this PR's Geometry and SampleRateShading modules need #375 to pass validation. I'd land this one first and add `Depends on #295` to #375.
MichonGoddijn231849 commented 2026-10-04 08:27:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-04T08:27:23Z.


Done in cd491902. lowerPackedAncillary now lowers only bit-field extracts (signed or unsigned, constant offset and count) that lie entirely inside bits 8..11 or 16..28. They are rebased onto SampleId or Layer. Every other use keeps reading the packed register, and if it survives dead-code removal, main's unsupported live use check throws as before. The SampleId << 8 | Layer << 16 fallback is gone.

It also fixes a bug in the old range check: count <= first + width - offset underflowed for an extract starting past a field's end, so an extract at offset 13, count 2 was lowered as sample id at offset 5.

New recompiler test pixel_ancillary:

  • Lowered: unsigned (8,4) and (9,2) to SampleId, unsigned (16,13) to Layer, signed (20,9) to Layer at offset 4.
  • Refused: a whole-register use, and extracts at (2,4), (10,4), (13,2) and (16,14), which lie outside or straddle a field.

A signed extract is lowered as-is because SampleId stays below 16 and Layer below 8192, so neither builtin has bits above its field. That's my inference, not from documentation.

I'll add Depends on #295 to #375 as you suggested.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5978101944 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/295#issuecomment-5978101944). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-04T08:27:23Z. --- Done in cd491902. `lowerPackedAncillary` now lowers only bit-field extracts (signed or unsigned, constant offset and count) that lie entirely inside bits 8..11 or 16..28. They are rebased onto `SampleId` or `Layer`. Every other use keeps reading the packed register, and if it survives dead-code removal, main's `unsupported live use` check throws as before. The `SampleId << 8 | Layer << 16` fallback is gone. It also fixes a bug in the old range check: `count <= first + width - offset` underflowed for an extract starting past a field's end, so an extract at offset 13, count 2 was lowered as sample id at offset 5. New recompiler test `pixel_ancillary`: - Lowered: unsigned (8,4) and (9,2) to SampleId, unsigned (16,13) to Layer, signed (20,9) to Layer at offset 4. - Refused: a whole-register use, and extracts at (2,4), (10,4), (13,2) and (16,14), which lie outside or straddle a field. A signed extract is lowered as-is because SampleId stays below 16 and Layer below 8192, so neither builtin has bits above its field. That's my inference, not from documentation. I'll add `Depends on #295` to #375 as you suggested.
MichonGoddijn231849 commented 2026-10-04 09:50:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-04T09:50:11Z.


A follow-up from testing the stricter lowering in GTA V (PPSA04264): one of its pixel shaders is now refused (packed pixel ancillary input has an unsupported live use). That skips 3 draw kinds on the way into the game which the old fallback drew. The IR, from replaying the request with the uses listed:

x = BitFieldUExtract(ancillary, 8, 1)          // sample id bit 0, lowered fine
v = SelectU32(INotEqual32(...), x, ancillary)  // whole register on the false side
IEqual32(1, v) -> SelectU32(...)

So on one side of a select it compares the whole raw register with 1. That depends on bits 0..7 and 12..15 too, not just the sample id and layer. Mesa (ac_nir_lower_intrinsics_to_args.c) documents only the VRS rates (2..5, which are 0 here because we never enable VRS), the sample id (8..11) and the layer (16..). I don't know of a source for bits 0..1, 6..7, 12..15 or 29..31, so I can't make this use exact.

Options as I see them:

  1. Keep throwing, as now: exact-or-throw, and GTA loses those draws.
  2. Serve whole-register uses as SampleId << 8 | Layer << 16 with every other bit 0, the old behaviour, recorded as technical debt for the undocumented bits.

I lean to keeping this PR as you asked (1). If the undocumented bits ever get pinned down, 2 can become a separate PR. Your call though, or @boykopovar's.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5978675120 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/295#issuecomment-5978675120). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-04T09:50:11Z. --- A follow-up from testing the stricter lowering in GTA V (PPSA04264): one of its pixel shaders is now refused (`packed pixel ancillary input has an unsupported live use`). That skips 3 draw kinds on the way into the game which the old fallback drew. The IR, from replaying the request with the uses listed: ``` x = BitFieldUExtract(ancillary, 8, 1) // sample id bit 0, lowered fine v = SelectU32(INotEqual32(...), x, ancillary) // whole register on the false side IEqual32(1, v) -> SelectU32(...) ``` So on one side of a select it compares the whole raw register with 1. That depends on bits 0..7 and 12..15 too, not just the sample id and layer. Mesa (`ac_nir_lower_intrinsics_to_args.c`) documents only the VRS rates (2..5, which are 0 here because we never enable VRS), the sample id (8..11) and the layer (16..). I don't know of a source for bits 0..1, 6..7, 12..15 or 29..31, so I can't make this use exact. Options as I see them: 1. Keep throwing, as now: exact-or-throw, and GTA loses those draws. 2. Serve whole-register uses as `SampleId << 8 | Layer << 16` with every other bit 0, the old behaviour, recorded as technical debt for the undocumented bits. I lean to keeping this PR as you asked (1). If the undocumented bits ever get pinned down, 2 can become a separate PR. Your call though, or @boykopovar's.
oneandonlydean commented 2026-10-04 09:51:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T09:51:46Z.


Thanks, that's exactly it. Only extracts that lie entirely inside bits 8 to 11 or 16 to 28 are lowered, every other use still reaches the unsupported live use check, and the new range check can't underflow. On the signed extracts: the extract only reads bits inside the field, and the field holds the low bits of SampleId or Layer, so it gives the same value as on the packed register whatever the builtin holds above the field. That part doesn't depend on an inference.

Merged with current main, together with #375, it builds and passes the full ctest here, including pixel_ancillary. Ready to merge from my side after a PPSA21564 run on my integration branch.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5978689333 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/295#issuecomment-5978689333). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T09:51:46Z. --- Thanks, that's exactly it. Only extracts that lie entirely inside bits 8 to 11 or 16 to 28 are lowered, every other use still reaches the `unsupported live use` check, and the new range check can't underflow. On the signed extracts: the extract only reads bits inside the field, and the field holds the low bits of SampleId or Layer, so it gives the same value as on the packed register whatever the builtin holds above the field. That part doesn't depend on an inference. Merged with current main, together with #375, it builds and passes the full ctest here, including `pixel_ancillary`. Ready to merge from my side after a PPSA21564 run on my integration branch.
MichonGoddijn231849 commented 2026-10-05 15:41:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-05T15:41:08Z.


Rebased onto current main. The conflict was in State.cpp with #469 (null pixel program): main's export-format read and PixelProgramUnset check stay, and this PR's Z-export format check now sits next to them. Build and ctest are clean apart from the failures main has locally. #375, #423 and #448 are restacked on it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5997834801 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/295#issuecomment-5997834801). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-05T15:41:08Z. --- Rebased onto current `main`. The conflict was in `State.cpp` with #469 (null pixel program): `main`'s export-format read and `PixelProgramUnset` check stay, and this PR's Z-export format check now sits next to them. Build and ctest are clean apart from the failures `main` has locally. #375, #423 and #448 are restacked on it.
adriadam10 commented 2026-10-06 20:35:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-06T20:35:11Z.

Review: CHANGES_REQUESTED


Checked the field ranges against Mesa, the Z formats against the gfx10 SPI_SHADER_Z_FORMAT enum, and the MRTZ export layout (Z in R, sample mask in B for 32_ABGR). pixel_ancillary fails with the non-test changes reverted and passes with them. Two small things before merging:

  • Graphics/src/State.cpp:793: DrawRejection calls read(cx, 0x1c4), which throws when the register is missing. That breaks the rule stated at the top of the function ("A register a rule needs that is absent gives no verdict here: DecodeState reports it"). Line 775 already reads it with value(cx, 0x1c4, zFormat). Could the export check reuse that zFormat, guarded by whether it was found?
  • The Z-export part has no test. core/libs/prx/libSceAgcDriver/tests/Graphics.cpp already covers DrawRejection/DecodeState. Rows that would pin it: formats 1/2/3/9 with Z_EXPORT_ENABLE accepted; format 0 with Z_EXPORT_ENABLE rejected; MASK_EXPORT_ENABLE accepted with 9 and rejected with 1; formats 4..8 rejected; 0x1c4 absent gives no rejection in DrawRejection.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5434271660 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/295#pullrequestreview-5434271660). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-06T20:35:11Z. **Review:** CHANGES_REQUESTED --- Checked the field ranges against Mesa, the Z formats against the gfx10 `SPI_SHADER_Z_FORMAT` enum, and the MRTZ export layout (Z in R, sample mask in B for 32_ABGR). `pixel_ancillary` fails with the non-test changes reverted and passes with them. Two small things before merging: - `Graphics/src/State.cpp:793`: `DrawRejection` calls `read(cx, 0x1c4)`, which throws when the register is missing. That breaks the rule stated at the top of the function ("A register a rule needs that is absent gives no verdict here: DecodeState reports it"). Line 775 already reads it with `value(cx, 0x1c4, zFormat)`. Could the export check reuse that `zFormat`, guarded by whether it was found? - The Z-export part has no test. `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp` already covers `DrawRejection`/`DecodeState`. Rows that would pin it: formats 1/2/3/9 with `Z_EXPORT_ENABLE` accepted; format 0 with `Z_EXPORT_ENABLE` rejected; `MASK_EXPORT_ENABLE` accepted with 9 and rejected with 1; formats 4..8 rejected; 0x1c4 absent gives no rejection in `DrawRejection`.
MichonGoddijn231849 commented 2026-10-07 08:09:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-07T08:09:56Z.


Both done in 048d9982:

  • DrawRejection reuses the zFormat read with value() at the top of the depth checks, so a missing 0x1c4 gives no verdict there any more.
  • tests/Graphics.cpp has a ZExportTests with the rows you listed: formats 1, 2, 3 and 9 with Z_EXPORT_ENABLE accepted, format 0 rejected, MASK_EXPORT_ENABLE accepted with 9 and rejected with 1, formats 4 to 8 rejected, and 0x1c4 absent accepted. Without the State.cpp change the last row fails with missing register in context bank at DWORD 0x1c4.

agc_driver_graphics and pixel_ancillary pass.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6033779921 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/295#issuecomment-6033779921). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-07T08:09:56Z. --- Both done in 048d9982: - `DrawRejection` reuses the `zFormat` read with `value()` at the top of the depth checks, so a missing 0x1c4 gives no verdict there any more. - `tests/Graphics.cpp` has a `ZExportTests` with the rows you listed: formats 1, 2, 3 and 9 with `Z_EXPORT_ENABLE` accepted, format 0 rejected, `MASK_EXPORT_ENABLE` accepted with 9 and rejected with 1, formats 4 to 8 rejected, and 0x1c4 absent accepted. Without the `State.cpp` change the last row fails with `missing register in context bank at DWORD 0x1c4`. `agc_driver_graphics` and `pixel_ancillary` pass.
adriadam10 commented 2026-10-07 08:18:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T08:18:57Z.


Both points addressed in 048d9982: the precheck no longer throws on a missing 0x1c4, and ZExportTests pins the format/enable rows. Checked build + full ctest merged onto current main (387/387), and agc_driver_graphics / pixel_ancillary fail with the non-test changes reverted. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6033922250 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/295#issuecomment-6033922250). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-07T08:18:57Z. --- Both points addressed in 048d9982: the precheck no longer throws on a missing 0x1c4, and `ZExportTests` pins the format/enable rows. Checked build + full ctest merged onto current main (387/387), and `agc_driver_graphics` / `pixel_ancillary` fail with the non-test changes reverted. Merging once CI is green.
MichonGoddijn231849 commented 2026-10-07 08:59:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-10-07T08:59:24Z.


@adriadam10 I don't know what your AI is doing but it keeps spamming the same comment

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6034570271 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/295#issuecomment-6034570271). Originally posted by [MichonGoddijn231849](https://github.com/MichonGoddijn231849) on 2026-10-07T08:59:24Z. --- @adriadam10 I don't know what your AI is doing but it keeps spamming the same comment
adriadam10 commented 2026-10-07 09:04:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T09:04:33Z.


@MichonGoddijn231849 Sorry about that, you were right. My merge script kept reposting the comment every two minutes while the merge was blocked. I've deleted the duplicates and fixed the script so it only posts once.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6034658729 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/295#issuecomment-6034658729). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-07T09:04:33Z. --- @MichonGoddijn231849 Sorry about that, you were right. My merge script kept reposting the comment every two minutes while the merge was blocked. I've deleted the duplicates and fixed the script so it only posts once.
adriadam10 commented 2026-10-07 09:06:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T09:06:29Z.

Review: APPROVED


Approving: both requested changes are in 048d9982 (details in my comment above). CI is green, merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5440069302 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/295#pullrequestreview-5440069302). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-07T09:06:29Z. **Review:** APPROVED --- Approving: both requested changes are in 048d9982 (details in my comment above). CI is green, merging.
alfalfa-star commented 2026-10-07 09:21:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-07T09:21:34Z.


A note from testing this with PPSA14632 (LEGO Horizon Adventures): its layered pixel shaders still fail with packed pixel ancillary input has an unsupported live use, although they only take the layer field (v_bfe_u32 v2, v2, 16, 11, inside the {16, 13} range).

vBfeU32 does not emit immediates. The offset is BitwiseAnd(16, 31) and the count is UMin(BitwiseAnd(11, 31), 32 - offset). ConstantFolder::Fold makes one pass in program order and reaches the ancillary GetBuiltin first, so when lowerPackedAncillary looks at its users, their offset and count are not folded yet and the use is skipped. The unit tests build the extract from constants directly, which is why they pass.

Lowering at the extract instead works, because the folder reaches it after its offset and count are folded. That means a BitFieldUExtract/BitFieldSExtract case that checks whether its source resolves to the PackedAncillary GetBuiltin and, inside a range, rewrites its source to the field's GetBuiltin and its offset relative to the field. Both of that title's shaders then recompile (45997 and 6633 words). I can open it as a follow-up or post the patch here, whichever you prefer.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6034936389 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/295#issuecomment-6034936389). Originally posted by [alfalfa-star](https://github.com/alfalfa-star) on 2026-10-07T09:21:34Z. --- A note from testing this with PPSA14632 (LEGO Horizon Adventures): its layered pixel shaders still fail with `packed pixel ancillary input has an unsupported live use`, although they only take the layer field (`v_bfe_u32 v2, v2, 16, 11`, inside the `{16, 13}` range). `vBfeU32` does not emit immediates. The offset is `BitwiseAnd(16, 31)` and the count is `UMin(BitwiseAnd(11, 31), 32 - offset)`. `ConstantFolder::Fold` makes one pass in program order and reaches the ancillary `GetBuiltin` first, so when `lowerPackedAncillary` looks at its users, their offset and count are not folded yet and the use is skipped. The unit tests build the extract from constants directly, which is why they pass. Lowering at the extract instead works, because the folder reaches it after its offset and count are folded. That means a `BitFieldUExtract`/`BitFieldSExtract` case that checks whether its source resolves to the `PackedAncillary` `GetBuiltin` and, inside a range, rewrites its source to the field's `GetBuiltin` and its offset relative to the field. Both of that title's shaders then recompile (45997 and 6633 words). I can open it as a follow-up or post the patch here, whichever you prefer.
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!295
No description provided.