fix(shader): name the per-invocation value behind a spanned-wave fallback #22432

Merged
milescoviello merged 2 commits from upstream-pr/22432 into main 2026-11-26 05:53:06 +00:00
milescoviello commented 2026-11-17 15:24:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-11-17T15:24:50Z.


What

When the spanned-wave uniformity check finds a barrier in divergent flow, the recompiler falls back to two lanes per invocation and logs the reason:

[spanned-wave] 0x... falls back to two lanes per invocation: an OpControlBarrier in block %N of function %N sits in control flow a per-invocation value decides

The line named the barrier's block, not the value. MXGP 26 (PPSA30839) logs 100 such fallbacks in one run and Borderlands 4 (PPSA01494) 168, and the log cannot tell which kind of value causes them. That decides what could keep those programs spanned.

The check now keeps a root for each per-invocation value it finds. A value derived from others takes the root of its first per-invocation operand. The roots are:

  • a load of a varying built-in (LocalInvocationIndex and the others VaryingBuiltin lists);
  • a load of an Input variable;
  • a load of a private variable that is stored a per-invocation value or in divergent flow;
  • a load or atomic load of memory the shader writes, with no barrier before it;
  • an atomic or subgroup result;
  • a phi in a block where divergent flow merges;
  • a call to a function that computes a per-invocation value;
  • a function parameter.

For each divergent construct it also keeps the branch that split it. The report appends that branch, its condition and the condition's root, for example:

...sits in control flow a per-invocation value decides; the branch at the end of block %100 on %102 decides it, and %102 comes from a load of the LocalInvocationIndex built-in

The decision itself is unchanged: the same programs are rejected and accepted as on main.

Second commit. A private variable's load had one merged reason. Each variable now keeps the first of three reasons, which a fix would treat differently: a per-invocation value stored to it (with that value's root), a store through a per-invocation pointer, or a store in divergent flow (with the store's block).

MXGP 26 with the first commit (main e7988a85b0 + #22052 + #22401 + #20827 + this PR's first commit, 600 s): 84 fallbacks in 42 distinct programs. The roots:

Root Fallbacks
a load of a private variable stored a per-invocation value or in divergent flow (the reason the second commit splits) 54
a load of memory the shader writes, with no barrier before the load 22
an exit from divergent flow 8

Tested

  • spanned_uniformity (core/shader/recompiler/tests/SpannedUniformityTests.cpp) gains four cases that require the report to name the root: a lane comparison (the LocalInvocationIndex built-in, with the deciding branch and condition), a phi joining a per-lane selection, an atomic result, and a workgroup word read after a store with no barrier before the load. The existing cases, which check only whether a program is rejected, are unchanged.
  • Linux (Ubuntu 26.04.1, GCC 15.2, Release): 3 of 3 runs pass. Windows 11 (VM, WinLibs GCC 15.2): 3 of 3 pass.
  • Negative control, main's SpirvSpannedUniformity.cpp with this PR's tests, on both: the four new cases fail, each with the old line, for example expected a rejection naming "the branch at the end of block %100 on %102 decides it, and %102 comes from a load of the LocalInvocationIndex built-in", got an OpControlBarrier in block %103 of function %16 sits in control flow a per-invocation value decides.
  • Second commit: two more cases require the split reasons, is stored in divergent flow in block %103 for a store on one side of a per-lane selection, and is stored %101, which comes from a load of the LocalInvocationIndex built-in for a stored lane value. Linux: 3 of 3 pass; with main's SpirvSpannedUniformity.cpp the new cases fail.
  • MXGP 26 run with the first commit: the table above.
  • Helldiverr's Windows run of 700f58b981 merged onto main aa11bb9111 (WinLibs GCC 15.2, Release): spanned_uniformity passes 3 of 3, and with only this PR's test on main all six new reason cases fail with the old message. Their extra GPU check, agc_driver_spanned_ballot_sequence on an AMD Radeon AI PRO R9700 with the Khronos validation layer, passes with 0 VUID- lines. That device has no full 32-lane subgroups, so it skipped the spanned mode, ran only the two-lane path, and does not exercise this change.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a (the check runs on SPIR-V words; no GPU in the test)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5359704577 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22432). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-11-17T15:24:50Z. --- ### What When the spanned-wave uniformity check finds a barrier in divergent flow, the recompiler falls back to two lanes per invocation and logs the reason: ``` [spanned-wave] 0x... falls back to two lanes per invocation: an OpControlBarrier in block %N of function %N sits in control flow a per-invocation value decides ``` The line named the barrier's block, not the value. MXGP 26 (PPSA30839) logs 100 such fallbacks in one run and Borderlands 4 (PPSA01494) 168, and the log cannot tell which kind of value causes them. That decides what could keep those programs spanned. The check now keeps a root for each per-invocation value it finds. A value derived from others takes the root of its first per-invocation operand. The roots are: - a load of a varying built-in (LocalInvocationIndex and the others `VaryingBuiltin` lists); - a load of an Input variable; - a load of a private variable that is stored a per-invocation value or in divergent flow; - a load or atomic load of memory the shader writes, with no barrier before it; - an atomic or subgroup result; - a phi in a block where divergent flow merges; - a call to a function that computes a per-invocation value; - a function parameter. For each divergent construct it also keeps the branch that split it. The report appends that branch, its condition and the condition's root, for example: ``` ...sits in control flow a per-invocation value decides; the branch at the end of block %100 on %102 decides it, and %102 comes from a load of the LocalInvocationIndex built-in ``` The decision itself is unchanged: the same programs are rejected and accepted as on `main`. **Second commit.** A private variable's load had one merged reason. Each variable now keeps the first of three reasons, which a fix would treat differently: a per-invocation value stored to it (with that value's root), a store through a per-invocation pointer, or a store in divergent flow (with the store's block). **MXGP 26 with the first commit** (`main` e7988a85b0 + #22052 + #22401 + #20827 + this PR's first commit, 600 s): 84 fallbacks in 42 distinct programs. The roots: | Root | Fallbacks | | --- | --- | | a load of a private variable stored a per-invocation value or in divergent flow (the reason the second commit splits) | 54 | | a load of memory the shader writes, with no barrier before the load | 22 | | an exit from divergent flow | 8 | ### Tested - `spanned_uniformity` (`core/shader/recompiler/tests/SpannedUniformityTests.cpp`) gains four cases that require the report to name the root: a lane comparison (the LocalInvocationIndex built-in, with the deciding branch and condition), a phi joining a per-lane selection, an atomic result, and a workgroup word read after a store with no barrier before the load. The existing cases, which check only whether a program is rejected, are unchanged. - Linux (Ubuntu 26.04.1, GCC 15.2, Release): 3 of 3 runs pass. Windows 11 (VM, WinLibs GCC 15.2): 3 of 3 pass. - Negative control, `main`'s `SpirvSpannedUniformity.cpp` with this PR's tests, on both: the four new cases fail, each with the old line, for example `expected a rejection naming "the branch at the end of block %100 on %102 decides it, and %102 comes from a load of the LocalInvocationIndex built-in", got an OpControlBarrier in block %103 of function %16 sits in control flow a per-invocation value decides`. - Second commit: two more cases require the split reasons, `is stored in divergent flow in block %103` for a store on one side of a per-lane selection, and `is stored %101, which comes from a load of the LocalInvocationIndex built-in` for a stored lane value. Linux: 3 of 3 pass; with `main`'s `SpirvSpannedUniformity.cpp` the new cases fail. - MXGP 26 run with the first commit: the table above. - [Helldiverr's Windows run](https://github.com/boykopovar/AnyPS5/pull/22432#issuecomment-7100035467) of `700f58b981` merged onto `main` `aa11bb9111` (WinLibs GCC 15.2, Release): `spanned_uniformity` passes 3 of 3, and with only this PR's test on `main` all six new reason cases fail with the old message. Their extra GPU check, `agc_driver_spanned_ballot_sequence` on an AMD Radeon AI PRO R9700 with the Khronos validation layer, passes with 0 `VUID-` lines. That device has no full 32-lane subgroups, so it skipped the spanned mode, ran only the two-lane path, and does not exercise this change. ### 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) and the licence notice of code adapted from upstream (see AGENTS.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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a (the check runs on SPIR-V words; no GPU in the test) - [x] AI-assisted: yes
MarcZX10 commented 2026-11-23 07:44:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T07:44:51Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the review is complete, and the inspected source and tests support merging.

What I ran

Reviewed head 700f58b9817c6685525db02283f164516e4fe460. No commands or tests were run in this review; the reported Linux and Windows runs are author supplied.

Results

Check Result Note
Source review passed Both changed files read
Tests not run Author reports passing runs

Findings

Blocking

None.

Non-blocking

None.

Not verified

No tests were run independently. The reported platform runs and negative control were not independently confirmed. Read core/shader/recompiler/SpirvBackend/src/SpirvSpannedUniformity.cpp and core/shader/recompiler/tests/SpannedUniformityTests.cpp; both changed files listed as reviewed were included and read. No changed files were excluded.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6018020017 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22432#pullrequestreview-6018020017). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T07:44:51Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the review is complete, and the inspected source and tests support merging. ## What I ran Reviewed head `700f58b9817c6685525db02283f164516e4fe460`. No commands or tests were run in this review; the reported Linux and Windows runs are author supplied. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | Both changed files read | | Tests | not run | Author reports passing runs | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No tests were run independently. The reported platform runs and negative control were not independently confirmed. Read `core/shader/recompiler/SpirvBackend/src/SpirvSpannedUniformity.cpp` and `core/shader/recompiler/tests/SpannedUniformityTests.cpp`; both changed files listed as reviewed were included and read. No changed files were excluded. ## To get this to a good state Nothing is required.
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!22432
No description provided.