fix(shader): call load_bda_span outside read_bda_span's per-lane selection #22774

Merged
zarmstrong merged 2 commits from upstream-pr/22774 into main 2026-11-26 16:06:39 +00:00
zarmstrong commented 2026-11-18 08:27:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by zarmstrong on 2026-11-18T08:27:38Z.


What

read_bda_span chooses per lane between the span's in-place loads, a call to the DontInline load_bda_span, and the dword fallback, which calls read_bda_dword_bytes in a loop. On NVIDIA's Blackwell driver (RTX 5090, 621.01) the lanes that take the fallback then get other lanes' results, so agc_driver_bda_device fails on every run (#22773). The diagnosis is in the issue.

read_bda_span now calls load_bda_span once before the selection, passing the used-dword mask for lanes whose span is mapped and aligned and 0 for the others, so load_bda_span loads nothing for them. The selection keeps that result for the in-place lanes and runs the fallback for the rest. load_bda_span itself is unchanged: DontInline, the four loads, no call, as 8c04efcfbc requires for the drivers that hung with the loads in the selection (#3291, #4975). Probe, loads, lookups, faults, stops and the APS5_BDA_BYTE_READS path are unchanged for every lane.

BdaContracts.cpp checks that read_bda_span and read_bda_span_coherent call their load function outside every selection and loop. CI runs on lavapipe, which does not show the fault, so without the check a later change could restore the shape unnoticed. With main's SpirvBdaRead.cpp the check fails (run on the Intel GPU; it reads only the generated SPIR-V).

Tested

Windows 11 Pro 10.0.26200, i9-13900K, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON, every execution test built. main 72cf170a25 and this branch on it.

ctest --test-dir build -R "agc|shader|video_out" -V -j 8 with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, ANYPS5_GPU=RTX 5090, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation and VK_LOADER_DEBUG=layer (validation layer 1.4.363, Vulkan SDK 1.4.363.0), on the RTX 5090. The OBS, Overwolf and Twitch implicit layers are disabled with VK_LOADER_LAYERS_DISABLE on both sides (see #20011).

main this branch
tests 2076 2076
passed 2052 2054
failed agc_driver_bda_device, agc_driver_msaa_dcc_unwatch, agc_driver_stencil_plane_memory, agc_driver_store_over_untracked agc_driver_msaa_dcc_unwatch, agc_driver_stencil_plane_memory
skipped / not run 19 / 1 19 / 1
Insert instance layer "VK_LAYER_KHRONOS_validation" in all 1465 tests that create an instance same
was not found but was requested 0 0
VUID-, SYNC-HAZARD-, UNASSIGNED- 0 0
  • agc_driver_bda_device on the RTX 5090: main fails 10 of 10 (an anchored BDA read differs from the same read through the lookups at anchor 0x7fff12340101 + 0 + (0), 32 bits, 4 dwords); this branch passes 10 of 10, with the validation layer and no VUID- lines.
  • The same test on the Intel UHD Graphics 770 in the same machine (101.6129): passes 3 of 3 on this branch, as on main.
  • agc_shader_memory and agc_shader_memory_coherent_atomic_loads, which check that load_bda_span stays DontInline with its four loads and is called once from the span read function: pass.
  • agc_driver_store_over_untracked fails intermittently on both sides on this machine (4 of 10 runs without the layer on 9b60c84343), so its pass here is not from this change. agc_driver_stencil_plane_memory is #22427. agc_driver_msaa_dcc_unwatch fails on both sides. agc_driver_upload_cache_read_only_flush does not build on Windows (setenv, #19899).

Not tested: the NVIDIA drivers that hung in #3291 and #4975 (591.86, 590.48.01, 595.97, 596.36, 610.x). The loads stay in their own DontInline function, but its call now runs for every lane, so a run of agc_driver_bda_span_reads, agc_driver_scalar_wide_loads and agc_driver_flat_apertures_* on one of those drivers would confirm they still pass.

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: Fixes #22773
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 5090, driver 621.01, Windows 11 Pro 26200 (AGC, shader recompiler and VideoOut tests); Intel UHD Graphics 770, driver 101.6129, Windows 11 Pro 26200 (agc_driver_bda_device only)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5372520504 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22774). Originally posted by [zarmstrong](https://github.com/zarmstrong) on 2026-11-18T08:27:38Z. --- ### What `read_bda_span` chooses per lane between the span's in-place loads, a call to the `DontInline` `load_bda_span`, and the dword fallback, which calls `read_bda_dword_bytes` in a loop. On NVIDIA's Blackwell driver (RTX 5090, 621.01) the lanes that take the fallback then get other lanes' results, so `agc_driver_bda_device` fails on every run (#22773). The diagnosis is in the issue. `read_bda_span` now calls `load_bda_span` once before the selection, passing the used-dword mask for lanes whose span is mapped and aligned and 0 for the others, so `load_bda_span` loads nothing for them. The selection keeps that result for the in-place lanes and runs the fallback for the rest. `load_bda_span` itself is unchanged: `DontInline`, the four loads, no call, as 8c04efcfbc requires for the drivers that hung with the loads in the selection (#3291, #4975). Probe, loads, lookups, faults, stops and the `APS5_BDA_BYTE_READS` path are unchanged for every lane. `BdaContracts.cpp` checks that `read_bda_span` and `read_bda_span_coherent` call their load function outside every selection and loop. CI runs on lavapipe, which does not show the fault, so without the check a later change could restore the shape unnoticed. With `main`'s `SpirvBdaRead.cpp` the check fails (run on the Intel GPU; it reads only the generated SPIR-V). ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 Pro 10.0.26200, i9-13900K, WinLibs GCC 15.2.0 r7, Release, `BUILD_TESTING=ON`, every execution test built. `main` `72cf170a25` and this branch on it. `ctest --test-dir build -R "agc|shader|video_out" -V -j 8` with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `ANYPS5_GPU=RTX 5090`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` and `VK_LOADER_DEBUG=layer` (validation layer 1.4.363, Vulkan SDK 1.4.363.0), on the RTX 5090. The OBS, Overwolf and Twitch implicit layers are disabled with `VK_LOADER_LAYERS_DISABLE` on both sides (see #20011). | | `main` | this branch | |---|---|---| | tests | 2076 | 2076 | | passed | 2052 | 2054 | | failed | `agc_driver_bda_device`, `agc_driver_msaa_dcc_unwatch`, `agc_driver_stencil_plane_memory`, `agc_driver_store_over_untracked` | `agc_driver_msaa_dcc_unwatch`, `agc_driver_stencil_plane_memory` | | skipped / not run | 19 / 1 | 19 / 1 | | `Insert instance layer "VK_LAYER_KHRONOS_validation"` | in all 1465 tests that create an instance | same | | `was not found but was requested` | 0 | 0 | | `VUID-`, `SYNC-HAZARD-`, `UNASSIGNED-` | 0 | 0 | - `agc_driver_bda_device` on the RTX 5090: `main` fails 10 of 10 (`an anchored BDA read differs from the same read through the lookups at anchor 0x7fff12340101 + 0 + (0), 32 bits, 4 dwords`); this branch passes 10 of 10, with the validation layer and no `VUID-` lines. - The same test on the Intel UHD Graphics 770 in the same machine (101.6129): passes 3 of 3 on this branch, as on `main`. - `agc_shader_memory` and `agc_shader_memory_coherent_atomic_loads`, which check that `load_bda_span` stays `DontInline` with its four loads and is called once from the span read function: pass. - `agc_driver_store_over_untracked` fails intermittently on both sides on this machine (4 of 10 runs without the layer on `9b60c84343`), so its pass here is not from this change. `agc_driver_stencil_plane_memory` is #22427. `agc_driver_msaa_dcc_unwatch` fails on both sides. `agc_driver_upload_cache_read_only_flush` does not build on Windows (`setenv`, #19899). Not tested: the NVIDIA drivers that hung in #3291 and #4975 (591.86, 590.48.01, 595.97, 596.36, 610.x). The loads stay in their own `DontInline` function, but its call now runs for every lane, so a run of `agc_driver_bda_span_reads`, `agc_driver_scalar_wide_loads` and `agc_driver_flat_apertures_*` on one of those drivers would confirm they still pass. ### 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) 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 <!-- #PR, or none --> - [x] Fixes: Fixes #22773 <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: NVIDIA GeForce RTX 5090, driver 621.01, Windows 11 Pro 26200 (AGC, shader recompiler and VideoOut tests); Intel UHD Graphics 770, driver 101.6129, Windows 11 Pro 26200 (`agc_driver_bda_device` only) <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no --> 🤖 Generated with [Claude Code](https://claude.com/claude-code)
milescoviello commented 2026-11-18 14:26:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-11-18T14:26:16Z.

Review: COMMENTED


Reviewed head 1f9ddd3783 by reading, and ran agc_driver_bda_device on an older NVIDIA generation.

Run: Windows 11 VM, GeForce GT 1030 (Pascal), NVIDIA 582.78, WinLibs GCC 16.2.0 POSIX UCRT, Ninja, Release, ANYPS5_REQUIRE_VULKAN=1.

  • main 8ba52d0287 and this PR merged onto it both pass agc_driver_bda_device 3 of 3 runs, so the uniform-call shape doesn't regress on Pascal.
  • Pascal doesn't show the Blackwell fault, so this only covers the no-regression side.

Reading SpirvBdaRead.cpp:

  • Lanes that fall back load nothing. The single load_bda_span call passes Select(wide, used, 0). With a used mask of 0, each of the four loads is inside its own EmitValueOrZeroIfCondition, so those lanes never form or dereference a pointer.
  • Inputs are unchanged. physical and firstBytes reaching the call for those lanes is harmless, since they're only used under the per-dword condition.
  • The result is the same as before. The wide lanes take loaded and the others run the unchanged dword fallback. The coherent variant goes through the same DefineBdaSpanReadFunction, so it gets the same shape.
  • The new contract in BdaContracts.cpp pins that shape (the call outside every selection and loop) on lavapipe CI, where the fault can't be observed.

No changes needed from my side.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5958527997 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22774#pullrequestreview-5958527997). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-11-18T14:26:16Z. **Review:** COMMENTED --- Reviewed head `1f9ddd3783` by reading, and ran `agc_driver_bda_device` on an older NVIDIA generation. **Run:** Windows 11 VM, GeForce GT 1030 (Pascal), NVIDIA 582.78, WinLibs GCC 16.2.0 POSIX UCRT, Ninja, Release, `ANYPS5_REQUIRE_VULKAN=1`. - `main` `8ba52d0287` and this PR merged onto it both pass `agc_driver_bda_device` 3 of 3 runs, so the uniform-call shape doesn't regress on Pascal. - Pascal doesn't show the Blackwell fault, so this only covers the no-regression side. **Reading `SpirvBdaRead.cpp`:** - **Lanes that fall back load nothing.** The single `load_bda_span` call passes `Select(wide, used, 0)`. With a used mask of 0, each of the four loads is inside its own `EmitValueOrZeroIfCondition`, so those lanes never form or dereference a pointer. - **Inputs are unchanged.** `physical` and `firstBytes` reaching the call for those lanes is harmless, since they're only used under the per-dword condition. - **The result is the same as before.** The `wide` lanes take `loaded` and the others run the unchanged dword fallback. The coherent variant goes through the same `DefineBdaSpanReadFunction`, so it gets the same shape. - **The new contract in `BdaContracts.cpp` pins that shape** (the call outside every selection and loop) on lavapipe CI, where the fault can't be observed. No changes needed from my side. AI-assisted: yes
MarcZX10 commented 2026-11-20 22:16:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T22:16:24Z.

Review: COMMENTED


Reviewed — no blocking findings

The source change moves the span loader call outside the lane selection and guards its loads with the selected mask; I found no verified blocking defect.

What I ran

Reviewed head 1f9ddd378332b86aaace2a12056025d515b6a4d1 using the prepared review bundle and repo_read.py. I did not run build or test commands; no merged-preview check was performed.

Results

Check Result Note
Changed-line review passed Both changed files reviewed
Build and tests not run Author-reported results only
Negative control not run Not run in this review

Findings

Blocking

None.

Non-blocking

  • The new SPIR-V contract check covers coherent and non-coherent span reads without the stop-invocation variant. Consider adding that variant if it can be generated by MakeBdaDwordReadTestShader.

Not verified

I did not independently verify the described GPU results, the unsupported NVIDIA driver behavior, or the author's CI and local test results. No changed files were excluded: core/libs/prx/libSceAgcDriver/tests/BdaContracts.cpp and core/shader/recompiler/SpirvBackend/src/SpirvBdaRead.cpp were read; files.json was not present in the prepared bundle.

To get this to a good state

Nothing is required. Optional: extend the SPIR-V contract coverage to the stop-invocation variant.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6000115547 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22774#pullrequestreview-6000115547). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-20T22:16:24Z. **Review:** COMMENTED --- # Reviewed — no blocking findings The source change moves the span loader call outside the lane selection and guards its loads with the selected mask; I found no verified blocking defect. ## What I ran Reviewed head `1f9ddd378332b86aaace2a12056025d515b6a4d1` using the prepared review bundle and `repo_read.py`. I did not run build or test commands; no merged-preview check was performed. ## Results | Check | Result | Note | |---|---|---| | Changed-line review | passed | Both changed files reviewed | | Build and tests | not run | Author-reported results only | | Negative control | not run | Not run in this review | ## Findings ### Blocking None. ### Non-blocking - The new SPIR-V contract check covers coherent and non-coherent span reads without the stop-invocation variant. Consider adding that variant if it can be generated by `MakeBdaDwordReadTestShader`. ## Not verified I did not independently verify the described GPU results, the unsupported NVIDIA driver behavior, or the author's CI and local test results. No changed files were excluded: `core/libs/prx/libSceAgcDriver/tests/BdaContracts.cpp` and `core/shader/recompiler/SpirvBackend/src/SpirvBdaRead.cpp` were read; `files.json` was not present in the prepared bundle. ## To get this to a good state Nothing is required. Optional: extend the SPIR-V contract coverage to the stop-invocation variant.
MarcZX10 commented 2026-11-25 17:35:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T17:35:34Z.

Review: APPROVED


Reviewed — looks good

Nothing in the inspected changes blocks merging; approval is justified by the code and author-reported GPU results, although those results were not run by me.

What I ran

Head: 27456456f4fe00394a2db86ecda85e3d70f52d10. No commands or tests were run. I read the prepared diff and both changed files at the pinned head through repo_read.py.

Results

Check Result Note
Diff and changed files passed Both changed files read
Tests in this review not run GPU runs reported by author
Prepared-file inventory not run files.json was unavailable

Findings

Blocking

None.

Non-blocking

None.

Not verified

I did not independently run tests or validate the reported NVIDIA/Intel GPU results. I did not inspect repository files outside the two changed files. The review folder’s files.json inventory was unavailable; manifest.json lists both changed files as included, and I read both.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6062167684 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22774#pullrequestreview-6062167684). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-25T17:35:34Z. **Review:** APPROVED --- # Reviewed — looks good Nothing in the inspected changes blocks merging; approval is justified by the code and author-reported GPU results, although those results were not run by me. ## What I ran Head: `27456456f4fe00394a2db86ecda85e3d70f52d10`. No commands or tests were run. I read the prepared diff and both changed files at the pinned head through `repo_read.py`. ## Results | Check | Result | Note | |---|---|---| | Diff and changed files | passed | Both changed files read | | Tests in this review | not run | GPU runs reported by author | | Prepared-file inventory | not run | `files.json` was unavailable | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified I did not independently run tests or validate the reported NVIDIA/Intel GPU results. I did not inspect repository files outside the two changed files. The review folder’s `files.json` inventory was unavailable; `manifest.json` lists both changed files as included, and I read both. ## 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!22774
No description provided.