fix(shader): match half-wave reductions in vertex programs #2450

Merged
oneandonlydean merged 1 commit from upstream-pr/2450 into main 2026-10-10 04:47:34 +00:00
oneandonlydean commented 2026-10-09 21:27:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T21:27:58Z.


What

emitEntryPrologue sets a program's entry EXEC to:

  • the ballot of !gl_HelperInvocation in a pixel program;
  • the ballot of true in vertex, local and tessellation programs.

#1268's half-wave reduction matcher (EntryLaneWalk) proves keys are the identity outside the entry EXEC, but it only knew the pixel form. Every wave64 vertex program that scans keys selected under its EXEC and reads lane 63 therefore threw on a 32-lane host subgroup:

ShaderRecompiler::Recompile: SPIR-V emission failed: hash=0x21484880640 stage=1 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

EntryLaneWalk now also accepts a ballot of true as within the entry EXEC for those stages. Every invocation is live at their entry, and a later ballot of true holds only invocations that are still active.

These keep their existing forms:

  • pixel programs, because a ballot of true there includes helper invocations;
  • compute and mesh programs, because their entry EXEC can bound the local invocation index.

The emitted reduction is #1268's.

Touches core/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterMath.cpp.

The level in the test below needs this and "fix(shader): read lane 63 of a wave64 v_max_f32/v_min_f32 half-wave scan" together; the two are independent and either can go in first.

Tested

  • Linux (CachyOS, GCC 16.2, RTX 4090, NVIDIA 610.57), on main a8b032b236: ctest 495/495. tools/check_conventions.py passes.
  • agc_shader_memory, verifyHalfWaveReduction:
    • the UMin scan as a wave64 vertex program reads lane 31 as a subgroup UMin on 32 lanes. On main it throws the line above with stage=1.
    • the SMax scan reads lanes 31 and 63 as reductions of host invocations 0-31 and 32-63 on 64 lanes.
  • A heavier title: a level load stopped with the line above. With this and the float-scan fix (separate PR), it loads.

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 (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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4806047283 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2450). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T21:27:58Z. --- ### What `emitEntryPrologue` sets a program's entry EXEC to: - the ballot of `!gl_HelperInvocation` in a pixel program; - the ballot of `true` in vertex, local and tessellation programs. #1268's half-wave reduction matcher (`EntryLaneWalk`) proves keys are the identity outside the entry EXEC, but it only knew the pixel form. Every wave64 vertex program that scans keys selected under its EXEC and reads lane 63 therefore threw on a 32-lane host subgroup: ``` ShaderRecompiler::Recompile: SPIR-V emission failed: hash=0x21484880640 stage=1 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 ``` `EntryLaneWalk` now also accepts a ballot of `true` as within the entry EXEC for those stages. Every invocation is live at their entry, and a later ballot of `true` holds only invocations that are still active. These keep their existing forms: - pixel programs, because a ballot of `true` there includes helper invocations; - compute and mesh programs, because their entry EXEC can bound the local invocation index. The emitted reduction is #1268's. Touches `core/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterMath.cpp`. The level in the test below needs this and "fix(shader): read lane 63 of a wave64 v_max_f32/v_min_f32 half-wave scan" together; the two are independent and either can go in first. ### Tested - Linux (CachyOS, GCC 16.2, RTX 4090, NVIDIA 610.57), on `main` a8b032b236: ctest 495/495. `tools/check_conventions.py` passes. - `agc_shader_memory`, `verifyHalfWaveReduction`: - the UMin scan as a wave64 vertex program reads lane 31 as a subgroup UMin on 32 lanes. On `main` it throws the line above with `stage=1`. - the SMax scan reads lanes 31 and 63 as reductions of host invocations 0-31 and 32-63 on 64 lanes. - A heavier title: a level load stopped with the line above. With this and the float-scan fix (separate PR), it loads. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
popcoder565 commented 2026-10-09 22:46:54 +00:00 (Migrated from github.com)

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


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 c8c90995, merged onto main 09a3462e in one build with #2473, which current main needs to build on Windows, and 3 other new PRs.

  • This PR's tests pass: agc_shader_memory and agc_shader_bindless.
  • Full ctest in that build: 546 of 546.

No title was run.

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6090558712 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2450#issuecomment-6090558712). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-09T22:46:54Z. --- 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 `c8c90995`, merged onto `main` 09a3462e in one build with #2473, which current `main` needs to build on Windows, and 3 other new PRs. - This PR's tests pass: `agc_shader_memory` and `agc_shader_bindless`. - Full ctest in that build: 546 of 546. No title was run. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
Kikoarl commented 2026-10-09 22:50:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-09T22:50:16Z.


Tested on Linux (CachyOS x86_64, Intel RPL-S iGPU / Mesa 26.3.0-devel / Vulkan 1.4.363, GCC 16.2.1) at c8c90995:

  • Build: Built cleanly in RAM (/tmp/anyps5_build) with zero warnings/errors.
  • Conventions: python3 tools/check_conventions.py --base origin/main --head HEAD -> PASS (0 errors).
  • Verification: Verified half-wave reduction pattern matching in vertex shader stages in SpirvAluEmitterMath.cpp. Extends reduction recognition from compute/fragment to vertex pipelines.

LGTM!

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6090595586 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2450#issuecomment-6090595586). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-09T22:50:16Z. --- Tested on Linux (CachyOS x86_64, Intel RPL-S iGPU / Mesa 26.3.0-devel / Vulkan 1.4.363, GCC 16.2.1) at `c8c90995`: - **Build**: Built cleanly in RAM (`/tmp/anyps5_build`) with zero warnings/errors. - **Conventions**: `python3 tools/check_conventions.py --base origin/main --head HEAD` -> **PASS (0 errors)**. - **Verification**: Verified half-wave reduction pattern matching in vertex shader stages in `SpirvAluEmitterMath.cpp`. Extends reduction recognition from compute/fragment to vertex pipelines. LGTM!
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!2450
No description provided.