fix(shader): avoid spinning in the spilled LDS lock #3015

Merged
MarcZX10 merged 1 commit from upstream-pr/3015 into main 2026-10-11 00:03:59 +00:00
MarcZX10 commented 2026-10-10 20:34:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T20:34:46Z.


What

LockedLdsUpdate retries an elected lane's 64-bit LDS compare-exchange in an inner loop. On Intel Arc / Mesa ANV, when LDS spills into a storage buffer and 64-bit shared atomics are unavailable, that inner spin can stop making progress and lose the Vulkan device. The change makes one compare-exchange attempt per outer election round; an unsuccessful lane remains pending and can be elected again. The lock update and result are unchanged.

Carries ThatsLeo’s tested fix from issue #2805, preserving the original commit author. The issue also records independent Intel Windows validation.

Tested

  • Linux x86_64, GCC 12.2, Release: built agc_driver_lds_beyond_device_limit_tests successfully.
  • On this environment’s llvmpipe (LLVM 15.0.6), agc_driver_lds_beyond_device_limit fails with the same incorrect counter result both with the patch and with the source file restored from current main; this software Vulkan implementation does not validate the reported Intel driver failure.
  • The issue reports all 12 agc_driver_lds* tests passing on Intel Arc 3/3, and independent Windows testing on Intel Arc and NVIDIA.
  • python3 tools/check_conventions.py --base upstream/main and git diff upstream/main...HEAD --check passed.

Checklist

  • Based on current main; no open PR implements this fix
  • One topic per PR; follow-ups go in a new PR
  • No source comments or unrelated files added
  • Generic behavior, not title-specific
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4814256488 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3015). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-10T20:34:46Z. --- ### What `LockedLdsUpdate` retries an elected lane's 64-bit LDS compare-exchange in an inner loop. On Intel Arc / Mesa ANV, when LDS spills into a storage buffer and 64-bit shared atomics are unavailable, that inner spin can stop making progress and lose the Vulkan device. The change makes one compare-exchange attempt per outer election round; an unsuccessful lane remains pending and can be elected again. The lock update and result are unchanged. Carries ThatsLeo’s tested fix from [issue #2805](https://github.com/boykopovar/AnyPS5/issues/2805), preserving the original commit author. The issue also records independent Intel Windows validation. ### Tested - Linux x86_64, GCC 12.2, Release: built `agc_driver_lds_beyond_device_limit_tests` successfully. - On this environment’s llvmpipe (LLVM 15.0.6), `agc_driver_lds_beyond_device_limit` fails with the same incorrect counter result both with the patch and with the source file restored from current `main`; this software Vulkan implementation does not validate the reported Intel driver failure. - The issue reports all 12 `agc_driver_lds*` tests passing on Intel Arc 3/3, and independent Windows testing on Intel Arc and NVIDIA. - `python3 tools/check_conventions.py --base upstream/main` and `git diff upstream/main...HEAD --check` passed. ### Checklist - [x] Based on current `main`; no open PR implements this fix - [x] One topic per PR; follow-ups go in a new PR - [x] No source comments or unrelated files added - [x] Generic behavior, not title-specific - [x] Depends on: none - [x] AI-assisted: yes
Dextroid17 commented 2026-10-10 23:53:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-10T23:53:32Z.

Review: COMMENTED


A lost Vulkan device is the most serious thing a shader recompiler can cause, so trading an unbounded inner spin for one attempt per outer election round deserves reading closely — and the reason it is safe is the part worth stating.

The equivalence claim is what makes it reviewable. "The lock update and the result are unchanged" is the right sentence to write, and the structure supports it: the compare-exchange still happens on an elected lane, a failed attempt now leaves that lane pending rather than re-spinning, and the OpPhi on attempted carries whether the lane has served. The only behaviour that changed is what happens after a failed attempt.

And the progress guarantee is worth stating, because it does not come from the election. OpGroupNonUniformElect re-runs every round and does not itself exclude lanes that have already served — but a served lane cannot be re-elected, because served is a uniform scalar OpPhi, so doneNext is uniform, the not-doneNext ballot comes back empty, and the outer loop exits the moment any lane is served. That is the sentence a reader will want beside this change: the attempt-per-round shape is safe because of what is uniform, not because of who the election picks.

And the testing note is the best thing here. Failing the same test both with the patch and with the source restored from main — on a software Vulkan implementation that cannot reproduce an Intel driver failure — is exactly the right thing to report: it says plainly which device can validate this and which cannot. What carries the rest is the issue's independent Intel Windows run, which is worth having named.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5481241492 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3015#pullrequestreview-5481241492). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-10T23:53:32Z. **Review:** COMMENTED --- A lost Vulkan device is the most serious thing a shader recompiler can cause, so trading an unbounded inner spin for one attempt per outer election round deserves reading closely — and the reason it is safe is the part worth stating. **The equivalence claim is what makes it reviewable.** "The lock update and the result are unchanged" is the right sentence to write, and the structure supports it: the compare-exchange still happens on an elected lane, a failed attempt now leaves that lane pending rather than re-spinning, and the `OpPhi` on `attempted` carries whether the lane has served. The only behaviour that changed is what happens *after* a failed attempt. **And the progress guarantee is worth stating, because it does not come from the election.** `OpGroupNonUniformElect` re-runs every round and does not itself exclude lanes that have already served — but a served lane cannot be re-elected, because `served` is a uniform scalar `OpPhi`, so `doneNext` is uniform, the not-`doneNext` ballot comes back empty, and the outer loop exits the moment any lane is served. That is the sentence a reader will want beside this change: the attempt-per-round shape is safe because of what is *uniform*, not because of who the election picks. **And the testing note is the best thing here.** Failing the same test *both* with the patch and with the source restored from `main` — on a software Vulkan implementation that cannot reproduce an Intel driver failure — is exactly the right thing to report: it says plainly which device can validate this and which cannot. What carries the rest is the issue's independent Intel Windows run, which is worth having named. Written with AI assistance.
adriadam10 commented 2026-10-10 23:58:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T23:58:42Z.


LockedLdsUpdate was refactored on main (type parameter for u32/u64), which conflicted with this change. Rebased onto current main: the two result phis now use type instead of TypeU64; the rest is unchanged.

Checked: scoped build + ctest (433 tests, all agc_driver_lds* and pixel_lds pass on RADV); the Intel failure itself isn't reproducible here, relying on the Intel Arc and Windows runs in #2805. Merging on green CI.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6103533134 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3015#issuecomment-6103533134). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T23:58:42Z. --- `LockedLdsUpdate` was refactored on main (`type` parameter for u32/u64), which conflicted with this change. Rebased onto current `main`: the two result phis now use `type` instead of `TypeU64`; the rest is unchanged. Checked: scoped build + ctest (433 tests, all `agc_driver_lds*` and `pixel_lds` pass on RADV); the Intel failure itself isn't reproducible here, relying on the Intel Arc and Windows runs in #2805. Merging on green CI.
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!3015
No description provided.