fix(shader): read the ancillary render target index as 0 #4842

Merged
LeandroLP23 merged 1 commit from upstream-pr/4842 into main 2026-10-13 01:31:33 +00:00
LeandroLP23 commented 2026-10-12 23:27:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-12T23:27:48Z.


What

Fixes #4800.

The packed pixel ancillary lowering now uses the constant 0 for the render target index field (bits 16+) instead of reading the Layer builtin.

Why 0 is right. No pre-rasterization stage writes Layer today:

  • State.cpp ignores the vertex layer and viewport exports of PA_CL_VS_OUT_CNTL.
  • The vertex request's paClVsOutCntl is never set, so no Layer output is emitted.

When the last pre-rasterization stage has no Layer output, Vulkan uses the first layer (Layer). So the value the field stood for is 0.

Why reading Layer is wrong here. On AMD's Windows driver, a fragment shader that consumes the unwritten Layer loses its colour writes, even when the value never reaches the output. lavapipe returns 0, so CI didn't see it.

#4800 has the module dumps and the edited-module runs that isolate this:

  • gl_SampleID replaced by 0: still loses the writes.
  • gl_Layer replaced by 0: writes land.
  • gl_Layer loaded but unused: writes land.

The shader.md debt entry for the packed ancillary word now says where the 0 comes from. #423 and #1077 (@alfalfa-star) make layered draws export Layer through PA_CL_VS_OUT_CNTL. Once they land, those draws need the real value: read Layer when the draw exports it, and 0 otherwise, which is the case this change covers. Nothing on main exports it yet, so I left that condition out.

Tested

Windows 11 (26300), AMD Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON, on main 43e3a70f8:

  • agc_driver_relative_ancillary: failed on main on this GPU; passes 3/3 with this change.
  • pixel_ancillary: 3/3. It now requires the render target index field to be 0 for rows whose layer is not 0.
  • ctest -R '^agc_' -j 1 (shader cache emptied): 445/445.
  • ctest -E '^agc_' -j 4: 574/574.
  • Revert check: with main's ConstantFolder.cpp, pixel_ancillary and agc_driver_relative_ancillary both fail.
  • Six homebrew titles run 60 s with no stop, as on main: Stremio Plus, Capy Mobile, DriftCheck, EVO Player, DOOM and OpenRCT2.
  • Fork CI (run): Linux 1001/1002, Windows 1018/1019, relinker 142/143, 133/134 and 137/138. The one failure in each job is conventions_ci_gate, because my fork runs the old build.yml without file filters, which main's checker rejects. It is not this change.
  • tools/check_conventions.py --base origin/main and git diff --check pass.

Not run on Linux locally. No title on hand reads the ancillary layer field; that is #2548's set: Stray, Kena, Lies of P and others.

Overlap. #4031 (@AlxcBTW) also changes lowerPackedAncillary and PixelAncillary.cpp: it adds the primitive class field. The two don't depend on each other. Whichever merges second has to take this into account:

  • #4031 adds a second Layer read: the whole-word composition, insertBuiltin(..., StageInputKind::Layer) shifted by 16. With this change that read becomes the same constant 0.
  • The merged pixel_ancillary cases need to agree on the field.

I merged #4031's head dd8403112 onto this branch locally and applied the same 0 at that read. Its new agc_driver_pixel_ancillary_word then passes on this AMD GPU, 3/3, where it failed on #4031 alone, and so does agc_driver_relative_ancillary. pixel_ancillary needs that merge reconciled. If #4031 goes in first, I'll rebase this one and do it.

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 under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4836191600 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4842). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-12T23:27:48Z. --- ### What Fixes #4800. The packed pixel ancillary lowering now uses the constant 0 for the render target index field (bits 16+) instead of reading the `Layer` builtin. **Why 0 is right.** No pre-rasterization stage writes `Layer` today: - `State.cpp` ignores the vertex layer and viewport exports of `PA_CL_VS_OUT_CNTL`. - The vertex request's `paClVsOutCntl` is never set, so no `Layer` output is emitted. When the last pre-rasterization stage has no `Layer` output, Vulkan uses the first layer ([`Layer`](https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/Layer.html)). So the value the field stood for is 0. **Why reading `Layer` is wrong here.** On AMD's Windows driver, a fragment shader that consumes the unwritten `Layer` loses its colour writes, even when the value never reaches the output. lavapipe returns 0, so CI didn't see it. #4800 has the module dumps and the edited-module runs that isolate this: - `gl_SampleID` replaced by 0: still loses the writes. - `gl_Layer` replaced by 0: writes land. - `gl_Layer` loaded but unused: writes land. The `shader.md` debt entry for the packed ancillary word now says where the 0 comes from. #423 and #1077 (@alfalfa-star) make layered draws export `Layer` through `PA_CL_VS_OUT_CNTL`. Once they land, those draws need the real value: read `Layer` when the draw exports it, and 0 otherwise, which is the case this change covers. Nothing on `main` exports it yet, so I left that condition out. ### Tested Windows 11 (26300), AMD Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), WinLibs GCC 15.2.0, Release, `BUILD_TESTING=ON`, on `main` `43e3a70f8`: - `agc_driver_relative_ancillary`: failed on `main` on this GPU; passes 3/3 with this change. - `pixel_ancillary`: 3/3. It now requires the render target index field to be 0 for rows whose layer is not 0. - `ctest -R '^agc_' -j 1` (shader cache emptied): 445/445. - `ctest -E '^agc_' -j 4`: 574/574. - Revert check: with `main`'s `ConstantFolder.cpp`, `pixel_ancillary` and `agc_driver_relative_ancillary` both fail. - Six homebrew titles run 60 s with no stop, as on `main`: Stremio Plus, Capy Mobile, DriftCheck, EVO Player, DOOM and OpenRCT2. - Fork CI ([run](https://github.com/LeandroLP23/AnyPS5/actions/runs/38319801977)): Linux 1001/1002, Windows 1018/1019, relinker 142/143, 133/134 and 137/138. The one failure in each job is `conventions_ci_gate`, because my fork runs the old `build.yml` without file filters, which `main`'s checker rejects. It is not this change. - `tools/check_conventions.py --base origin/main` and `git diff --check` pass. Not run on Linux locally. No title on hand reads the ancillary layer field; that is #2548's set: Stray, Kena, Lies of P and others. **Overlap.** #4031 (@AlxcBTW) also changes `lowerPackedAncillary` and `PixelAncillary.cpp`: it adds the primitive class field. The two don't depend on each other. Whichever merges second has to take this into account: - #4031 adds a second `Layer` read: the whole-word composition, `insertBuiltin(..., StageInputKind::Layer)` shifted by 16. With this change that read becomes the same constant 0. - The merged `pixel_ancillary` cases need to agree on the field. I merged #4031's head `dd8403112` onto this branch locally and applied the same 0 at that read. Its new `agc_driver_pixel_ancillary_word` then passes on this AMD GPU, 3/3, where it failed on #4031 alone, and so does `agc_driver_relative_ancillary`. `pixel_ancillary` needs that merge reconciled. If #4031 goes in first, I'll rebase this one and do it. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] AI-assisted: yes (Claude Code)
oneandonlydean commented 2026-10-13 01:03:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T01:03:32Z.


#4031 is merged, so I rebased this onto it and pushed (3334e41e45, your commit and message kept). The ConstantFolder.cpp change is the same: the render target index field is a constant 0, and the helper #4031 added now takes SampleId only. The debt entry in docs/dev/debt/shader.md is merged with the one #4031 added. Full build is running; agc_driver_relative_ancillary on AMD is the part we can't run here.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6135809591 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4842#issuecomment-6135809591). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T01:03:32Z. --- #4031 is merged, so I rebased this onto it and pushed (3334e41e45, your commit and message kept). The `ConstantFolder.cpp` change is the same: the render target index field is a constant 0, and the helper #4031 added now takes `SampleId` only. The debt entry in `docs/dev/debt/shader.md` is merged with the one #4031 added. Full build is running; `agc_driver_relative_ancillary` on AMD is the part we can't run here.
LeandroLP23 commented 2026-10-13 06:00:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-13T06:00:13Z.


Confirmed on AMD after the merge: main 88107b7de (with #4031 and this), Windows 11, Radeon 860M (driver 32.0.13058.8001), Release. agc_driver_relative_ancillary, agc_driver_pixel_ancillary_word and pixel_ancillary pass 3/3, and ctest -R '^agc_' -j 1 is 460/460. Thanks for carrying it over #4031.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6139314769 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4842#issuecomment-6139314769). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-13T06:00:13Z. --- Confirmed on AMD after the merge: `main` `88107b7de` (with #4031 and this), Windows 11, Radeon 860M (driver 32.0.13058.8001), Release. `agc_driver_relative_ancillary`, `agc_driver_pixel_ancillary_word` and `pixel_ancillary` pass 3/3, and `ctest -R '^agc_' -j 1` is 460/460. Thanks for carrying it over #4031.
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!4842
No description provided.