fix(shader): read lane 63 of half-wave reductions whose keys exclude helper lanes #5189

Merged
EagleBearerYS merged 2 commits from upstream-pr/5189 into main 2026-10-14 10:56:21 +00:00
EagleBearerYS commented 2026-10-13 14:10:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-13T14:10:09Z.


What

On a 32-lane host subgroup (NVIDIA), a wave64 pixel program's v_readlane_b32 of lane 63 is emitted only when its half-wave scan's keys are proven zero for lanes that did not enter (EntryLaneWalk, SpirvAluEmitterMath.cpp). Resident Evil Village (PPSA01556, content 01.210.000) has 8 pixel programs with a wave-wide OR reduction: DPP row_shr ORs, v_permlanex16_b32, then v_readlane_b32 of lanes 31 and 63. They fail with:

SPIR-V emission failed: ... opcode=ReadLane reason=v_readlane_b32 of lane 63 is outside the 32-lane host subgroup that runs this wave64 program at one lane per invocation

The keys' mask is exec & ~vcc from entry inside a loop: LogicalAnd(loop exec, LogicalAnd(IEqual32(HelperInvocation, 0), ...)). The proof failed for two reasons:

  • It accepted the not-helper test only inside ballots, not as a lane bit.
  • It searched conjunctions depth first, so the loop's exec phis took the whole 512-step budget before the walk reached the helper test. These programs need about 780,000-950,000 steps in that order.

Now the helper test is a lane bit, and a LogicalAnd first looks for a false or helper conjunct before it walks an operand. The scan then maps to a subgroup reduction for lane 31 and the identity for lane 63 (MatchHalfWaveScan), as it already did for keys the proof accepted.

Related: #5398 (the same message on NHL 26; a replay of the program dumped there still fails with this change, so it isn't fixed here).

Tested

  • Windows 11, WinLibs GCC 15.2.0 r7, Release, this branch merged into main a252fcd75: two new verifyHalfWaveReduction cases in agc_shader_memory. With main's SpirvAluEmitterMath.cpp, agc_shader_memory fails with the title's message.
    • Helper keys: an OR scan keyed by v_cmp_gt_f32 vcc, 0, v0 and s_andn2_b64 s[24:25], exec, vcc. It fails with the title's message on main and passes with the change.
    • Search order: 600 compares narrow exec before the same scan, which puts the helper test at the bottom of a 600-deep LogicalAnd chain. On the branch's base, 6d7b87370, it fails with only the search-order half reverted and passes with the full change.
    • agc_shader_memory, agc_shader_bindless, agc_shader_srt_read_patching, agc_shader_frontend_pair, agc_shader_frontend_pair_off and agc_shader_disk_cache pass, also with the other two Resident Evil Village fixes (listed in #5169) merged in.
  • Linux (WSL2 Ubuntu 24.04, GCC 13.3, CI configuration), with the three Resident Evil Village fixes (listed in #5169) merged into main a252fcd75: the same six tests pass.
  • PPSA01556 on Windows 11 (RTX 3070 Laptop GPU), on a local branch past the title's earlier stops: all 8 pixel programs prepare. Offline, the 11 dumped pixel programs recompile.
  • PPSA02530 (PRAGMATA), run by xXPBSXx on Windows 10 with an RTX 4080 SUPER, one run each (comment): without this change it stops about 45 s in with the same message. With it there's no ReadLane failure, and the run goes on about 160 s to a different stop (static bindless image capacity exceeded).
  • python3 tools/check_conventions.py --base origin/main: passed.

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: PPSA01556 #5169; PPSA02530 gets past the same stop (xXPBSXx's run above)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4844518447 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5189). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-13T14:10:09Z. --- ### What On a 32-lane host subgroup (NVIDIA), a wave64 pixel program's `v_readlane_b32` of lane 63 is emitted only when its half-wave scan's keys are proven zero for lanes that did not enter (`EntryLaneWalk`, `SpirvAluEmitterMath.cpp`). Resident Evil Village (PPSA01556, content 01.210.000) has 8 pixel programs with a wave-wide OR reduction: DPP `row_shr` ORs, `v_permlanex16_b32`, then `v_readlane_b32` of lanes 31 and 63. They fail with: ``` SPIR-V emission failed: ... opcode=ReadLane reason=v_readlane_b32 of lane 63 is outside the 32-lane host subgroup that runs this wave64 program at one lane per invocation ``` The keys' mask is `exec & ~vcc` from entry inside a loop: `LogicalAnd(loop exec, LogicalAnd(IEqual32(HelperInvocation, 0), ...))`. The proof failed for two reasons: - It accepted the not-helper test only inside ballots, not as a lane bit. - It searched conjunctions depth first, so the loop's exec phis took the whole 512-step budget before the walk reached the helper test. These programs need about 780,000-950,000 steps in that order. Now the helper test is a lane bit, and a `LogicalAnd` first looks for a false or helper conjunct before it walks an operand. The scan then maps to a subgroup reduction for lane 31 and the identity for lane 63 (`MatchHalfWaveScan`), as it already did for keys the proof accepted. Related: #5398 (the same message on NHL 26; a replay of the program dumped there still fails with this change, so it isn't fixed here). ### Tested - Windows 11, WinLibs GCC 15.2.0 r7, Release, this branch merged into `main` a252fcd75: two new `verifyHalfWaveReduction` cases in `agc_shader_memory`. With `main`'s `SpirvAluEmitterMath.cpp`, `agc_shader_memory` fails with the title's message. - Helper keys: an OR scan keyed by `v_cmp_gt_f32 vcc, 0, v0` and `s_andn2_b64 s[24:25], exec, vcc`. It fails with the title's message on `main` and passes with the change. - Search order: 600 compares narrow exec before the same scan, which puts the helper test at the bottom of a 600-deep `LogicalAnd` chain. On the branch's base, 6d7b87370, it fails with only the search-order half reverted and passes with the full change. - `agc_shader_memory`, `agc_shader_bindless`, `agc_shader_srt_read_patching`, `agc_shader_frontend_pair`, `agc_shader_frontend_pair_off` and `agc_shader_disk_cache` pass, also with the other two Resident Evil Village fixes (listed in #5169) merged in. - Linux (WSL2 Ubuntu 24.04, GCC 13.3, CI configuration), with the three Resident Evil Village fixes (listed in #5169) merged into `main` a252fcd75: the same six tests pass. - PPSA01556 on Windows 11 (RTX 3070 Laptop GPU), on a local branch past the title's earlier stops: all 8 pixel programs prepare. Offline, the 11 dumped pixel programs recompile. - PPSA02530 (PRAGMATA), run by xXPBSXx on Windows 10 with an RTX 4080 SUPER, one run each ([comment](https://github.com/boykopovar/AnyPS5/pull/5189#issuecomment-6163463739)): without this change it stops about 45 s in with the same message. With it there's no `ReadLane` failure, and the run goes on about 160 s to a different stop (`static bindless image capacity exceeded`). - `python3 tools/check_conventions.py --base origin/main`: passed. ### 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](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: PPSA01556 #5169; PPSA02530 gets past the same stop (xXPBSXx's run above) - [x] AI-assisted: yes
johandavidcm commented 2026-10-13 22:30:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by johandavidcm on 2026-10-13T22:30:30Z.


Cross-vendor validation on one Windows machine: Windows 11 26200, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON, this PR (b6bc7218f) merged into main c7601b797 (plus #5301, a relinker resource build fix my checkout path needs). ANYPS5_REQUIRE_VULKAN=1, ctest --timeout 120 --parallel 4 over the 502 agc/shader/video_out tests, then the 44 lane, wave, DPP, permlane, readlane, reduction and subgroup tests (including agc_shader_memory, _bindless, _srt_read_patching, _frontend_pair, _frontend_pair_off, _disk_cache) with --repeat until-fail:3.

GPU (ANYPS5_GPU) Driver 502-test suite 44 focused tests x3
NVIDIA GeForce RTX 4070 (subgroup 32) 32.0.16.1742 502 passed (7 skipped) 44/44
AMD Radeon(TM) Graphics, Ryzen 7 7800X3D iGPU (RDNA 2, 0x164e, subgroup 64) 32.0.21042.62 498 passed, 4 failed 44/44

The 4 AMD failures (agc_driver_pixel_interlock, agc_driver_layered_volume_draw, agc_driver_layered_volume_vertex, agc_driver_lds_mixed_width_atomics) fail identically on main c7601b797 without this PR on the same machine (#2009, #5271), so no regression on the 64-lane host, where the changed path is not taken. Not tested: PPSA01556.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6156598592 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5189#issuecomment-6156598592). Originally posted by [johandavidcm](https://github.com/johandavidcm) on 2026-10-13T22:30:30Z. --- Cross-vendor validation on one Windows machine: Windows 11 26200, WinLibs GCC 15.2.0 r7, Release, `BUILD_TESTING=ON`, this PR (`b6bc7218f`) merged into `main` `c7601b797` (plus #5301, a relinker resource build fix my checkout path needs). `ANYPS5_REQUIRE_VULKAN=1`, `ctest --timeout 120 --parallel 4` over the 502 agc/shader/video_out tests, then the 44 lane, wave, DPP, permlane, readlane, reduction and subgroup tests (including `agc_shader_memory`, `_bindless`, `_srt_read_patching`, `_frontend_pair`, `_frontend_pair_off`, `_disk_cache`) with `--repeat until-fail:3`. | GPU (`ANYPS5_GPU`) | Driver | 502-test suite | 44 focused tests x3 | |---|---|---|---| | NVIDIA GeForce RTX 4070 (subgroup 32) | 32.0.16.1742 | 502 passed (7 skipped) | 44/44 | | AMD Radeon(TM) Graphics, Ryzen 7 7800X3D iGPU (RDNA 2, `0x164e`, subgroup 64) | 32.0.21042.62 | 498 passed, 4 failed | 44/44 | The 4 AMD failures (`agc_driver_pixel_interlock`, `agc_driver_layered_volume_draw`, `agc_driver_layered_volume_vertex`, `agc_driver_lds_mixed_width_atomics`) fail identically on `main` `c7601b797` without this PR on the same machine (#2009, #5271), so no regression on the 64-lane host, where the changed path is not taken. Not tested: PPSA01556.
cookie42073-cmd commented 2026-10-14 04:26:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by cookie42073-cmd on 2026-10-14T04:26:43Z.


Hey everyone, I followed the NHL26 capture in #5398 through the compiler and have a small follow-up to #5189 ready locally.

Thanks to @milchgeldkassierer for the capture and @EagleBearerYS for the helper-lane proof work in #5189. With that PR applied, the capture still hit the lane-63 refusal because EntryLaneWalk kept rechecking the same loop-carried mask until it used up its budget. The follow-up reuses completed proofs, keeps proof kinds and mask halves separate, and avoids saving results that depend on unresolved Phi-cycle assumptions. The budget stays at 512.

Before/after on the same capture: pinned main a5f493f9 plus #5189 at b6bc7218 fails with the lane-63 error; adding the follow-up compiles and validates 69,230 SPIR-V words. The new CPU and GPU regressions fail with the original compiler and pass with the fix. Full Windows build and all 62 selected tests passed on Windows 11 build 26300 with an NVIDIA RTX 4070 SUPER, driver 617.42. The GPU regression compares rendered reduction values with CPU expectations and covers partial waves through a saved-EXEC loop.

This verifies the captured compiler failure and the synthetic tests. I haven't run NHL26 itself, tested native 64-lane hardware, or verified this on another GPU vendor. The loop test doesn't cover arbitrary changing execution masks.

The local follow-up is 9456e863e4cd4bb88ac77aa6871e86ad23a7349f, on main a5f493f9 plus #5189 at b6bc7218. @EagleBearerYS, would you prefer a separate PR depending on #5189, or a follow-up after yours merges?

Once we agree on a test branch, the useful next check is a fresh NHL26 run on PPSA26785 v01.060.000: tested commit, GPU/driver/OS, and the log through its next stopping point. If another shader fails, its full RecompileRequest would let us investigate that next. We already have the capture needed for this fix; no additional game dump is needed.

AI-assisted implementation and independent review; I've checked the final commit against the saved before/after evidence.

Patch and test logs: Blazing-Cook-NHL26-proof-cache-evidence.zip

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6160879528 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5189#issuecomment-6160879528). Originally posted by [cookie42073-cmd](https://github.com/cookie42073-cmd) on 2026-10-14T04:26:43Z. --- Hey everyone, I followed the NHL26 capture in #5398 through the compiler and have a small follow-up to #5189 ready locally. Thanks to @milchgeldkassierer for the capture and @EagleBearerYS for the helper-lane proof work in #5189. With that PR applied, the capture still hit the lane-63 refusal because EntryLaneWalk kept rechecking the same loop-carried mask until it used up its budget. The follow-up reuses completed proofs, keeps proof kinds and mask halves separate, and avoids saving results that depend on unresolved Phi-cycle assumptions. The budget stays at 512. Before/after on the same capture: pinned main a5f493f9 plus #5189 at b6bc7218 fails with the lane-63 error; adding the follow-up compiles and validates 69,230 SPIR-V words. The new CPU and GPU regressions fail with the original compiler and pass with the fix. Full Windows build and all 62 selected tests passed on Windows 11 build 26300 with an NVIDIA RTX 4070 SUPER, driver 617.42. The GPU regression compares rendered reduction values with CPU expectations and covers partial waves through a saved-EXEC loop. This verifies the captured compiler failure and the synthetic tests. I haven't run NHL26 itself, tested native 64-lane hardware, or verified this on another GPU vendor. The loop test doesn't cover arbitrary changing execution masks. The local follow-up is 9456e863e4cd4bb88ac77aa6871e86ad23a7349f, on main a5f493f9 plus #5189 at b6bc7218. @EagleBearerYS, would you prefer a separate PR depending on #5189, or a follow-up after yours merges? Once we agree on a test branch, the useful next check is a fresh NHL26 run on PPSA26785 v01.060.000: tested commit, GPU/driver/OS, and the log through its next stopping point. If another shader fails, its full RecompileRequest would let us investigate that next. We already have the capture needed for this fix; no additional game dump is needed. AI-assisted implementation and independent review; I've checked the final commit against the saved before/after evidence. Patch and test logs: [Blazing-Cook-NHL26-proof-cache-evidence.zip](https://github.com/user-attachments/files/33417343/Blazing-Cook-NHL26-proof-cache-evidence.zip)
EagleBearerYS commented 2026-10-14 04:28:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-14T04:28:50Z.


Thanks, and nice find. That explains why #5189 alone still refused the #5398 capture.

A separate PR that depends on #5189 sounds best to me. It can name NHL 26 as its title now instead of waiting for #5189 to merge. Put Depends on: #5189 in it and keep #5189's commit as it is under yours.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6160903606 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5189#issuecomment-6160903606). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-14T04:28:50Z. --- Thanks, and nice find. That explains why #5189 alone still refused the #5398 capture. A separate PR that depends on #5189 sounds best to me. It can name NHL 26 as its title now instead of waiting for #5189 to merge. Put `Depends on: #5189` in it and keep #5189's commit as it is under yours.
xXPBSXx commented 2026-10-14 07:43:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-14T07:43:39Z.


Title evidence for this pull request and #5398: PRAGMATA (PPSA02530), Windows 10 (19045), RTX 4080 SUPER (NVIDIA), one run per state, no picture checked.

  • Without this pull request (local merge tree a57296147 = main + #5457 + #5620 + #5550): the run ends after about 45 s with what(): shader 0x2111516000 stage 5: ShaderRecompiler::Recompile: SPIR-V emission failed: hash=0x142024466432 stage=2 opcode=ReadLane reason=v_readlane_b32 of lane 63 is outside the 32-lane host subgroup that runs this wave64 program at one lane per invocation, PPSA02530_rR/run_093132.err lines 117 and 121.
  • With this pull request added (head b6bc7218f, whose last commit is from 2026-10-13, so it was the head at test time; local merge tree 9aea9a660): no ReadLane line in PPSA02530_rR/run_093702.err (677 lines); the run goes on for about 160 s and ends with a different stop, what(): shader 0x2111d38400 stage 5: ShaderRecompiler::Recompile: static bindless image capacity exceeded (line 128).

Not established: whether the lane-63 shader of the first run is the one that compiles now (the second stop is a different shader hash; one run per state), so the link to this change is indirect.

Test conditions: the merge trees are local and not pushed (the base main commit was not recorded by me). ninja -j 8 libs exit 0 for each run, 128 .prx; libSceConvertKeycode.prx replaced by a local stub; title executable app.exe of 2026-10-14 07:36:44 relinked by another session (relinker version and relink command not recorded by me); run with run_title.ps1, 300 s limit, one game at a time.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6163463739 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5189#issuecomment-6163463739). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-14T07:43:39Z. --- Title evidence for this pull request and #5398: PRAGMATA (PPSA02530), Windows 10 (19045), RTX 4080 SUPER (NVIDIA), one run per state, no picture checked. - Without this pull request (local merge tree `a57296147` = `main` + #5457 + #5620 + #5550): the run ends after about 45 s with `what(): shader 0x2111516000 stage 5: ShaderRecompiler::Recompile: SPIR-V emission failed: hash=0x142024466432 stage=2 opcode=ReadLane reason=v_readlane_b32 of lane 63 is outside the 32-lane host subgroup that runs this wave64 program at one lane per invocation`, `PPSA02530_rR/run_093132.err` lines 117 and 121. - With this pull request added (head `b6bc7218f`, whose last commit is from 2026-10-13, so it was the head at test time; local merge tree `9aea9a660`): no `ReadLane` line in `PPSA02530_rR/run_093702.err` (677 lines); the run goes on for about 160 s and ends with a different stop, `what(): shader 0x2111d38400 stage 5: ShaderRecompiler::Recompile: static bindless image capacity exceeded` (line 128). Not established: whether the lane-63 shader of the first run is the one that compiles now (the second stop is a different shader hash; one run per state), so the link to this change is indirect. Test conditions: the merge trees are local and not pushed (the base `main` commit was not recorded by me). `ninja -j 8 libs` exit 0 for each run, 128 `.prx`; `libSceConvertKeycode.prx` replaced by a local stub; title executable `app.exe` of 2026-10-14 07:36:44 relinked by another session (relinker version and relink command not recorded by me); run with `run_title.ps1`, 300 s limit, one game at a time. AI-assisted (Claude Code).
EagleBearerYS commented 2026-10-14 07:51:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-14T07:51:31Z.


Thanks for the PRAGMATA runs. I've added them to the description's Tested section and the Unblocks line, with your caveats (one run per state, indirect link).

The second stop looks like a separate limit. On current main that message comes from a single check in ResourceMaterializer.cpp, which throws when a bindless image's static expansion (BindlessSlots() entries) would take the shader past ShaderInfo::MaxImages (64). This PR doesn't touch that path.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6163597683 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5189#issuecomment-6163597683). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-14T07:51:31Z. --- Thanks for the PRAGMATA runs. I've added them to the description's Tested section and the Unblocks line, with your caveats (one run per state, indirect link). The second stop looks like a separate limit. On current `main` that message comes from a single check in `ResourceMaterializer.cpp`, which throws when a bindless image's static expansion (`BindlessSlots()` entries) would take the shader past `ShaderInfo::MaxImages` (64). This PR doesn't touch that path.
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!5189
No description provided.